Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Hide Subscriber Users from BuddyPress member Directory

View hide-subscribers.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
function bpdev_exclude_users($qs=false,$object=false){
//list of users to exclude
$excluded_user=join(',',bpdev_get_subscriber_user_ids());//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 for friends list etc?, do not exclude in this case
if(!empty($args['user_id']))
return $qs;
if(!empty($args['exclude']))
$args['exclude']=$args['exclude'].','.$excluded_user;
else
$args['exclude']=$excluded_user;
$qs=build_query($args);
return $qs;
}
function bpdev_get_subscriber_user_ids(){
$users=array();
$subscribers= get_users( array( 'role' => 'subscriber' ) );
if(!empty($subscribers)){
foreach((array)$subscribers as $subscriber)
$users[]=$subscriber->ID;
}
return $users;
}

You can replace the entire bpdev_get_subscriber_user_ids() function, with this single line of code:

$excluded_user = implode(',',get_users('role=subscriber&fields=ID'));

What if you wanted to hide Administrators as well as Subscribers?

I want to Hide Subscriber Users from BuddyPress member Directory. Where exactly should I create the hide-subscribers.php file, in which folder? I'm a novice at this so any details that you can provide to help me with this will be greatly appreciated. Thank you.

Please explain bit more i want hide the subscriber user role in buddypress member list, then i want to know how to use this hook code used in another plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.