Make WordPress Core

Ticket #26239: 26239.patch

File 26239.patch, 3.1 KB (added by rzen, 11 years ago)

Localizes $wp_filter global in each hook function for improved recursion.

  • wp-includes/plugin.php

     
    187187                $merged_filters[ $tag ] = true;
    188188        }
    189189
    190         reset( $wp_filter[ $tag ] );
     190        // Localize the filters global for iteration
     191        $the_filters = $wp_filter[ $tag ];
     192        reset( $the_filters );
    191193
    192194        if ( empty($args) )
    193195                $args = func_get_args();
    194196
    195197        do {
    196                 foreach( (array) current($wp_filter[$tag]) as $the_ )
     198                foreach( (array) current( $the_filters ) as $the_ )
    197199                        if ( !is_null($the_['function']) ){
    198200                                $args[1] = $value;
    199201                                $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
    200202                        }
    201203
    202         } while ( next($wp_filter[$tag]) !== false );
     204        } while ( next( $the_filters ) !== false );
    203205
    204206        array_pop( $wp_current_filter );
    205207
     
    248250                $merged_filters[ $tag ] = true;
    249251        }
    250252
    251         reset( $wp_filter[ $tag ] );
     253        // Localize the filters global for iteration
     254        $the_filters = $wp_filter[ $tag ];
     255        reset( $the_filters );
    252256
    253257        do {
    254                 foreach( (array) current($wp_filter[$tag]) as $the_ )
     258                foreach( (array) current( $the_filters ) as $the_ )
    255259                        if ( !is_null($the_['function']) )
    256260                                $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    257261
    258         } while ( next($wp_filter[$tag]) !== false );
     262        } while ( next( $the_filters ) !== false );
    259263
    260264        array_pop( $wp_current_filter );
    261265
     
    421425                $merged_filters[ $tag ] = true;
    422426        }
    423427
    424         reset( $wp_filter[ $tag ] );
     428        // Localize the filters global for iteration
     429        $the_filters = $wp_filter[ $tag ];
     430        reset( $the_filters );
    425431
    426432        do {
    427                 foreach ( (array) current($wp_filter[$tag]) as $the_ )
     433                foreach ( (array) current( $the_filters ) as $the_ )
    428434                        if ( !is_null($the_['function']) )
    429435                                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    430436
    431         } while ( next($wp_filter[$tag]) !== false );
     437        } while ( next( $the_filters ) !== false );
    432438
    433439        array_pop($wp_current_filter);
    434440}
     
    499505                $merged_filters[ $tag ] = true;
    500506        }
    501507
    502         reset( $wp_filter[ $tag ] );
     508        // Localize the filters global for iteration
     509        $the_filters = $wp_filter[ $tag ];
     510        reset( $the_filters );
    503511
    504512        do {
    505                 foreach( (array) current($wp_filter[$tag]) as $the_ )
     513                foreach( (array) current( $the_filters ) as $the_ )
    506514                        if ( !is_null($the_['function']) )
    507515                                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    508516
    509         } while ( next($wp_filter[$tag]) !== false );
     517        } while ( next( $the_filters ) !== false );
    510518
    511519        array_pop($wp_current_filter);
    512520}
     
    732740function _wp_call_all_hook($args) {
    733741        global $wp_filter;
    734742
    735         reset( $wp_filter['all'] );
     743        // Localize the filters global for iteration
     744        $the_filters = $wp_filter['all'];
     745        reset( $the_filters );
    736746        do {
    737                 foreach( (array) current($wp_filter['all']) as $the_ )
     747                foreach( (array) current( $the_filters ) as $the_ )
    738748                        if ( !is_null($the_['function']) )
    739749                                call_user_func_array($the_['function'], $args);
    740750
    741         } while ( next($wp_filter['all']) !== false );
     751        } while ( next( $the_filters ) !== false );
    742752}
    743753
    744754/**