像这样的东西应该可以工作,但我没有测试它:
function o99_my_email_login($user, $pass) {
global $wpdb;
if (is_email($user)) {
$found = $wpdb->get_var($wpdb->prepare("SELECT user_login FROM $wpdb->users WHERE user_email = '%s'", $user));
$user = $found ? $found : $user;
} else {
$user = 1; // or $username = 1; ??
}
return;
}
add_action('wp_authenticate', 'o99_my_email_login', 10, 2);
这个类似的功能也有效,但我不确定它的安全性..
add_action('wp_authenticate','o99_smsa_allow_email_login');
function o99_smsa_allow_email_login($username) {
$user = get_user_by_email($username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
或者只使用像这样的现成插件:点击