Skip to content

Instantly share code, notes, and snippets.

@Longkt
Last active September 28, 2018 03:47
Show Gist options
  • Save Longkt/cb44478cdc2c3acd58b799628e6b0769 to your computer and use it in GitHub Desktop.
Save Longkt/cb44478cdc2c3acd58b799628e6b0769 to your computer and use it in GitHub Desktop.
Filter user's role in member page buddypress
// https://buddydev.com/hiding-users-on-buddypress-based-site/
add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
function buddydev_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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment