Skip to content

Instantly share code, notes, and snippets.

@dartiss
Last active June 5, 2024 16:22
Show Gist options
  • Save dartiss/9a7fda927ebf7ecc56884b4bb8871d4a to your computer and use it in GitHub Desktop.
Save dartiss/9a7fda927ebf7ecc56884b4bb8871d4a to your computer and use it in GitHub Desktop.
Disable Email Login for WP-Admin
<?php
remove_filter( 'authenticate', 'wp_authenticate_email_password', 20 );
/**
* Disable logging in via email
*
* Check for and serve an appropriate response to users attempting to sign in with email.
*
* @param string $user If the user is authenticated.
* @param string $username Username or email address.
* @return string Authentication details
*/
function disable_email_login( $user, $username ) {
if ( ! empty( $username ) && filter_var( $username, FILTER_VALIDATE_EMAIL ) ) {
return new WP_Error( 'email_login_disabled', __( 'Logging in with email is disabled.', 'text-domain' ) );
}
return $user;
}
add_filter( 'authenticate', 'disable_email_login', 20, 3 );
?>
@dartiss
Copy link
Author

dartiss commented Jun 3, 2024

Script created by my colleague @f0rthelulz, for a WordPress VIP customer.

Can be added to functions.php and will then prevent an email address from being used to login - usernames only can be used. Just change text-domain to, well, your text domain for the error translation to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment