uo_tincanny_set_slides_activity_id
Filters the activity ID for slides, allowing modification before it's set for display.
add_filter( 'uo_tincanny_set_slides_activity_id', $callback, 10, 2 );
Description
Filters the activity ID for Uncanny Tin Can slide tracking. Allows modification of the activity ID before it's used in Tin Can API requests for slide completion. Useful for dynamically setting activity IDs based on context.
Usage
add_filter( 'uo_tincanny_set_slides_activity_id', 'your_function_name', 10, 2 );
Parameters
-
$activity_id(mixed) - This parameter contains the activity ID, which is initially derived from a URL, and can be modified by filters.
-
$filter_args(mixed) - This parameter holds the identifier for the activity associated with the current slide, which can be a URL or another mixed type if modified by filters.
Return Value
The filtered value.
Examples
// Prevent the activity ID from being set if the URL points to a specific type of WordPress page,
// allowing it to be handled differently by other parts of the system.
add_filter( 'uo_tincanny_set_slides_activity_id', function( $activity_id, $filter_args ) {
// Assuming $filter_args contains information about the URL or the context of the slide.
// Let's simulate checking if the URL is a specific WordPress post type or page.
// In a real scenario, you might extract the URL from $filter_args or have access to it globally.
// For demonstration, let's assume $filter_args is an array and contains a 'url' key.
if ( isset( $filter_args['url'] ) && is_string( $filter_args['url'] ) ) {
$url = $filter_args['url'];
// Example: Check if the URL is for a WordPress "lesson" post type.
// You would replace 'lesson' with the actual post type slug you want to exclude.
// This check might involve using get_post_type_object() or checking the URL structure.
if ( strpos( $url, '/lesson/' ) !== false ) {
// If it's a lesson URL, we want to prevent the activity ID from being set
// based on the default logic. We'll return an empty string to signify this.
return '';
}
}
// If no specific condition is met, return the original or modified $activity_id.
// In this case, we are not modifying it, just conditionally preventing it.
return $activity_id;
}, 10, 2 );
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:119
$module_data = $this->get_slide_id_from_url($url);
if (is_array($module_data) && !empty($module_data) && !empty($module_data[1])) {
$activity_id = $url;
}
}
}
$activity_id = apply_filters( 'uo_tincanny_set_slides_activity_id', $activity_id, $filter_args );
// Validate
if ( empty( $auth ) || !is_string( $auth ) || empty( $activity_id ) || !is_string( $activity_id ) ) {
// TODO REVIEW: Log Error
return;
}