You are here

function simplenews_issue_send in Simplenews 7.2

Same name and namespace in other branches
  1. 7 includes/simplenews.admin.inc \simplenews_issue_send()

Callback to send newsletters.

2 string references to 'simplenews_issue_send'
hook_simplenews_issue_operations in ./simplenews.api.php
Return operations to be applied to newsletter issues.
simplenews_simplenews_issue_operations in includes/simplenews.admin.inc
Implements hook_simplenews_issue_operations().

File

includes/simplenews.admin.inc, line 268
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_issue_send($nids) {
  $sent_nodes = array();
  foreach (node_load_multiple($nids) as $node) {
    if (simplenews_issue_status($node) != SIMPLENEWS_STATUS_SEND_NOT) {
      continue;
    }
    if ($node->status == NODE_NOT_PUBLISHED) {
      simplenews_issue_update_sent_status($node, SIMPLENEWS_COMMAND_SEND_PUBLISH);
      drupal_set_message(t('Newsletter %title is unpublished and will be sent on publish.', array(
        '%title' => $node->title,
      )));
      continue;
    }
    simplenews_add_node_to_spool($node);
    $sent_nodes[$node->nid] = $node->title;
  }

  // If there were any newsletters sent, display a message.
  if (!empty($sent_nodes)) {
    $conditions = array(
      'entity_id' => array_keys($sent_nodes),
      'entity_type' => 'node',
    );

    // Attempt to send immediatly, if configured to do so.
    if (simplenews_mail_attempt_immediate_send($conditions)) {
      drupal_set_message(t('Sent the following newsletters: %titles.', array(
        '%titles' => implode(', ', $sent_nodes),
      )));
    }
    else {
      drupal_set_message(t('The following newsletter are now pending: %titles.', array(
        '%titles' => implode(', ', $sent_nodes),
      )));
    }
  }
}