apply_filters()是wp函数,再次召唤回调在这个钩子上的函数。用法是:
apply_filters( string $tag, mixed $value )
参数解释:
$tag
(string) (Required) The name of the filter hook.$value
(mixed) (Required) The value to filter.$args
(mixed) (Required) Additional parameters to pass to the callback functions.
举例使用:
我们创建一个钩子,example_filter, 然后创建一个回调函数: example_callback();
// The filter callback function.
function example_callback( $string, $arg1, $arg2 ) {
// (maybe) modify $string.
return $string;
}
add_filter( 'example_filter', 'example_callback', 10, 3 );
现在我们apply_filter(‘example_filter’,’filter_me’,$args1,$args2), 就会唤出回调函数example_callback,‘filter_me‘ 是要添加的内容,$args1,$args2是传递给回调函数的参数。