Filter tin-canny-learndash-reporting

uo_tincanny_question_analysis_report_disable_cache

Filters whether the Tincanny question analysis report cache should be disabled.

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

Description

Filters whether the Uncanny Automator Question Analysis Report should disable its data caching. Return `true` to force a fresh data retrieval, bypassing any cached results. Useful for ensuring the most up-to-date report data is displayed, especially during development or immediate post-update scenarios.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of disabling cache for Uncanny Question Analysis Report under specific conditions.
 *
 * This filter allows developers to conditionally disable the caching mechanism for the
 * Uncanny Question Analysis Report data. For instance, it might be useful during
 * development or testing to ensure fresh data is always loaded.
 *
 * @param bool   $disable_cache Whether to disable caching. Defaults to true.
 * @param string $class_name    The name of the class where the filter is applied (e.g., 'Uncanny_Question_Analysis_Report').
 *
 * @return bool Returns true to disable cache, false to allow caching.
 */
add_filter(
	'uo_tincanny_question_analysis_report_disable_cache',
	function ( $disable_cache, $class_name ) {
		// Only disable cache if we are in a staging or development environment,
		// or if a specific GET parameter is present in the URL.
		if ( defined( 'WP_ENVIRONMENT_TYPE' ) && in_array( WP_ENVIRONMENT_TYPE, array( 'development', 'staging' ) ) ) {
			return true; // Force fresh data in dev/staging environments.
		}

		if ( isset( $_GET['force_refresh_report'] ) && $_GET['force_refresh_report'] === '1' ) {
			return true; // Force fresh data if the specific GET parameter is set.
		}

		// Otherwise, rely on the default behavior (which is to cache).
		return $disable_cache;
	},
	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/uncanny-question-analysis-report/question-analysis-report.php:284

private static function is_fresh_data_required( $quiz_id ) {
		if ( true === apply_filters( 'uo_tincanny_question_analysis_report_disable_cache', true, __CLASS__ ) ) {
			return true;
		}
		$distractors       = self::cache_get( 'distractor_data_' . $quiz_id );
		$questions         = self::cache_get( 'questions_data_' . $quiz_id );
		$total_distractors = self::cache_get( 'total_distractors_' . $quiz_id );
		$col_headings      = self::cache_get( 'column_headings_' . $quiz_id );
		if ( empty( $questions ) || empty( $distractors ) || empty( $total_distractors ) || empty( $col_headings ) ) {
			return true;
		}
		self::$distractors       = $distractors;
		self::$total_distractors = $total_distractors;
		self::$columns           = $col_headings;
		self::$questions         = $questions;

		return false;
	}

Scroll to Top