Stop people logging in with a username, so only an email address and password work on the login form.
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20 );
add_filter( 'gettext', function ( string $translation, string $text, string $domain ): string {
if ( 'default' === $domain && 'Username or Email Address' === $text ) {
return 'Email Address';
}
return $translation;
}, 10, 3 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Usernames are often easy to guess, and people forget which one they picked. Logging in with an email address is simpler for users and gives attackers one less thing to try. This snippet allows email logins only.
WordPress checks logins through the authenticate filter. Two checks are attached to it: one for usernames and one for email addresses. Removing wp_authenticate_username_password leaves only the email check.
The gettext filter changes the form label from “Username or Email Address” to “Email Address”, so people know what to type.
authenticate and aren’t affected.Log out, then try to log in with your username. It should fail. Logging in with your email should work.