benecaster_subscriber_badge_assigned
Fires after a manual admin badge grant is written to the subscriber badges table. This hook covers only admin-initiated manual grants made via the subscriber detail panel — tier-based automatic badge reconciliation does not fire this hook.
The $definition_id parameter is the badge definition ID when the grant is backed by a definition; it is null for fully ad-hoc badges where the label, color, and icon are supplied directly in the grant row rather than pulled from a definition. Use this hook to notify the subscriber, trigger a welcome-back email variant, or write to an audit log. The companion hook benecaster_subscriber_badge_removed fires when a manual grant is deleted.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$id |
int |
— | Subscriber-badge row ID |
$user_id |
int |
— | Subscriber's WordPress user ID |
$definition_id |
int|null |
— | Badge definition ID when the assignment is definition-backed; null for a fully manual grant carrying its own label/color/icon |
$granted_by |
int |
— | Admin WordPress user ID that assigned the badge |
Examples
Notify subscriber of badge assignment
add_action( 'benecaster_subscriber_badge_assigned', function (
int $grant_id, int $user_id, ?int $definition_id, int $granted_by
): void {
// Notify the subscriber they've received a badge.
my_badge_notification( $user_id, $grant_id );
}, 10, 4 );
Notes
Tier-auto badge reconciliation does not fire this hook — only explicit admin-initiated manual grants trigger it. The badge removal companion benecaster_subscriber_badge_removed fires when a manual grant is deleted via the admin panel.
Need this built rather than just documented? See our services →