Created
November 6, 2021 19:45
-
-
Save vkartk/82962e2efe02052a9d8d0e1828c55615 to your computer and use it in GitHub Desktop.
Exclude Users from BuddyPress Members List by WordPress role. ( BuddyPress / BuddyBoss )
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
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