Created
September 29, 2021 14:30
-
-
Save lelandf/0d813cdaca27aee3dc9602d6daa7606f to your computer and use it in GitHub Desktop.
[TEC] working redirect sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'template_redirect', function() { | |
if ( is_user_logged_in() ) { | |
return; | |
} | |
if ( | |
tribe_is_event() || | |
tribe_is_event_category() || | |
tribe_is_in_main_loop() || | |
tribe_is_view() || | |
'tribe_events' === get_post_type() || | |
is_singular( 'tribe_events' ) | |
) { | |
$location = home_url( '/my-account/' ); | |
$location = wp_sanitize_redirect( $location ); | |
header( 'Location: '. $location, true, 302 ); | |
exit; | |
} | |
} ); |
Alternative while tacking on query arguments to URL:
add_action( 'template_redirect', function() {
if ( is_user_logged_in() ) {
return;
}
if (
tribe_is_event() ||
tribe_is_event_category() ||
tribe_is_in_main_loop() ||
tribe_is_view() ||
'tribe_events' === get_post_type() ||
is_singular( 'tribe_events' )
) {
$redirect = untrailingslashit( home_url() ) . filter_input( INPUT_SERVER, 'REQUEST_URI' );
$location = home_url( '/my-account/' );
$location = add_query_arg( 'redirect_to', urlencode( $redirect ), $location );
$location = wp_sanitize_redirect( $location );
header( 'Location: '. $location, true, 302 );
exit;
}
} );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative while tacking on $wp->request path as an encoded query argument: