Hi, sorry I don’t know the answer but I’m following this as I have the same issue. Thanks, Matt.
Thread Starter
Dandy
(@dandyjefferson)
Hi, @mattrea
I found this solution from someplace else (thanks for Buddydev.com) and it worked perfectly for me. So I shared it here and hope it will probably solve your issue as well.
/**
* Limit BP profile search plugin to user who are members of the current user's group
* @param $users
*
* @return array
*/
function buddydev_limit_users_search_to_group_members( $users ) {
// Do not check for non logged in or the site admin.
if ( ! is_user_logged_in() || is_super_admin() ) {
return $users;
}
$logged_id = get_current_user_id();
$groups = groups_get_user_groups( $logged_id );
// If the user does not belong to any group, the result should be empty.
if ( empty( $groups['groups'] ) ) {
//this user does not belong to any group
$users = array();//array( 0, 0 ); // Limit to invalid user.
return $users;
}
// if we are here, the user has some groups, let us find out the members of those groups.
global $wpdb;
$bp = buddypress();
$list = '(' . join( ',', $groups['groups'] ) . ')';
$member_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id IN {$list} AND is_confirmed = 1 AND is_banned = 0 AND user_id != %d",$logged_id ) );
if ( ! empty( $member_ids ) ) {
$users = array_intersect( $users, $member_ids ); // set intersection.
} else {
$users = array();
}
return $users;
}
add_filter( 'bps_filter_members', 'buddydev_limit_users_search_to_group_members' );
You can put it in your bp-custom.php file.
This code snippet is provided from BuddyDev.com. I just copied and pasted here as it worked for me.
Hope you have a good day!
-
This reply was modified 9 years, 1 month ago by
Dandy.
Hi @dandyjefferson and @mattrea,
Sorry I wasn’t able to reply earlier, and thank you Dandy for sharing the solution you found!
Thread Starter
Dandy
(@dandyjefferson)
Hi, @dontdream
No problem. Just hope it will help @mattrea as well.
Have a good day!