Skip to main content

benecaster_tier_gate_passes

Filter Premium

Whether the visitor gets the gated branch of [benecaster_tier_gate]. Fires before either branch renders, for conditions the min_tier/show_id attributes cannot express — a buy-up, a WordPress role, a date. Whichever branch the returned value selects is still the only one that runs.

Fires for every gate on the site, so a callback must scope itself by $show_id and $min_tier and return $passes untouched for gates it doesn’t mean to change.

Fires on every install, with no licence check — website gating isn’t licence-gated (operator decision).

Website only. Does not fire when the RSS feed resolves a gate (feature/tier-gate-feed-resolution) — feeds are compiled and cached per tier, not per visitor, and a per-visitor answer written into a per-tier cache would hand one subscriber’s result to their whole tier. A condition OR’d in through this filter therefore opens the gate on the website only; the feed still resolves by tier alone.

Never pass a buy-up’s token_type as min_tier. A buy-up holder resolves to their base tier slug via benecaster_get_user_tier_for_show(), so a buy-up slug matches no tier and the gate stays shut for exactly the people who bought it, with no error. Use this filter plus benecaster_user_has_buyup() instead.

Let buy-up holders through a tier gate

Premium Intermediate

min_tier expresses exactly one condition: “at or above this tier”. Anything else — a buy-up, a WordPress role, a date — goes through benecaster_tier_gate_passes, which fires before either branch is rendered, so whichever branch you choose is still the only one that runs.

The filter fires for every gate on the site, so scope it: check $show_id and $min_tier and return $passes untouched for gates you don’t mean to change.

Do not put the buy-up’s token_type in min_tier instead. benecaster_get_user_tier_for_show() returns only a subscriber’s base tier slug, so a buy-up slug matches no tier: the gate would stay shut for every buy-up holder and fail closed without any error.

Website only. This filter does not fire when the RSS feed resolves a gate — feeds are compiled and cached per tier, not per subscriber, so a gate inside an episode’s Full Page Content gives buy-up holders its else branch in their podcast app even though this snippet opens it on the episode page.

<?php
add_filter(
    'benecaster_tier_gate_passes',
    function ( bool $passes, int $show_id, string $min_tier, string $user_tier ): bool {
        // Already in on tier, or not a gate this snippet is about.
        if ( $passes || 'growth' !== $min_tier ) {
            return $passes;
        }

        // The buy-up's row ID in benecaster_buyups (here, "Transcripts").
        $transcripts_buyup_id = 12;

        // 0 = the current user. Passing $show_id scopes the grant to the
        // show the gate is on, so a buy-up bought on another show can't open it.
        return benecaster_user_has_buyup( 0, $transcripts_buyup_id, $show_id );
    },
    10,
    4
);

View on GitHub →

Parameters

Name Type Default Description
$passes bool Whether the visitor currently passes the gate, from the `min_tier` ranking check.
$show_id int ID of the show the gate is on.
$min_tier string The gate's `min_tier` attribute value.
$user_tier string The visitor's resolved tier slug for this show (empty string when none).

Returns: bool

Example

add_filter(
    'benecaster_tier_gate_passes',
    function ( bool $passes, int $show_id, string $min_tier, string $user_tier ): bool {
        // Already in on tier, or not a gate this snippet is about.
        if ( $passes || 'growth' !== $min_tier ) {
            return $passes;
        }

        // The buy-up's row ID in benecaster_buyups (here, "Transcripts").
        $transcripts_buyup_id = 12;

        // 0 = the current user. Passing $show_id scopes the grant to the
        // show the gate is on, so a buy-up bought on another show can't open it.
        return benecaster_user_has_buyup( 0, $transcripts_buyup_id, $show_id );
    },
    10,
    4
);

Notes

Fired by TierGateShortcode::render() before either branch is processed.