Skip to main content

benecaster_get_audio_variant_slug()

Episode Free
benecaster_get_audio_variant_slug( int $episode_id, string $tier_slug ): ?string

Tells you which tier’s audio variant a tier’s copy of an episode plays: the tier’s own variant if it has one, otherwise the nearest lower paid tier’s (see benecaster_get_paid_tier_hierarchy()), otherwise the base file. It is the same choice the feed’s enclosure makes, so anything you attach per variant, such as a transcript cut to the same audio, matches what the listener hears.

Parameters

Name Type Default Required Description
$episode_id int — Yes The episode (post) ID.
$tier_slug string — Yes The tier whose copy of the episode you are building. Inside benecaster_feed_podcast_episode_tags, pass $context['tier_slug'].

Return Value

Type: ?string

The tier slug of the audio variant that tier hears, or null when it hears the base file: the episode has no variants, none applies, the tier is public, or the ID is not an episode.

Example

add_filter( 'benecaster_feed_podcast_episode_tags', function ( array $tags, int $episode_id, int $show_id, array $context ): array {
    $variant = benecaster_get_audio_variant_slug( $episode_id, $context['tier_slug'] );
    if ( null !== $variant ) {
        // Point the transcript at the version that matches this audio.
        $tags['transcript'] = [ [ 'url' => my_transcript_url( $episode_id, $variant ), 'type' => 'text/vtt' ] ];
    }
    return $tags;
}, 10, 4 );

Notes

It answers for a tier's copy of the episode, not for a person. It runs no access check, so decide who may have the episode yourself.

Safe inside a feed filter. The answer depends only on the episode's variants and the show's tiers, which the feed cache already accounts for. In benecaster_feed_podcast_episode_tags pass $context['tier_slug'], so the tag and the enclosure always agree.

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