Skip to main content

benecaster_email_unsubscribe_allowed

Filter Free

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.

Return a boolean. Cast with (bool); the default is true.

Returning false makes the opt-out silently fail to record. The method returns before writing anything, and the visitor is not told — from their side the unsubscribe appears to have worked. Blocking a genuine opt-out also defeats the List-Unsubscribe headers Benecaster sets, which is what keeps mail out of spam folders. Use this to reject a forged request, never to keep a subscriber on a list.

$type is the opt-out level: broadcast, episode_notifications or all. $token is empty for opt-outs that did not arrive by token link. A token is accepted only for the show it was issued for.

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', 'episode_notifications' (new-episode emails only) or 'all'
$token string — The unsubscribe token from the link, or empty when the opt-out did not come from a link

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 );

Need this built rather than just documented? See our services →