Skip to content

Commit 5590d1b

Browse files
committed
feat: delete multiple options at once
1 parent 3eff3c3 commit 5590d1b

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

features/option.feature

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ Feature: Manage WordPress options
5757
When I run `wp option delete str_opt`
5858
Then STDOUT should not be empty
5959

60+
When I run `wp option add option_one "ONE"`
61+
And I run `wp option add option_two "TWO"`
62+
Then STDOUT should not be empty
63+
64+
When I try `wp option delete option_one option_two option_three`
65+
Then STDOUT should be:
66+
"""
67+
Success: Deleted 'option_one' option.
68+
Success: Deleted 'option_two' option.
69+
"""
70+
And STDERR should be:
71+
"""
72+
Warning: Could not delete 'option_three' option. Does it exist?
73+
"""
74+
6075
When I run `wp option list`
6176
Then STDOUT should not contain:
6277
"""
@@ -227,31 +242,31 @@ Feature: Manage WordPress options
227242
228243
When I try `wp option list --search='auto_opt' --autoload`
229244
Then STDOUT should not be empty
230-
And STDERR should be:
245+
And STDERR should be:
231246
"""
232247
Warning: --autoload parameter needs a value
233248
"""
234249
And the return code should be 0
235250
236251
When I try `wp option list --search='auto_opt' --autoload=no`
237252
Then STDOUT should be empty
238-
And STDERR should be:
253+
And STDERR should be:
239254
"""
240255
Error: Value of '--autoload' should be on or off.
241256
"""
242257
And the return code should be 1
243258
244259
When I try `wp option add str_opt_foo 'bar' --autoload`
245260
Then STDOUT should not be empty
246-
And STDERR should be:
261+
And STDERR should be:
247262
"""
248263
Warning: --autoload parameter needs a value
249264
"""
250265
And the return code should be 0
251266
252267
When I try `wp option add str_opt_foo 'bar' --autoload=off`
253268
Then STDOUT should be empty
254-
And STDERR should contain:
269+
And STDERR should contain:
255270
"""
256271
Error: Parameter errors:
257272
"""

src/Option_Command.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,22 +435,28 @@ public function update( $args, $assoc_args ) {
435435
*
436436
* ## OPTIONS
437437
*
438-
* <key>
438+
* <key>...
439439
* : Key for the option.
440440
*
441441
* ## EXAMPLES
442442
*
443443
* # Delete an option.
444444
* $ wp option delete my_option
445445
* Success: Deleted 'my_option' option.
446+
*
447+
* # Delete multiple options.
448+
* $ wp option delete option_one option_two option_three
449+
* Success: Deleted 'option_one' option.
450+
* Success: Deleted 'option_two' option.
451+
* Warning: Could not delete 'option_three' option. Does it exist?
446452
*/
447453
public function delete( $args ) {
448-
list( $key ) = $args;
449-
450-
if ( !delete_option( $key ) ) {
451-
WP_CLI::error( "Could not delete '$key' option. Does it exist?" );
452-
} else {
453-
WP_CLI::success( "Deleted '$key' option." );
454+
foreach ( $args as $arg ) {
455+
if ( ! delete_option( $arg ) ) {
456+
WP_CLI::warning( "Could not delete '$arg' option. Does it exist?" );
457+
} else {
458+
WP_CLI::success( "Deleted '$arg' option." );
459+
}
454460
}
455461
}
456462

0 commit comments

Comments
 (0)