benecaster_episode_is_accessible
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 reflects the result of the standard tier comparison — return it unchanged to preserve default behavior.
Return `true` to grant access regardless of tier. Return `false` to lock an otherwise-accessible episode. `$user_id` is `0` for unauthenticated visitors — 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). Returning `false` can lock episodes that core considers accessible, including public ones — use with care.
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|null |
— | WordPress user ID; null if not logged in |
$tier_slug |
string|null |
— | Current tier slug; null if user has no active tier |
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 core already considers accessible.