ulgm_group_course_report_user_data
Filters user data for a group course report, allowing modification before display.
add_filter( 'ulgm_group_course_report_user_data', $callback, 10, 4 );
Description
Filters the data for a specific user's course within a LearnDash group report. Developers can modify this data to customize how course access dates or other user-specific course information is displayed or processed in the report. The hook provides the user ID, group ID, and course ID for context.
Usage
add_filter( 'ulgm_group_course_report_user_data', 'your_function_name', 10, 4 );
Parameters
-
$user_id(mixed) - The ID of the user for whom the course report data is being generated.
-
$user_id(mixed) - The user's ID.
-
$group_id(mixed) - This parameter likely contains the user's ID.
-
$course_id(mixed) - This parameter contains the ID of the group for which the course report is being generated.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the user data for the group course report.
*
* This example demonstrates how to add additional user information to the
* report, or modify existing data, based on the provided user, group, and course IDs.
*
* @param array $user_course_data The array of user course data.
* @param int $user_id The ID of the user.
* @param int $group_id The ID of the group.
* @param int $course_id The ID of the course.
* @return array Modified user course data.
*/
add_filter(
'ulgm_group_course_report_user_data',
function ( $user_course_data, $user_id, $group_id, $course_id ) {
// Ensure we have valid IDs before proceeding.
if ( ! $user_id || ! $group_id || ! $course_id ) {
return $user_course_data;
}
// Add a custom field to the report indicating if the user has completed
// a specific lesson within this course.
$custom_lesson_id = 1234; // Replace with a real lesson ID.
$has_completed_custom_lesson = false;
if ( function_exists( 'learndash_is_lesson_complete' ) ) {
$has_completed_custom_lesson = learndash_is_lesson_complete( $custom_lesson_id, $user_id );
}
$user_course_data['has_completed_custom_lesson'] = $has_completed_custom_lesson ? __( 'Yes', 'your-text-domain' ) : __( 'No', 'your-text-domain' );
// Example of modifying existing data: Append the group name to the user's email.
// This is a contrived example; in a real-world scenario, you'd likely fetch
// the group name properly.
if ( isset( $user_course_data['user_email'] ) ) {
$user_course_data['user_email'] .= ' (Group: ' . $group_id . ')'; // Placeholder for actual group name retrieval
}
// You could also add the user's enrollment date for this specific course from this group.
$enrollment_date = learndash_get_user_group_enrollment_date( $user_id, $group_id, $course_id );
if ( $enrollment_date ) {
$user_course_data['group_course_enrollment_date'] = date( 'Y-m-d H:i:s', $enrollment_date );
}
return $user_course_data;
},
10,
4 // The filter accepts 4 arguments: $user_course_data, $user_id, $group_id, $course_id
);
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/group-reports-interface.php:754
if ( empty( $courses_access_from ) ) {
$courses_access_from = learndash_user_group_enrolled_to_course_from( $user_id, $course_id );
}
if ( ! empty( $courses_access_from ) ) {
$courses_access_from = '<span class="ulg-hidden-data" style="display: none;">' . $courses_access_from . '</span>' . learndash_adjust_date_time_display( $courses_access_from );
}
$user_course_data[] = apply_filters(
'ulgm_group_course_report_user_data',
array(
'user_id' => $user_id,
'first_name' => SharedFunctions::remove_special_character( $first_name ),
'last_name' => SharedFunctions::remove_special_character( $last_name ),
'user_email' => $user_email,
'user_name' => $user_name,