ulgm_group_course_report_user_course_data
Filters user course data for group course reports, allowing modification before display.
add_filter( 'ulgm_group_course_report_user_course_data', $callback, 10, 3 );
Description
Filters the user course data array for group course reports. This hook allows developers to modify or extend the information displayed for each user's progress within a specific course in a group context before it's rendered in the report. You can add custom metrics or alter existing ones.
Usage
add_filter( 'ulgm_group_course_report_user_course_data', 'your_function_name', 10, 3 );
Parameters
-
$user_course_data(mixed) - This parameter contains the data for a specific user's progress within a given course in the context of a group report.
-
$groups_user_object(mixed) - This parameter contains the data related to a specific user's progress and completion within a particular course, which can be modified by the filter.
-
$course_id(mixed) - This parameter contains an object representing the user's relationship to the group.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the ulgm_group_course_report_user_course_data filter.
* This example demonstrates how to conditionally modify the user's course data
* based on their user role and the course ID.
*
* @param array $user_course_data The original user course data.
* @param object $groups_user_object The user object from the ULGM Groups plugin.
* @param int $course_id The ID of the course.
* @return array Modified user course data.
*/
add_filter( 'ulgm_group_course_report_user_course_data', function( $user_course_data, $groups_user_object, $course_id ) {
// Check if the user has the 'administrator' role.
if ( isset( $groups_user_object->roles ) && in_array( 'administrator', $groups_user_object->roles ) ) {
// If it's a specific course, we want to highlight it or add extra info.
if ( $course_id === 123 ) {
if ( isset( $user_course_data['completion_percentage'] ) ) {
$user_course_data['completion_percentage'] = 100; // Mark as complete for admins on this course.
$user_course_data['admin_note'] = 'Admin Override: Marked as 100% complete.';
}
}
}
// Always return the (potentially modified) user course data.
return $user_course_data;
}, 10, 3 ); // 10 is the default priority, 3 is the number of arguments accepted by the callback.
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:777
),
$user_id,
$group_id,
$course_id
);
}
return apply_filters( 'ulgm_group_course_report_user_course_data', $user_course_data, $groups_user_object, $course_id );
}
/**
* @param $user_id
* @param $course_id
*
* @return int|mixed