ulgm_progress_report_courses
Filters the courses displayed in the progress report, allowing modification based on user, quiz attempts, and group.
add_filter( 'ulgm_progress_report_courses', $callback, 10, 5 );
Description
Filters the course data before it's displayed in a user's progress report. Developers can modify the array of courses, including adding, removing, or reordering them, to customize the report output. This hook fires after quiz attempt data has been processed.
Usage
add_filter( 'ulgm_progress_report_courses', 'your_function_name', 10, 5 );
Parameters
-
$courses(mixed) - This parameter contains the courses associated with the user, which will be further processed and formatted for the progress report.
-
$user_courses(mixed) - This parameter contains an array of course objects that represent the courses the user is enrolled in.
-
$user_id(mixed) - This parameter contains the user's enrolled courses.
-
$quiz_attempts(mixed) - This parameter represents the unique identifier of the user whose progress report is being generated.
-
$group_id(mixed) - This parameter contains an array of all quiz attempts made by the user.
Return Value
The filtered value.
Examples
add_filter( 'ulgm_progress_report_courses', 'my_custom_ulgm_progress_report_courses', 10, 5 );
/**
* Example callback function to modify the courses array for the ULGM progress report.
* This example demonstrates how to filter courses based on their completion status
* and perhaps add custom data to each course object.
*
* @param array $courses The original array of course data.
* @param array $user_courses The array of courses the user is enrolled in.
* @param int $user_id The ID of the user.
* @param array $quiz_attempts An array containing the user's quiz attempts.
* @param int $group_id The ID of the group the report is for.
*
* @return array Modified array of course data.
*/
function my_custom_ulgm_progress_report_courses( $courses, $user_courses, $user_id, $quiz_attempts, $group_id ) {
// Assume $courses is an array of course objects or arrays.
// Let's iterate through each course and potentially modify it.
foreach ( $courses as &$course ) {
// Example: Add a custom property to indicate if the user has completed at least one quiz in this course.
$course_has_quiz_completion = false;
$course_id = isset( $course['ID'] ) ? $course['ID'] : ( isset( $course->ID ) ? $course->ID : null );
if ( $course_id && ! empty( $quiz_attempts ) ) {
foreach ( $quiz_attempts as $quiz_id => $attempts ) {
// We need a way to associate quizzes with courses.
// This is a hypothetical example. In a real scenario, you'd likely
// retrieve quiz-course associations from WordPress meta or a plugin function.
$associated_course_id = get_post_meta( $quiz_id, '_ld_course_id', true ); // Example meta key for LearnDash quizzes
if ( $associated_course_id && $associated_course_id == $course_id && ! empty( $attempts ) ) {
$course_has_quiz_completion = true;
break; // Found a quiz completion for this course
}
}
}
// Add the custom property to the course object/array
if ( is_array( $course ) ) {
$course['user_has_quiz_completion'] = $course_has_quiz_completion;
} elseif ( is_object( $course ) ) {
$course->user_has_quiz_completion = $course_has_quiz_completion;
}
// Example: Filter out courses that the user hasn't started yet,
// unless they are specifically enrolled in the course ($user_courses).
// This assumes $courses might contain more than just enrolled courses.
// If $courses is already filtered to only include user-enrolled courses, this check might be redundant.
$is_user_enrolled = false;
if ( ! empty( $user_courses ) && $course_id ) {
foreach ( $user_courses as $enrolled_course ) {
if ( ( isset( $enrolled_course['ID'] ) && $enrolled_course['ID'] == $course_id ) || ( isset( $enrolled_course->ID ) && $enrolled_course->ID == $course_id ) ) {
$is_user_enrolled = true;
break;
}
}
}
// If the course is not in the user's enrolled courses and we are filtering based on that.
// This is an example of *removing* items, adjust logic as needed.
// if ( !$is_user_enrolled && $course_id ) {
// unset( $courses[ array_search( $course, $courses ) ] ); // This needs careful handling of array keys after unset
// }
}
// Re-index the array if items were unset to maintain numerical keys.
// $courses = array_values( $courses );
// Return the modified courses array.
return $courses;
}
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/reports/learndash-progress-report.php:877
// Get all users attempted and completed quizzes
$quiz_attempts = self::get_all_quiz_attemps( $user_id );
$quiz_attempts = apply_filters( 'ulgm_progress_report_user_quizzes', $quiz_attempts, $user_id, $group_id );
$courses = self::set_up_course_object( $user_courses, $user_id, $quiz_attempts, $group_id );
$courses = apply_filters( 'ulgm_progress_report_courses', $courses, $user_courses, $user_id, $quiz_attempts, $group_id );
remove_action( 'parse_query', array( __CLASS__, 'wpml_suppress_filters' ) );
if ( isset( $atts['expand_by_default'] ) && 'yes' === $atts['expand_by_default'] ) {
$expanded_on_load = true;
} else {
$expanded_on_load = false;