Skip to main content

benecaster_get_episode_access_url()

Access Tier Free
benecaster_get_episode_access_url( int $user_id, int $episode_id ): string

Returns an episode magic link: a link to one episode for one subscriber that plays it without a login. It is what the Email Editor puts in its new-episode emails, and you can put one in your own.

Opening the link checks that the subscriber can still play the episode today, sets a cookie for that one episode, fires benecaster_magic_link_validated, and lands on the episode page without the token (any other query arguments are kept). Nobody is logged in: the cookie opens that episode for a logged-out visitor, and nothing else. The link can be clicked again until it expires, 30 days by default (benecaster_signed_link_ttl, purpose episode_access). The cookie lasts 30 days from the click.

A refused link (a bad signature, an expired link, an unpublished episode, or a subscriber who no longer has access) lands on the episode’s ordinary locked page with ?benecaster_episode_link_refused=1. The reason is never shown.

Parameters

Name Type Default Required Description
user_id int — Yes The subscriber the link is for.
episode_id int — Yes The episode (post) ID.

Return Value

Type: string

An absolute URL to the episode's page carrying a signed token for that subscriber, or an empty string when the user or the episode cannot be used.

Example

$url = benecaster_get_episode_access_url( $user->ID, $episode_id );

if ( '' !== $url ) {
    $message = sprintf( "A new episode is out. Listen now, no login needed:\n%s", $url );
}

Hooks Fired

Notes

The link is a bearer credential. Whoever opens a forwarded email gets that episode as the subscriber until the link expires. Keep the lifetime short if your subscribers forward mail.

Full-page caches: an unlocked episode page is sent as uncacheable, but a cache can still serve its locked copy to someone holding the cookie unless it skips requests carrying benecaster_episode_access_* cookies.

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