Swap the audio enclosure URL per subscriber tier at feed compile time
Benecaster picks the audio URL for a given subscriber tier in three steps: it looks for a variant matching that tier exactly, then cascades down to broader tiers, and finally falls back to the episode’s base URL.
The benecaster_episode_audio_url filter runs after that choice is made, so an add-on can override the result per request — geo-routing, per-listener CDN tokens, dynamic ad insertion, and similar.
The filter fires once per episode and tier pair while the feed is being compiled, and whatever it returns becomes the enclosure URL verbatim.
Code
<?php
add_filter(
'benecaster_episode_audio_url',
function ( string $url, int $episode_id, string $tier_slug ): string {
// Route paid tiers through a signed-URL CDN; leave the public/free feed alone.
if ( in_array( $tier_slug, [ 'public', 'free' ], true ) ) {
return $url;
}
return my_addon_sign_cdn_url( $url, [ 'ttl' => 900 ] );
},
10,
3
);