Read an episode’s transcript, and react when it changes
Your add-on searches, links or analyses transcript text. Read it with benecaster_get_episode_transcript_text(), never from the Transcription Service add-on’s own storage, and re-process on benecaster_transcript_updated, the one action that fires for every change.
nullmeans there is no finished transcript to give, including after$reasondeleted, or for a transcript now set to Hidden ($reasonvisibility): drop what you indexed. The samevisibilityreason fires when a transcript stops being Hidden, and the reader then returns the text to index again.- The text is the transcript as stored, whoever may see it. Before showing it, or results built from it, to a viewer, check benecaster_user_can_see_transcript().
- Accept
$reasonvalues you don’t know: more causes can be added. - The action runs inside the request or job that changed the text, so the example hands the slow part to a background job.
Code
<?php
add_action( 'benecaster_transcript_updated', function ( int $transcript_id, int $episode_id, string $reason ): void {
// Slow work goes to the background; this runs inside the job that changed the text.
as_enqueue_async_action( 'my_addon_reindex_episode', [ $episode_id ], 'my-addon' );
}, 10, 3 );
add_action( 'my_addon_reindex_episode', function ( int $episode_id ): void {
$text = function_exists( 'benecaster_get_episode_transcript_text' )
? benecaster_get_episode_transcript_text( $episode_id )
: null;
null === $text ? my_addon_forget( $episode_id ) : my_addon_index( $episode_id, $text );
} );
Hooks Used
Need this built rather than just documented? See our services →