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

目录

描述

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.

apply_filters_ref_array() 描述

用法

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

apply_filters_ref_array() 用法

参数

$tag

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

默认值: None

$args

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

默认值: None

apply_filters_ref_array() 参数

注意

  • 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.

apply_filters_ref_array() 注意

历史

添加于 版本: 3.0.0

apply_filters_ref_array() 历史

源文件

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

apply_filters_ref_array() 源文件

相关