Skip to main content

benecaster_user_holds_grant()

Access Tier Free
benecaster_user_holds_grant( int $show_id, string $grant_slug, int $user_id = 0 ): bool

The direct form of benecaster_get_user_grants() — whether a person holds one named grant on a show, rather than the whole list. Same source and same rules. This is the one to write in a gate.

Parameters

Name Type Default Required Description
show_id int — Yes The show (post) ID. Required — a grant cannot exist without a show.
grant_slug string — Yes The grant slug to check, matched exactly — a slug is a named set, not a prefix. An empty string returns false without a lookup.
user_id int 0 No WordPress user ID. Defaults to the current user when 0 or omitted.

Return Value

Type: bool

Whether the person currently holds this specific live grant on the show. False for a logged-out visitor, an empty slug, or an expired grant.

Example

// One named product or bundle.
if ( benecaster_user_holds_grant( get_the_ID(), 'season-one' ) ) {
    get_template_part( 'parts/season-one-extras' );
}

Notes

Returns what the feed serves, not only the rows Benecaster stores. Resolved through Entitlement\GrantSlugResolver, so a grant an add-on registers through benecaster_entitlement_grant_slugs is included.

Buy-ups are excluded. A buy-up dies with the membership it rides on; a grant does not. Use benecaster_user_has_buyup() for buy-ups.

A grant slug is not a tier slug. Feeding one to a tier-shaped API ([benecaster_tier_gate]'s min_tier, or benecaster_get_user_tier_for_show()) fails closed for exactly the people who bought it, silently — the same trap buy-ups carry.

See Gate anything on a listener's episode purchases for the full recipe.

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