I am currently developing a social-network sort of site using Wordpress + Buddypress and the client has asked that profile pages not be publicly visible for the time being. Basically the client is okay with logged in users viewing their own profiles, but if they try viewing a profile page of another user it should redirect to the homepage.

I found the function: bp_is_my_profile() and tried using the following code at the top of the members/single/profile.php file to redirect users away, but it doesn't appear to be working. Any pointers?

if ( !bp_is_my_profile() )
    wp_redirect(site_url(), 302);

closed as off-topic by Pieter Goosen, kaiser Aug 4 '14 at 16:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Always exit(); after an redirect. – kaiser May 29 '12 at 8:41

I solved this issue myself, it was quite easy and I'm surprised nobody else supplied an answer. Having said that, the solution is to add a few lines of code that check what the author ID is of the profile you're viewing and compare it to the ID of the currently logged in user.

This code goes at the top of members/single/profile.php

    // 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)
    // redirect to home page url
  • how can we allow users to view other users posts under custom profile menu in Buddypress? When I try to view other usres posts it redirects me to home page. Please check this... thanks stackoverflow.com/q/44242507/1416821 – yadavr May 29 '17 at 14:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.