Filter tin-canny-learndash-reporting

uo_tincanny_set_slides_auth_value

Filters the authentication value for Tincanny slides before it's set.

add_filter( 'uo_tincanny_set_slides_auth_value', $callback, 10, 2 );

Description

Filters the authentication value used for Tin Can API slides requests. Developers can modify the `$auth` parameter, typically an array containing authentication credentials, before it's used in the request. The `$filter_args` provides context about the filter request.


Usage

add_filter( 'uo_tincanny_set_slides_auth_value', 'your_function_name', 10, 2 );

Parameters

$auth (mixed)
This parameter contains the authentication value for the Tin Can API slides request.
$filter_args (mixed)
This parameter holds the authentication value for the Tin Can API request.

Return Value

The filtered value.


Examples

/**
 * Example filter for uo_tincanny_set_slides_auth_value.
 *
 * This example demonstrates how to modify the authentication value
 * based on user role or other custom logic.
 */
add_filter(
	'uo_tincanny_set_slides_auth_value',
	function( $auth, $filter_args ) {
		// Check if the current user is an administrator.
		if ( current_user_can( 'administrator' ) ) {
			// If the user is an administrator, set a specific authentication value.
			$auth = 'admin_access_token_' . uniqid();
		} else {
			// For other users, you might want to use a default or a dynamically generated one.
			// For demonstration, we'll just append a user ID if logged in.
			if ( is_user_logged_in() ) {
				$auth = 'user_session_' . get_current_user_id();
			} else {
				// If not logged in, perhaps use a guest token or leave as is.
				// We'll assume the default $auth value is suitable here.
			}
		}

		// Always return the modified $auth value.
		return $auth;
	},
	10, // Priority
	2   // Accepted 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/Slides.php:103

if ( is_array($all_headers) && isset( $all_headers['uotcmodulereferer'] ) ) {
				$activity_id = $all_headers['uotcmodulereferer'];
			}
		}

		// Allow filtering
		$auth        = apply_filters( 'uo_tincanny_set_slides_auth_value', $auth, $filter_args );

		// Ensure we have activity id (URL). Detect it via custom header.
		if (empty($activity_id) && function_exists('getallheaders')) {
			$all_headers = array_change_key_case(getallheaders(), CASE_LOWER);
			if (!empty($all_headers['uotcmodulereferer'])) {
				$url = $all_headers['uotcmodulereferer'];


Scroll to Top