do_action_ref_array()

执行一个动作钩子,并向所有注册到它的动作传递一个数组

描述

执行挂接在特定操作挂钩上的函数,指定数组中的参数。

此函数与 do_action 相同,但传递给挂钩到$tag的函数的参数是使用数组提供的。

用法

 <?php do_action_ref_array( $tag, $args ); ?> 

参数

$tag

(string) (必填) 要执行的操作的名称。

默认值: None

$args

(array) (必填) 提供给与$tag挂钩的函数的参数

默认值: None

注意

当您的参数已经在数组中和/或有许多参数要传递时,此函数可能很有用。只要确保你的论点顺序正确!

在 PHP 5.4 之前,您的回调会传递一个指向数组的引用指针。回调可以使用此指针访问所有数组元素。添加一个动作并声明一个与上述示例动作挂钩的回调,可能如下所示:

/* ———————————-
* wordpress函数 XingkongWeb.com收集
* ———————————- */

add_action(‘my_action’, ‘my_callback’);
add_action(“my_action”、“my_callback”);

function my_callback( $args ) {
函数 my_callback( $args ) {

    //access values with $args[0], $args[1] etc.
使用 $args[0]、$args[1] 等访问值。

}

由于数组是通过引用传递的,因此对数组元素的任何更改都将应用于函数范围之外的原始数组。

无论 PHP 版本如何,都可以在添加动作时指定数组元素的数量,并在回调函数声明中以单独的参数接收每个元素,如下所示:

/* ———————————-
* wordpress函数 星空站长网收集
* ———————————- */

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.

}

由于原始数组是通过引用传递的,因此对数组元素的任何更改都将应用于函数范围之外的原始数组。

历史

添加于 版本: 2.1.0

源文件

do_action_ref_array() 函数的代码位于 wp-includes/plugin.php.

/* ———————————-
* wordpress函数 Xingkongweb.com
* ———————————- */
/**
* Execute functions hooked on a specific action hook, specifying arguments in an array.
*
* @since 2.1.0
*
* @see do_action() This function is identical, but the arguments passed to the

*                  functions hooked to $tag< are=”” supplied=”” using=”” an=”” array.=”” *=”” @global=”” array=”” $wp_filter=”” stores=”” all=”” of=”” the=”” filters=”” *=”” @global=”” array=”” $wp_actions=”” increments=”” the=”” amount=”” of=”” times=”” action=”” was=”” triggered.=”” *=”” @global=”” array=”” $merged_filters=”” merges=”” the=”” filter=”” hooks=”” using=”” this=”” function.=”” *=”” @global=”” array=”” $wp_current_filter=”” stores=”” the=”” list=”” of=”” current=”” filters=”” with=”” the=”” current=”” one=”” last=”” *=”” *=”” @param=”” string=”” $tag=”” the=”” name=”” of=”” the=”” action=”” to=”” be=”” executed.=”” *=”” @param=”” array=”” $args=”” the=”” arguments=”” supplied=”” to=”” the=”” functions=”” hooked=”” to=”” `$tag`.=”” */=“” function=“” do_action_ref_array($tag,=“” $args)=“” {=“” global=“” $wp_filter,=“” $wp_actions,=“” $merged_filters,=“” $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();” _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;” sort=“” if=“” (=“” !isset(=“” $merged_filters[=“” $tag=“” ]=“” )=“” )=“” {=“” ksort($wp_filter[$tag]);=“” $merged_filters[=“” $tag=“” ]=“true;” }=“” reset(=“” $wp_filter[=“” $tag=“” ]=“” );=“” do=“” {=“” foreach(=“” (array)=“” current($wp_filter[$tag])=“” as=“” $the_=“” )=“” if=“” (=“” !is_null($the_[‘function’])=“” )=“” call_user_func_array($the_[‘function’],=“” array_slice($args,=“” 0,=“” (int)=“” $the_[‘accepted_args’]));=“” }=“” while=“” (=“” next($wp_filter[$tag])=“” !=“=” false=“” );=“” array_pop($wp_current_filter);=“” }=“”>

相关

Actions:
has_action(),
add_action(),
do_action(),
do_action_ref_array(),
did_action(),
remove_action(),
remove_all_actions()

原文:http://codex.wordpress.org/Function_Reference/do_action_ref_array

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索