BuddyDev

Search

[Resolved] Make one page public on site

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

    Hi Brajesh,

    Hope this email finds you well. You may remember that we are using your custom code to make one page public. With that, prior to the code below, we were and are still using Peters Login Redirect to redirect logged in USERS to https://narrativeatlas.org/members/me/groups…

    Unfortuanately the plugin no longer works…When they user logs in, they are simply brought back to the homepage….Looks like I can place the redirect URL in your custom code – no sure where…And if I can indicated it in your code – should I delete peters login redirect?

    Best,
    chris

    Here is the code:

    ‘<?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 ;
    }

    //let us exclude the home page
    if ( is_front_page() ) {
    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 );’

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

    Hi Chris,
    Are you using any other code for redirect.

    The above code does not apply to logged in user.

    There is a code block that I have put at the top

    
    if ( is_user_logged_in() ) {
     return ;
    }
    

    It simply checks if a user is logged in and if they are, It won’t proceed. You may disable the code and check the same.

    I am not sure what is causing it but it is not the above code.

    Regards
    Brajesh

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

    We are using WPS hide login.

    Here is our use case:

    When a user logs in, we would like them redirected to https://narrativeatlas.org/members/me/groups

    When they are logged out, they are redirected to the homepage.

    Thoughts on how we can fix this?

  • Keymaster
    (BuddyDev Team)
    Posts: 24238
    Brajesh Singh on #18233

    Hi Chris,
    I am sorry, I don’t use WPS Hide login. Since the login redirection is not related to the code I have assisted you, I will suggest asking in the relevant plugin’s support forum.

    Regards
    Brajesh

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

    Please give it a try.

    
    
    /**
     * Redirect to groups on login.
     *
     * @param $redirect_to
     * @param $redirect_url_specified
     * @param $user
     *
     * @return string
     */
    function buddydev_on_user_login( $redirect_to, $redirect_url_specified, $user ) {
    
    	//check if we have a valid user?
    	if ( is_wp_error( $user ) ) {
    		return $redirect_to;
    	}
    
    	$redirect_to = site_url('/members/me/groups/');
    
    	return $redirect_to;
    }
    
    add_filter( 'login_redirect', 'buddydev_on_user_login', 110, 3 );
    

    It may or may not work depending on how are you handling login. For normal WordPress login, It will work though.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 118
    chris on #18248
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 118
    chris on #18249
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24238
    Brajesh Singh on #18250
    This reply has been marked as private.

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

This topic is: resolved