/** * 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; }
/** * Add idempotent checks and batch recording to the parent send method. * * @since 2.0.0 * * @return null|object|WP_Error */ public function send() { $this->batch->set_individual_message_values(array())->add_unsent_recipients()->lock_for_sending(); $result = parent::send(); if ($result and !is_wp_error($result)) { $this->record_successful_outbound_message_batch($result); } return $result; }