diff --git a/features/plugin-activate.feature b/features/plugin-activate.feature index 9264e004..10b47054 100644 --- a/features/plugin-activate.feature +++ b/features/plugin-activate.feature @@ -80,3 +80,29 @@ Feature: Activate WordPress plugins """ Success: No plugins installed. """ + + @require-wp-5.2 + Scenario: Activating a plugin that does not meet PHP minimum throws a warning + Given a wp-content/plugins/high-requirements.php file: + """ + check_optional_args_and_all( $args, $all ); + if ( ! $args ) { + return; + } $plugins = $this->fetcher->get_many( $args ); $auto_updates = get_site_option( static::SITE_OPTION ); @@ -152,6 +155,9 @@ public function disable( $args, $assoc_args ) { $enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false ); $args = $this->check_optional_args_and_all( $args, $all ); + if ( ! $args ) { + return; + } $plugins = $this->fetcher->get_many( $args ); $auto_updates = get_site_option( static::SITE_OPTION ); diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index d9e3ae5d..35764df8 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -330,10 +330,18 @@ public function activate( $args, $assoc_args = array() ) { deactivate_plugins( $plugin->file, false, false ); } - activate_plugin( $plugin->file, '', $network_wide ); - - $this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' ); - $successes++; + $result = activate_plugin( $plugin->file, '', $network_wide ); + + if ( is_wp_error( $result ) ) { + $message = $result->get_error_message(); + $message = preg_replace( '/]+>.*<\/a>/im', '', $message ); + $message = wp_strip_all_tags( $message ); + $message = str_replace( 'Error: ', '', $message ); + WP_CLI::warning( "Failed to activate plugin. {$message}" ); + } else { + $this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' ); + $successes++; + } } if ( ! $this->chained_command ) { @@ -877,7 +885,7 @@ public function uninstall( $args, $assoc_args = array() ) { $all = Utils\get_flag_value( $assoc_args, 'all', false ); - // Check if plugin names of --all is passed. + // Check if plugin names or --all is passed. $args = $this->check_optional_args_and_all( $args, $all, 'uninstall' ); if ( ! $args ) { return; @@ -1005,7 +1013,7 @@ public function is_active( $args, $assoc_args = array() ) { public function delete( $args, $assoc_args = array() ) { $all = Utils\get_flag_value( $assoc_args, 'all', false ); - // Check if plugin names of --all is passed. + // Check if plugin names or --all is passed. $args = $this->check_optional_args_and_all( $args, $all, 'delete' ); if ( ! $args ) { return; diff --git a/src/Theme_AutoUpdates_Command.php b/src/Theme_AutoUpdates_Command.php index 84630d44..5dd3d9a5 100644 --- a/src/Theme_AutoUpdates_Command.php +++ b/src/Theme_AutoUpdates_Command.php @@ -78,6 +78,9 @@ public function enable( $args, $assoc_args ) { $disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false ); $args = $this->check_optional_args_and_all( $args, $all ); + if ( ! $args ) { + return; + } $themes = $this->fetcher->get_many( $args ); $auto_updates = get_site_option( static::SITE_OPTION ); @@ -152,6 +155,9 @@ public function disable( $args, $assoc_args ) { $enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false ); $args = $this->check_optional_args_and_all( $args, $all ); + if ( ! $args ) { + return; + } $themes = $this->fetcher->get_many( $args ); $auto_updates = get_site_option( static::SITE_OPTION );