Skip to main content

benecaster_get_episode_access_tiers()

Access Tier Free
benecaster_get_episode_access_tiers( int $episode_id, int $show_id ): array

Returns what opens a locked episode, for copy such as “Available to Gold subscribers” on a locked card or a search result. It is one list covering two kinds of thing, and each entry says which:

  • tier — every tier on the show that the episode has an access date for. A date still in the future
    counts: the episode is scheduled for that tier. Ask benecaster_get_episode_available_at() with the slug for when it opens.

  • buyup — a buy-up the episode requires. Holding one opens the episode whatever the person’s tier. A
    buy-up that has been deleted, or that belongs to another show, is left out, because it could never open the episode.

Parameters

Name Type Default Required Description
episode_id int — Yes WordPress post ID of the episode.
show_id int — Yes WordPress post ID of the episode's show.

Return Value

Type: array

A list of entries, each with kind (tier or buyup), slug and name. Tiers come first, lowest rank first (the order of benecaster_get_show_tiers()), then the buy-ups the episode requires, in the order the episode stores them; a buy-up's slug is its token type. An empty list for a public episode, and for some locked ones too (see the notes).

Example

$openers = benecaster_get_episode_access_tiers( $episode_id, $show_id );
$tiers   = wp_list_pluck( wp_list_filter( $openers, [ 'kind' => 'tier' ] ), 'name' );
$buyups  = wp_list_pluck( wp_list_filter( $openers, [ 'kind' => 'buyup' ] ), 'name' );

if ( $tiers ) {
    /* translators: %l: tier names, e.g. "Silver and Gold" */
    echo esc_html( wp_sprintf( __( 'Available to %l subscribers', 'my-addon' ), $tiers ) );
}
if ( $buyups ) {
    /* translators: %l: buy-up names */
    echo esc_html( wp_sprintf( __( 'Included with %l', 'my-addon' ), $buyups ) );
}

Notes

Branch on kind. The name says tiers, but the list is not tiers only.

Outright purchases are not listed. A standalone grant (access a person owns outright, outside any tier) can open an episode too, but Benecaster has no name for one to report, and "Available to X subscribers" would be the wrong copy for it anyway. An add-on that sells such a grant knows its own and names it itself.

An empty list does not mean public. An episode whose public date has passed returns an empty list, but so does a locked episode that only a standalone grant opens, and one with no access dates at all. To ask whether a person can open the episode, call benecaster_user_can_access_episode().

There is no capability check.

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