将以下代码加入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
暂无评论内容