Skip to main content

Redefine tenure badge milestones with custom thresholds and labels

Premium Intermediate Since v1.0.0

The tenure badge shipped with Benecaster derives its label from a filterable milestone map. Core defaults to six thresholds (1, 6, 12, 24, 60, 120 months). Use benecaster_tenure_badge_milestones to replace the entire map with your own cadence — for example, quarterly recognition or a single “One-Year Anniversary” marker.

Compose with benecaster_tenure_badge_label when you need labels that the threshold map alone cannot express: the label filter fires after the milestone is matched, so you can override the selected label on a per-subscriber or per-tenure-range basis without changing the map. $label is an empty string when the subscriber’s tenure is below the lowest threshold — return a non-empty string there to inject a “New Supporter” label.

Code

<?php
// Quarterly recognition — thresholds at 3 / 6 / 9 / 12 / 24 months, with
// labels that read as anniversaries rather than "N-Month Member" progression.
add_filter( 'benecaster_tenure_badge_milestones', function ( array $default ): array {
	return [
		3  => 'First-Quarter Supporter',
		6  => 'Half-Year Supporter',
		9  => 'Three-Quarter Supporter',
		12 => 'One-Year Anniversary',
		24 => 'Two-Year Anniversary',
	];
} );

// Optional: fine-tune labels once picked. `benecaster_tenure_badge_label`
// fires AFTER the milestone match with the four args below — flag long-tenure
// supporters with a distinct label the milestone map alone can't express.
add_filter( 'benecaster_tenure_badge_label', function ( string $label, int $user_id, int $show_id, int $months_since_join ): string {
	// Beyond three years, override the milestone label with a
	// custom "Charter Member" designation regardless of what the
	// milestone matcher picked. The milestone map above tops out
	// at 24 months, so this branch kicks in for month 36 onwards.
	if ( $months_since_join >= 36 ) {
		return __( 'Charter Member', 'my-addon' );
	}
	return $label;
}, 10, 4 );

View on GitHub →

Hooks Used