Disable wp-admin console for subscribers

I do not want the users (role: subscriber) to be able to login via the wp-admin.

How would you suggest I do this ?

Related posts

Leave a Reply

1 comment

  1. You can remove the Read capability. That will prevent all access to wp-admin.

    function remove_read_wpse_93843(){  
        $role = get_role( 'subscriber' );
        $role->remove_cap( 'read' );    
    }
    add_action( 'admin_init', 'remove_read_wpse_93843' );
    

    See the note in the Codex about only needing to run this once.

    Then you need to hide the admin bar.

    function hide_admin_wpse_93843() {
      if (current_user_can('subscriber')) {
        add_filter('show_admin_bar','__return_false');
      }
    }
    add_action('wp_head','hide_admin_wpse_93843');
    

    And probably want to redirect subscriber logins:

    function redirect_sub_to_home_wpse_93843( $redirect_to, $request, $user ) {
        if ( isset($user->roles) && is_array( $user->roles ) ) {
          if ( in_array( 'subscriber', $user->roles ) ) {
              return home_url( );
          }   
        }
        return $redirect_to;
    }
    add_filter( 'login_redirect', 'redirect_sub_to_home_wpse_93843', 10, 3 );
    

    Other attempts to access wp-admin will result in the “You do not have sufficient permissions…” almost-white screen.

    That is somewhat bare-bones but I think it gets you there.