BuddyPress Fun: Playing with BuddyPress Friends List Visibility

Are you ready for another BuddyPress trick ? Well, today, we will be playing with the visibility of friends list on BuddyPress based sites. I got some time yesterday to play with the friend list visibility and I am sure some of you will find it helpful.

The goal of this tutorial is to control who can see a user's friend list on BuddyPress based site.

I will be covering 3 appraoches ( from the most extreme to easy and flexible ).

Approach 1:- Only a user can view His/Her friends list

Now, this is the most extreme way to implement it I guess. All we do here is just deregister the nav for friends component as shown below.

When the logged in user is super admin or He/she is viewing their own profile, we don't remove the nav, otherwise we remove the nav.

Though it works, For me, It seems the extremes. So, Let us forget it and move to our next spproach.

Approach 2:  Filter on bp_ajax_querystring to hide the friends from listing

In the code below, we will only show the friends list if it is user's own profile or the user is logged in as site admin.

Now, the code above hides the friends list from everyone except the user and the super admins.

So, how about adding a little more flexibility and allowing the friends of a user to view his/her friend list? Ok, That's not difficult, all we need to do is change the above code and add a check for friendship as shown below.

The above code allow users, site admins and friends of the user to view their friend list but non friends and non logged in users won't be able to see the friend list.

Please note, you will need only one of the above three code snippets. Put it in your bp-custom.php and you may want to wait for my next tip tomorrow 🙂

13 Responses to BuddyPress Fun: Playing with BuddyPress Friends List Visibility

  • How to hide myself from members lists?
    In Members and in Single Group>members, also in Single Member>friends..


    • Hi Mihail,
      Please look at our BuddyPress profile visibility plugin. That allows you to hide from everywhere.

      • Hi Brajesh,

        I know about that plugin, however I don't want to hide myself from members listing, but hide myself from ME.
        Seeing myself on lists as member or somebodies friend makes no sense to me…

        Thank you.

  • Can you modify Approach 2 to protect any other tabs content create by other plugins. I like this approach because still left navigation intact but show "Sorry, no members were found."

    Maybe could change "Sorry, no content were found." if that tab access from not own profile, change from what I do now that redirect them to homepage