Skip to content

Commit 18f1036

Browse files
authored
Merge pull request #103 from svenkaptein/feature-plugin-delete-all
Add --all flag to plugin delete
2 parents faa452b + 1bcaadc commit 18f1036

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

features/plugin-delete.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ Feature: Delete WordPress plugins
1212
"""
1313
And the return code should be 0
1414

15+
Scenario: Delete all installed plugins
16+
When I run `wp plugin delete --all`
17+
Then STDOUT should be:
18+
"""
19+
Deleted 'akismet' plugin.
20+
Deleted 'hello' plugin.
21+
Success: Deleted 2 of 2 plugins.
22+
"""
23+
And the return code should be 0
24+
25+
When I run the previous command again
26+
Then STDOUT should be:
27+
"""
28+
Success: No plugins deleted.
29+
"""
30+
1531
Scenario: Attempting to delete a plugin that doesn't exist
1632
When I try `wp plugin delete edit-flow`
1733
Then STDOUT should be:

src/Plugin_Command.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,11 @@ public function is_active( $args, $assoc_args = array() ) {
936936
*
937937
* ## OPTIONS
938938
*
939-
* <plugin>...
939+
* [<plugin>...]
940940
* : One or more plugins to delete.
941+
*
942+
* [--all]
943+
* : If set, all plugins will be deleted.
941944
*
942945
* ## EXAMPLES
943946
*
@@ -952,7 +955,15 @@ public function is_active( $args, $assoc_args = array() ) {
952955
* Success: Deleted 1 of 1 plugins.
953956
*/
954957
public function delete( $args, $assoc_args = array() ) {
958+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
959+
960+
// Check if plugin names of --all is passed.
961+
if ( ! ( $args = $this->check_optional_args_and_all( $args, $all, 'delete' ) ) ) {
962+
return;
963+
}
964+
955965
$successes = $errors = 0;
966+
956967
foreach ( $this->fetcher->get_many( $args ) as $plugin ) {
957968
if ( $this->_delete( $plugin ) ) {
958969
WP_CLI::log( "Deleted '{$plugin->name}' plugin." );
@@ -1076,15 +1087,15 @@ protected function get_status( $file ) {
10761087

10771088
/**
10781089
* Gets the template path based on installation type.
1079-
*/
1090+
*/
10801091
private static function get_template_path( $template ) {
10811092
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
10821093
$template_path = "{$command_root}/templates/{$template}";
1083-
1094+
10841095
if ( ! file_exists( $template_path ) ) {
10851096
WP_CLI::error( "Couldn't find {$template}" );
10861097
}
1087-
1098+
10881099
return $template_path;
10891100
}
10901101

0 commit comments

Comments
 (0)