uo_pro_transcript_cell_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the content of a specific transcript cell within the course, allowing for dynamic modification based on course ID.
add_filter( 'uo_pro_transcript_cell_{dynamic}', $callback, 10, 2 );
Description
This dynamic filter hook allows developers to modify the content displayed within individual cells of the user's transcript table. It fires for each transcript cell, except for specific date and order-related fields. Developers can use this hook to customize the output, add custom data, or conditionally alter the cell's `$value` based on the `$course_id` and cell `$key`.
Usage
add_filter( 'uo_pro_transcript_cell_{dynamic}', 'your_function_name', 10, 2 );
Parameters
-
$value(mixed) - This parameter contains the current value of the transcript cell, which can be modified by the filter.
-
$course_id(mixed) - This parameter represents the current value of the transcript cell being processed, which can be modified by the filter.
Return Value
The filtered value.
Examples
// Example: Modify the display of the 'course_name' in the transcript cell.
// This example will prepend "Completed: " to the course name if the completion timestamp is available.
add_filter( 'uo_pro_transcript_cell_course_name', 'my_custom_transcript_course_name', 10, 2 );
/**
* Customizes the course name displayed in the transcript.
*
* @param string $value The current value of the course name.
* @param int $course_id The ID of the course.
* @return string The modified course name.
*/
function my_custom_transcript_course_name( $value, $course_id ) {
// In a real scenario, you might fetch course completion data here.
// For demonstration, let's assume we have access to the course completion timestamp.
// You'd likely get this data from a meta field or a custom function.
// Example: Check if a completion timestamp exists for this course and student.
// This is a hypothetical example; actual data retrieval will depend on your setup.
$completion_timestamp = get_user_meta( get_current_user_id(), '_completion_timestamp_' . $course_id, true );
if ( ! empty( $completion_timestamp ) ) {
// If the course has been completed, prepend "Completed: "
return 'Completed: ' . esc_html( $value );
}
// Otherwise, return the original course name.
return esc_html( $value );
}
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/templates/transcript.php:136
if ( in_array( $key, array( 'course_date', 'course_order', 'completion_timestamp' ) ) ) {
continue;
}
?>
<div class="uo-ultp-transcript-table__cell uo-ultp-transcript-table__cell--<?php echo $key; ?>"
data-column="<?php echo $transcript->table->heading->$key; ?>">
<?php echo apply_filters( 'uo_pro_transcript_cell_' . $key, $value, $course_id ); ?>
</div>
<?php } ?>
</div>
<?php } ?>