WordPress Snippets at WPcustoms

Login with Username or E-mail

This functions code snippet adds the option to login with the username OR your registered email. By default WP requires a username.


/**
 * Snippet Name: Login with Username or E-mail
 * Snippet URL: http://www.wpcustoms.net/snippets/login-with-username-or-e-mail/
 */
 function login_with_email_address($username) {
    $user = get_user_by('email',$username);
    if(!empty($user->user_login))
        $username = $user->user_login;
    return $username;
}
add_action('wp_authenticate','login_with_email_address');
 
function change_username_wps_text($text){
    if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){
        if ($text == 'Username'){$text = 'Username / Email';}
    }
 
    return $text;
}
add_filter( 'gettext', 'change_username_wps_text' );