From dcef5d458334ee66d87a6f9dbdc25ff3cca227bb Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 2 Oct 2014 15:55:51 +0000 Subject: [PATCH] In `activate_plugin()`, do not re-run the activation routine for already-active network-wide plugins. Adds unit test. Props jbrinley. Fixes #28651. git-svn-id: https://develop.svn.wordpress.org/trunk@29818 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/plugin.php | 2 +- tests/phpunit/tests/ms.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index bad5e9fded..d4bf57ea51 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -533,7 +533,7 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen if ( is_wp_error($valid) ) return $valid; - if ( !in_array($plugin, $current) ) { + if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { if ( !empty($redirect) ) wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error ob_start(); diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index dc968dde78..88d658f857 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -301,6 +301,29 @@ class Tests_MS extends WP_UnitTestCase { $this->assertEquals( 1, $this->plugin_hook_count ); // testing actions and silent mode } + /** + * @ticket 28651 + */ + function test_duplicate_network_active_plugin() { + $path = "hello.php"; + $mock = new MockAction(); + add_action( 'activate_' . $path, array ( $mock, 'action' ) ); + + // should activate on the first try + activate_plugin( $path, '', true ); + $active_plugins = wp_get_active_network_plugins(); + $this->assertCount( 1, $active_plugins ); + $this->assertEquals( 1, $mock->get_call_count() ); + + // should do nothing on the second try + activate_plugin( $path, '', true ); + $active_plugins = wp_get_active_network_plugins(); + $this->assertCount( 1, $active_plugins ); + $this->assertEquals( 1, $mock->get_call_count() ); + + remove_action( 'activate_' . $path, array ( $mock, 'action' ) ); + } + function _helper_deactivate_hook() { $this->plugin_hook_count++; }