Created
March 8, 2020 23:22
-
-
Save johnalarcon/c3a2f0672fb8a5ba89f148738286df20 to your computer and use it in GitHub Desktop.
Whitelist the usernames that can login to a ClassicPress site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function codepotent_disable_rogue_logins($user, $username, $pass) { | |
// An array of usernames allowed to login. | |
$allowed_usernames = [ | |
'coolChick582', | |
'geekdude1', | |
'some_other_username' | |
]; | |
// Not an allowed username? Fail the login. | |
if (!in_array($username, $allowed_usernames, true)) { | |
remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3); | |
return null; | |
} | |
// Login ok to proceed. | |
return $user; | |
} | |
add_filter('authenticate', 'codepotent_disable_rogue_logins', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one! Thanks for sharing.