You are here

function campaignmonitor_unsubscribe_process in Campaign Monitor 8

Unsubscribes a member from a CampaignMonitor list.

See also

CampaignMonitor_Lists::unsubscribe()

1 call to campaignmonitor_unsubscribe_process()
campaignmonitor_unsubscribe in ./campaignmonitor.module
Unsubscribes a member from a CampaignMonitor list.
1 string reference to 'campaignmonitor_unsubscribe_process'
campaignmonitor_unsubscribe in ./campaignmonitor.module
Unsubscribes a member from a CampaignMonitor list.

File

./campaignmonitor.module, line 489
Module that plugs in Campaign Monitor functionality to your Drupal web site. For Campaign Monitor information see: http://www.campaignmonitor.com/.

Code

function campaignmonitor_unsubscribe_process($list_id, $email, $delete, $goodbye, $notify) {
  $lists = campaignmonitor_get_lists();
  try {

    /* @var \CampaignMonitor\CampaignMonitorLists $mc_lists */
    $cm = CampaignMonitor::getConnector();
    if ($cm
      ->unsubscribe($list_id, $email)) {
      drupal_set_message(t('You are now unsubscribed from the "@list" list.', [
        '@list' => html_entity_decode($lists[$list_id]['name']),
      ]), 'status');
      \Drupal::moduleHandler()
        ->invokeAll('campaignmonitor_unsubscribe', [
        $list_id,
        $email,
      ]);

      // Clear user cache:
      campaignmonitor_cache_clear_subscriber($list_id, $email);
      return TRUE;
    }
    return FALSE;
  } catch (Exception $e) {
    \Drupal::logger('campaignmonitor')
      ->error('An error occurred unsubscribing {email} from list {list}. "{message}"', [
      'email' => $email,
      'list' => $list_id,
      'message' => $e
        ->getMessage(),
    ]);
  }
  return FALSE;
}