I'm working on a setup where user logins have to follow this format :
login : user-john@doe.com
Even though Wordpress has no problem creating such accounts, it seems they don't play well with the "Forgotten password" form :
The culprit is in wp-login.php
:
function retrieve_password() {
$errors = new WP_Error();
if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) {
$errors->add( 'empty_username', __( '<strong>ERROR</strong>: Enter a username or email address.' ) );
} elseif ( strpos( $_POST['user_login'], '@' ) ) {
$user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) );
if ( empty( $user_data ) ) {
$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: There is no account with that username or email address.' ) );
}
} else {
$login = trim( $_POST['user_login'] );
$user_data = get_user_by( 'login', $login );
}
Specifically this line :
} elseif ( strpos( $_POST['user_login'], '@' ) ) {
When Wordpress finds a @ in the login, it thinks that it's actually the email.
Is there a way to get around this without having to modifiy this core file ?
The two constraints I have is I cannot change the login format and the user has to submit his login (password reset calling the email field is not allowed, for reasons irrelevant to this tread)