Hide Logged In Users from all the listings( directory, search, members, friends list, widgets etc ) on BuddyPress Site
Do you want to hide the logged in users from all the listing on your BuddyPress site? Mihail asked me about it in a comment and I thought It is an interesting Idea.
The code below will hide the logged in users from
- Members Directory
- Other Users Friends List( when the logged in user is viewing it )
- Members search
- Group Members Listing
- All the widgets( Who is online, Recently active members etc).
Please put the following code into bp-custom.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //filter on pre_user_query add_action( 'pre_user_query', 'devb_exclude_loggedin_user', 201 ); function devb_exclude_loggedin_user( $query ) { //don't modify the query if the user is not logged in if ( !is_user_logged_in() ) return; //do not hide users inside the admin if ( is_admin() && !defined('DOING_AJAX') ) return; $qv = $query->query_vars; global $wpdb; //hide $query->query_where .= $wpdb->prepare(" AND {$wpdb->users}.ID !=%d ", get_current_user_id()); } |
That's it. Loging to your site and see if you are visible or not? Let me know in comments if you liked it, whether it worked for you or not ?
BRAVO! Super fast!
I've put it in theme functions.php and it works like charm!
I believe people would use it a lot as a plugin …
Thank you!!!
(Only thing that is still to fix is the "count" in the members tabs. It counts the current user "me" as member also)
Cheers!
Hi Mihail,
Thank you.
I left the count intentionally as It will cause issues with my other plugins like BP Limit Group Membership and BP Limit Groups Per User. Will put a plugin today..
Thank you
Brajesh
Hi @sbrajesh,
Thanks for this great tips as usual, but what of if you just want to hide the current member that is viewing the members directory from the directory alone and not the rest?
Currently BP will display you first in members directory if you are viewing it.
It seems the support has improved greatly on this site so I will renew my membership soon.
Thanks
Naijaping
Hi Abbey,
Thank you for the comment. We are certainly improving 🙂
Here is the code you can use to hide the logged in user from directory only
https://gist.github.com/sbrajesh/11038074
Hope that helps
Thanks
Brajesh
@sbrajesh,
just what i needed but it make the person unsearchable which may be a little problem.
regards
Hi Abbey,
I have updated the gist to not hide users on search. Please check it here https://gist.github.com/sbrajesh/11038074
Hi abbey,
Sine we both are implementing similar members listing behavior, can you please explain me the benefits of being able to search for myself? or as you mentioned, what could be the "little problem" if a logged in user becomes unsearchable?
Thank you.
Cheers!
Hi Brajesh,
Is there a way to include in this code to hide specific user or specific role from specific listings (or all listings)?
For example I don't want site-admin to be listed anywhere except in fiends or following (bp-follow plugin)…
Thanks!
Hii
How to approve
user profile image by admin