Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Block an additional Page w/ Walled Garden code

  • Profile photo of mrjarbenne
    mrjarbenne
    Participant

    @mrjarbenne

    I’m using this code to make my buddypress site private to logged in users only, but keeping the blog and non-BP pages available to visitors.

    function sh_walled_garden()
    {
    if( ! bp_is_blog_page() && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain );
    }
    add_action( 'wp_loaded', 'sh_walled_garden' );

    I’m now trying to block access to one specific page. I thought I could do it with the same code like this

    if( ! is_page( 697 ) && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain );

    but I think I’ve got a few too many exclamation marks creating redirects that will never complete.

    Any thoughts on how I can block a specific page from view?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Profile photo of Tammie Lister
    Tammie Lister
    Moderator

    @karmatosed

    Hmm try (not tested):

    `if ((!is_page(‘697’)) && (!is_user_logged_in()))
    bp_core_redirect($bp->root_domain);
    `

    Profile photo of mrjarbenne
    mrjarbenne
    Participant

    @mrjarbenne

    Thanks Tammi, That didn’t seem to work though.

    Profile photo of modemlooper
    modemlooper
    Moderator

    @modemlooper

    use : is_page(697)

    no quotes when an ID

    quotes when slug or page title

    https://codex.wordpress.org/Conditional_Tags

    But I’d write your code using a category:

    in_category( ‘public’ )

    This way you can add whatever pages you want to show via admin

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Block an additional Page w/ Walled Garden code’ is closed to new replies.
Skip to toolbar