Skip to main content

Swap the audio enclosure URL per subscriber tier at feed compile time

Free Intermediate Since v1.0.0

Core resolves the audio URL via AudioVariantResolver (exact-tier match → cascade-down → base URL). The benecaster_episode_audio_url filter runs after that resolution, letting add-ons override the URL per-request (geo-routing, per-listener CDN tokens, dynamic ad injection, etc.). The filter fires once per (episode, tier) pair during feed compilation and the returned URL is written straight into the enclosure url="…" attribute.

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
);

View on GitHub →

Hooks Used