You are here

function mailchimp_get_members in Mailchimp 7.4

Same name and namespace in other branches
  1. 8 mailchimp.module \mailchimp_get_members()
  2. 7.5 mailchimp.module \mailchimp_get_members()
  3. 7.3 mailchimp.module \mailchimp_get_members()
  4. 2.x mailchimp.module \mailchimp_get_members()

Retrieve all members of a given list with a given status.

Note that this function can cause locking an is somewhat slow. It is not recommended unless you know what you are doing! See the MCAPI documentation.

2 calls to mailchimp_get_members()
mailchimp_lists_get_subscribers in modules/mailchimp_lists/mailchimp_lists.module
Batch processor for pulling in subscriber information for a list.
mailchimp_lists_update_member_batch in modules/mailchimp_lists/mailchimp_lists.module
Batch processor for member mergevar updates.

File

./mailchimp.module, line 856
Mailchimp module.

Code

function mailchimp_get_members($list_id, $status = 'subscribed', $options = array()) {
  $results = FALSE;
  if (lock_acquire('mailchimp_get_members', 60)) {
    try {

      /* @var \Mailchimp\MailchimpLists $mc_lists */
      $mc_lists = mailchimp_get_api_object('MailchimpLists');
      if (!$mc_lists) {
        throw new MailchimpException('Cannot get members without Mailchimp API. Check API key has been entered.');
      }
      $options['status'] = $status;
      if (!isset($options['count']) || empty($options['count'])) {
        $options['count'] = 500;
      }
      $results = $mc_lists
        ->getMembers($list_id, $options);
    } catch (Exception $e) {
      watchdog('mailchimp', 'An error occurred pulling member info for a list. "%message"', array(
        '%message' => $e
          ->getMessage(),
      ), WATCHDOG_ERROR);
    }
    lock_release('mailchimp_get_members');
  }
  return $results;
}