WordPress函数文档apply_filters_ref_array()

创建一个过滤器钩子,并向所有注册到它的过滤器传递一个数组 描述 Execute functions hooke…

创建一个过滤器钩子,并向所有注册到它的过滤器传递一个数组

描述

Execute functions hooked on a specific filter hook, specifying arguments in an array.

This function is identical to apply_filters, but the arguments passed to
the functions hooked to $tag are supplied using an array.

用法

 <?php apply_filters_ref_array$tag$args ); ?> 

参数

$tag

(string) (必填) The name of the action to be executed.

默认值: None

$args

(array) (必填) The arguments supplied to the functions hooked to $tag

默认值: None

注意

  • This function can be useful when your arguments are already in an array, and/or when there are many arguments to pass. Just make sure that your arguments are in the proper order!
  • Before PHP 5.4, your callback is passed a reference pointer to the array. Your callback can use this pointer to access all the array elements. Adding a 过滤器 and declaring a call back that hooks the above example 过滤器 could look like this:

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.

  • Regardless of PHP version, you can specify the number of array elements when adding the 过滤器, and receive each element in a separate parameter in the callback function declaration like so:

This method copies the array elements into the parameter variables. Any changes to the parameter variables do not affect the original array.

  • As of PHP 5.4, the array is no longer passed by reference despite the function’s name. You cannot even use the reference sign ‘&’ because call time pass by reference now throws an error. What you can do is pass the reference pointer as an array element. Doing so does require all callbacks added to the 过滤器 to expect a reference pointer. This is not something you will see in WordPress 动作s. This technique is provided for informational purposes only.

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.

历史

添加于 版本: 3.0.0

源文件

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

相关

Filters:
has_filter(),
add_filter(),
apply_filters(),
current_filter(),
merge_filters(),
remove_filter(),
remove_all_filters()

  • 原文:http://codex.wordpress.org/Function_Reference/apply_filters_ref_array
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT