Created
August 23, 2014 21:15
-
-
Save noahbass/37c47023248b84ba4443 to your computer and use it in GitHub Desktop.
Use the users email address to login in wordpress.
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 | |
/* Use the users email address to login */ | |
add_filter('authenticate', 'bainternet_allow_email_login', 20, 3); | |
/** | |
* bainternet_allow_email_login 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 | |
*/ | |
function bainternet_allow_email_login( $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 ); | |
} | |
add_filter( 'gettext', 'addEmailToLogin', 20, 3 ); | |
/** | |
* addEmailToLogin function to add email address to the username label | |
* @param string $translated_text translated text | |
* @param string $text original text | |
* @param string $domain text domain | |
*/ | |
function addEmailToLogin( $translated_text, $text, $domain ) { | |
if ( "Username" == $translated_text ) | |
$translated_text .= __( ' or Email Address'); | |
return $translated_text; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment