Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Locking a website using bp-custom

  • Avatar of icepin
    icepin
    Participant

    @icepin

    Hello,

    I am trying to improve this code found here (credits to David Carson I guess):

    <?php

    // **** Privacy ********
    function restrict_access(){
    global $bp, $bp_unfiltered_uri;
    // If user is not logged in and
    if (!is_user_logged_in() &&
    (
    // The current page is not register or activation
    !bp_is_register_page() &&
    !bp_is_activation_page()
    )

    ) {
    // Redirect to registration page. Change /join to your register page slug
    bp_core_redirect( get_option(‘home’) . ‘/register’ );
    }
    }
    add_action( ‘wp’, ‘restrict_access’, 3 );
    ?>

    It does the job great but what I’m trying to do is to make 2-3 more pages available for unregistered user. So next to !bp_is_register_page() && !bp_is_activation_page() need to add few more pages to exclude. I’ve been struggling to find a way but fail every time. I’m guessing is simple but my php skills are close to none and I just can’t figure it out.

    I guess the simplest way would be to exclude specific page slugs or IDs but, how to add them there. Specifying with get_site_url() or get_page() the script is not working (unless I’m doing something wrong). (I don’t want to use a membership plugin because I have dozen of plugins already and…)

    Any help appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Avatar of Hugo
    Hugo
    Moderator

    @hnla

    well doubt it would be ‘get_page()’ try ‘is_page()’ with a name, slug, or id.

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    Or use the unfiltered_uri, for example…

    function restrict_access(){
     global $bp_unfiltered_uri;
    
     if ( !is_user_logged_in() && !bp_is_register_page() && !bp_is_activation_page() && ( $bp_unfiltered_uri[0] != 'some-slug') )
      bp_core_redirect( get_option('home') . '/register' );
    
    }
    add_action( 'wp', 'restrict_access', 3 );
    Avatar of icepin
    icepin
    Participant

    @icepin

    both options working like a charm!
    you guys are awesome, herzlichen dank!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.