uo_csv_report_column_value
Filters the value for a specific column within a CSV report before it's outputted.
add_filter( 'uo_csv_report_column_value', $callback, 10, 4 );
Description
Filters the value of a column in CSV reports. Developers can modify the displayed data for specific columns. This hook fires after the default column value is retrieved but before it's outputted in the CSV. It provides access to the column's key, the report item, and the associated user for dynamic value manipulation.
Usage
add_filter( 'uo_csv_report_column_value', 'your_function_name', 10, 4 );
Parameters
-
$column_value(mixed) - This parameter holds the calculated or retrieved value for the current column being processed in the CSV report.
-
$column_key(mixed) - This parameter contains the value that will be outputted for the current column in the report.
-
$report_item(mixed) - This parameter represents the unique key or identifier for the current column being processed in the report.
-
$report_user(mixed) - This parameter contains the current item being processed in the report, which could be a lesson, topic, quiz, or assignment.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to modify a column value in the CSV report.
*
* This function intercepts the 'uo_csv_report_column_value' filter to
* conditionally modify the value of a specific column ('course_progress')
* for users who have completed a certain course.
*
* @param mixed $column_value The original value of the column.
* @param mixed $column_key The key (ID) of the column.
* @param mixed $report_item The current report item being processed.
* @param WP_User $report_user The WP_User object for the current report user.
* @return mixed The modified or original column value.
*/
function my_custom_csv_report_column_value( $column_value, $column_key, $report_item, $report_user ) {
// Check if we are dealing with the 'course_progress' column
if ( 'course_progress' === $column_key ) {
// Assuming $report_item might contain course ID information or that we can fetch it.
// For realism, let's imagine $report_item is an array and we can get a course ID from it.
// In a real scenario, you'd need to know the structure of $report_item.
// Let's pretend $report_item contains 'course_id'.
$course_id_to_check = 123; // Replace with a real course ID or logic to get it.
// Let's assume $column_value is a numerical progress percentage.
// If the user has completed the course (e.g., progress is 100%)
if ( is_numeric( $column_value ) && intval( $column_value ) >= 100 ) {
// Let's add a custom status for completed courses.
// We'll need to know the course ID associated with this specific report item.
// This is a placeholder. In reality, you'd need to fetch the course ID from $report_item
// or by inspecting the $report_user's course data more deeply.
// For this example, let's assume $report_item contains 'course_id'.
if ( isset( $report_item['course_id'] ) && $report_item['course_id'] == $course_id_to_check ) {
return '<span style="color: green;">Completed</span>';
}
} elseif ( is_numeric( $column_value ) && intval( $column_value ) > 0 ) {
// If the course is in progress, display the percentage.
return sprintf( '%d%%', intval( $column_value ) );
} else {
// If no progress or not applicable, display "Not started".
return 'Not started';
}
}
// For any other column, return the original value.
return $column_value;
}
// Add the filter to WordPress.
// The parameters 4 indicate that our callback function accepts 4 arguments:
// $column_value, $column_key, $report_item, $report_user.
add_filter( 'uo_csv_report_column_value', 'my_custom_csv_report_column_value', 10, 4 );
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:754
} else {
$column_value = get_user_meta( $report_user->ID, $column_key, true );
}
}
break;
}
return apply_filters( 'uo_csv_report_column_value', $column_value, $column_key, $report_item, $report_user );
}
/**
* Method is used to get value of specific assignment.
*
* @param $report_user