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 three opt-out levels, one per show:
-
'broadcast'stops non-transactional emails such as broadcasts and announcements. Transactional emails (welcome messages, token resets, billing) continue, and so do new-episode emails. -
'episode_notifications'stops new-episode emails only. Broadcasts and transactional emails continue. The footer link and the one-clickList-Unsubscribeheader on a new-episode email record this level, so leaving from one stops new-episode mail and nothing else. -
'all'stops every Benecaster email except the few that must always arrive, such as a feed link the subscriber asked for. Use with care, since transactional emails are typically expected.
Which level an email type answers to is fixed by Benecaster and cannot be filtered. An unsubscribe link is accepted only for the show it was sent for. 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 |
$type |
string |
— | The opt-out level: 'broadcast', 'episode_notifications' or 'all' |
$email_address |
string |
— | Email address |
$method |
string |
— | How the opt-out was made — 'api' by default (e.g. the List-Unsubscribe link) |
$token |
string |
— | The unsubscribe token the request carried, or '' when there was none (an opt-out made in the account page or by an admin). Added last, so a five-argument callback is unaffected. |
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 === 'episode_notifications' ) {
my_esp_client()->remove_from_list( $email_address, 'new-episode-alerts' );
} elseif ( $email_type === 'all' ) {
my_esp_client()->unsubscribe_globally( $email_address );
}
}, 10, 5 );
Need this built rather than just documented? See our services →