I have been trying to enable the user login by email. I found at wordpress codex and some few blogs the way to write the following code in functions.php
add_action( 'wp_authenticate', 'wp_authenticate_by_email' );
function wp_authenticate_by_email( $username ) {
$user = get_user_by( 'email', $username );
if ( empty( $user ) ) {
return;
}
return $user->user_login;
}
But it does not work for me. I found it is remained as earlier.
I had a similar issue but got this to work:
function my_authenticate_by_email( $user, $username, $password ) {
//try to get user by email
$user = get_user_by( 'email', $username );
//validate we got a user.
if ($user && !is_wp_error($user))
{
//use normal auth
return wp_authenticate_username_password(null, $user->user_login, $password);
}
//continue to next filter, like normal.
return null;
}
add_filter( 'authenticate', 'my_authenticate_by_email', 0, 3);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.