uo_pro_transcript_public_url
Filters the public URL for a transcript, allowing customization before it's displayed.
add_filter( 'uo_pro_transcript_public_url', $callback, 10, 3 );
Description
Filters the public URL for a transcript. Developers can use this hook to modify the transcript's permalink before it's displayed. The filter receives the permalink, post object, and user object as arguments. It fires after the default permalink is generated but before it's returned.
Usage
add_filter( 'uo_pro_transcript_public_url', 'your_function_name', 10, 3 );
Parameters
-
$transcript_permalink(mixed) - This parameter contains the permalink to the transcript, potentially modified with query arguments.
-
$post(mixed) - This parameter holds the initial transcript permalink generated by the function.
-
$user(mixed) - This parameter is the WordPress post object representing the lesson or topic for which the transcript URL is being generated.
Return Value
The filtered value.
Examples
/**
* Modify the public URL for a transcript to include a custom parameter.
*
* This filter allows developers to add extra query arguments to the transcript's
* public URL, for example, to track referral sources or provide additional context.
*
* @param string $transcript_permalink The original transcript permalink.
* @param WP_Post $post The post object associated with the transcript.
* @param WP_User $user The user object associated with the transcript.
* @return string The modified transcript permalink.
*/
add_filter( 'uo_pro_transcript_public_url', function( $transcript_permalink, $post, $user ) {
// Add a custom query parameter for tracking or analytics.
$tracking_code = 'XYZ789'; // Example tracking code
$transcript_permalink = add_query_arg( 'utm_source', 'course_transcript_' . $tracking_code, $transcript_permalink );
// You could also conditionally modify the URL based on the user or post.
// For instance, if the user has a specific role, you might append a different parameter.
if ( in_array( 'administrator', $user->roles ) ) {
$transcript_permalink = add_query_arg( 'admin_view', 'true', $transcript_permalink );
}
return $transcript_permalink;
}, 10, 3 ); // Priority 10, accepts 3 arguments.
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:1308
public static function generate_public_url( $post, $user ) {
if( ! ($post instanceof WP_Post) || ! ($user instanceof WP_User) ) {
return '';
}
$transcript_permalink = add_query_arg( array(
self::$public_transcript_arg => self::get_hash_value( $user )
), get_the_permalink( $post ));
$transcript_permalink = apply_filters( 'uo_pro_transcript_public_url', $transcript_permalink, $post, $user );
return $transcript_permalink;
}