Filter
uncanny-automator-pro
automator_learndash_repair_course_progress
Filters course progress repair for a specific course and user, allowing customization of the repair process.
add_filter( 'automator_learndash_repair_course_progress', $callback, 10, 2 );
Description
This filter hook, `automator_learndash_repair_course_progress`, allows developers to control whether LearnDash's built-in course completion processing runs after an Uncanny Automator course progress repair. By default, it returns `false`, preventing automatic completion. Return `true` to trigger `learndash_process_mark_complete` for the specified user and course.
Usage
add_filter( 'automator_learndash_repair_course_progress', 'your_function_name', 10, 2 );
Parameters
-
$course_id(mixed) - This parameter is a boolean that can be used to stop the repair process by returning `true`.
-
$user_id(mixed) - This parameter contains the ID of the course whose progress is being repaired.
Return Value
The filtered value.
Examples
/**
* Example of how to use the automator_learndash_repair_course_progress filter.
* This example demonstrates how to conditionally prevent the automatic course completion
* processing if a specific condition is met, for instance, if the user is an administrator.
*/
add_filter( 'automator_learndash_repair_course_progress', 'my_automator_learndash_prevent_auto_completion', 10, 3 );
function my_automator_learndash_prevent_auto_completion( $process, $course_id, $user_id ) {
// If the user is an administrator, prevent the automatic course completion processing.
// This might be useful to avoid accidental full course completion for admins testing.
if ( user_can( $user_id, 'manage_options' ) ) {
return false; // Do not process course completion
}
// Otherwise, allow the default behavior (which is to process course completion if $process is true).
// In this specific hook context, the default value passed to apply_filters is false,
// so returning true here would initiate the learndash_process_mark_complete call.
// If you wanted to *always* process unless a condition is met, you'd return true here.
// For this example, we only want to prevent it for admins, so if they are not an admin,
// we allow the original $process value (which is false in the source code) to persist.
return $process;
}
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
uncanny-automator-pro/src/integrations/learndash/actions/ld-anon-repaircourseprogress.php:136
// Mark Steps Complete.
$this->mark_course_steps_complete( $user_id, $course_id, $course_steps );
$completed ++;
// Check if course completion behaviour needs to be processed.
$process = apply_filters( 'automator_learndash_repair_course_progress', false, $course_id, $user_id );
if ( $process ) {
learndash_process_mark_complete( $user_id, $course_id );
}
}
// If no courses were completed, return with errors.
if ( empty( $completed ) ) {