Last active
September 5, 2024 01:48
-
-
Save norcross/ba1dd4e89223b10c1f2d to your computer and use it in GitHub Desktop.
allow email address to be used as login name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter ( 'authenticate', 'rkv_login_options', 20, 3 ); | |
function rkv_login_options( $user, $username, $password ) { | |
if ( is_email( $username ) ) { | |
$user = get_user_by( 'email', $username ); | |
} | |
if ( $user ) { | |
$username = $user->user_login; | |
} | |
return wp_authenticate_username_password( null, $username, $password ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worth removing the authenticate filter first or else you get an PHP error: "Notice: Undefined property: WP_Error::$user_login....."
Also for the Label and error message you can add these filters.