Make WordPress Core

Changeset 13756


Ignore:
Timestamp:
03/18/2010 09:24:07 PM (15 years ago)
Author:
westi
Message:

Introduce apply_filters_ref_array(). See #9886 props scribu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/plugin.php

    r13674 r13756  
    166166                $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
    167167            }
     168
     169    } while ( next($wp_filter[$tag]) !== false );
     170
     171    array_pop( $wp_current_filter );
     172
     173    return $value;
     174}
     175
     176/**
     177 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
     178 *
     179 * @see apply_filters() This function is identical, but the arguments passed to the
     180 * functions hooked to <tt>$tag</tt> are supplied using an array.
     181 *
     182 * @package WordPress
     183 * @subpackage Plugin
     184 * @since 3.0
     185 * @global array $wp_filter Stores all of the filters
     186 * @global array $merged_filters Merges the filter hooks using this function.
     187 * @global array $wp_current_filter stores the list of current filters with the current one last
     188 *
     189 * @param string $tag The name of the filter hook.
     190 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
     191 * @return mixed The filtered value after all hooked functions are applied to it.
     192 */
     193function apply_filters_ref_array($tag, $args) {
     194    global $wp_filter, $merged_filters, $wp_current_filter;
     195
     196    $wp_current_filter[] = $tag;
     197
     198    $value = $args[0];
     199
     200    // Do 'all' actions first
     201    if ( isset($wp_filter['all']) ) {
     202        $all_args = func_get_args();
     203        _wp_call_all_hook($all_args);
     204    }
     205
     206    if ( !isset($wp_filter[$tag]) ) {
     207        array_pop($wp_current_filter);
     208        return $value;
     209    }
     210
     211    // Sort
     212    if ( !isset( $merged_filters[ $tag ] ) ) {
     213        ksort($wp_filter[$tag]);
     214        $merged_filters[ $tag ] = true;
     215    }
     216
     217    reset( $wp_filter[ $tag ] );
     218
     219    do {
     220        foreach( (array) current($wp_filter[$tag]) as $the_ )
     221            if ( !is_null($the_['function']) )
     222                $value = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    168223
    169224    } while ( next($wp_filter[$tag]) !== false );
Note: See TracChangeset for help on using the changeset viewer.