You are here

function mailchimp_unsubscribe_user in Mailchimp 7.2

Unsubscribe a user from the given list.

Parameters

stdclass $list: A mailchimp lists entity.

string $email: Email address to be unsubscribed.

bool $message: Whether or not to display a message in the web interface.

object $mcapi: Mailchimp API object if one is already loaded.

bool $delete: Indicates whether an email should be deleted or just unsubscribed.

Return value

bool Indicates whether unsubscribe was successful.

2 calls to mailchimp_unsubscribe_user()
mailchimp_lists_execute_change in modules/mailchimp_lists/mailchimp_lists.module
Calls the appropriate API function, or adds to the queue, as appropriate.
mailchimp_lists_rules_action_unsubscribe_list in modules/mailchimp_lists/mailchimp_lists.rules.inc
Action callback: Unsubscribe a user to a list.

File

./mailchimp.module, line 206
Mailchimp module.

Code

function mailchimp_unsubscribe_user($list, $email, $message = TRUE, $mcapi = NULL, $delete = FALSE) {
  $success = FALSE;
  if ($mcapi || ($mcapi = mailchimp_get_api_object())) {
    if (mailchimp_is_subscribed($list->mc_list_id, $email)) {
      $success = $mcapi
        ->listUnsubscribe($list->mc_list_id, $email, $delete, FALSE, FALSE);
      if ($success) {
        module_invoke_all('mailchimp_unsubscribe_user', $list, $email);
        if ($message) {
          drupal_set_message(t('You have unsubscribed from %list.', array(
            '%list' => $list->label,
          )));
        }
      }

      // Clear user cache:
      mailchimp_cache_clear_user($list->mc_list_id, $email);
    }
  }
  return $success;
}