uo_get_courses_overview_data
Filters the course overview data Filters the course overview data before it is returned, allowing for customization of what information is displayed.
add_filter( 'uo_get_courses_overview_data', $callback, 10, 1 );
Description
Fires after course overview data is prepared, allowing modification of the data array. Developers can customize which data points are included or alter their values before the report is displayed or cached. Accepts the data array and report type as arguments.
Usage
add_filter( 'uo_get_courses_overview_data', 'your_function_name', 10, 1 );
Parameters
-
$return(mixed) - - **$type** `mixed`
Return Value
The filtered value.
Examples
/**
* Example of modifying the course overview data before it's returned.
*
* This function demonstrates how to hook into 'uo_get_courses_overview_data'
* to filter or add information to the course overview data.
*
* @param array $return The original course overview data.
* @param string $type The type of overview requested (e.g., 'both', 'users', 'courses').
* @return array The modified course overview data.
*/
add_filter( 'uo_get_courses_overview_data', function ( $return, $type ) {
// Example: Add a custom statistic for courses with over 80% completion rate.
if ( isset( $return['course_completion_by_course'] ) && is_array( $return['course_completion_by_course'] ) ) {
$high_completion_courses_count = 0;
foreach ( $return['course_completion_by_course'] as $course_id => $completion_data ) {
if ( isset( $completion_data['percentage'] ) && $completion_data['percentage'] > 80 ) {
$high_completion_courses_count++;
}
}
// Add our custom statistic to the return array.
$return['high_completion_course_count'] = $high_completion_courses_count;
}
// Example: If only 'users' type is requested, maybe remove course-specific data.
if ( $type === 'users' && isset( $return['course_completion_by_course'] ) ) {
unset( $return['course_completion_by_course'] );
}
// Always return the (potentially modified) data.
return $return;
}, 10, 2 ); // Priority 10, accepting 2 arguments ($return, $type)
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/reporting/learndash/courses-users-report/endpoint-courses-overview.php:72
src/reporting/learndash/courses-users-report/endpoint-courses-overview.php:91
public static function get_courses_overview_data( $type = 'both' ) {
$cache = Cache::get( __FUNCTION__ );
if ( ! empty( $cache ) ) {
return apply_filters( 'uo_get_courses_overview_data', $cache, $type );
}
// Build the dashboard data
self::get_dashboard_data();
$return['users_overview'] = self::$all_user_data_rearranged;
$return['completions'] = self::$completions_rearranged;
$return['in_progress'] = self::$in_progress_rearranged;
$return['course_access_list'] = self::$course_access_list;
$return['course_quiz_averages'] = self::$course_quiz_average;
$return['course_completion_by_course'] = self::$course_completion_by_course;
$return['dashboard_data'] = self::$dashboard_data_object;
Cache::create( __FUNCTION__, $return );
/**
* Filters the course overview data
*/
return apply_filters( 'uo_get_courses_overview_data', $return, $type );
}