Created
February 29, 2024 10:22
-
-
Save KaineLabs/32109282032930a75e46256216fb968e to your computer and use it in GitHub Desktop.
BuddyPress - Youzify Exclude Multiple Roles from Members Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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