diff --git a/features/help.feature b/features/help.feature index 5cc41d6e10..65c1d1e3c7 100644 --- a/features/help.feature +++ b/features/help.feature @@ -195,7 +195,7 @@ Feature: Get help about WP-CLI commands Then the return code should be 1 And STDERR should contain: """ - We were able to connect to the database server (which means your username and password is okay) but not able to select the `wp_cli_test` database. + Error establishing a database connection. """ And STDERR should contain: """ diff --git a/php/WP_CLI/Fetchers/User.php b/php/WP_CLI/Fetchers/User.php index 395c30b1f4..cacd1dddc5 100644 --- a/php/WP_CLI/Fetchers/User.php +++ b/php/WP_CLI/Fetchers/User.php @@ -23,20 +23,42 @@ class User extends Base { * @return WP_User|false The item if found; false otherwise. */ public function get( $arg ) { - if ( is_numeric( $arg ) ) { - $user = get_user_by( 'id', $arg ); + $users = get_users( + [ + 'include' => [ (int) $arg ], + 'number' => 1, + ] + ); } elseif ( is_email( $arg ) ) { - $user = get_user_by( 'email', $arg ); + $users = get_users( + [ + 'search' => $arg, + 'search_columns' => [ 'user_email' ], + 'number' => 1, + ] + ); // Logins can be emails. - if ( ! $user ) { - $user = get_user_by( 'login', $arg ); + if ( ! $users ) { + $users = get_users( + [ + 'search' => $arg, + 'search_columns' => [ 'user_login' ], + 'number' => 1, + ] + ); } } else { - $user = get_user_by( 'login', $arg ); + $users = get_users( + [ + 'search' => $arg, + 'search_columns' => [ 'user_login' ], + 'number' => 1, + ] + ); } - return $user; + return ( is_array( $users ) && count( $users ) > 0 ) ? $users[0] : false; } }