Filter uncanny-toolkit-pro

uo_transcript_print_elements

Filters the transcript print elements to allow customization of the HTML and CSS output for the transcript.

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

Description

Filters the array of elements to be printed for the Uncanny Toolkit LearnDash transcript. Developers can modify this array to add or remove specific HTML elements or CSS classes that are output as part of the transcript. This allows for fine-grained control over the transcript's appearance and content.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Conditionally add another element to be included when printing the transcript.
 *
 * This example adds a specific element to the list of elements that will be
 * cloned and printed when the transcript printing functionality is triggered.
 *
 * @param array $print_version_elements An array of CSS selectors for elements to include in the print version.
 * @return array The modified array of CSS selectors.
 */
add_filter( 'uo_transcript_print_elements', function( $print_version_elements ) {
	// Check if a specific condition is met before adding the new element.
	// For example, check if a certain user capability exists or if a specific
	// plugin is active.
	if ( current_user_can( 'edit_posts' ) && class_exists( 'SomeOtherPlugin' ) ) {
		// Add a new CSS selector to the array. This selector targets a hypothetical
		// element that should also be included in the print output.
		$print_version_elements[] = '#my-custom-transcript-notes';
	}

	// Always return the array, whether modified or not.
	return $print_version_elements;
}, 10, 1 );

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

public static function enqueue_scripts() {
		// Get the URL of the assets
		$assets = array(
			'css' => plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/legacy/frontend/css/transcript.css',
			'js'  => plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/legacy/frontend/js/transcript.js',
		);

		// Enqueue stylesheet
		wp_enqueue_style(
			'ultp-transcript',
			$assets['css'],
			array(),
			UNCANNY_TOOLKIT_PRO_VERSION
		);

		// Enqueue the JS
		wp_enqueue_script(
			'ultp-transcript',
			$assets['js'],
			array(),
			UNCANNY_TOOLKIT_PRO_VERSION,
			true
		);

		// Get the list of styles that we'll use to print the transcript
		$print_version_styles = apply_filters( 'uo_transcript_print_styles', array(
			$assets['css'] . '?v=' . UNCANNY_TOOLKIT_PRO_VERSION,
		) );

		// Get the list of elements/nodes that we'll clone when printing the transcript
		$print_version_elements = apply_filters( 'uo_transcript_print_elements', array(
			'#ultp-transcript-css-extra',
		) );

		// Localize the script with the data
		wp_localize_script(
			'ultp-transcript',
			'ULTP_Transcript',
			array(
				'print_version_styles'   => $print_version_styles,
				'print_version_elements' => $print_version_elements,
			)
		);
	}


Scroll to Top