tc_api_get_userSingleCourseProgressSummaryTable
Filters the user's single course progress summary table data before it's returned.
add_filter( 'tc_api_get_userSingleCourseProgressSummaryTable', $callback, 10, 3 );
Description
Filters the data for the User Single Course Progress Summary table. Developers can modify the JSON response, user ID, or course ID before the table data is returned. This hook fires after initial data retrieval and before the final JSON output.
Usage
add_filter( 'tc_api_get_userSingleCourseProgressSummaryTable', 'your_function_name', 10, 3 );
Parameters
-
$json_return(mixed) - This parameter contains the JSON response array that will be returned by the API, including messages, success status, and course progress data.
-
$user_id(mixed) - This parameter contains the JSON response array that will be returned by the API call, initially structured with default success and data fields.
-
$course_id(mixed) - This parameter contains the unique identifier for the user whose course progress summary is being requested.
Return Value
The filtered value.
Examples
<?php
/**
* Example callback function for the tc_api_get_userSingleCourseProgressSummaryTable filter hook.
*
* This function modifies the returned JSON data to include additional information
* about the user's progress within a specific course, such as the completion status
* of individual lessons and the time spent on the course.
*
* @param array $json_return The original JSON return array containing 'message', 'success', and 'data'.
* @param int $user_id The ID of the user.
* @param int $course_id The ID of the course.
* @return array The modified JSON return array.
*/
function my_custom_user_course_progress_summary( $json_return, $user_id, $course_id ) {
// Ensure that the original call was successful and we have data to work with.
if ( ! $json_return['success'] || empty( $json_return['data'] ) ) {
return $json_return;
}
// Retrieve additional progress details if available (assuming a function like this exists).
// This is a hypothetical example; you would replace this with actual functions
// that fetch detailed progress data from your WordPress installation or LearnDash.
$lesson_progress = tc_get_user_lesson_progress( $user_id, $course_id );
$time_spent = tc_get_user_course_time_spent( $user_id, $course_id );
// Add the new information to the existing data array.
$json_return['data']['lesson_completion'] = $lesson_progress;
$json_return['data']['time_spent_on_course'] = $time_spent;
// Optionally, you could add a custom message or adjust the success status.
// $json_return['message'] = 'User course progress summary enhanced.';
return $json_return;
}
add_filter( 'tc_api_get_userSingleCourseProgressSummaryTable', 'my_custom_user_course_progress_summary', 10, 3 );
/*
* Hypothetical helper functions (replace with actual implementations if they exist in your context):
*
* function tc_get_user_lesson_progress( $user_id, $course_id ) {
* // Logic to fetch lesson completion status for a user in a course.
* // Example: return array('lesson_1' => 'completed', 'lesson_2' => 'in_progress');
* return array();
* }
*
* function tc_get_user_course_time_spent( $user_id, $course_id ) {
* // Logic to fetch the total time spent by a user on a course.
* // Example: return '05:30:15'; // Hours:Minutes:Seconds
* return '00:00:00';
* }
*/
?>
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-table-data.php:448
public static function user_single_course_progress_summary_table() {
$json_return = array(
'message' => '',
'success' => false,
'data' => array(),
);
// $json_return['success'] = false;
// $json_return['data'] = $_POST;// phpcs:ignore WordPress.Security
if ( ! ultc_filter_has_var( 'userId', INPUT_POST ) && ! ultc_filter_has_var( 'courseId', INPUT_POST ) ) {
$json_return['message'] = 'userId or courseId not set';
return $json_return;
}
$user_id = absint( ultc_filter_input( 'userId', INPUT_POST ) );
$course_id = absint( ultc_filter_input( 'courseId', INPUT_POST ) );
$json_return['success'] = true;
$json_return['data'] = self::get_user_single_course_overview( $user_id, $course_id );
return apply_filters( 'tc_api_get_userSingleCourseProgressSummaryTable', $json_return, $user_id, $course_id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName
}