Uses
Uses | Description |
---|---|
wp-includes/plugin.php: _wp_call_all_hook() | Call the ‘all’ hook, which will process the functions hooked into it. |
Calls the callback functions that have been added to an action hook, specifying arguments in an array.
$tag
are supplied using an array.(string) (Required) The name of the action to be executed.
(array) (Required) The arguments supplied to the functions hooked to $tag
.
<pre>add_action('my_action', 'my_callback'); function my_callback( $args ) { //access values with $args[0], $args[1] etc. }</pre>
Because the array was passed by reference, any changes to the array elements are applied to the original array outside of the function’s scope.
<pre>add_action('my_action', 'my_callback', 10, 4 ); function my_callback( $arg1, $arg2, $arg3, $arg4 ) { //access values with $args1, $args2 etc. }</pre>
This method copies the array elements into the parameter variables. Any changes to the parameter variables do not affect the original array.
do_action_ref_array( 'my_action', array( &$args ) ); add_action('my_action', 'my_callback'); function my_callback( &$args ) { //access values with $args[0], $args[1] etc. }
Because the original array was passed by reference, any changes to the array elements are applied to the original array outside of the function’s scope.
If the array contains an object reference, the technique is as follows:
<do_action_ref_array( 'my_action', array( &$my_object ) ); add_action('my_action', 'my_callback'); function my_callback( $my_object ) { // $my_object->some_method()... etc. }
The object’s properties can be changed. See the action ‘phpmailer_init
‘ with the callback fix_phpmailer_messageid()
in WordPress for an example.
File: wp-includes/plugin.php
function do_action_ref_array( $tag, $args ) { global $wp_filter, $wp_actions, $wp_current_filter; if ( ! isset( $wp_actions[ $tag ] ) ) { $wp_actions[ $tag ] = 1; } else { ++$wp_actions[ $tag ]; } // Do 'all' actions first. if ( isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; $all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection _wp_call_all_hook( $all_args ); } if ( ! isset( $wp_filter[ $tag ] ) ) { if ( isset( $wp_filter['all'] ) ) { array_pop( $wp_current_filter ); } return; } if ( ! isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; } $wp_filter[ $tag ]->do_action( $args ); array_pop( $wp_current_filter ); }
Version | Description |
---|---|
2.1.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/do_action_ref_array