Got the code from this Q&A, Remove Ability for Other Users to View Administrator in User List?.
You will need to tweak it a bit to adapt to your roles and capabilities, much probably changing the meta_key
and meta_value
values. I've added the check for $pagenow
just to be sure this will only fire in /wp-admin/users.php
.
add_action( 'pre_user_query', 'filter_users_wpse_10742' );
function filter_users_wpse_10742( $user_search )
{
global $pagenow;
if( 'users.php' != $pagenow)
return;
$user = wp_get_current_user();
if ( $user->roles[0] != 'administrator' )
{
global $wpdb;
$user_search->query_where =
str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}user_level'
AND {$wpdb->usermeta}.meta_value != 10)",
$user_search->query_where
);
}
}