Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created May 29, 2013 18:31
Show Gist options
  • Save strangerstudios/5672579 to your computer and use it in GitHub Desktop.
Save strangerstudios/5672579 to your computer and use it in GitHub Desktop.
Keep users with no role from viewing a WordPress site.
/*
Keep users with no role from viewing the site.
From the WP dashboard, go to Users to find the user,
then edit the user and change role to "no role for this site".
*/
function my_no_role_lockout()
{
if(is_user_logged_in())
{
global $current_user;
if(empty($current_user->roles))
{
//log them out
wp_logout();
//show an error
die("Your account has been banned from using this site.");
}
}
}
add_action("init", "my_no_role_lockout", 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment