Make WordPress Core

Ticket #36653: 36653.01.diff

File 36653.01.diff, 1.4 KB (added by websupporter, 9 years ago)

To try to login via email, we just checked if there is an @ in the login. I changed this to is_email. Furthermore, when we do not find a user by email, I propose, we check, if there is a username in the format of an email address.

  • src/wp-login.php

     
    290290        global $wpdb, $wp_hasher;
    291291
    292292        $errors = new WP_Error();
    293 
     293       
     294        $login = trim( $_POST['user_login'] );
    294295        if ( empty( $_POST['user_login'] ) ) {
    295                 $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or email address.'));
    296         } elseif ( strpos( $_POST['user_login'], '@' ) ) {
    297                 $user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
    298                 if ( empty( $user_data ) )
    299                         $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
     296                $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Enter a username or email address.' ) );
     297        } elseif ( is_email( $login ) ) {
     298                $user_data = get_user_by( 'email', $login );
     299                if ( empty( $user_data ) ) {
     300                       
     301                        //Maybe the username has the format of an email address
     302                        //So we check here, if we find a username for $login
     303                        $user_data = get_user_by( 'login' , $login );
     304                        if ( empty( $user_data ) ) {
     305                                $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
     306                        }
     307                }
    300308        } else {
    301                 $login = trim($_POST['user_login']);
    302                 $user_data = get_user_by('login', $login);
     309                $user_data = get_user_by( 'login', $login );
    303310        }
    304311
    305312        /**