Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wbcomdev/e6726f8607dd1cc7b5ea2f5cc162befd to your computer and use it in GitHub Desktop.

Select an option

Save wbcomdev/e6726f8607dd1cc7b5ea2f5cc162befd to your computer and use it in GitHub Desktop.
<?php
/**
* Hide Users from BuddyPress Members List by User role.
*
* @param array $args Args.
*
* @return array
*/
function wbcom_hide_members_from_member_lists_by_user_role( $args ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return $args;
}
$excluded = isset( $args['exclude'] ) ? $args['exclude'] : array();
if ( ! is_array( $excluded ) ) {
$excluded = explode( ',', $excluded );
}
$role = 'administrator';
$user_ids = get_users(
array(
'role' => $role,
'fields' => 'ID',
)
);
$excluded = array_merge( $excluded, $user_ids );
$args['exclude'] = $excluded;
return $args;
}
add_filter( 'bp_after_has_members_parse_args', 'wbcom_hide_members_from_member_lists_by_user_role' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment