[英]login with username or email in wordpress
I am working on login template...but I want to make login with username as well as email .I got code with for that but it is not worked,it is as follow: 我正在使用登录模板...但是我想使用用户名以及电子邮件进行登录。我得到了用于此的代码,但是它不起作用,如下所示:
function login_with_email_address($username) {
$user = get_user_by('email',$username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address',10,1);
I already put action in ' authenticate ' for email verification,it is as follow: 我已经在“ 身份验证 ”中添加了用于电子邮件验证的操作,如下所示:
function check_user_status($user, $username, $password) {
if (in_array( 'subscriber', (array) $user->roles ) ) {
if (get_user_meta($user->ID, 'confirm_mail', true) == 1) { return $user; }
else{ return new WP_Error('Account Not Active.'); }
}
else{ return $user; }
}
add_filter('authenticate','check_user_status', 30, 3);
Try this 尝试这个
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
add_filter( 'authenticate', 'tcb_authenticate_username_password', 20, 3 );
function tcb_authenticate_username_password( $user, $username, $password ) {
if ( ! empty( $username ) && is_email( $username ) ) :
if ( $user = get_user_by_email( $username ) )
$username = $user->user_login;
endif;
return wp_authenticate_username_password( null, $username, $password );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.