Make WordPress Core

Changeset 4955


Ignore:
Timestamp:
02/28/2007 01:09:20 AM (18 years ago)
Author:
ryan
Message:

add and apply filter optimizations from FraT. fixes #3875

File:
1 edited

Legend:

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

    r4630 r4955  
    88    global $wp_filter;
    99
    10     // check that we don't already have the same filter at the same priority
    11     if ( isset($wp_filter[$tag]["$priority"]) ) {
    12         foreach ( $wp_filter[$tag]["$priority"] as $filter ) {
    13             // uncomment if we want to match function AND accepted_args
    14             // if ( $filter == array($function, $accepted_args) ) {
    15             if ( $filter['function'] == $function_to_add )
    16                 return true;
    17         }
    18     }
    19 
    20     // So the format is wp_filter['tag']['array of priorities']['array of ['array (functions, accepted_args)]']
    21     $wp_filter[$tag]["$priority"][] = array('function'=>$function_to_add, 'accepted_args'=>$accepted_args);
     10    // So the format is wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]']
     11    $wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
    2212    return true;
    2313}
     
    2616    global $wp_filter;
    2717
    28     $args = array();
    29     for ( $a = 2; $a < func_num_args(); $a++ )
    30         $args[] = func_get_arg($a);
    31 
    3218    merge_filters($tag);
    3319
     
    3521        return $string;
    3622
    37     foreach ( (array) $wp_filter[$tag] as $priority => $functions ) {
    38         if ( !is_null($functions) ) {
    39             foreach ( (array) $functions as $function ) {
    40                 $function_name = $function['function'];
    41                 $accepted_args = $function['accepted_args'];
    42                 $the_args = $args;
    43                 array_unshift($the_args, $string);
    44                 if ( $accepted_args > 0 )
    45                     $the_args = array_slice($the_args, 0, $accepted_args);
    46                 elseif ( 0 == $accepted_args )
    47                     $the_args = NULL;
    48                 $string = call_user_func_array($function_name, $the_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] = $string;
     29                $string = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
    4930            }
    50         }
    51     }
     31
     32    } while ( next($wp_filter[$tag]) );
     33
    5234    return $string;
    5335}
     
    5537function merge_filters($tag) {
    5638    global $wp_filter;
    57     if ( isset($wp_filter['all']) ) {
    58         foreach ( (array) $wp_filter['all'] as $priority => $functions ) {
    59             if ( isset($wp_filter[$tag][$priority]) )
    60                 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
    61             else
    62                 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
    63             $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
    64         }
     39
     40    if ( isset($wp_filter['all']) )
     41        $wp_filter[$tag] = array_merge($wp_filter['all'], (array) $wp_filter[$tag]);
     42
     43    if ( isset($wp_filter[$tag]) ){
     44        reset($wp_filter[$tag]);
     45        uksort($wp_filter[$tag], "strnatcasecmp");
    6546    }
    66 
    67     if ( isset($wp_filter[$tag]) )
    68         uksort( $wp_filter[$tag], "strnatcasecmp" );
    6947}
    7048
     
    7250    global $wp_filter;
    7351
    74     // rebuild the list of filters
    75     if ( isset($wp_filter[$tag]["$priority"]) ) {
    76         $new_function_list = array();
    77         foreach ( (array) $wp_filter[$tag]["$priority"] as $filter ) {
    78             if ( $filter['function'] != $function_to_remove )
    79                 $new_function_list[] = $filter;
    80         }
    81         $wp_filter[$tag]["$priority"] = $new_function_list;
    82     }
     52    unset($GLOBALS['wp_filter'][$tag][$priority][serialize($function_to_remove)]);
     53
    8354    return true;
    8455}
     
    10879        return;
    10980
    110     foreach ( (array) $wp_filter[$tag] as $priority => $functions ) {
    111         if ( !is_null($functions) ) {
    112             foreach ( (array) $functions as $function ) {
    113                 $function_name = $function['function'];
    114                 $accepted_args = $function['accepted_args'];
     81    do{
     82        foreach( (array) current($wp_filter[$tag]) as $the_ )
     83            if ( !is_null($the_['function']) )
     84                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    11585
    116                 if ( $accepted_args > 0 )
    117                     $the_args = array_slice($args, 0, $accepted_args);
    118                 elseif ( $accepted_args == 0 )
    119                     $the_args = NULL;
    120                 else
    121                     $the_args = $args;
    122 
    123                 call_user_func_array($function_name, $the_args);
    124             }
    125         }
    126     }
     86    } while ( next($wp_filter[$tag]) );
    12787
    12888    if ( is_array($wp_actions) )
     
    152112        return;
    153113
    154     foreach ( (array) $wp_filter[$tag] as $priority => $functions ) {
    155         if ( !is_null($functions) ) {
    156             foreach ( (array) $functions as $function ) {
    157                 $function_name = $function['function'];
    158                 $accepted_args = $function['accepted_args'];
    159                 if ( $accepted_args > 0 )
    160                     $the_args = array_slice($args, 0, $accepted_args);
    161                 elseif ( 0 == $accepted_args )
    162                     $the_args = NULL;
    163                 else
    164                     $the_args = $args;
     114    do{
     115        foreach( (array) current($wp_filter[$tag]) as $the_ )
     116            if ( !is_null($the_['function']) )
     117                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    165118
    166                 call_user_func_array($function_name, $the_args);
    167             }
    168         }
    169     }
     119    } while ( next($wp_filter[$tag]) );
     120
    170121}
    171122
Note: See TracChangeset for help on using the changeset viewer.