Skip to content

Commit

Permalink
Merge pull request #360 from BhargavBhandari90/issue-34
Browse files Browse the repository at this point in the history
Support filtering for users without a role with `--role=none`
  • Loading branch information
danielbachhuber authored Aug 22, 2022
2 parents 4839ce5 + 90c7c13 commit 66bdeae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions features/user-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ Feature: List WordPress users
"""
bobjones
"""

@require-wp-4.9
Scenario: List users without roles
Given a WP install
When I run `wp user create bili bili@example.com --porcelain`
Then save STDOUT as {USER_ID}

And I run `wp user create sally sally@example.com --role=editor`
And I run `wp user remove-role {USER_ID} subscriber`

When I run `wp user list --role=none --field=user_login`
Then STDOUT should be:
"""
bili
"""
12 changes: 11 additions & 1 deletion src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,17 @@ public function list_( $args, $assoc_args ) {

$assoc_args['count_total'] = false;
$assoc_args = self::process_csv_arguments_to_arrays( $assoc_args );
$users = get_users( $assoc_args );

if ( ! empty( $assoc_args['role'] ) && 'none' === $assoc_args['role'] ) {
$norole_user_ids = wp_get_users_with_no_role();

if ( ! empty( $norole_user_ids ) ) {
$assoc_args['include'] = $norole_user_ids;
unset( $assoc_args['role'] );
}
}

$users = get_users( $assoc_args );

if ( 'ids' === $formatter->format ) {
echo implode( ' ', $users );
Expand Down

0 comments on commit 66bdeae

Please sign in to comment.