Action tin-canny-learndash-reporting

tincanny_module_result_processed

Fires after a Tincanny module result is processed, providing the module ID, user ID, and the result itself.

add_action( 'tincanny_module_result_processed', $callback, 10, 3 );

Description

Fired after an LRS module result is processed and saved. Developers can use this hook to perform custom actions, such as triggering notifications, updating user progress, or logging additional data related to the module completion for a specific user.


Usage

add_action( 'tincanny_module_result_processed', 'your_function_name', 10, 3 );

Parameters

$module_id (mixed)
This parameter contains the unique identifier of the module for which the result has been processed.
$user_id (mixed)
This parameter represents the unique identifier for the processed module.
$result (mixed)
This parameter contains the ID of the user who performed the action.

Examples

/**
 * Example of how to hook into the 'tincanny_module_result_processed' action.
 *
 * This function will be called after a module's result has been processed
 * by Uncanny Tincan. It demonstrates how to access and potentially use
 * the module ID, user ID, and the result of the module.
 */
function my_tincanny_module_result_processed_handler( $module_id, $user_id, $result ) {

	// In a real-world scenario, you might want to log this event,
	// send a notification, or trigger other custom logic based on the result.

	// For demonstration purposes, let's log the details to the WordPress debug log.
	if ( WP_DEBUG === true ) {
		error_log( sprintf(
			'Uncanny Tincan: Module result processed. Module ID: %s, User ID: %d, Result: %s',
			$module_id,
			absint( $user_id ), // Ensure user ID is a positive integer
			var_export( $result, true ) // Export result for detailed logging
		) );
	}

	// Example: Award custom points if the user passed a specific module.
	$custom_passed_module_id = 'your_specific_module_id'; // Replace with an actual module ID
	$passing_score_threshold = 80; // Example threshold for passing

	if ( $module_id === $custom_passed_module_id && is_numeric( $result ) && $result >= $passing_score_threshold ) {
		// Logic to award custom points or trigger other user meta updates.
		// Example: update_user_meta( $user_id, 'custom_points', get_user_meta( $user_id, 'custom_points', true ) + 10 );
		error_log( sprintf(
			'User %d achieved a passing score (%s) for module %s. Awarding custom points.',
			absint( $user_id ),
			$result,
			$module_id
		) );
	}
}

// Hook the function to the 'tincanny_module_result_processed' action.
// The third parameter '3' specifies that this callback function accepts 3 arguments.
add_action( 'tincanny_module_result_processed', 'my_tincanny_module_result_processed_handler', 10, 3 );

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

$database->set_report( $group_id, $course_id, $lesson_id, $module, $module_name, $target, $target_name, $verb, $result, $maximum, $completion, $user_id );

		$module_match = $database->get_slide_id_from_module( $module );
		if ( isset( $module_match[1] ) ) {

			$module_id = $module_match[1];
			if ( ( $this->TC_Result->getCompletion() || in_array( strtolower( $verb ), array( 'passed', 'completed', 'failed' ), true ) ) && $result >= 0 ) {
				do_action( 'tincanny_module_result_processed', $module_id, $user_id, $result );
			}
		}

		if ( ! is_null( $this->TC_Result->getResponse() ) ) {

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


Scroll to Top