Code Snippets

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:

[php]
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\’ );
[/php]

Add this to your functions.php or bp-custom.php file

Script courtesy of Traveljunkie.

Tired of having a slow BuddyPress site?

I'm constantly updating my BuddyPress Hosting Guide to help you get the most out of your hosting. SiteGround and WPEngine have proven to be fast and reliable but see my BuddyPress Hosting guide for a full overview of your options

 

About Bowe Frankema

Building communities on BuddyPress is something I am very passionate about. The decision to focus exclusively on BuddyPress projects over the last few years inspired me to share back some of the things I've learned here on BP-Tricks! You can find me on WordCamps & BuddyCamps across the globe and on Twitter! Follow me on Twitter

Discussion

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

  1. 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

  2. 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

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">