Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

<?php
if ( !bp_is_my_profile() )
{
    wp_redirect(site_url(), 302);
}
?>
share|improve this question
    
Always exit(); after an redirect. –  kaiser May 29 '12 at 8:41
add comment

1 Answer

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

<?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
        wp_redirect(home_url());
        exit();
    }
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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