wordpress 修改为email或用户名登陆后台系统
打开当前模板下的function.php 增加如下代码
// 修改WordPress用户名过滤机制,通过Email获取用户名 function ludou_allow_email_login($username, $raw_username, $strict) { if (filter_var($raw_username, FILTER_VALIDATE_EMAIL)) { $username = get_user_by('email', $raw_username)->user_login; } else { return $username; } return sanitize_user($username, $strict); } // 修改登录界面的文字,"用户名"改成"用户名或邮箱" function ludou_change_text() { echo '<script type="text/javascript"> var user_login_node = document.getElementById("user_login"); var old_username_text = user_login_node.parentNode.innerHTML; user_login_node.parentNode.innerHTML = old_username_text.replace(/用户名/, "用户名或邮箱"); </script>'; } if (in_array($GLOBALS['pagenow'], array('wp-login.php')) && 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); add_action('login_footer', 'ludou_change_text'); } |