benecaster_get_episode_transcript_text()
benecaster_get_episode_transcript_text( int $episode_id, string $audio_variant_key = '' ): ?string
Reads an episode’s transcript from the Transcription Service add-on. Use it whenever your add-on searches, links or analyses transcript text, and re-read on benecaster_transcript_updated, which fires whenever this function’s answer changes.
Read transcripts through this function and never from the add-on’s own storage, which is the add-on’s to change.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
episode_id |
int |
— | Yes | The episode (post) ID. |
audio_variant_key |
string |
'' |
No | '' for the main audio, the one the episode page plays, or the tier key of one of the episode's audio variants, for that variant's transcript. |
Return Value
Type:
?string
The plain text of the episode's finished transcript, or null when there is none to give: no transcript, one still pending, processing or failed, an empty text, a post that is not an episode, or a transcript set to Hidden. A tier's audio resolves its own setting, so one source can be Hidden alone. A tier's audio with no transcript of its own returns null, not the base audio's text, so reading every source never indexes one transcript twice.
Example
$text = function_exists( 'benecaster_get_episode_transcript_text' )
? benecaster_get_episode_transcript_text( $episode_id )
: null;
if ( null !== $text ) {
my_addon_index( $episode_id, $text );
}
Notes
Hidden reads as null. A transcript whose visibility is Hidden (the episode's own
setting, else the show's; a setting that cannot be read counts as Hidden) is unpublished,
for every audio source, so nothing that indexes through this function indexes it. Every
other setting returns the text.
Apart from Hidden, it does not decide who may see the text. Before showing the text, or a match, snippet, summary or answer built from it, to a viewer, ask benecaster_user_can_see_transcript().
It is defined on every request, whether or not the show's licence is current or
Transcription is switched on for it: a show keeps its transcripts. Guard calls with
function_exists(), since Transcription Service may not be installed.
See Read an episode's transcript, and react when it changes.
Need this built rather than just documented? See our services →