Skip to main content

benecaster_email_unsubscribed

Action Free Since v1.0.0

Fires after a subscriber’s email opt-out is recorded. Use this hook to sync opt-out status to external email marketing platforms or update CRM records.

There are two opt-out levels. A `’broadcast’` opt-out stops non-transactional emails (episode announcements, broadcasts) while transactional emails such as welcome messages and token resets continue. An `’all’` opt-out suppresses every Benecaster email for that subscriber — use with care, since transactional emails are typically expected. The `$method` parameter identifies how the opt-out was recorded: one of `’one_click_header’`, `’footer_link’`, `’subscriber_dashboard’`, `’admin_action’`, or `’api’`.

Parameters

Name Type Default Description
$user_id int|null WordPress user ID, or null if unsubscribing via token without being logged in
$show_id int ID of the show
$email_type string Opt-out level: 'broadcast' or 'all'
$email_address string Email address that unsubscribed

Examples

Sync opt-out to email platform

add_action( 'benecaster_email_unsubscribed', function(
    ?int   $user_id,
    int    $show_id,
    string $email_type,
    string $email_address,
    string $method
): void {
    if ( $email_type === 'broadcast' ) {
        my_esp_client()->remove_from_list( $email_address, 'podcast-broadcasts' );
    } elseif ( $email_type === 'all' ) {
        my_esp_client()->unsubscribe_globally( $email_address );
    }
}, 10, 5 );