Make WordPress Core

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

File wp-current-filter-revised-r6278.patch, 1.8 KB (added by tellyworth, 18 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
    112112        if ( !isset( $merged_filters[ $tag ] ) )
    113113                merge_filters($tag);
    114114
    115115        if ( !isset($wp_filter[$tag]) )
    116116                return $value;
     117               
     118        @$wp_current_filter[] = $tag;
    117119
    118120        reset( $wp_filter[ $tag ] );
    119121
     
    127129                        }
    128130
    129131        } while ( next($wp_filter[$tag]) !== false );
     132       
     133        array_pop( $wp_current_filter );
    130134
    131135        return $value;
    132136}
     
    196200}
    197201
    198202/**
     203 * Return the name of the current filter or action.
     204 */
     205function current_filter() {
     206        global $wp_current_filter;
     207        return end( $wp_current_filter );
     208}
     209
     210
     211/**
    199212 * Hooks a function on to a specific action.
    200213 *
    201214 * Actions are the hooks that the WordPress core launches at specific points
     
    241254 * @return null Will return null if $tag does not exist in $wp_filter array
    242255 */
    243256function do_action($tag, $arg = '') {
    244         global $wp_filter, $wp_actions;
     257        global $wp_filter, $wp_actions, $wp_current_filter;
    245258
    246259        if ( is_array($wp_actions) )
    247260                $wp_actions[] = $tag;
     
    260273
    261274        if ( !isset($wp_filter[$tag]) )
    262275                return;
     276               
     277        @$wp_current_filter[] = $tag;
    263278
    264279        do{
    265280                foreach( (array) current($wp_filter[$tag]) as $the_ )
     
    267282                                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    268283
    269284        } while ( next($wp_filter[$tag]) !== false );
     285       
     286        array_pop( $wp_current_filter );
    270287
    271288}
    272289