Filter tin-canny-learndash-reporting

uo_tin_can_filter_groups

Filters the array of groups used for Tin Can API statements before they are output.

add_filter( 'uo_tin_can_filter_groups', $callback, 10, 1 );

Description

Filters the groups displayed in the Tin Can filter. Developers can use this hook to modify the list of groups or add custom ones before they are rendered in the Tin Can reporting interface. This hook is applied during template rendering.


Usage

add_filter( 'uo_tin_can_filter_groups', 'your_function_name', 10, 1 );

Parameters

$groups (mixed)
This parameter contains an array of group names that are used to filter the results displayed in the Tin Can filter.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the $groups variable for the 'uo_tin_can_filter_groups' hook.
 * This example demonstrates how to modify the list of groups before they are displayed
 * in the Tin Can filter dropdown.
 *
 * In this specific example, we'll assume $groups is an array of arrays, where each inner
 * array represents a group and has keys like 'group_id' and 'group_name'.
 * We'll add a new hypothetical group to the beginning of the list if a certain condition is met.
 *
 * @param array $groups The original array of groups.
 * @return array The modified array of groups.
 */
add_filter( 'uo_tin_can_filter_groups', 'my_custom_tin_can_filter_groups', 10, 1 );

function my_custom_tin_can_filter_groups( $groups ) {
    // Ensure $groups is an array, if not, return it as is.
    if ( ! is_array( $groups ) ) {
        return $groups;
    }

    // Example: Add a "New Department" group if there are already existing groups.
    // This is a hypothetical condition. In a real scenario, you might check
    // user roles, specific course IDs, or other relevant data.
    if ( ! empty( $groups ) ) {
        // We're adding a hypothetical new group with ID 999 and name 'New Department'.
        // You would typically fetch this information from your custom logic or a database.
        $new_department_group = array(
            'group_id'   => 999, // A unique ID for the new group
            'group_name' => 'New Department', // The display name for the new group
        );

        // Add the new group to the beginning of the array.
        array_unshift( $groups, $new_department_group );
    }

    // Return the modified groups array.
    return $groups;
}
?>

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/reporting/xapi-quiz/templates/xapi-quiz-filter.php:117
src/reporting/tin-can/templates/tc-tincan-filter.php:121

/* translators: %s: Group label */
												__( 'All %s', 'uncanny-learndash-reporting' ),
												apply_filters( 'uo_tin_can_filter_group_label', esc_html_x( 'Groups', 'Tin Can Filter Group name', 'uncanny-learndash-reporting' ), true)
											)
										);
										?>
                                    </option>
									<?php $groups = apply_filters( 'uo_tin_can_filter_groups', $groups ); ?>
									<?php if ( ! empty( $groups ) ) { ?>
										<?php foreach ( $groups as $group ) { ?>
											<?php $tc_group_selected = $tc_group_filter === (int) $group['group_id'] ? ' selected="selected"' : ''; ?>
                                            <option value="<?php echo esc_attr( $group['group_id'] ); ?>"<?php echo esc_attr( $tc_group_selected ); ?>>
												<?php echo esc_html( $group['group_name'] ); ?>
                                            </option>
										<?php } ?>


Scroll to Top