uo_tincanny_reporting_module_request_language_keys
Filter: uo_tincanny_reporting_module_request_language_keys Filters the language keys used for Tincanny reporting module requests.
add_filter( 'uo_tincanny_reporting_module_request_language_keys', $callback, 10, 1 );
Description
Fires when language keys are retrieved for the Tincanny reporting module. Developers can use this filter to modify the array of language keys before they are returned. The `$args` parameter provides context about the current request, such as the activity, group, course, and lesson IDs.
Usage
add_filter( 'uo_tincanny_reporting_module_request_language_keys', 'your_function_name', 10, 1 );
Parameters
-
$lang_keys(array) - - **$args** `array`
Return Value
array
Examples
add_filter( 'uo_tincanny_reporting_module_request_language_keys', 'my_custom_tincanny_language_keys', 10, 2 );
/**
* Example function to modify the language keys for Tin Can reporting.
*
* This function demonstrates how to add custom language keys or modify existing ones
* passed to the Tin Can reporting module request.
*
* @param array $lang_keys The original array of language keys.
* @param array $args The arguments passed to the filter, including activity, group_id, course_id, and lesson_id.
* @return array The modified array of language keys.
*/
function my_custom_tincanny_language_keys( $lang_keys, $args ) {
// Check if we are dealing with a specific lesson or course, and if it's a certain type of activity.
if ( isset( $args['lesson_id'] ) && ! empty( $args['lesson_id'] ) ) {
// Example: Add a custom key specific to a particular lesson.
// Let's say lesson ID 123 is a quiz.
if ( 123 === (int) $args['lesson_id'] ) {
$lang_keys['custom_quiz_completion_message'] = __( 'You have successfully completed the quiz!', 'my-text-domain' );
}
}
// Example: Modify an existing key or add a general one.
// Let's ensure a common key is present, or override it if it exists.
$lang_keys['course_progress_label'] = __( 'Your Progress in Course', 'my-text-domain' );
// Example: Remove a key if it's not needed.
if ( isset( $lang_keys['lesson_title'] ) ) {
// Maybe we don't want the lesson title to be reported directly in this context.
// unset( $lang_keys['lesson_title'] );
}
// It's crucial to return the modified array of language keys.
return $lang_keys;
}
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:253
* Filter: uo_tincanny_reporting_module_request_language_keys
*
* @param array $lang_keys
* @param array $args
*
* @return array
*/
$lang_keys_filtered = apply_filters(
'uo_tincanny_reporting_module_request_language_keys',
$lang_keys,
array(
'activity' => $activity,
'group_id' => $group_id,
'course_id' => $course_id,
'lesson_id' => $lesson_id,