ulgm_progress_report_user_quizzes
Filters the user's quiz attempts for a specific group before displaying the progress report.
add_filter( 'ulgm_progress_report_user_quizzes', $callback, 10, 3 );
Description
Filters the user's attempted and completed quiz data before it's displayed in the progress report. Developers can modify the $quiz_attempts array to alter the displayed quiz results for a specific user within a group. This hook fires after fetching initial quiz attempt data.
Usage
add_filter( 'ulgm_progress_report_user_quizzes', 'your_function_name', 10, 3 );
Parameters
-
$quiz_attempts(mixed) - This parameter contains an array of all quizzes attempted by a specific user, along with their attempt details.
-
$user_id(mixed) - This parameter contains an array of quiz attempts for the specified user, which can be filtered to modify the data before it's displayed in the progress report.
-
$group_id(mixed) - This parameter represents the unique identifier of the user whose quiz progress is being reported.
Return Value
The filtered value.
Examples
/**
* Example filter for 'ulgm_progress_report_user_quizzes'.
*
* This filter allows modifying the list of quiz attempts for a user within a specific group.
* For instance, you might want to exclude certain quiz types or add custom status information.
*
* @param array $quiz_attempts An array of the user's quiz attempts. Each element likely represents a single attempt
* and might contain details like quiz ID, score, completion status, timestamp, etc.
* @param int $user_id The ID of the user whose progress report is being generated.
* @param int $group_id The ID of the group the user belongs to (if applicable).
* @return array The modified array of quiz attempts.
*/
add_filter(
'ulgm_progress_report_user_quizzes',
function ( $quiz_attempts, $user_id, $group_id ) {
// Example: If this is for a specific group (e.g., group ID 15),
// and we want to filter out quiz attempts that are not yet completed.
// In a real-world scenario, you'd need to know the structure of $quiz_attempts.
// Assuming each item has a 'status' key.
if ( $group_id === 15 ) {
$filtered_attempts = array_filter(
$quiz_attempts,
function ( $attempt ) {
// Replace 'completed' with the actual value indicating completion.
return isset( $attempt['status'] ) && $attempt['status'] === 'completed';
}
);
return $filtered_attempts;
}
// If no specific filtering is needed for other groups or conditions,
// return the original array.
return $quiz_attempts;
},
10, // Priority
3 // Number of accepted arguments
);
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:873
}
$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 );
$courses = apply_filters( 'ulgm_progress_report_courses', $courses, $user_courses, $user_id, $quiz_attempts, $group_id );
remove_action( 'parse_query', array( __CLASS__, 'wpml_suppress_filters' ) );