benecaster_get_episode_audio_url()
benecaster_get_episode_audio_url( int $episode_id, int $user_id = 0 ): string
Returns the audio URL the website plays a viewer for an episode: their tier’s audio variant when the episode has one, chosen the way their podcast feed chooses it, otherwise the episode’s audio file. It has already been through benecaster_episode_audio_url as a website call, so a theme’s own player or download template can echo it straight into src or href. Benecaster’s episode player, archive card player and download link all use it.
A viewer who cannot play the episode gets the plain audio file, never a tier’s variant, so a preview clip swapped in by another callback still works.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
episode_id |
int |
— | Yes | The episode (post) ID. |
user_id |
int |
0 |
No | WordPress user ID. Defaults to the current viewer when 0 or omitted, including a signed-out visitor holding an episode magic link, who is answered as that link's subscriber. |
Return Value
Type:
string
The audio URL to play, or an empty string when the post is not an episode or has no audio file.
Example
$src = benecaster_get_episode_audio_url( $episode_id );
if ( '' !== $src ) {
echo '<audio controls preload="none" src="' . esc_url( $src ) . '"></audio>';
}
Hooks Fired
Notes
It does not decide whether to show a player. Ask benecaster_user_can_access_episode() for that first.
Audio only. Video has no tier variants.
One difference from the feed: a subscriber over their plan's limit is not moved to the public file on the website.
Need this built rather than just documented? See our services →