uo_wpfroms_maybe_autocomplete_redirect
Filters whether a student should be redirected after completing Filters whether a redirect should occur after a student completes a form.
add_filter( 'uo_wpfroms_maybe_autocomplete_redirect', $callback, 10, 1 );
Description
This filter hook, `uo_wpfroms_maybe_autocomplete_redirect`, fires just before a student's redirect is processed after completing a lesson or topic. Developers can use this to conditionally prevent or modify the redirect behavior by returning `false`. This is useful for custom logic that might require keeping the student on the current page.
Usage
add_filter( 'uo_wpfroms_maybe_autocomplete_redirect', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'uo_wpfroms_maybe_autocomplete_redirect', 'my_custom_redirect_logic', 10, 1 );
/**
* Custom logic to conditionally prevent redirection after lesson/topic completion.
*
* This function demonstrates how to use the 'uo_wpfroms_maybe_autocomplete_redirect'
* filter to control whether a student is redirected to the next lesson/topic
* after completing the current one.
*
* In this example, we'll prevent redirection if the user is on the last step
* of a course and a specific meta key is not set.
*
* @param bool $should_redirect The default value, which is true.
* @return bool Whether to proceed with the redirect.
*/
function my_custom_redirect_logic( $should_redirect ) {
// Ensure we're working within the context of a WordPress post (lesson/topic).
if ( ! is_singular() || ! function_exists( 'learndash_next_post_link' ) ) {
return $should_redirect;
}
$post = get_post();
// Get the next post link to determine if it's the last step.
$next_post_link = learndash_next_post_link( '', true, $post );
$is_last_step = empty( $next_post_link );
// Example condition: If it's the last step and a custom meta key is NOT set,
// then we want to prevent the redirect.
// Replace 'your_custom_meta_key_to_enable_redirect' with an actual meta key
// you might use to force a redirect even on the last step.
$custom_meta_key = get_post_meta( $post->ID, 'your_custom_meta_key_to_enable_redirect', true );
if ( $is_last_step && empty( $custom_meta_key ) ) {
// Do not redirect if it's the last step and the custom meta key is not present.
return false;
}
// Otherwise, return the original value or true to 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/wpf-lesson-topic-auto-complete.php:281
/**
* Filters whether a student should be redirected after completing
*
* @param bool
*
* @since 3.5.1
*/
if ( false === apply_filters( 'uo_wpfroms_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;