Skip to content

Commit a931978

Browse files
committed
Add --all flag to plugin delete
1 parent 941e7e3 commit a931978

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,11 @@ public function is_installed( $args, $assoc_args = array() ) {
904904
*
905905
* ## OPTIONS
906906
*
907-
* <plugin>...
907+
* [<plugin>...]
908908
* : One or more plugins to delete.
909+
*
910+
* [--all]
911+
* : If set, all plugins will be deleted.
909912
*
910913
* ## EXAMPLES
911914
*
@@ -920,7 +923,20 @@ public function is_installed( $args, $assoc_args = array() ) {
920923
* Success: Deleted 1 of 1 plugins.
921924
*/
922925
public function delete( $args, $assoc_args = array() ) {
926+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
927+
928+
// Check if plugin names of --all is passed.
929+
if ( ! ( $args = $this->check_optional_args_and_all( $args, $all, 'delete' ) ) ) {
930+
return;
931+
}
932+
923933
$successes = $errors = 0;
934+
935+
$plugins = $this->fetcher->get_many( $args );
936+
if ( count( $plugins ) < count( $args ) ) {
937+
$errors = count( $args ) - count( $plugins );
938+
}
939+
924940
foreach ( $this->fetcher->get_many( $args ) as $plugin ) {
925941
if ( $this->_delete( $plugin ) ) {
926942
WP_CLI::log( "Deleted '{$plugin->name}' plugin." );

0 commit comments

Comments
 (0)