How can I prevent a Subscriber to login?

I want to prevent the user role.

  • 2
    The question would why do you allow subscribers to register if you don't want them to be able to log in? – butlerblog Mar 22 at 10:48

The authenticate filter hook is used to perform additional validation/authentication any time a user logs in to WordPress.

add_filter('authenticate', 'check_login', 100, 3);
function check_login($user, $username, $password) {
      if ( isset( $user->roles ) && is_array( $user->roles ) ) {
          // Check if user is a subscriber then stop login
          if (in_array( 'subscriber', $user->roles) {
               return null;

    return $user;

I hope this may help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.