Skip to main content

benecaster_episode_is_accessible

Filter Premium

Filters whether the current user can access a specific episode. Fires at the end of benecaster_user_can_access_episode() for every episode, including public ones. The $can_access value entering the filter is Benecaster’s own answer, decided by the episode’s tier dates: for a signed-out visitor, whether the public tier’s date has passed; for a signed-in user, a required buy-up they hold, a passed date for their active tier or for anything they own outright on the show, or a passed public date. An episode with no dates at all enters as false. Return the value unchanged to preserve default behavior.

Benecaster itself listens at priority 20 for episode magic links: a signed-out visitor holding a link’s cookie for this episode is answered as the link’s subscriber, for that episode only. A callback at a later priority runs after it.

Return true to grant access regardless of tier. Return false to lock an otherwise-accessible episode. $user_id is the resolved user (the current user when the caller passed 0), and 0 for a signed-out visitor — check $user_id > 0 before calling any user-specific functions. $tier_slug is an empty string when the user has no active token for this show (logged in but not subscribed, or unauthenticated), even when something they own outright opened the episode, so $tier_slug === '' does not mean “no access”. Returning false can lock episodes that Benecaster considers accessible, including public ones — use with care.

Where the answer is used. Everything on the website that decides whether a visitor can hear an episode goes through benecaster_user_can_access_episode(), so this filter reaches all of it: the episode page and its download and transcript links, the archive and show episode list, [benecaster_player], [benecaster_episodes] (with tier=, it decides which listed items get a player), [benecaster_latest_episode] and [benecaster_related_episodes]. A callback that returns false therefore locks the website player, for a public episode too. It is not a feed or download gate. Feed compilation and the download proxy decide access their own way, so this filter changes nothing about what a podcast app receives. Never rely on it as the only thing between someone and a file. Check that is what you mean before returning false for anything broader than the episodes you are targeting.

Parameters

Name Type Default Description
$is_accessible bool — Whether the episode is accessible to the user
$episode_id int — ID of the episode
$user_id int — WordPress user ID, resolved to the current user; 0 for a signed-out visitor
$tier_slug string — The active subscription's tier slug; empty string when there is none

Returns: bool

Examples

Grant access via WooCommerce purchase

add_filter( 'benecaster_episode_is_accessible', function( $is_accessible, $episode_id, $user_id, $tier_slug ) {
    // Grant access to logged-in WooCommerce customers who purchased a specific product.
    if ( ! $is_accessible && $user_id ) {
        $product_id = (int) get_post_meta( $episode_id, '_access_product_id', true );
        if ( $product_id && wc_customer_bought_product( '', $user_id, $product_id ) ) {
            return true;
        }
    }
    return $is_accessible;
}, 10, 4 );

Grant access by episode category

add_filter( 'benecaster_episode_is_accessible', function(
    bool   $can_access,
    int    $episode_id,
    int    $user_id,
    string $tier_slug
): bool {
    if ( $user_id > 0 && has_term( 'free-preview', 'category', $episode_id ) ) {
        return true;
    }
    return $can_access;
}, 10, 4 );

Grant WooCommerce product access

add_filter( 'benecaster_episode_is_accessible', function(
    bool   $can_access,
    int    $episode_id,
    int    $user_id,
    string $tier_slug
): bool {
    if ( $can_access || $user_id === 0 ) {
        return $can_access; // already accessible, or not logged in
    }

    $required_product_id = 42;
    if ( wc_customer_bought_product( '', $user_id, $required_product_id ) ) {
        return true;
    }

    return $can_access;
}, 10, 4 );

Notes

$user_id is 0 for unauthenticated visitors — not null. $tier_slug is an empty string (not null) when the user has no active token for this show. This filter fires for every episode, including public ones. Returning false can lock episodes that Benecaster already considers accessible.

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