You are here

function constant_contact_user_operations_unsubscribe in Constant Contact 6.2

Same name and namespace in other branches
  1. 6.3 constant_contact.module \constant_contact_user_operations_unsubscribe()
  2. 7.3 constant_contact.module \constant_contact_user_operations_unsubscribe()

Add a mass unsubscribe option

1 string reference to 'constant_contact_user_operations_unsubscribe'
constant_contact_user_operations in ./constant_contact.module
Alter the bulk user operations option

File

./constant_contact.module, line 534

Code

function constant_contact_user_operations_unsubscribe($accounts) {
  $cc = constant_contact_create_object();

  // use the API to remove these users
  foreach ($accounts as $uid) {
    $account = user_load(array(
      'uid' => (int) $uid,
    ));

    // Skip unsubscribing user if they are already unsubscribed.
    if ($account !== FALSE && $account->cc_newsletter) {
      user_save($account, array(
        'cc_newsletter' => 0,
      ));

      // find contact
      $contact = $cc
        ->query_contacts($account->mail);
      if ($contact) {
        $cc
          ->delete_contact($contact['id']);
      }
    }
  }
}