函数原型
apply_filters( string $hook_name, mixed $value, mixed $args ): mixed
函数描述
Calls the callback functions that have been added to a filter hook.
是否弃用
未弃用
函数参数
-
$hook_name
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.
函数返回值
mixed The filtered value after all hooked functions are applied to it.
函数位置
File: wp-includes/plugin.php.
函数源码
// The filter callback function.
function example_callback( $string, $arg1, $arg2 ) {
// (maybe) modify $string.
return $string;
}
add_filter( 'example_filter', 'example_callback', 10, 3 );
/*
* Apply the filters by calling the 'example_callback()' function
* that's hooked onto `example_filter` above.
*
* - 'example_filter' is the filter hook.
* - 'filter me' is the value being filtered.
* - $arg1 and $arg2 are the additional arguments passed to the callback.
$value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );源码链接
变更日志
| Version | Description |
|---|---|
| 6.0.0 | Formalized the existing and already documented ...$args parameter by adding it to the function signature. |
| 0.71 | Introduced. |

