Update: we have found that with a multisite with multiblog enabled to share the member list from the parent across all the child sites, code to filter out roles such as “administrator” only work if that user is also added to the child site.
Example:
Does not work in this scenario:
– parent site setup with user “johnadmin” with admin role is hidden on parent site directory
– child site without this user created does not hide him from the site directory
Works in this scenario:
– parent site setup with user “johnadmin” with admin role is hidden on parent site directory
– child site ALSO setup with user “johnadmin” with admin role is hidden on child site directory
For anyone wondering, the code that is partially working for us is below found at buddydev.com. This code has been added to the functions.php in the child site so that we can control what the child site loop shows individually. (example: parent shows everyone, child 1 shows only subscribers, child 2 only shows x, child 3 only shows y, etc.)
Would super appreciate any suggestions thx!
add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
function buddydev_exclude_users_by_role( $args ) {
//do not exclude in admin
if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return $args;
}
$excluded = isset( $args['exclude'] )? $args['exclude'] : array();
if( !is_array( $excluded ) ) {
$excluded = explode(',', $excluded );
}
//$role = 'administrator';//change to the role to be excluded
$user_ids = get_users( array( 'role__in' => ['administrator' , 'contributor' , 'author', 'editor'] ,'fields'=>'ID') );
$excluded = array_merge( $excluded, $user_ids );
$args['exclude'] = $excluded;
return $args;
}