From a9319784050b56c1123e8762904e65e06ea2cbba Mon Sep 17 00:00:00 2001 From: Sven Kaptein Date: Fri, 15 Jun 2018 00:08:10 +0200 Subject: [PATCH 1/2] Add --all flag to plugin delete --- features/plugin-delete.feature | 16 ++++++++++++++++ src/Plugin_Command.php | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/features/plugin-delete.feature b/features/plugin-delete.feature index 3501ebf98..274d35941 100644 --- a/features/plugin-delete.feature +++ b/features/plugin-delete.feature @@ -12,6 +12,22 @@ Feature: Delete WordPress plugins """ And the return code should be 0 + Scenario: Delete all installed plugins + When I run `wp plugin delete --all` + Then STDOUT should be: + """ + Deleted 'akismet' plugin. + Deleted 'hello' plugin. + Success: Deleted 2 of 2 plugins. + """ + And the return code should be 0 + + When I run the previous command again + Then STDOUT should be: + """ + Success: No plugins deleted. + """ + Scenario: Attempting to delete a plugin that doesn't exist When I try `wp plugin delete edit-flow` Then STDOUT should be: diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 5ca1988e3..1922180f0 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -904,8 +904,11 @@ public function is_installed( $args, $assoc_args = array() ) { * * ## OPTIONS * - * ... + * [...] * : One or more plugins to delete. + * + * [--all] + * : If set, all plugins will be deleted. * * ## EXAMPLES * @@ -920,7 +923,20 @@ public function is_installed( $args, $assoc_args = array() ) { * Success: Deleted 1 of 1 plugins. */ public function delete( $args, $assoc_args = array() ) { + $all = Utils\get_flag_value( $assoc_args, 'all', false ); + + // Check if plugin names of --all is passed. + if ( ! ( $args = $this->check_optional_args_and_all( $args, $all, 'delete' ) ) ) { + return; + } + $successes = $errors = 0; + + $plugins = $this->fetcher->get_many( $args ); + if ( count( $plugins ) < count( $args ) ) { + $errors = count( $args ) - count( $plugins ); + } + foreach ( $this->fetcher->get_many( $args ) as $plugin ) { if ( $this->_delete( $plugin ) ) { WP_CLI::log( "Deleted '{$plugin->name}' plugin." ); From 1bcaadc46060cf60692a31a4ee9ddae8a38f5d39 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 31 Jul 2018 18:31:05 +0200 Subject: [PATCH 2/2] Remove superfluous plugin iteration --- src/Plugin_Command.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index e938bbdc6..c61d7d0f3 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -964,11 +964,6 @@ public function delete( $args, $assoc_args = array() ) { $successes = $errors = 0; - $plugins = $this->fetcher->get_many( $args ); - if ( count( $plugins ) < count( $args ) ) { - $errors = count( $args ) - count( $plugins ); - } - foreach ( $this->fetcher->get_many( $args ) as $plugin ) { if ( $this->_delete( $plugin ) ) { WP_CLI::log( "Deleted '{$plugin->name}' plugin." ); @@ -1092,15 +1087,15 @@ protected function get_status( $file ) { /** * Gets the template path based on installation type. - */ + */ private static function get_template_path( $template ) { $command_root = Utils\phar_safe_path( dirname( __DIR__ ) ); $template_path = "{$command_root}/templates/{$template}"; - + if ( ! file_exists( $template_path ) ) { WP_CLI::error( "Couldn't find {$template}" ); } - + return $template_path; }