ulgm_progress_report_user_courses
Filters user courses for progress reports before displaying them, allowing modification based on user, group, and sorting attributes.
add_filter( 'ulgm_progress_report_user_courses', $callback, 10, 4 );
Description
Filters the user's course data used in the progress report. Developers can modify the array of courses, their properties, or even replace it entirely before it's displayed in the report for a specific user within a group.
Usage
add_filter( 'ulgm_progress_report_user_courses', 'your_function_name', 10, 4 );
Parameters
-
$user_courses(mixed) - This parameter contains an array or object representing the courses associated with the user.
-
$user_id(mixed) - This parameter contains an array of courses associated with the user, potentially filtered or sorted based on other parameters.
-
$group_id(mixed) - This parameter contains the ID of the user whose course progress is being reported.
-
$sort_atts(mixed) - This parameter holds the ID of the group for which the user's course progress is being reported.
Return Value
The filtered value.
Examples
/**
* Example function to modify the user courses data for the progress report.
* This function might, for instance, remove courses that the user has already completed
* if the group settings indicate they should not be repeated or if we want to
* highlight only incomplete courses.
*
* @param array $user_courses The original array of user courses data.
* @param int $user_id The ID of the user.
* @param int $group_id The ID of the group.
* @param array $sort_atts The sorting attributes used for the report.
* @return array The modified array of user courses data.
*/
add_filter( 'ulgm_progress_report_user_courses', function( $user_courses, $user_id, $group_id, $sort_atts ) {
// Check if the user_courses is an array and not empty.
if ( ! is_array( $user_courses ) || empty( $user_courses ) ) {
return $user_courses;
}
// Example: Let's say we want to filter out courses that are already marked as 'completed'
// for this specific group, perhaps to only show pending tasks.
// This assumes $user_courses is an array of objects or associative arrays
// where each item represents a course and has a 'status' key/property.
$filtered_courses = [];
foreach ( $user_courses as $course_id => $course_data ) {
// Assuming $course_data is an object with a 'completed' property or an array with a 'completed' key.
$is_completed = false;
if ( is_object( $course_data ) && isset( $course_data->completed ) ) {
$is_completed = (bool) $course_data->completed;
} elseif ( is_array( $course_data ) && isset( $course_data['completed'] ) ) {
$is_completed = (bool) $course_data['completed'];
}
// If the course is not completed, keep it in the filtered list.
if ( ! $is_completed ) {
$filtered_courses[ $course_id ] = $course_data;
}
}
// You could also add conditional logic based on $group_id or $sort_atts if needed.
// For example:
// if ( $group_id === 123 && isset( $sort_atts['order'] ) && $sort_atts['order'] === 'asc' ) {
// // Apply a different filtering logic
// }
// Return the modified array of courses.
return $filtered_courses;
}, 10, 4 );
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:868
}
}
$user_courses = $group_courses;
}
}
$user_courses = apply_filters( 'ulgm_progress_report_user_courses', $user_courses, $user_id, $group_id, $sort_atts );
// 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 );