Filter tin-canny-learndash-reporting

uo_tincanny_quiz_report_show_multiple_attempts

Filters whether to display the multiple attempts section on a quiz report.

add_filter( 'uo_tincanny_quiz_report_show_multiple_attempts', $callback, 10, 2 );

Description

This filter hook determines whether to display multiple quiz attempt data in reports. Developers can filter the return value to `true` to enable this display, or keep it `false` (default) to hide it. It fires after initial checks and before displaying the quiz report summary.


Usage

add_filter( 'uo_tincanny_quiz_report_show_multiple_attempts', 'your_function_name', 10, 2 );

Parameters

$course_id (mixed)
This parameter is a boolean value that determines whether to display multiple quiz attempts for a given quiz.
$quiz_attempt_post_id (mixed)
This parameter represents the ID of the course for which the quiz report is being generated.

Return Value

The filtered value.


Examples

/**
 * Filters whether to show multiple quiz attempts in the report.
 *
 * By default, this filter returns false, meaning multiple attempts are not shown.
 * This example demonstrates how to enable showing multiple attempts if a
 * specific user role is present.
 *
 * @param bool   $show_multiple_attempts Whether to show multiple quiz attempts.
 * @param int    $course_id              The ID of the course.
 * @param int    $quiz_attempt_post_id   The ID of the quiz attempt post.
 * @return bool  True if multiple attempts should be shown, false otherwise.
 */
add_filter(
	'uo_tincanny_quiz_report_show_multiple_attempts',
	function( $show_multiple_attempts, $course_id, $quiz_attempt_post_id ) {
		// Check if the current user has the 'administrator' role.
		if ( current_user_can( 'administrator' ) ) {
			// If the user is an administrator, allow showing multiple attempts.
			return true;
		}

		// Otherwise, return the default value (false).
		return $show_multiple_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/reporting/learndash/frontend-reports/quiz-module-reports.php:932

href="#">';
									$modal_link .= '<div class="statistic_icon"></div>';
									$modal_link .= '</a>';
								}
							}
						}

						$show_multiple_quiz_attempts = apply_filters( 'uo_tincanny_quiz_report_show_multiple_attempts', false, $course_id, $quiz_attempt_post_id );

						$date = learndash_adjust_date_time_display( $quiz_attempt['time'] );

						$data_key = sanitize_title( $course_id . $quiz_title );
						if ( $show_multiple_quiz_attempts ) {
							$data_key = sanitize_title( $course_id . $quiz_title . $k );
						}


Scroll to Top