Is there a way to remove the “Filter user list” from the top of the “All Users” screen for non-admins?

For clarification its the section which lists totals for each user role type and filters the table when clicked eg:

All (5) | Administrator (1) | Editor (3) | Subscriber (1)

1 Answer
1

You can use the views_users filter to alter it. Here’s an example:

/**
 * Remove the users view
 */
add_filter( 'views_users', '__return_empty_array' );

if you want to remove it for every user.

Here’s another example how you could remove it for non-admins (PHP 5.4+):

/**
 * Remove the users view for non-admins
 */
add_filter( 'views_users', function( $views ) 
{
    return current_user_can( 'manage_options' ) ? $views : [];
} );

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *