Make WordPress Core


Ignore:
Timestamp:
08/13/2016 03:59:03 PM (10 years ago)
Author:
jorbin
Message:

Bootstrap/Load: Revert Plugin Global restoration around advance-cache.php.

First added in [37588] and later modified in [38224], the idea was to ensure that filters/actions added before advance-cache.php would not disappear if advance-cache.php overloaded the filters/actions with code such as $wp_filter = array(). This is an edge case and one that there is no documented case of existing.

This restores the behavior from WordPress 4.5 and before. It is strongly encouraged that developers using advance-cache.php to use the Plugins API that is available before the loading of advance-cache.php rather than directly interacting with any of the globals.

Props azaozz, jorbin, dd32 for review, pento for review, westi for investigation, ipstenu for research.
See #36819.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/actions.php

    r38223 r38251  
    329329        }
    330330
    331         /**
    332          * @ticket 36819
    333          */
    334         function test_backup_plugin_globals_returns_filters() {
    335                 $backup = _backup_plugin_globals( true );
    336                 $this->assertArrayHasKey( 'backup_wp_filter',         $backup );
    337                 $this->assertArrayHasKey( 'backup_wp_actions',        $backup );
    338                 $this->assertArrayHasKey( 'backup_wp_current_filter', $backup );
    339                 $this->assertArrayHasKey( 'backup_merged_filters', $backup );
    340         }
    341 
    342         /**
    343          * @ticket 36819
    344          */
    345         function test_backup_plugin_globals_returns_filters_from_first_time_called() {
    346                 $backup = _backup_plugin_globals( true );
    347 
    348                 $a = new MockAction();
    349                 $tag = rand_str();
    350 
    351                 add_action($tag, array(&$a, 'action'));
    352 
    353                 $new_backup = _backup_plugin_globals( false );
    354                 $this->assertEquals( $backup, $new_backup );
    355         }
    356 
    357         /**
    358          * @ticket 36819
    359          */
    360         function test_restore_plugin_globals_from_stomp() {
    361                 global $wp_actions;
    362                 $original_actions = $wp_actions;
    363 
    364                 _backup_plugin_globals( true );
    365 
    366                 $wp_actions = array();
    367 
    368                 $this->assertEmpty( $wp_actions );
    369                 _restore_plugin_globals();
    370 
    371                 $this->assertEquals( $GLOBALS['wp_actions'], $original_actions );
    372         }
    373 
    374         /**
    375          * @ticket 36819
    376          */
    377         function test_restore_plugin_globals_includes_additions() {
    378                 global $wp_filter;
    379                 $original_filter = $wp_filter;
    380 
    381                 $backup = _backup_plugin_globals( true );
    382 
    383                 $a = new MockAction();
    384                 $tag = rand_str();
    385                 add_action($tag, array(&$a, 'action'));
    386 
    387                 $this->assertNotEquals( $GLOBALS['wp_filter'], $original_filter );
    388 
    389                 _restore_plugin_globals();
    390 
    391                 $this->assertNotEquals( $GLOBALS['wp_filter'], $original_filter );
    392         }
    393 
    394         /**
    395          * @ticket 36819
    396          */
    397         function test_applied_actions_are_counted_after_restore() {
    398                 global $wp_actions;
    399 
    400                 $action_name = 'this_is_a_fake_action_name';
    401                 $this->assertArrayNotHasKey( $action_name, $wp_actions );
    402 
    403                 do_action( $action_name );
    404 
    405                 $this->assertEquals( 1, $wp_actions[ $action_name ] );
    406 
    407                 _backup_plugin_globals( true );
    408                 do_action( $action_name );
    409                 _restore_plugin_globals();
    410 
    411                 $this->assertEquals( 2, $wp_actions[ $action_name ] );
    412         }
    413 
    414331        function apply_testing_filter() {
    415332                $this->apply_testing_filter = true;
Note: See TracChangeset for help on using the changeset viewer.