Skip to main content

Hide locked episodes from all listing shortcodes

Free Beginner Since v1.0.0

By default Benecaster renders locked episodes with a “Subscriber only” badge so the episode is still discoverable. This recipe hides locked items entirely — nothing renders in their place, and the list only shows episodes the current visitor can play.

One callback covers all three episode-listing shortcodes ([benecaster_episodes], [benecaster_latest_episode], [benecaster_related_episodes]) because they all fire the same benecaster_episode_item_output filter with the same signature.

Difference from show_locked="false". The [benecaster_episodes] shortcode has a built-in no-code shortcut: [benecaster_episodes show_locked="false"]. But that attribute only applies to the one shortcode instance and fast-paths locked items out of the render loop before this filter fires. This recipe works site-wide with a single callback, covering every listing surface without editing each shortcode tag.

Access rule composition. $is_locked reflects the current user’s access at the moment of render, computed via benecaster_user_can_access_episode(). Third-party locking rules registered on benecaster_episode_is_accessible flow through automatically — no need to duplicate that logic in this callback.

Code

<?php
// Hide locked episodes from every Benecaster listing surface.
//
// Fires from [benecaster_episodes], [benecaster_latest_episode], and
// [benecaster_related_episodes] — one callback handles all three because
// the filter signature is shared.
//
// Logged-out visitors + logged-in-but-wrong-tier subscribers both see the
// pruned list. Subscribers with access see everything normally.
add_filter( 'benecaster_episode_item_output', function ( string $html, int $episode_id, int $show_id, string $user_tier, bool $is_locked ): string {
    return $is_locked ? '' : $html;
}, 10, 5 );

View on GitHub →

Hooks Used

  • benecaster-episode-item-output