Filter tin-canny-learndash-reporting

tincanny_result_override

Filters the result of the Tin Canny plugin before it is displayed, allowing custom modifications.

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

Description

Fires after a Tin Can statement's success status is determined, allowing you to override the calculated result. Developers can use this filter to modify the success value (e.g., 0 or 1) based on custom logic before it's saved to the database. The original result is passed as the first argument, and the `TinCanRequest` object as the second.


Usage

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

Parameters

$this (mixed)
This parameter is used to provide an initial value for the result that can be overridden by the filter.

Return Value

The filtered value.


Examples

// Example of how to use the 'tincanny_result_override' filter.
// This filter allows you to manually set the result of a Tin Can API statement,
// overriding the default logic. For instance, you might want to enforce a
// specific score or success status based on external factors.
add_filter( 'tincanny_result_override', function( $null_param, $tin_can_result_object ) {
	// In this example, we'll check if the Tin Can result indicates success
	// and if a score is present. If both are true, and the original score is
	// less than 0.7, we'll override the result to be 0.7 (e.g., forcing a minimum passing score).

	// The first parameter ($null_param) is provided by the hook and is typically null.
	// We'll primarily work with the second parameter, which is the $this->TC_Result object.

	$current_result = $tin_can_result_object->getResult(); // This might be an array or a specific object depending on the Tin Can API implementation

	// Check if the result object has a success property and it's true
	if ( $tin_can_result_object->getSuccess() === true ) {

		// Check if a score exists and if it's below a certain threshold (e.g., 0.7)
		$score = $tin_can_result_object->getScore();
		if ( ! is_null( $score ) && is_array( $score ) && isset( $score['raw'] ) && $score['raw'] < 0.7 ) {
			// Override the result to enforce a minimum score of 0.7
			return 0.7;
		}
	}

	// If no override is needed, return null to let the default logic proceed.
	return null;

}, 10, 2 ); // Priority 10, accepting 2 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/uncanny-tincan/classes/TinCanRequest.php:406

if ( $this->TC_Result->getSuccess() ) {
				if ( false === $result && is_null( $this->TC_Result->getScore() ) ) {
					$result = 1;
				}
			}

			$tincanny_result_override = apply_filters( 'tincanny_result_override', null, $this->TC_Result );
			if ( ! is_null( $tincanny_result_override ) ) {
				$result = $tincanny_result_override;
			}


			$database->set_quiz_data(
				$group_id,


Scroll to Top