diff --git a/features/plugin-activate.feature b/features/plugin-activate.feature index a479e801..62326bbd 100644 --- a/features/plugin-activate.feature +++ b/features/plugin-activate.feature @@ -177,3 +177,51 @@ Feature: Activate WordPress plugins Debug (plugin): Unexpected output: Unexpected output from plugin activation """ And the return code should be 1 + + Scenario: Force activate an already active plugin to re-run activation hooks + Given a wp-content/plugins/force-test.php file: + """ + name}' is already network active." ); - continue; + // If force flag is set, deactivate and reactivate to run activation hooks. + if ( $force ) { + deactivate_plugins( $plugin->file, false, true ); + } else { + WP_CLI::warning( "Plugin '{$plugin->name}' is already network active." ); + continue; + } } // Don't reactivate active plugins, but do let them become network-active. if ( ! $network_wide && 'active' === $status ) { - WP_CLI::warning( "Plugin '{$plugin->name}' is already active." ); - continue; + // If force flag is set, deactivate and reactivate to run activation hooks. + if ( $force ) { + deactivate_plugins( $plugin->file, false, false ); + } else { + WP_CLI::warning( "Plugin '{$plugin->name}' is already active." ); + continue; + } } // Plugins need to be deactivated before being network activated. diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 52f9f5bf..12d17f27 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -314,14 +314,23 @@ public function install( $args, $assoc_args ) { if ( true === $allow_activation && count( $extension ) > 0 ) { $this->chained_command = true; + $force = Utils\get_flag_value( $assoc_args, 'force', false ); if ( Utils\get_flag_value( $assoc_args, 'activate-network' ) ) { WP_CLI::log( "Network-activating '$slug'..." ); - $this->activate( array( $slug ), array( 'network' => true ) ); + $activate_args = array( 'network' => true ); + if ( $force ) { + $activate_args['force'] = true; + } + $this->activate( array( $slug ), $activate_args ); } if ( Utils\get_flag_value( $assoc_args, 'activate' ) ) { WP_CLI::log( "Activating '$slug'..." ); - $this->activate( array( $slug ) ); + $activate_args = array(); + if ( $force ) { + $activate_args['force'] = true; + } + $this->activate( array( $slug ), $activate_args ); } $this->chained_command = false; }