Tagged: buddyboss, buddypress, PHP
This code snippet (https://buddydev.com/hiding-users-on-buddypress-based-site/) works great to hide users who have a specific role (among other roles), but is there a way to modify it so that ONLY users who have ONE role are hidden?
In other words, if we want to only hide users with the “subscriber” role, but still show users that have BOTH the “subscriber” role AND another role (e.g. “member”), how could we do this?
Alternatively, another option that would work for us is to hide all users, except for any user that has the “member” role (even if they also have other roles). If this is easier to do, could anyone help us with this code?
Hello Hastibe,
Thank you for posting. Try the following it will include only users with subscriber role.
/** * Exclude Users from BuddyPress Members List by WordPress role. * * @param array $args args. * * @return array */ function buddydev_include_users_by_role( $args ) { // do not exclude in admin. if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $included = isset( $args['include'] ) ? $args['include'] : array(); if ( ! is_array( $included ) ) { $included = explode( ',', $included ); } $role = 'subscriber';// change to the role to be include. $user_ids = get_users( array( 'role' => $role, 'fields' => 'ID', ) ); $included = array_merge( $included, $user_ids ); $args['include'] = $included; return $args; } add_filter( 'bp_after_has_members_parse_args', 'buddydev_include_users_by_role' );
Please let me know if is works or not.
Regrads
Ravi
You must be logged in to reply to this topic.