Remove Adminstrator Hyperlink from a user having role to add and see users

I think something like this should work just fine:

function my_views_users($args) {
    $hidden_role="administrator";  // it will hide filter with role 'administrator' - you can change it to some other role

    $users_counts = count_users();
    $total_users = $users_counts['total_users'] - $users_counts['avail_roles'][$hidden_role];

    $args['all'] = "<a href="https://wordpress.stackexchange.com/questions/97309/$url"$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
    unset($args[$hidden_role]);
    return $args;
}
add_filter('views_users', 'my_views_users');

Of course you should add some if statement to disable this code, when user is logged in as admin (you don’t want to hide users from admin, I guess).

Leave a Comment