Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created February 29, 2024 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/32109282032930a75e46256216fb968e to your computer and use it in GitHub Desktop.
Save KaineLabs/32109282032930a75e46256216fb968e to your computer and use it in GitHub Desktop.
BuddyPress - Youzify Exclude Multiple Roles from Members Directory
<?php
// BuddyPress - Youzify Exclude Multiple Roles from Members Directory
function yzc_exclude_users( $args ) {
$excluded = isset( $args['exclude'] )? $args['exclude'] : array();
if( !is_array( $excluded ) ) {
$excluded = explode(',', $excluded );
}
$user_roles = array( 'administrator', 'subscriber' );
$users = get_users( array( 'role__in' => $user_roles, 'fields' => array( 'ID' ) ) );
$users_ids = wp_list_pluck( $users, 'ID' );
$excluded = array_merge( $excluded, $users_ids );
$args['exclude'] = $excluded;
return $args;
}
add_filter( 'bp_after_has_members_parse_args', 'yzc_exclude_users' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment