Skip to content

Instantly share code, notes, and snippets.

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 = [
// 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);
Copy link

Nice one! Thanks for sharing.

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