How to Add Profile Privacy to BuddyPress

Privacy controls are critical to any successful social network. Right now there are roughly zero plugin options for adding privacy to BuddyPress 1.5+. Some basic privacy controls are in discussion for future versions of BuddyPress, but there aren’t any usable options yet. Here’s a trick that may tide you over in the meantime.

Restrict User Profiles Based on Friendship

This is a hack that I drudged up from the BuddyPress forums, a solution originally proposed by our very own Richie_KS. It basically checks to see if users are friends before displaying a profile. Here’s how to use it:

1. Add this to your theme’s functions.php file:

// ------- Check if member is a friend  ------------- //

function bp_displayed_user_is_friend() {
global $bp;
if ( bp_is_profile_component() || bp_is_member() ) {
if ( ('is_friend' != BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $bp->displayed_user->id )) && (bp_loggedin_user_id() != bp_displayed_user_id()) )
if ( !is_super_admin( bp_loggedin_user_id() ) )

return true;
}
}

2. Create a non-friend template file:

Essentially that will look something like this, with your own edits, of course:

1
2
3
4
5
<div id="not_friend_message">

You must be friends in order to access users' profiles.

</div>

Name it “not-friend.php” and it in your BuddyPress theme folder at: /members/single/

3. Edit your theme file to include the friendship check:
To restrict profile info, open up /members/single/profile.php and add this at the top of the page:

1
2
3
4
5
<?php if ( bp_displayed_user_is_friend() ) : ?>

<?php locate_template( array( 'members/single/not-friend.php' ), true ) ?>

<?php else : ?>

Then you’ll need to add this at the bottom of the page:

1
<?php endif; ?>

Here’s what it will look like with the code in place:

The downside of this is that it doesn’t allow users to set their own privacy levels. However, I do like that it is a simple solution that can be implemented on the theme-level, without having to save anything new to the database. It’s by no means a full privacy solution, but I hope this tutorial helps those of you in a pinch who need some basic profile privacy in place.

Tags

Comments (8)

  1. I wish to have a system in place at my BuddyPress website where for example:

    Level 1 members can see and maintain their own profiles only. (NO ACCESS TO OTHERS PROFILES, they can access entire pages and posts but not other members’ profiles)

    Level 2 members can see others profiles too.

    (I may use s2member for levels but it doesn’t provide any function like above)

    Any idea to achieve the above.

    Thank you very much

Participate