You are here

function constant_contact_user_operations_unsubscribe_and_delete in Constant Contact 7.3

Same name and namespace in other branches
  1. 6.3 constant_contact.module \constant_contact_user_operations_unsubscribe_and_delete()

Callback function for admin mass unsubscribe and delete users.

1 string reference to 'constant_contact_user_operations_unsubscribe_and_delete'
constant_contact_user_operations in ./constant_contact.module
Implements hook_user_operations().

File

./constant_contact.module, line 776

Code

function constant_contact_user_operations_unsubscribe_and_delete($accounts) {
  $cc = constant_contact_create_object();
  if (!is_object($cc)) {
    return;
  }

  // Use the API to remove these, users then delete their drupal account.
  foreach ($accounts as $uid) {
    $account = user_load($uid);
    if ($account !== FALSE) {

      // Skip unsubscribing user if they are already unsubscribed.
      // Find contact.
      $contact = $cc
        ->query_contacts($account->mail);
      if ($contact) {
        $cc
          ->delete_contact($contact['id']);
      }
      user_delete(array(), (int) $uid);
    }
  }
}