Last active
September 28, 2018 03:47
-
-
Save Longkt/cb44478cdc2c3acd58b799628e6b0769 to your computer and use it in GitHub Desktop.
Filter user's role in member page buddypress
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
// 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