private function _send_cancel_event_email($event_id) { $event = new Eab_EventModel(get_post($event_id)); $rsvps = $event->get_event_bookings(Eab_EventModel::BOOKING_YES); if (empty($rsvps)) { return false; } $from = $this->_data->get_option('eab_cancelations-email-from'); $from = $from ? $from : get_option('admin_email'); $subject = trim($this->_data->get_option('eab_cancelations-email-subject')); $subject = !empty($subject) ? $subject : $this->_default_subject; $body = trim($this->_data->get_option('eab_cancelations-email-body')); $body = !empty($body) ? $body : $this->_default_message; if (empty($from) || empty($subject) || empty($body)) { return false; } $already_sent = $this->_get_users_notification_queue($event->get_id()); $limit = $this->_get_email_batch_limit(); $counter = 0; $codec = new Eab_Macro_Codec($event_id); $headers = array('From: ' . $from, 'Content-Type: ' . $this->email_charset() . '; charset="' . get_option('blog_charset') . '"'); add_filter('wp_mail_content_type', array($this, 'email_charset')); foreach ($rsvps as $rsvp) { if (in_array($rsvp->user_id, $already_sent)) { continue; } // Don't send email twice $user = get_user_by('id', $rsvp->user_id); if (!is_email($user->user_email)) { continue; } $codec->set_user($user); wp_mail($user->user_email, $codec->expand($subject, Eab_Macro_Codec::FILTER_TITLE), $codec->expand($body, Eab_Macro_Codec::FILTER_BODY), $headers); $already_sent[] = $rsvp->user_id; $counter++; if ($counter == $limit) { break; } } remove_filter('wp_mail_content_type', array($this, 'email_charset')); $this->_set_users_notification_queue($event->get_id(), $already_sent); if (count($rsvps) == count($already_sent)) { $this->_remove_event_from_schedule_queue($event->get_id()); } return $counter; }