WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);
share|improve this question

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
up vote 0 down vote accepted

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
share|improve this answer

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