Make WordPress Core


Ignore:
Timestamp:
08/09/2016 01:44:20 AM (10 years ago)
Author:
pento
Message:

Boostrap/Load: Improve forward compatiblity of plugin global backup methods.

[37588] added methods to backup the plugin globals, for ensuring that advanced cache drop-ins don't overwrite hooks that've been added earlier in the load process.

The method for restoring the plugin globals wasn't compatible with the implementation of WP_Hook in #17817. WP_Hook implements ArrayAccess, so _restore_plugin_globals() was treating it as an array, and inadvertantly overwriting the WP_Hook object with a plain array.

To avoid having to re-write this code as part of #17817, we now use add_filter() to restore any hooks that were added by cache drop-ins, which WP_Hook correctly supports.

Props pento, jorbin.
See #36819.

File:
1 edited

Legend:

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

    r37909 r38223  
    333333         */
    334334        function test_backup_plugin_globals_returns_filters() {
    335                 $backup = _backup_plugin_globals();
     335                $backup = _backup_plugin_globals( true );
    336336                $this->assertArrayHasKey( 'backup_wp_filter',         $backup );
    337337                $this->assertArrayHasKey( 'backup_wp_actions',        $backup );
     
    344344         */
    345345        function test_backup_plugin_globals_returns_filters_from_first_time_called() {
    346                 $backup = _backup_plugin_globals();
    347 
    348                 $a = new MockAction();
    349                 $tag = rand_str();
    350 
    351                 add_action($tag, array(&$a, 'action'));
    352 
    353                 $new_backup = _backup_plugin_globals();
     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 );
    354354                $this->assertEquals( $backup, $new_backup );
    355355        }
     
    362362                $original_actions = $wp_actions;
    363363
    364                 _backup_plugin_globals();
     364                _backup_plugin_globals( true );
    365365
    366366                $wp_actions = array();
     
    379379                $original_filter = $wp_filter;
    380380
    381                 $backup = _backup_plugin_globals();
     381                $backup = _backup_plugin_globals( true );
    382382
    383383                $a = new MockAction();
     
    390390
    391391                $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 ] );
    392412        }
    393413
Note: See TracChangeset for help on using the changeset viewer.