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);
}
?>
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