My LearnDash plugin is configured to have shared course steps, so that I can use the same lessons and topics across multiple courses. However, if a users marks a topic as complete in one particular course, it is not reflected across all courses (default setting). I want to make it such that any change in the completion status of a shared topics is reflected across all courses containing that topic.
This is the code that I used but it’s not working
function nzf_sync_topic_completion($topic_data) {
// Extract relevant data
$topic_id = isset($topic_data['topic']->ID) ? $topic_data['topic']->ID : null;
$course_id = isset($topic_data['course']->ID) ? $topic_data['course']->ID :
$user_id = isset($topic_data['user']->ID) ? $topic_data['user']->ID : null;
// Validate that essential data exists
if (!$topic_id || !$course_id || !$user_id) {
error_log('nzf_sync_topic_completion: Missing required data. Topic, course,
return;
}
// Check if LearnDash shared steps is enabled
if (learndash_is_course_shared_steps_enabled()) {
// Get all courses sharing the topic
$shared_courses = learndash_get_courses_for_step($topic_id, true);
// Loop through shared courses
foreach ($shared_courses as $shared_course_id => $value) {
// Skip the current course
if ($shared_course_id == $course_id) {
continue;
}
// Mark the topic as complete for the user in the shared course
learndash_process_mark_complete($user_id, $topic_id, true,
}
} else {
error_log('nzf_sync_topic_completion: Shared steps not enabled.');
}
// Hook into the LearnDash topic completion action
add_action('learndash_topic_completed', 'nzf_sync_topic_completion', 10, 1);
Carmi Human is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.