In order to remove a specific user role from the members directory, this can be achieved by adding such a code within the functions.php file:
function hide_users_from_directory( $ms = false, $object = false ) {
$excluded_user = implode( ',', get_users( 'role=administrator&fields=ID' ) );
if ( $object != 'members' && $object != 'friends' )
return $qs;
$args = wp_parse_args( $ms );
if( ! empty( $args['user_id'] ) )
return $ms;
if( ! empty( $args['exclude'] ) )
$args['exclude'] = $args['exclude'] . ',' . $excluded_user;
else
$args['exclude'] = $excluded_user;
$ms = build_query( $args );
return $ms;
}
add_action( 'bp_ajax_querystring', 'hide_users_from_directory', 20, 2 );
The above code hides administrator users from the members directory. You can specify any role you wish by altering the String “administrator” to any desired role such as “subscriber”.