Skip to content

Instantly share code, notes, and snippets.

@niksudan
Last active September 6, 2018 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksudan/77d4ee06c79fc16dc8efbb5acc2a4c4f to your computer and use it in GitHub Desktop.
Save niksudan/77d4ee06c79fc16dc8efbb5acc2a4c4f to your computer and use it in GitHub Desktop.
Disable WordPress author accounts from logging in
<?php
/**
* Disable author accounts from logging in
*/
function disable_author_login($user, $password)
{
if ($user) {
$roles = (array) $user->roles;
if ($roles[0] === 'author') {
return new WP_Error('disable_author_login', 'You do not have permission to log in');
}
}
return $user;
}
add_filter('wp_authenticate_user', 'disable_author_login', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment