uo_assignments_columns
Filters the columns displayed in the assignments table, allowing customization before rendering.
add_filter( 'uo_assignments_columns', $callback, 10, 1 );
Description
Filters the columns displayed in the Uncanny Assignments report. Developers can add, remove, or modify existing columns, influencing the data presented. This hook fires during the report generation process before columns are rendered. Use it to customize the assignment report's structure and content.
Usage
add_filter( 'uo_assignments_columns', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the 'uo_assignments_columns' hook.
* This example demonstrates how to add or remove columns displayed in the assignments report.
* By default, the hook returns 3. This example will add an extra column if a specific
* meta key is present on the current course.
*
* @param int $total_columns The current number of columns to display.
* @return int The modified number of columns to display.
*/
add_filter( 'uo_assignments_columns', function( $total_columns ) {
// Assume we're on a single course page or have access to the current course object.
// In a real scenario, you'd likely get this from global $post or by passing
// the course ID through. For this example, we'll simulate checking for a meta key.
$current_course_id = get_queried_object_id(); // Example: get ID of the current course being viewed.
if ( $current_course_id && get_post_meta( $current_course_id, 'my_custom_assignment_data_key', true ) ) {
// If a specific custom meta key exists on the course, add an extra column.
$total_columns++;
}
// You could also choose to remove columns based on certain conditions.
// For example, if $total_columns is greater than a certain threshold,
// you might want to cap it.
// $max_allowed_columns = 5;
// if ( $total_columns > $max_allowed_columns ) {
// $total_columns = $max_allowed_columns;
// }
return $total_columns;
}, 10, 1 ); // Priority 10, accepting 1 argument.
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/classes/enhanced-learndash-report.php:434
src/classes/enhanced-learndash-report.php:614
src/classes/enhanced-learndash-report.php:738
'type' => 'text',
'label' => esc_attr__( '', 'uncanny-pro-toolkit' ),
'placeholder' => esc_attr__( 'Course Meta Key 3', 'uncanny-pro-toolkit' ),
'option_name' => 'uncanny-learndash-report-coursemetakey-3',
);
// Field Course meta key 3 end.
$total_columns = apply_filters( 'uo_assignments_columns', 3 );
for ( $loop = 1; $loop <= $total_columns; $loop ++ ) {
$options[] = array(
'type' => 'checkbox',
'label' => sprintf( esc_html__( 'Assignment info #%d', 'uncanny-pro-toolkit' ), $loop ),
'option_name' => 'uncanny-learndash-report-assignmentsinfo-' . $loop,
);
}