benecaster_email_unsubscribed
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 |
$show_id |
int |
— | ID of the show |
$email_type |
string |
— | Email type key |
$email_address |
string |
— | Email address |
$method |
string |
— | How the opt-out was made — 'api' by default (e.g. the List-Unsubscribe link) |
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 );
Need this built rather than just documented? See our services →