benecaster_show_episode_player
Controls whether the audio/video player is rendered for the current user — on the episode page, each archive card, and in [benecaster_player]. The primary hook for add-ons that implement preview players or time-limited access. Benecaster registers a callback at priority 10 (Episode\PreviewClipPlayer): it turns an incoming false into true when the episode has a preview clip (_benecaster_preview_url) and a base audio URL, and never the reverse — an episode with no clip is left alone. A callback at priority > 10 runs after it and has the final say.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$show_player |
bool |
— | Whether to show the player to the current user |
$episode_id |
int |
— | ID of the episode |
$user_id |
int|null |
— | WordPress user ID; null if not logged in |
$user_tier |
string|null |
— | Current tier slug; null if user has no active tier |
Returns:
bool
Example
// For most preview-clip use cases the no-code path is simpler: paste a URL into the
// episode's Media -> Preview clip URL field and Benecaster's own priority-10 callback
// handles this filter and benecaster_episode_audio_url together. Reach for a callback
// here only when you need something the field can't do — a per-visitor clip, or one
// resolved at request time. See the show-preview-player-to-non-subscribers recipe.
add_filter( 'benecaster_show_episode_player', function( $show_player, $episode_id, $user_id, $user_tier ) {
if ( $user_id ) {
return $show_player;
}
// Only open the player when this episode actually has a clip to swap in. Whatever
// you open here you MUST swap on benecaster_episode_audio_url too, or a logged-out
// visitor gets the FULL episode instead of a preview.
$clip = get_post_meta( $episode_id, '_my_addon_preview_url', true );
return '' !== $clip ? true : $show_player;
}, 10, 4 );
Need this built rather than just documented? See our services →