Created
March 5, 2015 07:49
-
-
Save qutek/462792ee0e43b16bca47 to your computer and use it in GitHub Desktop.
[Wordpress] Allow user login with email
This file contains hidden or 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 | |
/** | |
* login_with_email filter to the authenticate filter hook, to fetch a username based on entered email | |
* @param obj $user | |
* @param string $username [description] | |
* @param string $password [description] | |
* @return boolean | |
*/ | |
add_filter('authenticate', 'login_with_email', 20, 3); | |
function login_with_email( $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