Reroute list/edit page when not logged in

Home Forums Calendar Products Community Events Reroute list/edit page when not logged in

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1082749
    clarity
    Participant

    I was given this code to re-route a user who is not logged in from adding an event:

    <?php
    
    add_action( 'tribe_ce_event_submission_login_form', 'redirect_to_better_login_page' );
    
    function redirect_to_better_login_page() {
    	if ( ! is_user_logged_in() ) {
    		wp_safe_redirect( 'http://avindustrycalendar.com/login-register/' );
    		die();
    	}
    }
    
    ?>

    It works great. Now, is there a way to do the same for the /events/community/list page as well?

    When a user is not logged in and the go to the /events/community/list page, they get routed to a generic login page. We want them to go to our registration page.

    Thanks

    #1082766
    George
    Participant

    Hey @clarity,

    If you are trying to redirect to the same URL, http://avindustrycalendar.com/login-register/, then you should be able to have the same redirection happening by using the callback function for just another action; an action on the List View page.

    So, adding this line of code to your theme’s functions.php file should do the trick:

    add_action( 'tribe_ce_before_event_list_top_buttons', 'redirect_to_better_login_page' );

    Cheers,
    George

    #1082809
    clarity
    Participant

    George,

    I tried… nothing I did worked…

    <?php
    
    add_action( 'tribe_ce_before_event_list_top_buttons', 'redirect_to_better_login_page' );
    add_action( 'tribe_ce_event_submission_login_form', 'redirect_to_better_login_page' );
    
    function redirect_to_better_login_page() {
    	if ( ! is_user_logged_in() ) {
    		wp_safe_redirect( 'http://avindustrycalendar.com/login-register/' );
    		die();
    	}
    }
    
    ?>
    

    I also tried:

    <?php
    
    add_action( 'tribe_ce_event_submission_login_form', 'redirect_to_better_login_page' );
    
    function redirect_to_better_login_page() {
    	if ( ! is_user_logged_in() ) {
    		wp_safe_redirect( 'http://avindustrycalendar.com/login-register/' );
    		die();
    	}
    }
    
    add_action( 'tribe_ce_before_event_list_top_buttons', 'redirect_to_better_login_page' );
    
    function redirect_to_better_login_page() {
    	if ( ! is_user_logged_in() ) {
    		wp_safe_redirect( 'http://avindustrycalendar.com/login-register/' );
    		die();
    	}
    }
    
    ?>
    

    Both resulted in errors

    • This reply was modified 10 years, 1 month ago by clarity.
    #1083025
    George
    Participant

    Hi @Clarity,

    You can try this code instead:

    add_action( 'login_form_top', 'redirect_to_better_login_page' );

    Do not define the redirect_to_better_login_page() function more than one time.

    Also, ensure that your links end up like this:


    'http://avindustrycalendar.com/login-register/'

    Not like this:


    'http://avindustrycalendar.com/login-register/&#O39;

    The closing PHP tag is also not required and I would recommend removing it.

    — George

    #1085729
    clarity
    Participant

    This is perfect. It worked great. Thank you.

    It seems that the previous functions.php file had an issue, for some reason. Don’t know why, but finally creating a new file worked.

    • This reply was modified 10 years, 1 month ago by clarity.
    #1086006
    George
    Participant

    Glad to hear it! Best of luck with your site. 🙂

    Thanks,
    George

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Reroute list/edit page when not logged in’ is closed to new replies.