Filter Since 3.5.1 uncanny-toolkit-pro

uo_gf_maybe_autocomplete_redirect

Filters whether a student should be redirected after completing Filters whether a student should be redirected after completing a form, allowing for custom redirect logic.

add_filter( 'uo_gf_maybe_autocomplete_redirect', $callback, 10, 1 );

Description

Allows developers to conditionally prevent a student redirect after completing a lesson topic via Gravity Forms. By default, it returns true, enabling the redirect. Developers can return false to disable the redirect, for example, to display a custom success message or perform alternative actions. This hook fires after the completion is registered but before any potential redirect logic.


Usage

add_filter( 'uo_gf_maybe_autocomplete_redirect', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

add_filter( 'uo_gf_maybe_autocomplete_redirect', 'my_custom_redirect_logic', 10, 1 );

/**
 * Conditionally disable redirection after lesson completion.
 *
 * This example demonstrates how to prevent the automatic redirect after a student
 * completes a lesson, but only if the lesson is marked as "optional" in
 * custom meta data.
 *
 * @param bool $should_redirect The default value, true, indicating redirection should occur.
 * @return bool Whether the redirection should proceed.
 */
function my_custom_redirect_logic( $should_redirect ) {
	// Check if we are in the context of a lesson post.
	if ( is_singular( 'sfwd-lessons' ) ) {
		$post_id = get_the_ID();
		// Get custom meta data to determine if the lesson is optional.
		// Replace 'optional_lesson_meta_key' with your actual meta key.
		$is_optional_lesson = get_post_meta( $post_id, 'optional_lesson_meta_key', true );

		// If the lesson is marked as optional, prevent redirection.
		if ( ! empty( $is_optional_lesson ) && 'yes' === $is_optional_lesson ) {
			return false; // Do not redirect
		}
	}

	// For all other cases, or if the lesson is not optional, allow redirection.
	return $should_redirect;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/gf-lesson-topic-auto-complete.php:316

/**
		 * Filters whether a student should be redirected after completing
		 *
		 * @param bool
		 *
		 * @since 3.5.1
		 */
		if ( false === apply_filters( 'uo_gf_maybe_autocomplete_redirect', true ) ) {
			return;
		}

		$next_post_link = learndash_next_post_link( '', true, $post );
		$is_last_step   = empty( $next_post_link );
		$button_link    = $next_post_link;

Scroll to Top