benecaster_email_unsubscribe_allowed
Filters whether an email unsubscribe request should be processed. CRITICAL: Use with extreme caution — blocking a subscriber’s unsubscribe request may violate CAN-SPAM, GDPR, and similar regulations. Only use for fraud detection or rate limiting, never to prevent legitimate opt-outs.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$allowed |
bool |
— | Whether the unsubscribe request should be processed |
$user_id |
int|null |
— | WordPress user ID; null if not a known user |
$show_id |
int |
— | ID of the show |
$email_type |
string |
— | 'broadcast' to unsubscribe from broadcasts only; 'all' to unsubscribe from all emails |
$token |
string |
— | HMAC-signed unsubscribe token from the URL |
Returns:
bool
Example
add_filter( 'benecaster_email_unsubscribe_allowed', function( $allowed, $user_id, $show_id, $email_type, $token ) {
// Rate-limit unsubscribe requests to once per 60 seconds per user.
if ( $user_id ) {
$last = (int) get_transient( 'bc_unsub_' . $user_id );
if ( $last && ( time() - $last ) < 60 ) {
return false;
}
set_transient( 'bc_unsub_' . $user_id, time(), 60 );
}
return $allowed;
}, 10, 5 );