You are here

function mailchimp_process_webhook in Mailchimp 7.5

Same name and namespace in other branches
  1. 8 mailchimp.module \mailchimp_process_webhook()
  2. 7.2 mailchimp.module \mailchimp_process_webhook()
  3. 7.3 mailchimp.module \mailchimp_process_webhook()
  4. 7.4 mailchimp.module \mailchimp_process_webhook()
  5. 2.x mailchimp.module \mailchimp_process_webhook()

Process a webhook post from MailChimp.

1 string reference to 'mailchimp_process_webhook'
mailchimp_menu in ./mailchimp.module
Implements hook_menu().

File

./mailchimp.module, line 1609
Mailchimp module.

Code

function mailchimp_process_webhook() {
  if (empty($_POST)) {
    return "MailChimp Webhook Endpoint.";
  }
  $data = $_POST['data'];
  $type = $_POST['type'];
  switch ($type) {
    case 'unsubscribe':
    case 'profile':
    case 'cleaned':
      mailchimp_get_memberinfo($data['list_id'], $data['email'], TRUE);
      break;
    case 'upemail':
      mailchimp_cache_clear_member($data['list_id'], $data['old_email']);
      mailchimp_get_memberinfo($data['list_id'], $data['new_email'], TRUE);
      break;
    case 'campaign':
      mailchimp_cache_clear_list_activity($data['list_id']);
      mailchimp_cache_clear_campaign($data['id']);
      break;
  }

  // Allow other modules to act on a webhook.
  module_invoke_all('mailchimp_process_webhook', $type, $data);

  // Log event:
  watchdog('mailchimp', 'Webhook type @type has been processed.', array(
    '@type' => $type,
  ), WATCHDOG_INFO);
  return NULL;
}