Import a transcript into an episode from your add-on
Your add-on has a transcript for an episode, from a feed it migrated, say, and wants it to become the episode’s transcript, shown, gated and searched like any other. Call the function: never write benecaster_transcripts or the episode’s transcript meta yourself.
- Pass the tag’s
typeas$format, orautowhen there is none. Prefer an SRT or WebVTT tag overtext/plain: it keeps the timestamps. - It returns the transcript id;
benecaster_transcript_importedandbenecaster_transcript_updatedhave fired by then. - It checks the show but no capability: run it only where the current user (or your background job) may change the episode.
- The default
$import_methodisrss_feed; passfilefor a transcript the podcaster uploaded to your screen.
Code
<?php
if ( ! function_exists( 'benecaster_import_episode_transcript' ) ) {
return; // Transcription Service is not active.
}
// $tag is one <podcast:transcript> from the source feed: [ 'url' => …, 'type' => 'application/x-subrip', 'language' => 'en' ].
$response = wp_safe_remote_get( $tag['url'], [ 'timeout' => 15 ] );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
return;
}
$result = benecaster_import_episode_transcript( $episode_id, wp_remote_retrieve_body( $response ), $tag['type'], 'rss_feed', $tag['language'] ?? '' );
if ( is_wp_error( $result ) ) {
// 'benecaster_transcription_import_exists': the episode already has one; leave it.
// 'benecaster_transcription_import_unsupported': an HTML or Podcasting 2.0 JSON transcript; try the feed's next tag.
my_addon_report( $episode_id, $result->get_error_message() );
}
Hooks Used
Need this built rather than just documented? See our services →