uotc_quiz_report_hide_unattempted_users
Filters whether to hide unattempted users from quiz reports.
add_filter( 'uotc_quiz_report_hide_unattempted_users', $callback, 10, 2 );
Description
Filters whether to hide users who haven't attempted a quiz in the group quiz report. By default, unattempted users are shown. Developers can return `true` to hide them, offering finer control over report display for specific quizzes or user groups.
Usage
add_filter( 'uotc_quiz_report_hide_unattempted_users', 'your_function_name', 10, 2 );
Parameters
-
$quiz_id(mixed) - This parameter is a boolean value that determines whether to hide users who have not attempted the quiz.
-
$user_group_id(mixed) - This parameter represents the ID of the quiz for which the report is being generated.
Return Value
The filtered value.
Examples
/**
* Example of using the 'uotc_quiz_report_hide_unattempted_users' filter.
*
* This function demonstrates how to hook into the filter to dynamically
* decide whether to hide users who haven't attempted a specific quiz within
* a group report. In this example, we'll hide unattempted users if the
* quiz ID is 'quiz_123' and the user group ID is 'group_abc'.
*
* @param bool $hide_unattempted_users The current value of whether to hide unattempted users.
* @param int $quiz_id The ID of the quiz being reported on.
* @param int $user_group_id The ID of the user group being reported on.
* @return bool The modified value of whether to hide unattempted users.
*/
add_filter(
'uotc_quiz_report_hide_unattempted_users',
function( $hide_unattempted_users, $quiz_id, $user_group_id ) {
// Define specific conditions under which to hide unattempted users.
$specific_quiz_id = 'quiz_123';
$specific_group_id = 'group_abc';
// If the current quiz and group match our specific criteria,
// and the default is to hide, then return true.
if ( $quiz_id === $specific_quiz_id && $user_group_id === $specific_group_id ) {
return true; // Hide unattempted users for this specific quiz and group.
}
// Otherwise, return the original value passed to the filter.
return $hide_unattempted_users;
},
10, // Priority: 10 is the default and usually sufficient.
3 // Accepted arguments: The filter function accepts 3 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/reporting/learndash/frontend-reports/group-quiz-report.php:441
$users_added = array();
$no_attempts = array();
$results = array();
foreach ( $user_group_data as $user_group_id => $group_data ) {
$group_user_ids = $group_data['groups_user'];
$group_courses = $group_data['groups_course_access'];
$hide_unattempted_users = apply_filters( 'uotc_quiz_report_hide_unattempted_users', false, $quiz_id, $user_group_id );
foreach ( $group_user_ids as $group_user_id ) {
$user_data = $all_user_data[ $group_user_id ];
$quiz_data = is_null( $user_data->quizzes ) ? array() : maybe_unserialize( $user_data->quizzes );
if ( empty( $quiz_data ) && $hide_unattempted_users ) {
continue;
}
$user_attempt_added = false;