tincan_table_columns
Filters the default columns displayed in the Uncanny Toolkit reporting table.
add_filter( 'tincan_table_columns', $callback, 10, 1 );
Description
Filter the columns displayed in the Tin Can reporting table. Developers can add, remove, or reorder columns to customize the data presented to users, offering greater flexibility in reporting Learner experience.
Usage
add_filter( 'tincan_table_columns', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to add or modify columns for the Tin Can XAPI table.
* This function demonstrates adding a new 'Activity Type' column and
* reordering existing columns.
*
* @param array $columns The original array of table columns.
* @return array The modified array of table columns.
*/
function my_custom_tincan_table_columns( $columns ) {
// Define the new column we want to add.
$new_column_key = 'activity_type';
$new_column_label = __( 'Activity Type', 'my-text-domain' );
// Find the position where we want to insert the new column.
// For example, let's insert it after 'Module'.
$module_index = array_search( __( 'Module', 'uncanny-learndash-reporting' ), $columns );
if ( $module_index !== false ) {
// Insert the new column after 'Module'.
$columns = array_slice( $columns, 0, $module_index + 1, true ) +
array( $new_column_key => $new_column_label ) +
array_slice( $columns, $module_index + 1, count( $columns ) - 1, true );
} else {
// If 'Module' is not found, just append the new column.
$columns[$new_column_key] = $new_column_label;
}
// Example of reordering: Move 'Target' to be the last column.
$target_index = array_search( __( 'Target', 'uncanny-learndash-reporting' ), $columns );
if ( $target_index !== false ) {
$target_column = $columns[$target_index];
unset( $columns[$target_index] );
// Append it to the end
$columns[$target_index] = $target_column;
}
// You can also remove columns if needed.
// For example, to remove the 'Group' column:
/*
$group_index = array_search( __( 'Group', 'uncanny-learndash-reporting' ), $columns );
if ( $group_index !== false ) {
unset( $columns[$group_index] );
// Re-index the array if you removed an element and need contiguous keys
$columns = array_values( $columns );
}
*/
return $columns;
}
add_filter( 'tincan_table_columns', 'my_custom_tincan_table_columns', 10, 1 );
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/shortcode-tincanny/shortcode-tincanny.php:1736
$columns = apply_filters( 'tincan_xapi_table_columns', $columns );
} else {
add_filter( 'tincan_table_columns', array( __CLASS__, 'tincan_remove_success_column' ), 10 );
$columns = apply_filters(
'tincan_table_columns',
array(
__( 'Group', 'uncanny-learndash-reporting' ),
__( 'User', 'uncanny-learndash-reporting' ),
__( 'Course', 'uncanny-learndash-reporting' ),
__( 'Module', 'uncanny-learndash-reporting' ),
__( 'Target', 'uncanny-learndash-reporting' ),