Put a “listen now, no login” link to an episode in your own email
benecaster_get_episode_access_url() returns the episode’s page with a signed token for one subscriber. Opening it sets a 30-day cookie for that one episode, so the page plays for them without a login, and then drops the token from the address. Nobody is logged in, and account pages still need a real login. Their access is checked again on every click, so a cancelled subscriber’s link stops working at once. Your own query arguments, such as campaign tags, survive.
benecaster_magic_link_validated fires on the click, not on the later visits the cookie opens, so it counts clicks rather than plays.
Code
<?php
// In your own newsletter loop, per recipient:
$url = benecaster_get_episode_access_url( $user->ID, $episode_id );
if ( '' !== $url ) {
$url = add_query_arg( [ 'utm_source' => 'my_newsletter', 'utm_medium' => 'email' ], $url );
$body .= sprintf( '<a href="%s">%s</a>', esc_url( $url ), esc_html__( 'Listen now', 'my-plugin' ) );
}
// Count clicks — fires on the click only, not on later visits the cookie opens.
add_action( 'benecaster_magic_link_validated', function ( int $user_id, int $episode_id, int $show_id ): void {
update_post_meta( $episode_id, '_my_email_clicks', (int) get_post_meta( $episode_id, '_my_email_clicks', true ) + 1 );
}, 10, 3 );
Hooks Used
Need this built rather than just documented? See our services →