Action tin-canny-learndash-reporting

tincanny_module_completed

Fires when a module is completed by a user, passing the module ID, user ID, and the verb used.

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

Description

Fires when a user completes a module, passing the module ID, user ID, and the verb used to record completion. Developers can use this hook to trigger custom actions, log completion data, or integrate with other systems upon module completion.


Usage

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

Parameters

$module_id (mixed)
The `$module_id` parameter contains a unique identifier for the completed module.
$user_id (mixed)
The ID of the module that has been completed.
$verb (mixed)
This parameter represents the unique identifier of the user who has completed the module.

Examples

add_action( 'tincanny_module_completed', 'my_tincanny_module_completed_handler', 10, 3 );

/**
 * Handles the tincanny_module_completed action hook.
 *
 * This function logs when a module is completed by a user and potentially
 * triggers further actions based on the completion.
 *
 * @param mixed $module_id The ID of the completed module.
 * @param mixed $user_id The ID of the user who completed the module.
 * @param mixed $verb The verb associated with the module completion (e.g., 'completed', 'passed').
 */
function my_tincanny_module_completed_handler( $module_id, $user_id, $verb ) {
	// Log the module completion event for debugging purposes.
	error_log( sprintf(
		'Tincanny module completed: Module ID = %s, User ID = %s, Verb = %s',
		$module_id,
		$user_id,
		$verb
	) );

	// Example: If the module is marked as 'passed', grant a badge to the user.
	if ( 'passed' === $verb ) {
		$badge_id = 'module-' . $module_id . '-completion';
		// Assuming a function `grant_user_badge` exists in your theme or plugin.
		// grant_user_badge( $user_id, $badge_id );
	}

	// Example: Send a notification to the user if it's a specific critical module.
	$critical_modules = array( 'module-101', 'module-205' );
	if ( in_array( $module_id, $critical_modules ) ) {
		// Assuming a function `send_custom_notification` exists.
		// send_custom_notification(
		// 	$user_id,
		// 	__( 'Congratulations!', 'your-text-domain' ),
		// 	sprintf(
		// 		__( 'You have successfully completed the "%s" module!', 'your-text-domain' ),
		// 		get_the_title( $module_id ) // Assuming get_the_title can retrieve module title by ID
		// 	)
		// );
	}
}

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/Database.php:473

);

		$user_id = ( $user_id ) ? $user_id : self::$user_id;

		$module_match = $this->get_slide_id_from_module( $module );
		if ( isset( $module_match[1] ) ) {
			$module_id = $module_match[1];
			do_action( 'tincanny_module_completed', $module_id, $user_id, $verb );
		}

		return true;
	}

	/**
	 * @param $url

Scroll to Top