Make WordPress Core

Ticket #26640: apply_filters.2.patch

File apply_filters.2.patch, 1.9 KB (added by dshafik, 11 years ago)
  • wp-includes/plugin.php

    diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php
    index e02139d..8d24167 100644
    a b function apply_filters( $tag, $value ) { 
    206206        if ( empty($args) )
    207207                $args = func_get_args();
    208208
     209        $current = current($wp_filter[$tag]);
    209210        do {
    210                 foreach( (array) current($wp_filter[$tag]) as $the_ )
    211                         if ( !is_null($the_['function']) ){
     211                foreach( (array) $current as $the_ )
     212                        if ( $the_['function'] !== null ){
    212213                                $args[1] = $value;
    213                                 $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
     214
     215                                $func = $the_['function'];
     216
     217                                if (!is_callable($func)) {
     218                                        trigger_error("function '$func' not found or invalid function name", E_USER_WARNING);
     219                                        continue;
     220                                }
     221                               
     222                                // If it's a string (function) callback, or it's PHP >= 5.4, we can do this much faster for <= 5 args
     223                                if (is_string($func) || $func instanceof Closure || version_compare(PHP_VERSION, '5.4.0', 'ge') === true) {
     224                                        switch ((int) $the_['accepted_args']) {
     225                                                case 1:
     226                                                        $value = $func($args[1]);
     227                                                        break;
     228                                                case 2:
     229                                                        $value = $func($args[1], $args[2]);
     230                                                        break;
     231                                                case 3:
     232                                                        $value = $func($args[1], $args[2], $args[3]);
     233                                                        break;
     234                                                case 4:
     235                                                        $value = $func($args[1], $args[2], $args[3], $args[4]);
     236                                                        break;
     237                                                case 5:
     238                                                        $value = $func($args[1], $args[2], $args[3], $args[4], $args[5]);
     239                                                        break;
     240                                                default:
     241                                                        $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
     242                                        }
     243                                } else {
     244                                        $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
     245                                }
    214246                        }
    215247
    216         } while ( next($wp_filter[$tag]) !== false );
     248        } while ( $current = next($wp_filter[$tag]) !== false );
    217249
    218250        array_pop( $wp_current_filter );
    219251