Filter tin-canny-learndash-reporting

uo_tincanny_quiz_report_show_multiple_module_attempts

Filters whether multiple module attempts are displayed on the Tincanny quiz report, before the report is rendered.

add_filter( 'uo_tincanny_quiz_report_show_multiple_module_attempts', $callback, 10, 1 );

Description

This filter hook controls whether to display multiple attempts for H5P modules within quiz reports. By default, it returns `false`, hiding multiple attempts. Developers can return `true` to allow displaying all module attempts for a quiz.


Usage

add_filter( 'uo_tincanny_quiz_report_show_multiple_module_attempts', 'your_function_name', 10, 1 );

Parameters

$_quiz (mixed)
This parameter controls whether to display multiple attempts for a quiz module in the report.

Return Value

The filtered value.


Examples

/**
 * Conditionally display multiple attempts for specific modules in the Tincanny quiz report.
 *
 * This filter allows developers to control whether multiple attempts of a specific
 * module within a Tincanny quiz are displayed in the report. By default, it's set to false.
 *
 * @param bool $_show_multiple_attempts The current value of whether to show multiple attempts.
 * @param string $_module_id The unique identifier of the module being processed.
 * @return bool Whether to show multiple attempts for the current module.
 */
add_filter( 'uo_tincanny_quiz_report_show_multiple_module_attempts', function( $_show_multiple_attempts, $_module_id ) {

	// Example: Enable multiple attempts display only for modules with 'advanced-lesson' in their ID.
	if ( strpos( $_module_id, 'advanced-lesson' ) !== false ) {
		return true;
	}

	// Example: Disable multiple attempts display for modules with 'introductory' in their ID.
	if ( strpos( $_module_id, 'introductory' ) !== false ) {
		return false;
	}

	// For all other modules, respect the default value passed to the filter.
	return $_show_multiple_attempts;

}, 10, 2 );

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:990

// Loop through H5P completed and answered modules
		foreach ( $tc_quizzes as $mk => $_quiz ) {

			// Sanity check that the result is valid
			$score = 0 === absint( $_quiz->result ) ? '' : (int) $_quiz->result;

			$show_multiple_module_attempts = apply_filters( 'uo_tincanny_quiz_report_show_multiple_module_attempts', false, $_quiz->module );

			$unique_module_path = preg_replace( '/[^ w]+/', '', $_quiz->module );
			if ( $show_multiple_module_attempts ) {
				$unique_module_path = $unique_module_path . $mk;
			}

			if ( isset( $data[ $unique_module_path ] ) ) {


Scroll to Top