You are here

function simplenews_confirmation_send_combined in Simplenews 7.2

Same name and namespace in other branches
  1. 7 simplenews.module \simplenews_confirmation_send_combined()

Send collected confirmations.

Depending on the settings, always sends a combined confirmation, only when there are multiple changes for a subscriber or never.

Calling this functions also resets the combine flag so that later confirmations are sent separately. simplenews_combine_confirmations() needs to be called again to re-enable combining.

@todo This function currently does not return information about which subscriber received a confirmation.

Return value

TRUE if any confirmation mails have been sent.

1 call to simplenews_confirmation_send_combined()
simplenews_subscriptions_page_form_submit in includes/simplenews.subscription.inc
FAPI PAGE subscription form_submit.

File

./simplenews.module, line 3026
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_confirmation_send_combined() {
  global $language;

  // Disable combining for further confirmations.
  simplenews_confirmation_combine(FALSE);
  $group = simplenews_confirmation_add_combined();
  foreach ($group as $mail => $changes) {
    module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
    $params['from'] = _simplenews_set_from();
    $subscriber = simplenews_subscriber_load_by_mail($mail);
    if (!$subscriber) {
      $subscriber = new stdClass();
      $subscriber->mail = $mail;
      $subscriber->language = $language->language;
      $subscriber->newsletter_ids = array();
    }
    $params['context']['simplenews_subscriber'] = $subscriber;

    // Send multiple if there is more than one change for this subscriber
    // single otherwise.
    $use_combined = variable_get('simplenews_use_combined', 'multiple');
    $subscriber->changes = $changes;
    if (count($changes) > 1 && $use_combined != 'never' || $use_combined == 'always') {
      $key = 'subscribe_combined';
      drupal_mail('simplenews', $key, $subscriber->mail, $subscriber->language, $params, $params['from']['address']);
    }
    else {
      foreach ($changes as $newsletter_id => $key) {
        $params['context']['newsletter'] = simplenews_newsletter_load($newsletter_id);
        drupal_mail('simplenews', $key, $subscriber->mail, $subscriber->language, $params, $params['from']['address']);
      }
    }

    // Save the changes in the subscriber if there is a real subscriber object.
    if (!empty($subscriber->snid)) {
      simplenews_subscriber_save($subscriber);
    }
  }
  return !empty($group);
}