benecaster_badge_definition_created
Fires after a new badge definition row is inserted via the badge definition REST endpoint. Use this hook to precompute a rendered chip variant, publish a change notice to connected systems, or seed an autocomplete cache with the new badge.
Two related actions cover the rest of the badge definition lifecycle: benecaster_badge_definition_updated fires after a row is updated (with a $previous snapshot so integrations can detect meaningful changes without persisting their own snapshots), and benecaster_badge_definition_deleted fires after a row and all its cascaded subscriber badge assignments are deleted. The $badge array passed to _deleted holds the pre-delete row values so listeners can clean up external resources without re-querying.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$id |
int |
— | New badge definition ID |
$tier_id |
int |
— | Membership tier the badge belongs to |
$badge |
array |
— | Full badge row (label, color, icon_key, icon_attachment_id, etc.) |
Examples
Audit log on badge deletion
add_action( 'benecaster_badge_definition_deleted', function ( int $badge_id, int $tier_id, array $badge ): void {
// Log for audit trail
my_audit_log( 'badge_deleted', [
'badge_id' => $badge_id,
'label' => $badge['label'],
'tier_id' => $tier_id,
] );
}, 10, 3 );
Notes
When a badge definition is deleted, all tier_auto grants for that definition are cascade-deleted from the subscriber badge table. manual grants that referenced the definition have their foreign key nulled out — the subscriber keeps the label, icon, and color that were snapshotted at grant time. This cascade happens in core before the action fires; third-party listeners do not need to handle it.