Ticket #5232: wp-current-filter-revised-r6317.patch

File wp-current-filter-revised-r6317.patch, 2.3 KB (added by tellyworth, 5 years ago)
  • wordpress/wp-includes/plugin.php

     
    107107 * @return string The text in <tt>$string</tt> after all hooked functions are applied to it. 
    108108 */ 
    109109function apply_filters($tag, $value) { 
    110         global $wp_filter, $merged_filters; 
     110        global $wp_filter, $merged_filters, $wp_current_filter; 
    111111 
     112        @$wp_current_filter[] = $tag; 
     113 
    112114        // Do 'all' actions first 
    113115        if ( isset($wp_filter['all']) ) { 
    114116                reset( $wp_filter['all'] ); 
     
    120122                } while ( next($wp_filter['all']) !== false ); 
    121123        } 
    122124 
    123         if ( !isset($wp_filter[$tag]) ) 
     125        if ( !isset($wp_filter[$tag]) ) { 
     126                array_pop($wp_current_filter); 
    124127                return $value; 
     128        } 
    125129 
    126130        // Sort 
    127131        if ( !isset( $merged_filters[ $tag ] ) ) { 
     
    142146                        } 
    143147 
    144148        } while ( next($wp_filter[$tag]) !== false ); 
     149         
     150        array_pop( $wp_current_filter ); 
    145151 
    146152        return $value; 
    147153} 
     
    182188 
    183189 
    184190/** 
     191 * Return the name of the current filter or action. 
     192 */ 
     193function current_filter() { 
     194        global $wp_current_filter; 
     195        return end( $wp_current_filter ); 
     196} 
     197 
     198 
     199/** 
    185200 * Hooks a function on to a specific action. 
    186201 * 
    187202 * Actions are the hooks that the WordPress core launches at specific points 
     
    233248 * @return null Will return null if $tag does not exist in $wp_filter array 
    234249 */ 
    235250function do_action($tag, $arg = '') { 
    236         global $wp_action, $wp_actions; 
     251        global $wp_action, $wp_actions, $wp_current_filter; 
    237252 
    238253        if ( is_array($wp_actions) ) 
    239254                $wp_actions[] = $tag; 
     
    248263        for ( $a = 2; $a < func_num_args(); $a++ ) 
    249264                $args[] = func_get_arg($a); 
    250265 
     266        @$wp_current_filter[] = $tag; 
     267 
    251268        // Do 'all' actions first 
    252269        if ( isset($wp_action['all']) ) { 
    253270                do { 
     
    258275                } while ( next($wp_action['all']) !== false ); 
    259276        } 
    260277 
    261         if ( !isset($wp_action[$tag]) ) 
     278        if ( !isset($wp_action[$tag]) ) { 
     279                array_pop($wp_current_filter); 
    262280                return; 
    263  
     281        } 
     282                 
    264283        // Sort 
    265284        if ( !isset( $merged_actions[ $tag ] ) ) { 
    266285                reset($wp_action[$tag]); 
     
    277296 
    278297        } while ( next($wp_action[$tag]) !== false ); 
    279298 
     299                array_pop($wp_current_filter); 
    280300} 
    281301 
    282302/** 
     
    524544                return $function[0].$function[1]; 
    525545} 
    526546 
    527 ?> 
    528  No newline at end of file 
     547?>