Created
March 10, 2014 15:44
-
-
Save dsebao/9467474 to your computer and use it in GitHub Desktop.
Use email instead of loginname in WP
This file contains 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 | |
/* | |
* | |
* | |
* Usar mails para el login en vez de usuarios | |
* | |
* | |
*/ | |
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); | |
add_filter( 'authenticate', 'fb_authenticate_username_password', 20, 3 ); | |
function fb_authenticate_username_password( $user, $username, $password ) { | |
// If an email address is entered in the username box, | |
// then look up the matching username and authenticate as per normal, using that. | |
if ( ! empty( $username ) ) | |
$user = get_user_by( 'email', $username ); | |
if ( isset( $user->user_login, $user ) ) | |
$username = $user->user_login; | |
// using the username found when looking up via email | |
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