apply_filters
Call the functions added to a filter hook.
Description
The callback functions attached to filter hook $tag
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 allows for additional arguments to be added and passed to hooks.
return $string
;
Parameters (2)
- 0. $tag (string)
- The name of the filter hook.
- 1. $value (mixed)
- The value on which the filters hooked to
$tag
are applied on.
Usage
if ( !function_exists( 'apply_filters' ) ) { require_once ABSPATH . WPINC . '/plugin.php'; } // The name of the filter hook. $tag = ''; // The value on which the filters hooked to `$tag` are applied on. $value = null; // NOTICE! Understand what this does before running. $result = apply_filters($tag, $value);
Defined (2)
The function is defined in the following location(s).
- /wp-includes/plugin.php
- function apply_filters( $tag, $value ) {
- global $wp_filter, $wp_current_filter;
- $args = array();
- // Do 'all' actions first.
- if ( isset($wp_filter['all']) ) {
- $wp_current_filter[] = $tag;
- $args = func_get_args();
- _wp_call_all_hook($args);
- }
- if ( !isset($wp_filter[$tag]) ) {
- if ( isset($wp_filter['all']) )
- array_pop($wp_current_filter);
- return $value;
- }
- if ( !isset($wp_filter['all']) )
- $wp_current_filter[] = $tag;
- if ( empty($args) )
- $args = func_get_args();
- // don't pass the tag name to WP_Hook
- array_shift( $args );
- $filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
- array_pop( $wp_current_filter );
- return $filtered;
- }
- /wp-admin/includes/noop.php
- function apply_filters() {}