mirror of
git://develop.git.wordpress.org/
synced 2025-02-24 16:43:06 +01:00
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
This commit is contained in:
parent
46b4ea2a6c
commit
dcef5d4583
@ -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();
|
||||
|
@ -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++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user