Skip to main content

benecaster_token_accessed

Action Premium

Fires on every valid feed request after the token has been verified and the subscriber’s membership confirmed active. Fires once per feed request, immediately before feed compilation begins.

This is a high-frequency hook. Podcast apps poll feeds often — typically every few hours per subscriber — meaning an active subscriber base will trigger this hook hundreds or thousands of times per day. Keep callbacks extremely lightweight. Avoid database writes or external HTTP calls on each request; instead, use a transient or object cache to batch any writes and flush them via a scheduled cron job.

Parameters

Name Type Default Description
$token_id int ID of the token record
$user_id int WordPress user ID
$show_id int ID of the show
$tier_slug string Tier slug for this subscription

Examples

Batch feed hits via transient

add_action( 'benecaster_token_accessed', function (
    int    $token_id,
    int    $user_id,
    int    $show_id,
    string $tier_slug
) {
    // Batch access counts in a transient keyed by hour.
    // A cron job flushes this to persistent storage once per hour.
    $cache_key = sprintf( 'bc_feed_hits_%d_%d_%s', $show_id, $user_id, gmdate( 'Y-m-d-H' ) );
    $count     = (int) get_transient( $cache_key );
    set_transient( $cache_key, $count + 1, HOUR_IN_SECONDS * 2 );
}, 10, 4 );

Notes

Any I/O in this callback — database writes, external API calls, transient writes per request — will slow every feed response and will not scale. Never make HTTP calls to external services in this callback.

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