apply_filters

Call the functions added to a filter hook.

Description

apply_filters( (string) $tag, (mixed) $value ); 

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

  1. if ( !function_exists( 'apply_filters' ) ) { 
  2. require_once ABSPATH . WPINC . '/plugin.php'; 
  3.  
  4. // The name of the filter hook. 
  5. $tag = ''; 
  6.  
  7. // The value on which the filters hooked to `$tag` are applied on. 
  8. $value = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = apply_filters($tag, $value); 
  12.  

Defined (2)

The function is defined in the following location(s).

/wp-includes/plugin.php  
  1. function apply_filters( $tag, $value ) { 
  2. global $wp_filter, $wp_current_filter; 
  3.  
  4. $args = array(); 
  5.  
  6. // Do 'all' actions first. 
  7. if ( isset($wp_filter['all']) ) { 
  8. $wp_current_filter[] = $tag; 
  9. $args = func_get_args(); 
  10.  
  11. if ( !isset($wp_filter[$tag]) ) { 
  12. if ( isset($wp_filter['all']) ) 
  13. array_pop($wp_current_filter); 
  14. return $value; 
  15.  
  16. if ( !isset($wp_filter['all']) ) 
  17. $wp_current_filter[] = $tag; 
  18.  
  19. if ( empty($args) ) 
  20. $args = func_get_args(); 
  21.  
  22. // don't pass the tag name to WP_Hook 
  23. array_shift( $args ); 
  24.  
  25. $filtered = $wp_filter[ $tag ]->apply_filters( $value, $args ); 
  26.  
  27. array_pop( $wp_current_filter ); 
  28.  
  29. return $filtered; 
/wp-admin/includes/noop.php  
  1. function apply_filters() {}