Make WordPress Core

Ticket #57394: 53394.diff

File 53394.diff, 1.4 KB (added by dunhakdis, 2 years ago)

Added check to determine if username supplied already exists as an email of an existing user.

  • src/wp-includes/user.php

    diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
    index ca4b3d03fdb..8572c98c483 100644
    a b function wp_insert_user( $userdata ) { 
    21122112                return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) );
    21132113        }
    21142114
     2115        // Username must be unique.
    21152116        if ( ! $update && username_exists( $user_login ) ) {
    21162117                return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) );
    21172118        }
    21182119
     2120        // Username must not exist as an existing email.
     2121        if ( email_exists( $user_login ) ) {
     2122                return new WP_Error( 'existing_user_login_as_email', 'Sorry, that username is not available.');
     2123        }
     2124
    21192125        /**
    21202126         * Filters the list of disallowed usernames.
    21212127         *
    function register_new_user( $user_login, $user_email ) { 
    33293335                $sanitized_user_login = '';
    33303336        } elseif ( username_exists( $sanitized_user_login ) ) {
    33313337                $errors->add( 'username_exists', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) );
    3332 
     3338        } elseif ( email_exists( $sanitized_user_login ) ) {
     3339                $errors->add( 'username_exists_as_email', __( '<strong>Error:</strong> This username is not available. Please choose another one.' ) );
    33333340        } else {
    33343341                /** This filter is documented in wp-includes/user.php */
    33353342                $illegal_user_logins = (array) apply_filters( 'illegal_user_logins', array() );