apply_filters_ref_array()函数是Wordpress函数

apply_filters_ref_array()函数是Wordpress函数,调用已添加到筛选器挂钩的回调函数,并在数组中指定参数。apply_filters_ref_array( string $

apply_filters_ref_array()函数是Wordpress函数,调用已添加到筛选器挂钩的回调函数,并在数组中指定参数。

apply_filters_ref_array( string $tag, array $args )

说明(Description)

另见函数 apply_filters()


参数(Parameters)

参数

类型

必填

说明

$tag

(string)

必需

筛选器挂钩的名称。

$args

(array)

必需

提供给钩住$tag的函数的参数。


返回(Return)

(mixed)应用所有挂接函数后的过滤值。


源码(Source)


/**
 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
 *
 * @see 3.0.0
 *
 * @see apply_filters() 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 $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 filter hook.
 * @param array  $args The arguments supplied to the functions hooked to $tag.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters_ref_array($tag, $args) {
	global $wp_filter, $merged_filters, $wp_current_filter;
	// 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 $args[0];
	}
	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']) )
				$args[0] = 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 );
	return $args[0];
}


更新版本

源码位置

使用

被使用

3.0.0

wp-includes/plugin.php:228

12

1 function


笔记(Notes)

例子
注意
从PHP 5.4开始,数组不再通过引用传递

文章说明:

本文原创发布于探乎站长论坛,未经许可,禁止转载。

题图来自Unsplash,基于CC0协议

该文观点仅代表作者本人,探乎站长论坛平台仅提供信息存储空间服务。

评论列表 评论
发布评论

评论: apply_filters_ref_array()函数是Wordpress函数

粉丝

0

关注

0

收藏

0

已有0次打赏