I have two roles called Agent and Subagent. I want to hide these two specific roles from the admin user list.
I tried using the pre_user_query filter but couldn't get it to work.
Could anyone please suggest a correct way to do it?
Thanks,
I have two roles called Agent and Subagent. I want to hide these two specific roles from the admin user list.
I tried using the pre_user_query filter but couldn't get it to work.
Could anyone please suggest a correct way to do it?
Thanks,
 On
                        
                            
                        
                        
                            On
                            
                                                    
                    
                Simpler & safer:
add_filter('pre_get_users', function ($user_query) {
  // use the sluglike role names, not their "display_name"s 
  $user_query->set('role__not_in', ['agent', 'subagent']);
});
role__not_in available since WP 4.4.
Caveat: the roles (and their user count) will still show up above the users table.
I found the perfect solution for what I wanted here: https://rudrastyh.com/wordpress/pre_user_query.html