diff --git a/wp-includes/user.php b/wp-includes/user.php index 867df81e16..e0cfae9188 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -2123,10 +2123,16 @@ function wp_insert_user( $userdata ) { return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); } + // Username must be unique. if ( ! $update && username_exists( $user_login ) ) { return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); } + // Username must not match an existing user email. + if ( email_exists( $user_login ) ) { + return new WP_Error( 'existing_user_login_as_email', __( 'Sorry, that username is not available.' ) ); + } + /** * Filters the list of disallowed usernames. * @@ -3340,7 +3346,8 @@ function register_new_user( $user_login, $user_email ) { $sanitized_user_login = ''; } elseif ( username_exists( $sanitized_user_login ) ) { $errors->add( 'username_exists', __( 'Error: This username is already registered. Please choose another one.' ) ); - + } elseif ( email_exists( $sanitized_user_login ) ) { + $errors->add( 'username_exists_as_email', __( 'Error: This username is not available. Please choose another one.' ) ); } else { /** This filter is documented in wp-includes/user.php */ $illegal_user_logins = (array) apply_filters( 'illegal_user_logins', array() ); diff --git a/wp-includes/version.php b/wp-includes/version.php index c172abf486..1ce6ce4707 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-beta2-55356'; +$wp_version = '6.2-beta2-55358'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.