Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Profile fields visible to admin and the logged in user only

@mossyoak

Participant

I mis-read your question sorry. I found a solution which lets users only view other users profiles if they are a friend of that user. The admin can see all members regardless of them being his/her friend.

I put the function in my functions.php:

 // BuddyPress create conditional if friend
function flatportal_bp_is_friend() {
global $bp;

if (friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() )  )
return true;

return false;
}

and created a custom header file with this at the top:

// Global $bp variable holds all of our info

global $bp;
// The user ID of the currently logged in user
$current_user_id = (int) trim($bp->loggedin_user->id);
// The author that we are currently viewing
$author_id  = (int) trim($bp->displayed_user->id);
if ($current_user_id !== $author_id && !current_user_can('delete_others_pages') && !flatportal_bp_is_friend() )
{
wp_redirect( home_url() );
exit();
}

Then in header php (using multiple headers)

elseif ( bp_is_user()):
get_header('restrict-profile');

If they are not a friend they will be redirected to the home page or wherever you want them. I suppose you could re-direct them to a “you are not a friend of this user” page if you wanted.

Skip to toolbar