Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Whitelist the usernames that can login to a ClassicPress site.
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);
@devsrealm

This comment has been minimized.

Copy link

@devsrealm devsrealm commented Mar 8, 2020

Nice one! Thanks for sharing.

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