apply_filters_ref_array

Execute functions hooked on a specific filter hook, specifying arguments in an array.

Description

apply_filters_ref_array( (string) $tag, (array) $args ); 

Parameters (2)

0. $tag (string)
The name of the filter hook.
1. $args (array)
The arguments supplied to the functions hooked to $tag.

Usage

  1. if ( !function_exists( 'apply_filters_ref_array' ) ) { 
  2. require_once ABSPATH . WPINC . '/plugin.php'; 
  3.  
  4. // The name of the filter hook. 
  5. $tag = ''; 
  6.  
  7. // The arguments supplied to the functions hooked to $tag. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = apply_filters_ref_array($tag, $args); 
  12.  

Defined (1)

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

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