Close down your site for logged-in members only

This code snippet will make most Buddypress pages viewable to members only. The exceptions being the registration and activation pages. And also blog pages are viewable to unregistered users. Unregistered users trying to access members only pages will be redirected to the front page.

Place the function below into functions.php in your theme folder:

function sh_walled_garden()
{
global $bp;
if ( bp_is_register_page() || bp_is_activation_page() )
return;
if( ! bp_is_blog_page() && ! is_user_logged_in() )
bp_core_redirect( $bp->root_domain .\'/\'. BP_REGISTER_SLUG );
}
add_action( \'walled_garden\', \'sh_walled_garden\' );

Add this to your functions.php or bp-custom.php file
Script courtesy of Traveljunkie.

BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

5 Responses to Close down your site for logged-in members only

  1. Rafael Pires January 3, 2011 at 12:21 pm #

    The code is not fineshed.

    What the end for the last line.

    “and this right on top of header.php (before the …..”

    TKS

  2. bowe January 7, 2011 at 1:40 pm #

    Hi Rafael,

    It has been fixed. it should work now!

    • Lore July 23, 2011 at 3:25 pm #

      And to think I was going to talk to someone in poresn about this.

  3. leewilloughby April 23, 2013 at 7:51 pm #

    This is what I came up with:

    place the function below into functions.php in your THEME folder.

    function sh_walled_garden()

    {

    global $bp;

    if ( bp_is_register_page() || bp_is_activation_page() )

    return;

    if( ! bp_is_blog_page() && ! is_user_logged_in() )

    bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );

    }

    add_action( ‘walled_garden’, ‘sh_walled_garden’ );

    and this right on top of header.php (before the <!DOCTYPE… parts):

    The above makes all BP pages private, except the registration and activation pages. It also leaves all blog pages public. It’s a bit easier than editing all theme pages.

    Lee

  4. Mick December 9, 2013 at 2:02 am #

    This doesn’t seem to work on WP v3.7.1 with BP. I’ve added the code suggested by Lee and I see no difference when Logged out in what I can and cant view.

Leave a Reply