Skip to content

Instantly share code, notes, and snippets.

@vkartk
Created November 6, 2021 19:45
Show Gist options
  • Save vkartk/82962e2efe02052a9d8d0e1828c55615 to your computer and use it in GitHub Desktop.
Save vkartk/82962e2efe02052a9d8d0e1828c55615 to your computer and use it in GitHub Desktop.
Exclude Users from BuddyPress Members List by WordPress role. ( BuddyPress / BuddyBoss )
function buddy_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' => $role, 'fields' => 'ID' ) );
$excluded = array_merge( $excluded, $user_ids );
$args['exclude'] = $excluded;
return $args;
}
add_filter( 'bp_after_has_members_parse_args', 'buddy_exclude_users_by_role' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment