Annotate episode references with tracked redirect URLs
Fires before references is returned in the episode REST response. Each entry is a full reference object. Use to inject extra fields (e.g. a tracked redirect URL) or rewrite the url to point to a proxy. The Outlinks add-on uses this pattern to swap the canonical URL for a per-episode tracked short link without modifying stored data. Core ignores unknown keys — they’re safe to add.
Code
<?php
add_filter( 'benecaster_episode_references', function ( array $references, int $episode_id, int $show_id ): array {
return array_map( function ( array $ref ) use ( $episode_id ) {
$tracked_url = get_post_meta( $episode_id, '_outlinks_tracked_' . $ref['id'], true );
if ( $tracked_url ) {
$ref['tracked_url'] = $tracked_url;
}
return $ref;
}, $references );
}, 10, 3 );