Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4769,6 +4769,36 @@ make sure to reassign their posts prior to deleting the user.



### wp user exists

Verifies whether a user exists.

~~~
wp user exists <id>
~~~

Displays a success message if the user does exist.

**OPTIONS**

<id>
The ID of the user to check.

**EXAMPLES**

# The user exists.
$ wp user exists 1337
Success: User with ID 1337 exists.
$ echo $?
0

# The user does not exist.
$ wp user exists 10000
$ echo $?
1



### wp user generate

Generates some users.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"user add-role",
"user create",
"user delete",
"user exists",
"user generate",
"user get",
"user import-csv",
Expand Down
11 changes: 11 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ Feature: Manage WordPress users
| ID | {USER_ID} |
| roles | author |

When I run `wp user exists {USER_ID}`
Then STDOUT should be:
"""
Success: User with ID {USER_ID} exists.
"""
And the return code should be 0

When I try `wp user exists 1000`
And STDOUT should be empty
And the return code should be 1

When I run `wp user get {USER_ID} --field=user_registered`
Then STDOUT should not contain:
"""
Expand Down
31 changes: 31 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,37 @@ public function generate( $args, $assoc_args ) {
}
}

/**
* Verifies whether a user exists.
*
* Displays a success message if the user does exist.
*
* ## OPTIONS
*
* <id>
* : The ID of the user to check.
*
* ## EXAMPLES
*
* # The user exists.
* $ wp user exists 1337
* Success: User with ID 1337 exists.
* $ echo $?
* 0
*
* # The user does not exist.
* $ wp user exists 10000
* $ echo $?
* 1
*/
public function exists( $args ) {
if ( $this->fetcher->get( $args[0] ) ) {
WP_CLI::success( "User with ID {$args[0]} exists." );
} else {
WP_CLI::halt( 1 );
}
}

/**
* Sets the user role.
*
Expand Down