Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support emails in user_login field #21

Merged
merged 2 commits into from
Jun 29, 2017
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
16 changes: 16 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,19 @@ Feature: Manage WordPress users
http://example.com/?author=1
http://example.com/?author=2
"""

Scenario: Get user with email as login
Given a WP install
And I run `wp user create [email protected] [email protected]`

When I run `wp user get [email protected] --field=user_login`
Then STDOUT should be:
"""
[email protected]
"""

When I run `wp user get [email protected] --field=user_login`
Then STDOUT should be:
"""
[email protected]
"""
11 changes: 8 additions & 3 deletions src/WP_CLI/Fetchers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ class User extends Base {
*/
public function get( $id_email_or_login ) {

if ( is_numeric( $id_email_or_login ) )
if ( is_numeric( $id_email_or_login ) ) {
$user = get_user_by( 'id', $id_email_or_login );
else if ( is_email( $id_email_or_login ) )
} elseif ( is_email( $id_email_or_login ) ) {
$user = get_user_by( 'email', $id_email_or_login );
else
// Logins can be emails
if ( ! $user ) {
$user = get_user_by( 'login', $id_email_or_login );
}
} else {
$user = get_user_by( 'login', $id_email_or_login );
}

return $user;
}
Expand Down