Skip to content

Commit

Permalink
feat: delete multiple options at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Apr 7, 2019
1 parent 3eff3c3 commit 716c154
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
23 changes: 19 additions & 4 deletions features/option.feature
Expand Up @@ -57,6 +57,21 @@ Feature: Manage WordPress options
When I run `wp option delete str_opt`
Then STDOUT should not be empty

When I run `wp option add option_one "ONE"`
And I run `wp option add option_two "TWO"`
Then STDOUT should not be empty

When I try `wp option delete option_one option_two option_three`
Then STDOUT should be:
"""
Success: Deleted 'option_one' option.
Success: Deleted 'option_two' option.
"""
And STDERR should contain:
"""
Warning: Could not delete 'option_three' option. Does it exist?
"""

When I run `wp option list`
Then STDOUT should not contain:
"""
Expand Down Expand Up @@ -227,31 +242,31 @@ Feature: Manage WordPress options
When I try `wp option list --search='auto_opt' --autoload`
Then STDOUT should not be empty
And STDERR should be:
And STDERR should be:
"""
Warning: --autoload parameter needs a value
"""
And the return code should be 0
When I try `wp option list --search='auto_opt' --autoload=no`
Then STDOUT should be empty
And STDERR should be:
And STDERR should be:
"""
Error: Value of '--autoload' should be on or off.
"""
And the return code should be 1
When I try `wp option add str_opt_foo 'bar' --autoload`
Then STDOUT should not be empty
And STDERR should be:
And STDERR should be:
"""
Warning: --autoload parameter needs a value
"""
And the return code should be 0
When I try `wp option add str_opt_foo 'bar' --autoload=off`
Then STDOUT should be empty
And STDERR should contain:
And STDERR should contain:
"""
Error: Parameter errors:
"""
Expand Down
20 changes: 13 additions & 7 deletions src/Option_Command.php
Expand Up @@ -435,22 +435,28 @@ public function update( $args, $assoc_args ) {
*
* ## OPTIONS
*
* <key>
* <key>...
* : Key for the option.
*
* ## EXAMPLES
*
* # Delete an option.
* $ wp option delete my_option
* Success: Deleted 'my_option' option.
*
* # Delete multiple options
* $ wp option delete option_one option_two option_three
* Success: Deleted 'option_one' option.
* Success: Deleted 'option_two' option.
* Warning: Could not delete 'option_three' option. Does it exist?
*/
public function delete( $args ) {
list( $key ) = $args;

if ( !delete_option( $key ) ) {
WP_CLI::error( "Could not delete '$key' option. Does it exist?" );
} else {
WP_CLI::success( "Deleted '$key' option." );
foreach ( $args as $arg ) {
if ( ! delete_option( $arg ) ) {
WP_CLI::warning( "Could not delete '$arg' option. Does it exist?" );
} else {
WP_CLI::success( "Deleted '$arg' option." );
}
}
}

Expand Down

0 comments on commit 716c154

Please sign in to comment.