apply_filters() WP 1.0
Call the functions added to a filter hook.
The callback functions attached to the filter hook are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter.
The function also allows for multiple additional arguments to be passed to hooks.
Example usage:
// 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 );
1 time = 0.000001s = speed of light | 50000 times = 0.02s = speed of light | PHP 7.0.32, WP 5.0.3
No Hooks.
Return
Mixed. The filtered value after all hooked functions are applied to it.
Usage
apply_filters( $tag, $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.
Notes
- Global. WP_Hook[]. $wp_filter Stores all of the filters and actions.
- Global. String[]. $wp_current_filter Stores the list of current filters with the current one last.
Changelog
Since 0.71 | Introduced. |