function mailchimp_unsubscribe_process in Mailchimp 8
Same name and namespace in other branches
- 7.5 mailchimp.module \mailchimp_unsubscribe_process()
- 7.3 mailchimp.module \mailchimp_unsubscribe_process()
- 7.4 mailchimp.module \mailchimp_unsubscribe_process()
- 2.x mailchimp.module \mailchimp_unsubscribe_process()
Unsubscribes a member from a Mailchimp list.
See also
Mailchimp_Lists::unsubscribe()
1 call to mailchimp_unsubscribe_process()
- mailchimp_unsubscribe in ./
mailchimp.module - Unsubscribes a member from a Mailchimp list.
1 string reference to 'mailchimp_unsubscribe_process'
- mailchimp_unsubscribe in ./
mailchimp.module - Unsubscribes a member from a Mailchimp list.
File
- ./
mailchimp.module, line 842 - Mailchimp module.
Code
function mailchimp_unsubscribe_process($list_id, $email) {
try {
/* @var \Mailchimp\MailchimpLists $mc_lists */
$mc_lists = mailchimp_get_api_object('MailchimpLists');
if (!$mc_lists) {
throw new Exception('Cannot unsubscribe from list without Mailchimp API. Check API key has been entered.');
}
$mc_lists
->removeMember($list_id, $email);
\Drupal::moduleHandler()
->invokeAll('mailchimp_unsubscribe_success', [
$list_id,
$email,
]);
// Clear user cache:
mailchimp_cache_clear_member($list_id, $email);
return TRUE;
} catch (\Exception $e) {
\Drupal::logger('mailchimp')
->error('An error occurred unsubscribing {email} from list {list}. "{message}"', [
'email' => $email,
'list' => $list_id,
'message' => $e
->getMessage(),
]);
}
return FALSE;
}