Let Editors See the Users List (Read-Only)
Lets editors open the Users screen to look people up, without being able to add, edit, promote or delete anyone.
Opens WPIDE on
Code
// Roles that may view the Users list.
$wpide_list_users_roles = array( 'editor' );
add_filter( 'user_has_cap', function ( $allcaps, $caps, $args, $user ) use ( $wpide_list_users_roles ) {
if ( in_array( 'list_users', $caps, true ) && array_intersect( $wpide_list_users_roles, (array) $user->roles ) ) {
$allcaps['list_users'] = true;
}
return $allcaps;
}, 10, 4 );
Notes
Grants only the list_users capability, in memory; turning the snippet off removes it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.