Filter tin-canny-learndash-reporting

tincanny_module_url

Filters the URL for a module.

add_filter( 'tincanny_module_url', $callback, 10, 3 );

Description

Filters the URL for a Uncanny Automations module. Developers can use this hook to modify the module's URL before it's used. The hook provides the original URL, the module item data, and the module object itself.


Usage

add_filter( 'tincanny_module_url', 'your_function_name', 10, 3 );

Parameters

$url (mixed)
The current module URL.
$item (mixed)
The current module URL, which can be modified by the filter.
$module (mixed)
This parameter contains the data of the specific module item being processed.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the tincanny_module_url filter.
 *
 * This filter allows you to modify the URL of a module before it's used.
 * For instance, you might want to append a query parameter for tracking
 * or change the URL entirely if the module is hosted externally.
 *
 * @param string $url The current module URL.
 * @param array  $item The module item data from the database.
 * @param object $module The module object instance.
 * @return string The modified module URL.
 */
function my_custom_tincanny_module_url_filter( $url, $item, $module ) {
	// Example: Append a version query parameter to the URL if it's a Storyline module.
	if ( $module instanceof Uncanny_Automator_Pro_ClassesFileSystemModuleStoryline ) {
		$version = get_post_meta( $item['ID'], '_my_custom_module_version', true );
		if ( ! empty( $version ) ) {
			$url = add_query_arg( 'ver', $version, $url );
		}
	}

	// Example: If the module is hosted on an external CDN, override the default URL.
	$external_host = 'https://my-cdn.example.com/courses/';
	if ( 'external_hosted' === $item['type'] ) { // Assuming 'external_hosted' is a valid $item['type']
		$url = $external_host . $item['file_name'];
	}

	return $url;
}
add_filter( 'tincanny_module_url', 'my_custom_tincanny_module_url_filter', 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-articulate-and-captivate/classes/Module.php:76

public static function get_module( $item_id ) {
		$item   = Module_CRUD::get_item( $item_id );
		$module = false;

		if ( ! $item ) {
			return false;
		}

		if ( ! $item['ID'] ) {
			return false;
		}

		$item['type'] = strtolower( str_replace( ' ', '', $item['type'] ) );

		switch ( $item['type'] ) {
			case 'articulaterise':
				$module = new FileSystemModuleArticulateRise( $item_id );
				break;
			case 'ar2017':
				$module = new FileSystemModuleArticulateRise2017( $item_id );
				break;
			case 'storyline':
				$module = new FileSystemModuleStoryline( $item_id );
				break;
			case 'ispring':
				$module = new FileSystemModuleiSpring( $item_id );
				break;
			case 'captivate':
				$module = new FileSystemModuleCaptivate( $item_id );
				break;
			case 'captivate2017':
				$module = new FileSystemModuleCaptivate2017( $item_id );
				break;
			/* add Presenter360 tin can format */
			case 'presenter360':
				$module = new FileSystemModulePresenter360( $item_id );
				break;
			/* END Presenter360 */

			/* add Lectora tin can format */
			case 'lectora':
				$module = new FileSystemModuleLectora( $item_id );
				break;
			/* END Lectora */
			case 'scorm':
				$module = new FileSystemModuleScorm( $item_id );
				break;
			case 'tincan':
				$module = new FileSystemModuleXapi( $item_id );
				break;
			default:
				$module = new FileSystemModuleUnknownType( $item_id );
				break;
		}

		$url         = get_site_url() . $item['url'];
		$item['url'] = apply_filters( 'tincanny_module_url', $url, $item, $module );

		if ( $module ) {
			if ( is_ssl() ) {
				$item['url'] = str_replace( 'http://', 'https://', $item['url'] );
			}

			$module->set_url( $item['url'] );
			$module->set_name( $item['file_name'] );

			return $module;
		}

		return false;
	}

Scroll to Top