1 | |
---|
2 | @@ -2864,9 +2864,11 @@ |
---|
3 | * |
---|
4 | * @param string $user_login Optional. Username to send a password retrieval email for. |
---|
5 | * Defaults to `$_POST['user_login']` if not set. |
---|
6 | + * @param string $field Optional. The field to retrieve the user with. id | ID | slug | email | login. |
---|
7 | + * Defaults to `login` |
---|
8 | * @return true|WP_Error True when finished, WP_Error object on error. |
---|
9 | */ |
---|
10 | -function retrieve_password( $user_login = null ) { |
---|
11 | +function retrieve_password( $user_login = null, $field = 'login' ) { |
---|
12 | $errors = new WP_Error(); |
---|
13 | $user_data = false; |
---|
14 | |
---|
15 | @@ -2877,13 +2879,11 @@ |
---|
16 | |
---|
17 | if ( empty( $user_login ) ) { |
---|
18 | $errors->add( 'empty_username', __( '<strong>Error</strong>: Please enter a username or email address.' ) ); |
---|
19 | - } elseif ( strpos( $user_login, '@' ) ) { |
---|
20 | - $user_data = get_user_by( 'email', trim( wp_unslash( $user_login ) ) ); |
---|
21 | + } else { |
---|
22 | + $user_data = get_user_by( $field, trim( wp_unslash( $user_login ) ) ); |
---|
23 | if ( empty( $user_data ) ) { |
---|
24 | $errors->add( 'invalid_email', __( '<strong>Error</strong>: There is no account with that username or email address.' ) ); |
---|
25 | } |
---|
26 | - } else { |
---|
27 | - $user_data = get_user_by( 'login', trim( wp_unslash( $user_login ) ) ); |
---|
28 | } |
---|
29 | |
---|
30 | /** |
---|