Skip to content

Commit

Permalink
Exit early with error if no roles are specified during user add-role
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnhooper committed Nov 10, 2023
1 parent 480e4cf commit 19b1005
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ Feature: Manage WordPress users
Scenario: Managing user roles
Given a WP install

When I run `wp user add-role 1`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify at least one role to add.
"""
And STDOUT should be empty

When I run `wp user add-role 1 editor`
Then STDOUT should not be empty
And I run `wp user get 1 --field=roles`
Expand Down
4 changes: 4 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ public function add_role( $args, $assoc_args ) {
$roles = $args;
array_shift( $roles );

if ( empty( $roles ) ) {
WP_CLI::error( 'Please specify at least one role to add.' );
}

foreach ( $roles as $role ) {
self::validate_role( $role );
}
Expand Down

0 comments on commit 19b1005

Please sign in to comment.