BuddyDev

Search

Make one page public on site

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

    Hi Brajesh,

    Hope that you are well. As you may remember, our entire site is private. We need to add a privacy policy….So, ideally we would like that page to be publicly visible. We use this code that you crrated to make our site private
    https://buddydev.com/making-a-wordpress-buddypress-site-private-the-right-way/

    For example, we would like to make https://narrativeatlas.org/privacypolicy this public. Also, ideally centered on the bottom portion of the white rectangular login window (beneath Rember Me and LOGin. If this is not possible, we can also have it below ”
    Back to Narrative Atlas”

    Best
    chris

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #17631
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 118
    chris on #17652
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17655

    Hi Chris,
    Here is the updated code. Add your page slug to the excluded pages and those pages will be excluded.

    
    
    /**
     * 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 ;
    	}
    
    	// let us exclude the home page.
    	if ( is_front_page() ) {
    		return ;
    	}
    
    	// Exclude some page.
    	$excluded_pages = array( 'terms' ); //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 );
    
    

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #17658
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17668
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 118
    chris on #17675

    Awesome!Thx

    If I wanted to add multiple pages, how would i do that?

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

    Do i need to use the plugin force login then? Essentially what we want to have happen is that when someone visits https://narrativeatlas.org….if directs them to https://narrativeatlas.org/wp-admin…..our login page? Looks like your code does that already?

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #17677
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 118
    chris on #17680

    One more update. I used the following code and deactivated the force login plugin. The use case scenario that I have identified in my prior note now seems to work.

    Here is the code. Can you tell me if its ok based on what I have shared above. Also, per my last message, is it possible to hide the WP-content/uploads folder. I know that you said it does not scale. Not sure what that means. I found this: https://www.getastra.com/blog/cms/wordpress-security/hide-wp-includes-wp-content-uploads-from-your-wordpress-site/

    
    <?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.
    
    	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 );
    

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

This topic is: not resolved