React when a new membership tier is detected without a Benecaster mapping
Fires when a new tier appears in the membership plugin without a matching Benecaster tier mapping. The built-in admin notice already reacts to this action; this recipe adds supplementary Slack alerting so the admin doesn’t miss it. Debounce if needed — it fires on every event where the mapping is absent.
When This Is Useful
An unmapped tier means some subscribers may have active memberships that Benecaster doesn’t know how to handle — they’ll get empty feeds until the mapping is set. This is worth alerting on promptly. Common uses:
-
Slack / email alert to the site owner so they know to visit Settings → Subscription
-
Audit log to track when new tiers appear, useful in multi-admin setups
How It Works
The action passes the external tier ID and the slug of the bridge that reported it. Two responses are worth building:
-
A Slack alert, debounced. Key a transient on both the bridge slug and the tier ID, bail if it’s already set, then post the webhook non-blocking so the alert never holds up the request that triggered it. Include a link to Settings → Subscription so the recipient can act immediately.
-
An audit log entry. Insert a row into your own table on every occurrence, deliberately without a debounce — for multi-admin sites the repeat detections are the signal.
Notes
It fires from two places. Most detections are immediate, the moment a tier is saved in the membership plugin. Bridges that cannot report a save as it happens are covered by a daily sync instead, so a tier that slips past the immediate path is caught within 24 hours either way. Your callback cannot tell the two apart, and should not need to.
Debounce when alerting. A tier that is re-saved in the membership plugin fires this action again each time while it remains unmapped. Use a transient as a debounce gate, keyed on both the bridge slug and the tier ID.
Creating the mapping for the subscriber is not available to add-on code. There is no public, documented route to write a tier mapping, so the supported responses are the two above — alert a human, and let them map it in Settings → Subscription.
The built-in admin notice still fires. Your callback is additive — Benecaster’s own notice system handles surfacing the alert in the dashboard. You’re supplementing it, not replacing it.
Related
- Mapping Your Membership Tiers — how to resolve unmapped tiers in the admin
Code
<?php
add_action( 'benecaster_tier_unmapped', function ( $tier_id, string $plugin_slug ): void {
$message = sprintf(
'New %s tier (ID: %s) detected — no Benecaster mapping found. Visit Benecaster settings to map it.',
$plugin_slug,
$tier_id
);
wp_remote_post( MY_SLACK_WEBHOOK_URL, [
'body' => wp_json_encode( [ 'text' => $message ] ),
'headers' => [ 'Content-Type' => 'application/json' ],
] );
}, 10, 2 );
Hooks Used
Need this built rather than just documented? See our services →