Languages: English • 日本語 (Add your language)
Execute functions hooked on a specific action hook, specifying arguments in an array.
This function is identical to do_action, but the arguments passed to the functions hooked to $tag are supplied using an array.
<?php do_action_ref_array( $tag, $args ); ?>
Call an action and pass an array of arguments:
$args = array( 'arg_1', true, 'foo', 'arg_4' ); do_action_ref_array( 'my_action', $args );
This is the same as:
do_action( 'my_action', 'arg_1', true, 'foo', 'arg_4' );
add_action('my_action', 'my_callback'); function my_callback( $args ) { //access values with $args[0], $args[1] etc. }
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.
add_action('my_action', 'my_callback', 10, 4 ); function my_callback( $arg1, $arg2, $arg3, $arg4 ) { //access values with $args1, $args2 etc. }
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.
Since: 2.1.0
do_action_ref_array() is located in wp-includes/plugin.php
.