Filter uncanny-toolkit-pro

uo_pro_transcript_template

Filters the transcript template before it is displayed, allowing for customization of the output.

add_filter( 'uo_pro_transcript_template', $callback, 10, 1 );

Description

Filters the LearnDash transcript template file path. Developers can modify this to use a custom transcript template for public sharing. The original `$template` variable holds the default path.


Usage

add_filter( 'uo_pro_transcript_template', 'your_function_name', 10, 1 );

Parameters

$template (mixed)
This parameter contains the path to the transcript template file.

Return Value

The filtered value.


Examples

// Modify the transcript template to include custom styling or additional information.
add_filter( 'uo_pro_transcript_template', 'my_custom_transcript_template', 10, 1 );

function my_custom_transcript_template( $template ) {
    // Example: Add a custom CSS class to the template's wrapper div if it exists.
    // This assumes the transcript.php template has a main wrapper div.
    // In a real-world scenario, you'd likely need to inspect the template's structure.
    if ( strpos( $template, 'transcript.php' ) !== false ) {
        // For demonstration, let's assume we're targeting a file named 'transcript.php'
        // and want to prepend some HTML. In a real case, you might read the file content.
        // For this hook, $template is the file path.

        // A more realistic scenario would involve reading the file content and modifying it.
        // However, without knowing the exact structure of 'transcript.php',
        // it's hard to provide a truly robust example of modifying its content directly
        // through this path variable.

        // A common use case for this filter might be to *replace* the template
        // with an entirely different one under certain conditions, or to append
        // data *before* the template is included.

        // Let's simulate appending some HTML to be included *before* the actual transcript.
        // This is just an illustrative example. The actual modification of the template
        // content would typically happen *within* the included template file itself,
        // potentially by passing data to it.

        // A more practical approach for modifying *content* might be to use another filter
        // *inside* the transcript.php template, or to modify variables *before* the template is included.

        // For the sake of demonstrating a realistic filter hook for modifying the template *path*,
        // let's say we want to use a different template file for users with a specific role.
        if ( current_user_can( 'editor' ) ) {
            // Assume 'my-custom-transcript.php' exists in the same directory for editors.
            $custom_template_path = dirname( $template ) . '/my-custom-transcript.php';
            if ( file_exists( $custom_template_path ) ) {
                return $custom_template_path; // Return the path to our custom template.
            }
        }
    }

    // If no modifications are needed or our custom template wasn't found, return the original template path.
    return $template;
}

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:893

$allow_public_sharing = self::is_public_sharing_allowed() && ! self::is_public_sharing_url();
		$transcript_permalink = '';
		if($allow_public_sharing) {
			$transcript_permalink = self::generate_public_url( $post, $current_user );
		}

		$template = self::get_template( 'transcript.php', dirname( dirname( __FILE__ ) ) . '/src' );
		$template = apply_filters( 'uo_pro_transcript_template', $template );
		include $template;

		return ob_get_clean();
	}

	/**
	 * Maybe add or adjust quiz scores.

Scroll to Top