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.

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 . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/backpress/functions.plugin-api.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 (1)

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

/bp-forums/bbpress/bb-includes/backpress/functions.plugin-api.php  
  1. function apply_filters($tag, $value) { 
  2. global $wp_filter, $merged_filters, $wp_current_filter; 
  3.  
  4. $args = array(); 
  5. $wp_current_filter[] = $tag; 
  6.  
  7. // Do 'all' actions first 
  8. if ( isset($wp_filter['all']) ) { 
  9. $args = func_get_args(); 
  10.  
  11. if ( !isset($wp_filter[$tag]) ) { 
  12. array_pop($wp_current_filter); 
  13. return $value; 
  14.  
  15. // Sort 
  16. if ( !isset( $merged_filters[ $tag ] ) ) { 
  17. ksort($wp_filter[$tag]); 
  18. $merged_filters[ $tag ] = true; 
  19.  
  20. reset( $wp_filter[ $tag ] ); 
  21.  
  22. if ( empty($args) ) 
  23. $args = func_get_args(); 
  24.  
  25. do { 
  26. foreach( (array) current($wp_filter[$tag]) as $the_ ) 
  27. if ( !is_null($the_['function']) ) { 
  28. $args[1] = $value; 
  29. $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args'])); 
  30.  
  31. } while ( next($wp_filter[$tag]) !== false ); 
  32.  
  33. array_pop( $wp_current_filter ); 
  34.  
  35. return $value;