It seems to be more and more common to see sites that allow users to log in with their username or email address.
Here’s how to add that ability to WordPress
//remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
add_filter('authenticate', 'wp_authenticate_username_password_redux', 20, 3);
function wp_authenticate_username_password_redux( $user, $username, $password ) {
if ( is_email( $username ) ) {
$user_obj = get_user_by_email( $username );
if ( $user_obj ) $username = $user_obj->user_login;
}
return wp_authenticate_username_password( $user, $username, $password );
}
* works with or without the remove_filter line.
Still valid @2015, but you should update the call to ‘get_user_by_email()’ as this function has been deprecated. Use get_user_by(’email’, $username ) instead.
The whole line should read:
$user_obj = get_user_by( 'email', $username );Nice piece of code.
Thank you for publishing it.