Filter uncanny-toolkit-pro

uo_pro_transcript

Filters the transcript data before it's output, allowing modification based on user, class, and request details.

add_filter( 'uo_pro_transcript', $callback, 10, 4 );

Description

Fires after the transcript data is prepared but before it's potentially modified by specific quiz settings. Developers can use this filter to modify the entire transcript object, add custom data, or alter existing transcript elements for display purposes before it's returned. The `$transcript` parameter is the primary target for modifications.


Usage

add_filter( 'uo_pro_transcript', 'your_function_name', 10, 4 );

Parameters

$transcript (mixed)
This parameter contains the transcript object that is being filtered.
$current_user (mixed)
This parameter contains the transcript object being built, which includes data like course progress, lesson completion, and quiz scores.
$data (mixed)
This parameter contains the name of the current class that is being executed.
$request (mixed)
This parameter likely holds additional data related to the transcript request, potentially including specific user actions or content details.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the Uncanny Owl Pro transcript data.
 * This function demonstrates how to add a custom column or modify existing data.
 *
 * @param object $transcript The transcript object to be modified.
 * @param WP_User $current_user The current WordPress user object.
 * @param string $class The class name where the filter is applied (e.g., 'LearnDash_Transcript').
 * @param array $data Additional data related to the transcript.
 * @param WP_REST_Request $request The REST API request object, if applicable.
 *
 * @return object The modified transcript object.
 */
add_filter( 'uo_pro_transcript', 'my_custom_transcript_modification', 10, 5 );

function my_custom_transcript_modification( $transcript, $current_user, $class, $data, $request ) {

	// Example: Add a custom column to the transcript table if it doesn't exist.
	// Let's assume the $transcript object has a structure like:
	// $transcript->table->heading = (object) ['course_title' => 'Course Title', ...];
	// $transcript->table->rows = [ ['course_title' => 'Course 1', ...], ... ];

	// Check if the 'my_custom_column' key is not already in the table headings.
	if ( ! isset( $transcript->table->heading->my_custom_column ) ) {
		// Add a new heading for our custom column.
		$transcript->table->heading->my_custom_column = esc_html__( 'Custom Data', 'your-text-domain' );

		// Now, loop through each row and add data to our custom column.
		if ( ! empty( $transcript->table->rows ) && is_array( $transcript->table->rows ) ) {
			foreach ( $transcript->table->rows as &$row ) {
				// Example: Populate the custom column with some user-specific data.
				// This could be fetched from user meta, post meta, or other sources.
				// For demonstration, let's just put a placeholder value.
				$row['my_custom_column'] = sprintf(
					esc_html__( 'User ID: %s', 'your-text-domain' ),
					$current_user->ID
				);
			}
		}
	}

	// Example: Modify an existing column value.
	// Let's say we want to append some text to the 'course_title' if it meets certain criteria.
	if ( ! empty( $transcript->table->rows ) && is_array( $transcript->table->rows ) ) {
		foreach ( $transcript->table->rows as &$row ) {
			if ( isset( $row['course_title'] ) && strpos( $row['course_title'], 'Advanced' ) !== false ) {
				$row['course_title'] .= ' (Premium)';
			}
		}
	}

	// Always return the modified $transcript object.
	return $transcript;
}

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/learn-dash-transcript.php:767

}
		if ( 'on' !== self::get_settings_value( 'uncanny-disable-transcript-finalquizscore-col', __CLASS__ ) ) {
			$transcript->table->heading->final_score = esc_attr__( 'Final Score', 'uncanny-pro-toolkit' );
		}

		// Store Unfiltered.
		$unfiltered = unserialize( serialize( $transcript ) );
		$transcript = apply_filters( 'uo_pro_transcript', $transcript, $current_user, __CLASS__, $data, $request );

		// CEU Maybe Display Dates In Status Column
		if ( $transcript->table->rows !== $unfiltered->table->rows ) {
			// Check if CEUs are enabled.
			if ( 'on' !== self::get_settings_value( 'uncanny-disable-ceus-col', __CLASS__ ) ) {
				// Check if we need to add the date to the status column.
				if ( 'on' !== self::get_settings_value( 'uncanny-disable-transcript-status-col', __CLASS__ ) ) {

Scroll to Top