Browse: Home / Snippets /

Redirect comment back to nested URL

Contents


Snippet #

/**
 * LearnDash filter to redirect comment back to nested URL
 */
add_action( 'comment_form_top', function( ) {
	$queried_object = get_queried_object();
	
	if ( is_a( $queried_object, 'WP_Post' ) ) {
		if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_Permalinks', 'nested_urls' ) == 'yes' ) {
			if ( in_array( $queried_object->post_type, array( 'sfwd-lessons', 'sfwd-topic', 'sfwd-quiz' ) ) ) {
				echo '<input type="hidden" name="step_id" value="'. $queried_object->ID .'" />';

				$course_id = learndash_get_course_id( $queried_object->ID );
				if ( !empty( $course_id ) ) {
					echo '<input type="hidden" name="course_id" value="'. $course_id .'" />';
					
					$redirect_to = learndash_get_step_permalink( $queried_object->ID, $course_id );
					if ( !empty( $redirect_to ) ) {
						echo '<input type="hidden" name="redirect_to" value="'. $redirect_to .'" />';
					}
				}
			}
		}
	}
});