/**
  * Send email notifications for a comment.
  *
  * Sends up to emails_per_chunk unsent notifications, and schedules another chunk if there are more.
  */
 public function send()
 {
     $recipient_values = $this->batch->get_individual_message_values();
     $chunks = array_chunk($recipient_values, intval(Prompt_Core::$options->get('emails_per_chunk')));
     if (empty($chunks[0])) {
         return null;
     }
     $chunk = $chunks[0];
     /**
      * Filter whether to send new comment notifications.
      *
      * @param boolean $send Default true.
      * @param Prompt_Comment_Email_Batch $batch
      * @param array $chunk
      */
     if (!apply_filters('prompt/send_comment_notifications', true, $this->batch, $chunk)) {
         return null;
     }
     $this->batch->set_individual_message_values($chunk)->lock_for_sending();
     // Turn off native comment notifications
     add_filter('pre_option_comments_notify', create_function('$a', 'return null;'));
     $result = parent::send();
     if (!$this->rescheduled and !empty($chunks[1])) {
         $this->schedule_next_chunk();
     }
     return $result;
 }
Example #2
0
 /**
  * Send email notifications for a post.
  *
  * Sends up to emails_per_chunk unsent notifications, and schedules another chunk if there are more.
  */
 public function send()
 {
     $recipient_values = $this->batch->add_unsent_recipients()->get_individual_message_values();
     $chunks = array_chunk($recipient_values, absint(Prompt_Core::$options->get('emails_per_chunk')));
     if (empty($chunks[0])) {
         return null;
     }
     $chunk = $chunks[0];
     /**
      * Filter whether to send new post notifications. Default true.
      *
      * @param boolean $send Whether to send notifications.
      * @param WP_Post $post
      * @param array $recipient_ids
      */
     if (!apply_filters('prompt/send_post_notifications', true, $this->batch->get_context()->get_post(), $chunk)) {
         return null;
     }
     $this->batch->set_individual_message_values($chunk)->lock_for_sending();
     $result = parent::send();
     if (!$this->rescheduled and !empty($chunks[1])) {
         $this->schedule_next_chunk();
     }
     return $result;
 }
 /**
  * Augment sending to add chunking.
  *
  * @return array
  */
 public function send()
 {
     // Bail if we've already sent this chunk
     if ($this->chunk <= $this->get_delivered_chunk()) {
         return array();
     }
     // Block other processes from sending this chunk
     $batch_key = $this->set_delivered_chunk();
     $chunks = array_chunk($this->batch->get_individual_message_values(), 30);
     $this->batch->set_individual_message_values($chunks[$this->chunk]);
     $result = parent::send();
     if (is_wp_error($result)) {
         Prompt_Logging::add_error(Prompt_Enum_Error_Codes::OUTBOUND, __('A subscription agreement sending operation encountered a problem.', 'Postmatic'), array('error' => $result, 'batch' => $this->batch, 'chunk' => $this->chunk));
     }
     if (!empty($chunks[$this->chunk + 1])) {
         $this->schedule_next_chunk($batch_key);
     }
     return $result;
 }