mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@38251 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -328,89 +328,6 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
$this->assertFalse( doing_filter( 'testing' ) ); // No longer doing this filter
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36819
|
||||
*/
|
||||
function test_backup_plugin_globals_returns_filters() {
|
||||
$backup = _backup_plugin_globals( true );
|
||||
$this->assertArrayHasKey( 'backup_wp_filter', $backup );
|
||||
$this->assertArrayHasKey( 'backup_wp_actions', $backup );
|
||||
$this->assertArrayHasKey( 'backup_wp_current_filter', $backup );
|
||||
$this->assertArrayHasKey( 'backup_merged_filters', $backup );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36819
|
||||
*/
|
||||
function test_backup_plugin_globals_returns_filters_from_first_time_called() {
|
||||
$backup = _backup_plugin_globals( true );
|
||||
|
||||
$a = new MockAction();
|
||||
$tag = rand_str();
|
||||
|
||||
add_action($tag, array(&$a, 'action'));
|
||||
|
||||
$new_backup = _backup_plugin_globals( false );
|
||||
$this->assertEquals( $backup, $new_backup );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36819
|
||||
*/
|
||||
function test_restore_plugin_globals_from_stomp() {
|
||||
global $wp_actions;
|
||||
$original_actions = $wp_actions;
|
||||
|
||||
_backup_plugin_globals( true );
|
||||
|
||||
$wp_actions = array();
|
||||
|
||||
$this->assertEmpty( $wp_actions );
|
||||
_restore_plugin_globals();
|
||||
|
||||
$this->assertEquals( $GLOBALS['wp_actions'], $original_actions );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36819
|
||||
*/
|
||||
function test_restore_plugin_globals_includes_additions() {
|
||||
global $wp_filter;
|
||||
$original_filter = $wp_filter;
|
||||
|
||||
$backup = _backup_plugin_globals( true );
|
||||
|
||||
$a = new MockAction();
|
||||
$tag = rand_str();
|
||||
add_action($tag, array(&$a, 'action'));
|
||||
|
||||
$this->assertNotEquals( $GLOBALS['wp_filter'], $original_filter );
|
||||
|
||||
_restore_plugin_globals();
|
||||
|
||||
$this->assertNotEquals( $GLOBALS['wp_filter'], $original_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36819
|
||||
*/
|
||||
function test_applied_actions_are_counted_after_restore() {
|
||||
global $wp_actions;
|
||||
|
||||
$action_name = 'this_is_a_fake_action_name';
|
||||
$this->assertArrayNotHasKey( $action_name, $wp_actions );
|
||||
|
||||
do_action( $action_name );
|
||||
|
||||
$this->assertEquals( 1, $wp_actions[ $action_name ] );
|
||||
|
||||
_backup_plugin_globals( true );
|
||||
do_action( $action_name );
|
||||
_restore_plugin_globals();
|
||||
|
||||
$this->assertEquals( 2, $wp_actions[ $action_name ] );
|
||||
}
|
||||
|
||||
function apply_testing_filter() {
|
||||
$this->apply_testing_filter = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user