Skip to main content

Keep a restricted transcript private when your add-on is switched off

Free Advanced

If your add-on writes an episode’s transcript URL and decides who may see it with its own filters, those filters stop running when your plugin is deactivated or deleted. Without anything else, Benecaster would then publish the URL to everyone: in the public feed, on the episode page and in the REST API.

Record your add-on as the URL’s owner and Benecaster withholds it whenever your add-on is not loaded: no <podcast:transcript> in any feed, no Read the transcript link on the episode page, and no URL in wp/v2 episode responses. The podcaster’s own episode editor still shows it, so they can see and replace it. It comes back when your add-on is activated again.

Three rules

Write the owner every time you write the URL, and clear it when you clear the URL. EpisodeMeta’s set_podcast2_transcript_owner() takes your entitlement slug; an empty string removes the owner. A leftover owner would hide a URL the podcaster sets later.

Declare your add-on loaded outside any entitlement or licence check. Benecaster reads “not in benecaster_installed_addons” as “not loaded”, so an add-on that stops declaring itself when its licence lapses hides its own transcripts as well.

The podcaster can take the URL over. Changing the URL in the episode editor removes your owner, and from then on the URL is always published. A save that leaves the URL as it was keeps your owner. A URL the podcaster set themselves is never withheld.

Cached feeds

Benecaster clears every cached feed when a plugin carrying the Benecaster Add-on: header is activated or deactivated. A plugin folder deleted by hand fires nothing, so its URL can stay in cached feeds until they next expire, up to a day.

Code

<?php
// Your add-on's main file, outside the entitlement-gated bootstrap.
add_filter( 'benecaster_installed_addons', static function ( array $slugs ): array {
    $slugs[] = 'benecaster-addon-my-transcripts';
    return $slugs;
} );

// Wherever you store a transcript URL.
function my_transcripts_store_url( int $episode_id, string $url, string $mime_type ): void {
    ( new \Benecaster\Episode\EpisodeMeta( $episode_id ) )
        ->set_podcast2_transcript_url( $url )
        ->set_podcast2_transcript_type( $mime_type )
        ->set_podcast2_transcript_owner( '' === $url ? '' : 'benecaster-addon-my-transcripts' );
    if ( '' !== $url ) {
        \Benecaster\Episode\TranscriptUrlSource::announce( $episode_id, $url, $mime_type );
    }
}

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →