doing_action()
Retrieve the name of an action currently being processed.
The function current_action() only returns the most recent action being executed. did_action() returns the number of times an action has been fired during the current request.
This function allows detection for any action currently being executed (regardless of whether it's the most recent action to fire, in the case of hooks called from hook callbacks) to be verified.
Uses: doing_filter()
1 time — 0.000001 sec (speed of light) | 50000 times — 0.02 sec (speed of light) | PHP 7.2.5, WP 4.9.8
No Hooks.
Return
true|false
. Whether the action is currently in the stack.
Usage
doing_action( $hook_name );
- $hook_name(string|null)
- Action hook to check.
Default: null, which checks if any action is currently being run
Examples
#1 Demo
add_filter( 'wp_head', function(){ var_dump( doing_filter( 'wp_head' ) ); die; } ); /* Result: When the wp_head event is triggered, WP will be interrupted and the bool(true) will be displayed. */
Notes
- See: current_action()
- See: did_action()
Changelog
Since 3.9.0 | Introduced. |
doing_action() doing action code WP 6.4.1
function doing_action( $hook_name = null ) { return doing_filter( $hook_name ); }