Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Privacy

@ouegy

Participant

@rosyteddy Here is the final code which goes in functions.php

add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);

function bpdev_exclude_users($qs=false,$object=false){
 //list of users to exclude

global $wpdb;

$currentuser_id = get_current_user_id();

$sql= "SELECT friend_user_id  FROM wp_bp_friends WHERE initiator_user_id='".$currentuser_id."' AND is_confirmed = 1";
$friendsid = $wpdb->get_results($sql);
$friendsarray = array();
foreach($friendsid as $oneitem){
    $friendsarray[]=$oneitem->friend_user_id;
}
// $friends =implode(", ",$friendsarray);
// echo $friends;

$ffidarray =array();
 
foreach ( $friendsid as $row )
{
$sql1= "SELECT friend_user_id  FROM wp_bp_friends WHERE initiator_user_id='".$row->friend_user_id."' AND is_confirmed = 1";
$ffid = $wpdb->get_results($sql1);
//print_r($ffid);
foreach($ffid as $oneitem){
    $ffidarray[]=$oneitem->friend_user_id;
}
}
// $fof =implode(", ",$ffidarray);
// echo $fof;

$sql2= "SELECT user_id FROM wp_bp_xprofile_data";
$users = $wpdb->get_results($sql2);
//print_r($users);

$result = array_merge($friendsarray, $ffidarray);
//echo $result;

$usersarray =array();
foreach($users as $oneitem){
    $usersarray[]=$oneitem->user_id;
} 

$resultarray =array();
foreach($result as $oneitem){
    $resultarray[]=$oneitem->friend_user_id;
} 

$excluded_user = array_diff($usersarray , $resultarray);
$excluded_user =implode(", ",$excluded_user); //comma separated ids of users whom you want to exclude
 
 if($object!='members')//hide for members only
 return $qs;
 
 $args=wp_parse_args($qs);
 
 //check if we are searching  or we are listing friends?, do not exclude in this case
 if(!empty($args['user_id'])||!empty($args['search_terms']))
 return $qs;
 
 if(!empty($args['exclude']))
 $args['exclude']=$args['exclude'].','.$excluded_user;
 else
 $args['exclude']=$excluded_user;
 
 $qs=build_query($args);
 
 return $qs;
 
}

Seems to be working but feel free to test further!

Skip to toolbar