ulgm_quiz_report_hide_unattempted_users
Filters whether unattempted users are hidden from quiz reports, allowing customization of report visibility.
add_filter( 'ulgm_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. Developers can return `true` to hide unattempted users. This filter fires after matching users are identified but before they are displayed in the report.
Usage
add_filter( 'ulgm_quiz_report_hide_unattempted_users', 'your_function_name', 10, 2 );
Parameters
-
$quiz_ID(mixed) - This parameter is the default value for the filter, which can be modified by other filters.
-
$group_ID(mixed) - This parameter contains the ID of the quiz for which the report is being generated.
Return Value
The filtered value.
Examples
<?php
/**
* Hide users who have not attempted a quiz from the group quiz report.
*
* This filter allows administrators to choose whether or not to display users
* who have not yet started or completed a specific quiz within a group.
*
* @param bool $hide_unattempted_users Whether to hide unattempted users. Defaults to false.
* @param int $quiz_ID The ID of the quiz.
* @param int $group_ID The ID of the group.
* @return bool True if unattempted users should be hidden, false otherwise.
*/
add_filter( 'ulgm_quiz_report_hide_unattempted_users', 'my_plugin_hide_unattempted_quiz_users', 10, 3 );
function my_plugin_hide_unattempted_quiz_users( $hide_unattempted_users, $quiz_ID, $group_ID ) {
// Example logic: Always hide unattempted users for a specific quiz.
// Replace '123' with the actual Quiz ID you want to apply this rule to.
if ( $quiz_ID === 123 ) {
return true;
}
// Example logic: Hide unattempted users if the group is a "premium" group.
// This assumes you have a way to identify premium groups, e.g., a custom field.
if ( get_post_meta( $group_ID, '_is_premium_group', true ) === 'yes' ) {
return true;
}
// By default, do not hide unattempted users.
return $hide_unattempted_users;
}
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-quiz-report.php:858
'quiz_modal' => $modal_link,
'quiz_date' => $date,
);
}
}
}
if ( false === apply_filters( 'ulgm_quiz_report_hide_unattempted_users', false, $quiz_ID, $group_ID ) ) {
$array_unique = array_diff( array_merge( $matched_user_ids, $group_users ), array_intersect( $matched_user_ids, $group_users ) );
if ( isset( $array_unique ) && ! empty( $array_unique ) ) {
foreach ( $array_unique as $user_id ) {
$user_info = $data[ $user_id ];
$score = _x( 'Pending', 'Pending Certificate Status Label', 'learndash' );
$modal_link = __( 'No stats recorded', 'uncanny-learndash-groups' );
$html_vars[] = (object) array(