"Unknown email address. Check again or try your username."
I understand a user can log in with either username or email. But when username is an email (and particularly different to the actual email) I think it freaks out with above message. I can imagine if it finds an @ symbol it presumes its an email and only looks up email and not username. In my testing, every user that has a different username email to primary email this is a problem. Is there a snippet I can insert to capture this?
"Unknown email address. Check again or try your username."
I understand a user can log in with either username or email. But when username is an email (and particularly different to the actual email) I think it freaks out with above message. I can imagine if it finds an @ symbol it presumes its an email and only looks up email and not username. In my testing, every user that has a different username email to primary email this is a problem. Is there a snippet I can insert to capture this?
Share Improve this question asked Feb 2, 2022 at 5:46 MikeMike 1 3- Instead of trying to find a solution for a problem that shouldn't exist in the first place, why not allow email formats in nickname. How do you even have a nickname as a email, was that on purpose? – Buttered_Toast Commented Feb 2, 2022 at 7:15
- For context; our website distributes google datastudio dashboards. A user registers with a primary email that by default becomes their username. This is the email we would ordinarily contact them with. If it's not a google email then they can change the email (not username) to add a second email. This is also used for google apps SSO and synced to an external CRM. It's quite complex but this turned out to be the simplest way to join all the dots... except for this strange little issue. – Mike Commented Feb 2, 2022 at 9:48
- This website suggests it should simple move through each authentication method (username/password then email/password) active-directory-wp.com/docs/Technical_details/…. But that's not what is happening when username is an email. When username is not an email it works fine with login as username or email. – Mike Commented Feb 2, 2022 at 9:49
1 Answer
Reset to default 0The answer is this: to disable standard authentication by email and update username by first attempting to looking up email.
remove_filter( 'authenticate', 'wp_authenticate_email_password', 100 );
add_action('wp_authenticate','login_verification');
function login_verification($username) {
$username = sanitize_user( $username );
//check if this is an email
$user = get_user_by('email',$username);
if(!empty($user->user_login)) {
$username = $user->user_login;
}
//else just leave as username
return $username;
}