PHP
// Remove the default username label and set it to Email
add_filter('gettext', 'force_email_login_label');
function force_email_login_label($translated_text) {
if ($translated_text == 'Username or Email Address') {
return 'Email Address';
}
return $translated_text;
}
// Force authentication using the email only
add_filter('authenticate', 'force_email_login', 20, 3);
function force_email_login($user, $email, $password) {
if (!empty($email) && is_email($email)) {
$user = get_user_by('email', $email);
if (isset($user, $user->user_login, $user->user_status)) {
if (0 == (int) $user->user_status) {
$email = $user->user_login;
}
}
} else {
// If it's not an email, remove the ability to login using the username.
$user = null;
}
return wp_authenticate_username_password(null, $email, $password);
}