TenureBadgeAppender
\Benecaster\Membership\TenureBadgeAppender
Adds the automatic tenure badge (“New Member”, “1-Year Member” and so on) to a subscriber’s badge list. It hooks the benecaster_user_badges filter at priority 20, so anything that displays badges through benecaster_get_user_badges() or benecaster_render_user_badges(), including the Supporter Wall, the account page and the REST badge output, shows the tenure badge next to tier and manual badges with no extra work.
The tenure badge is off by default and is switched on site-wide from the Memberships → Badges panel. While it is off, the class adds nothing. When a show is in scope the badge reflects the subscriber’s tenure on that show; with no show in scope (the site-wide account page) it reflects their earliest active membership across all shows.
The badge is computed, not stored. Its row has a synthetic id of -1, a source of tenure_auto and the label chosen by TenureBadgeCalculator, so code that branches on badge identity can tell it from a granted badge. The plugin registers the class at boot, so you never construct it. To change the milestones or the label text, use the benecaster_tenure_badge_milestones and benecaster_tenure_badge_label filters; to change the chip markup, use benecaster_tenure_badge_output. The two static methods are the only parts intended for reuse, for code that needs the same on/off check or badge row shape outside the filter.
Constructor Dependencies
| Type | Description |
|---|---|
\Benecaster\Membership\TenureBadgeCalculator |
Produces the tenure snapshot (join date, months, milestone and label) the badge row is built from. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
register(): void |
Public | — | Adds append_tenure_badge() to the benecaster_user_badges filter at priority 20, accepting three arguments. |
append_tenure_badge( array $badges, int $user_id, ?int $show_id ): array |
Public | — | The benecaster_user_badges filter callback. Returns $badges unchanged when the tenure badge is switched off, when $user_id is not positive, when the user has no token in scope, or when the calculated label is empty. Otherwise appends one row built by build_row(). With a positive $show_id the snapshot comes from TenureBadgeCalculator::calculate(); with null or zero it comes from calculate_for_user(). |
is_enabled(): bool |
Public | — | Static. Returns true when the site-wide tenure badge setting is on. The setting defaults to off. Use this rather than reading the stored option yourself. |
build_row( array $snapshot, int $user_id = 0, ?int $show_id = null ): \stdClass |
Public | — | Static. Builds a badge row object from a TenureBadgeCalculator snapshot, in the same shape the stored-badge repository produces: id (-1), label (from the snapshot), icon_slug (calendar), icon_attachment_id (0), color (#6B7280), source (tenure_auto), granted_at (the snapshot's since date), user_id, and show_id (0 when $show_id is null or not positive). token_type is copied from the snapshot when the snapshot has one, so the chip is classified as a follower or subscriber chip; a snapshot without the key yields a row without it. It does not check is_enabled() or whether the label is empty; the caller does. |
Constants
| Name | Value | Description |
|---|---|---|
ENABLED_OPTION |
'benecaster_tenure_badge_enabled' |
The option name that stores the site-wide on/off setting. Read it with is_enabled(); the Memberships → Badges panel writes it. |
SOURCE |
'tenure_auto' |
The source value on every row this class produces. Test for it to tell a computed tenure badge from a granted one. |
ICON_SLUG |
'calendar' |
The icon slug set on tenure badge rows. |
COLOR |
'#6B7280' |
The chip color set on tenure badge rows (a mid gray). The chip's markup can be replaced through the benecaster_tenure_badge_output filter. |
SYNTHETIC_ID |
-1 |
The id on every tenure badge row. Stored badge rows have positive IDs, so a negative ID marks a computed one. |
Notes
The class registers a callback on benecaster_user_badges but fires no hooks of its own. The benecaster_tenure_badge_output filter is fired later, by the chip renderer, and only for rows whose source is tenure_auto. Because the row is synthetic, never pass its id to a function that expects a stored badge grant.