Wordpress更改认证从用户名到电子邮件


Wordpress change Autentication From username to email

如何或在哪里我必须编辑wordpress使用户认证与电子邮件,而不是与用户名(因为它是默认的)

这应该可以工作,将其添加到functions.php文件中:

// remove the default filter
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
// add custom filter
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 );
}

(上面是在这里找到的,我测试了它,并为我工作)

编辑:如果你不想修改函数文件,这个插件也可以工作。

相关文章: