BuddyDev

Search

[Resolved] Make one page public on site

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #18132

    Hi Brajesh,

    Hope this message finds you well. As you may remember you helped me make one page on our site visible to non logged in users via your code snippet

    ‘<?php
    /**
    * Make a WordPress site Private, works with/Without BuddyPress
    *
    * @author sbrajesh
    * @global string $pagenow
    *
    */
    function buddydev_private_site() {

    //do not restrict logged in users
    if ( is_user_logged_in() ) {
    return ;
    }
    //first exclude the wp-login.php
    //register
    //activate
    global $pagenow;

    //if we are here, the user is not logged in, so let us check for exclusion
    //we selectively exclude pages from the list

    //are we on login page?
    if ( $pagenow == ‘wp-login.php’ ) {
    return ;
    }

    // Exclude some page.
    $excluded_pages = array( ‘privacy-policy’ ); //add all your pages that you want to exclude.
    $excluded_pages = array( ‘join’ ); //add all your pages that you want to exclude.

    if ( is_page( $excluded_pages ) ) {
    return;
    }

    //handle Special case of BuddyPress registration/Login
    if ( function_exists( ‘is_buddypress’ ) && is_buddypress() ) {

    if ( bp_is_activation_page() || bp_is_register_page() ) {
    return ;
    }
    }

    $redirect_url = wp_login_url( site_url(‘/’) );//get login url,

    wp_safe_redirect( $redirect_url );
    exit( 0 );
    }

    add_action( ‘template_redirect’, ‘buddydev_private_site’, 0 );

    This Is what we are using….With that, our privacy-policy page does not open up – after I have added another page to be excluded and made visible to the public. I added Join as another page. when I added join…..Join is visible but privacy policy can not be viewed.

    When I remove $excluded_pages = array( ‘join’ ); //add all your pages that you want to exclude. the privacy policy is once again visible.

    thoughts

    best
    chris

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #18134

    A slight correction. Basically what is happening is that if I add more than one page, the privacy policy will not open. For example, when I added the page ‘join’ to the list above, join is visible, however the privacy policy is not longer visible to the public, only logged in users.

    best
    chris

  • Keymaster
    (BuddyDev Team)
    Posts: 24232
    Brajesh Singh on #18139

    Hi Chris,
    You should use it like this

    
    
    $excluded_pages = array( 'privacy-policy', 'join',  ); // add others as comma separated string. 
    

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #18142
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24232
    Brajesh Singh on #18152

    Thank you.

The topic ‘ [Resolved] Make one page public on site’ is closed to new replies.

This topic is: resolved