diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
index 867df81e166..fce40a91bae 100644
a
|
b
|
function wp_insert_user( $userdata ) { |
2123 | 2123 | return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); |
2124 | 2124 | } |
2125 | 2125 | |
| 2126 | // Username must be unique. |
2126 | 2127 | if ( ! $update && username_exists( $user_login ) ) { |
2127 | 2128 | return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); |
2128 | 2129 | } |
2129 | 2130 | |
| 2131 | // Username must not exist as an existing email. |
| 2132 | if ( email_exists( $user_login ) ) { |
| 2133 | return new WP_Error( 'existing_user_login_as_email', __( 'Sorry, that username is not available.' ) ); |
| 2134 | } |
| 2135 | |
2130 | 2136 | /** |
2131 | 2137 | * Filters the list of disallowed usernames. |
2132 | 2138 | * |
… |
… |
function register_new_user( $user_login, $user_email ) { |
3340 | 3346 | $sanitized_user_login = ''; |
3341 | 3347 | } elseif ( username_exists( $sanitized_user_login ) ) { |
3342 | 3348 | $errors->add( 'username_exists', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) ); |
3343 | | |
| 3349 | } elseif ( email_exists( $sanitized_user_login ) ) { |
| 3350 | $errors->add( 'username_exists_as_email', __( '<strong>Error:</strong> This username is not available. Please choose another one.' ) ); |
3344 | 3351 | } else { |
3345 | 3352 | /** This filter is documented in wp-includes/user.php */ |
3346 | 3353 | $illegal_user_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php
index 7157a00cfa9..5ebd91f690f 100644
a
|
b
|
public function test_wp_insert_user_should_not_generate_user_nicename_longer_tha |
934 | 934 | $this->assertSame( $expected, $user->user_nicename ); |
935 | 935 | } |
936 | 936 | |
| 937 | /** |
| 938 | * @ticket 57394 |
| 939 | */ |
| 940 | public function test_wp_insert_user_should_reject_username_that_matches_existing_user_email() { |
| 941 | $existing_email = get_option( 'admin_email' ); |
| 942 | $user = wp_insert_user( |
| 943 | array( |
| 944 | 'user_login' => $existing_email, |
| 945 | 'user_email' => 'whatever@example.com', |
| 946 | 'user_pass' => 'whatever', |
| 947 | 'user_nicename' => 'whatever', |
| 948 | ) |
| 949 | ); |
| 950 | |
| 951 | $this->assertWPError( $user ); |
| 952 | $this->assertSame( 'existing_user_login_as_email', $user->get_error_code() ); |
| 953 | } |
| 954 | |
937 | 955 | /** |
938 | 956 | * @ticket 33793 |
939 | 957 | */ |