Skip to content

Instantly share code, notes, and snippets.

@woogist
Last active December 7, 2015 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogist/89d1627fb6dc9a448d00 to your computer and use it in GitHub Desktop.
Save woogist/89d1627fb6dc9a448d00 to your computer and use it in GitHub Desktop.
This code snippet was used on ZD ticket 274932 . It stops Sensei from automatically redirecting from the lesson to the quiz. Tags: Sensei Redirect, Lesson Redirect, Sensei Auto Redirect.
add_action('template_redirect', 'custom_remove_sensei_quiz_view');
function custom_remove_sensei_quiz_view(){
if( is_singular('quiz') ){
global $post;
//redirect back to the lesson page
$lesson_id = $post->post_parent;
//make sure this does not run again
$lesson_link = add_query_arg( 'sa', '1', get_permalink( $lesson_id ) );
wp_redirect( $lesson_link );
}
}
add_filter( 'wp_redirect', 'custom_sensei_stop_redirect_loop', 0, 2 );
function custom_sensei_stop_redirect_loop( $location, $status ){
$block_redirect = get_query_var( 'sa', '0' );
if( '1' == $block_redirect ){
$location = false;
}
return $location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment