How to remove “Super Admin” from All Users for those that are not a “Super Admin”?

I would like to remove the filter at the top that says “Super Admin” for users that are not a “Super Admin”. How do I go about doing this?

This screenshot shows what I am talking about:
enter image description here

Related posts

Leave a Reply

1 comment

  1. This list of filters at the top of admin screens are called Views. You can manage views using the views_{$this->screen->id} filter. Where you’d replace {$this->screen->id} with the name of the screen you’d like to manage.

    In order to filter the Users screen, you can try the following:

    // filter the 'users' views
    add_filter( "views_users", "wse57231_filter_user_views");
    
    function wse57231_filter_user_views($views){
      // This assumes the key for the role is 'super_admin'
      // Is the current user not a "super_admin"?
    
      if( !current_user_can('super_admin')){
        // Remove the super_admin view from the list of views
        unset($views['super_admin']);
      }
    
      return $views;
    }
    

    References:
    * https://developer.wordpress.org/reference/hooks/views_this-screen-id/
    * http://codex.wordpress.org/Function_Reference/current_user_can

    Note: Based on the comments, it sounds like Super Admin is a custom role you’ve created. This is partially confusing because Super Admin is also the name of a special role when using WordPress Multisite.