You are here

function mailchimp_segment_add_subscriber in Mailchimp 7.3

Same name and namespace in other branches
  1. 7.5 mailchimp.module \mailchimp_segment_add_subscriber()
  2. 7.4 mailchimp.module \mailchimp_segment_add_subscriber()

Add a specific subscriber to a static segment of a list.

Parameters

string $list_id: ID of a MailChimp list

string $segment_id: ID of a segment of the MailChimp list

string $email: Email address to add to the segment (does NOT subscribe to the list)

bool $batch: Whether to queue this for the batch processor. Defaults to TRUE.

string $queue_id: The ID of the queue to use in batch processing.

Return value

bool Success boolean

2 calls to mailchimp_segment_add_subscriber()
MailchimpListsTestCase::testAddSegmentSubscriber in modules/mailchimp_lists/tests/mailchimp_lists.test
Tests adding a subscriber to a list segment.
mailchimp_lists_add_to_segment_action in modules/mailchimp_lists/mailchimp_lists.module
Action function for the Add To Segment action.

File

./mailchimp.module, line 834
Mailchimp module.

Code

function mailchimp_segment_add_subscriber($list_id, $segment_id, $email, $batch = TRUE, $queue_id = MAILCHIMP_BATCH_QUEUE_CRON) {
  $item = array(
    'email' => $email,
  );
  if (!$batch) {
    $batch = array(
      $item,
    );
    $success = mailchimp_segment_batch_add_subscribers($list_id, $segment_id, $batch);
  }
  else {
    $queue = DrupalQueue::get($queue_id);
    $queue
      ->createQueue();
    $success = $queue
      ->createItem(array(
      'function' => 'mailchimp_segment_batch_add_subscribers',
      'list_id' => $list_id,
      'arg' => $segment_id,
      'item' => $item,
    ));
    if (!$success) {
      watchdog('mailchimp', 'A problem occurred adding a MailChimp segment subscribe to the queue. Email: @email List: @list Segment: @segment.', array(
        '@email' => $email,
        '@list' => $list_id,
        '@segment' => $segment_id,
      ), WATCHDOG_WARNING);
    }
  }
  return $success;
}