在 WordPress 管理仪表板上的用户列表中隐藏具有特定角色的用户

Rak*_*ati 4 wordpress wordpress-admin

我有两个角色,称为代理和子代理。我想从管理员用户列表中隐藏这两个特定角色。

我尝试使用pre_user_query过滤器但无法使其工作。

有人可以建议正确的方法吗?

谢谢,

kub*_*ubi 6

更简单、更安全:

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']);
});
Run Code Online (Sandbox Code Playgroud)

role__not_in自 WP 4.4 起可用。

注意:角色(及其用户数量)仍将显示在用户表上方。