Skip to main content

BadgeChipRenderer

\Benecaster\Membership\BadgeChipRenderer

Class Free

Renders subscriber badge rows as HTML chip components. The companion template function benecaster_render_user_badges() is the recommended entry point for theme templates and delegates to render_for_user(). Output is already escaped — do not double-escape. Follower vs. subscriber classification: when a show is in context, the wrapper carries is-follower or is-subscriber plus data-token-type, and any chip whose row knows its token type (the Follower chip from FollowerBadgeAppender, a tenure chip computed with one) carries the same class. A styling hook for themes — it changes no badge and hides nobody. With no show in context the wrapper carries neither: one person can follow one show and pay for another.

Constructor Dependencies

Type Description
\Benecaster\Membership\BadgeIconRegistry Icon lookup for chip rendering.
\Benecaster\Token\TokenRepository Optional. Backs token_type_for()'s classification; built lazily (new TokenRepository()) if omitted so existing 1-arg construction keeps working.

Methods

Method Visibility Since Description
render_for_user( int $user_id, ?int $show_id = null ): string Public — Calls benecaster_get_user_badges() (which runs the benecaster_user_badges filter), resolves the user's token type on $show_id via token_type_for(), and returns classified chip HTML for the user's badges.
render_chips( array $badges, ?string $token_type = null ): string Public — Renders a pre-fetched array of badge rows as chip HTML. Use when badge rows are already in memory to avoid re-querying. $token_type ('subscriber' / 'follower', or null) classifies the wrapper is-follower / is-subscriber plus data-token-type; pass null (the default) to leave it unclassified — the correct choice with no show in context.
render_chip( object $badge, array $icons ): string Public — Renders a single badge row as one chip . Public so callers assembling a custom chip list can reuse it directly.
token_type_for( int $user_id, ?int $show_id ): ?string Public — The user's active token type on $show_id ('subscriber' / 'follower') — the value the wrapper's classification reads — or null with no show, or no active token. Backed by the optional TokenRepository constructor arg (built lazily if omitted).
serialize_for_rest( array $badges ): array Public — Returns badge rows in the shape used by GET /shows/{id}/subscribers and GET /subscribers/{id} REST responses: [{label, color, icon_svg, icon_attachment_url, source}].

Notes

The rendering method is render_for_user(); there is no render(). The badge CSS does not auto-enqueue on render: the [benecaster_user_badge] and [benecaster_supporter_wall] shortcodes enqueue benecaster-badges themselves, only when they actually emit markup.