Skip to main content

ExplicitBadgeRenderer

\Benecaster\Episode\ExplicitBadgeRenderer

Class Free

Renders the explicit-content badge. One class serves every surface the badge appears on — the episode single page, archive cards, the [benecaster_episodes] list, the [benecaster_player] title strip, and the [benecaster_explicit_badge] shortcode — so the three badge filters apply everywhere without each caller re-implementing them.

Stateless and not container-bound. Instantiate it directly wherever you need it; there is no registered service to resolve and nothing to inject. Templates and shortcodes both do exactly that.

The class also owns the resolution step. resolve_mode() collapses the episode override against the show default and applies benecaster_explicit_badge_mode, so callers get a single settled value rather than having to know that an episode set to inherit needs its show consulted.

Methods

Method Visibility Since Description
resolve_mode( int $episode_id, int $show_id ): string Public Resolves the episode's override against the show default and returns 'clean', 'yes', or 'explicit', after passing the value through benecaster_explicit_badge_mode. Note this is the show-side enum — inheritance is already resolved, so 'inherit' is not a possible return value. A filter returning anything outside the three modes is coerced to 'clean'.
default_label( string $mode ): string Public The untranslated default text for a mode — 'Explicit' for both explicit modes, 'Clean' for clean. Exposed so callers building their own markup can reuse the wording; the benecaster_explicit_badge_label filter is applied by render(), not here.
render( int $episode_id, int $show_id, string $context = 'single', bool $show_clean = false ): string Public Returns the badge markup, or an empty string when the mode is clean and $show_clean is false. $context is one of 'single', 'card', 'list', 'player', or 'shortcode' and becomes the --context-{surface} class modifier. Applies all three badge filters in order: mode, then label, then html.
render_schema_meta( int $episode_id, int $show_id ): string Public Returns the schema.org contentRating markup for the PodcastEpisode structured data on the episode page. Separate from render() because structured data is emitted whether or not the visible badge is shown, and must not be suppressed by a theme that hides the badge with CSS.

Hooks Fired

Notes

Prefer the filters to subclassing. All three extension points — the resolved mode, the label text, and the markup — are filters applied inside render(), so a theme or plugin can change any of them without replacing the renderer or overriding the template.

render() returns a string; it does not echo. Callers are responsible for output. The return value is already escaped, so echo it directly rather than running it through esc_html(), which would display the markup as text.

An empty return is a normal outcome, not a failure. Clean episodes render nothing by default. Code that treats an empty string as an error will misreport most of a clean show's catalogue.