让WordPress支持Email邮箱登录

将以下代码加入function.php即可:

// 修改WordPress用户名过滤机制,通过Email获取用户名登陆
function ludou_allow_email_login($username, $raw_username, $strict) {
 if (filter_var($raw_username, FILTER_VALIDATE_EMAIL)) {
 $user_data = get_user_by('email', $raw_username);
 if (empty($user_data))
 wp_die(__('<strong>ERROR</strong>: There is no user registered with that email address.'), '用户名不正确');
 else
 return $user_data->user_login;
 }
 else {
 return $username;
 }
}
if (strpos($_SERVER['REQUEST_URI'], '?action=register') === FALSE && strpos($_SERVER['REQUEST_URI'], '?action=lostpassword') === FALSE && strpos($_SERVER['REQUEST_URI'], '?action=rp') === FALSE ) {
 add_filter('sanitize_user', 'ludou_allow_email_login', 10, 3);
}

© 版权声明
THE END
請多多支持
点赞0
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情图片

    暂无评论内容