diff --git a/modules/contact-form/admin.php b/modules/contact-form/admin.php index b66672045690d..062a2c720a28d 100644 --- a/modules/contact-form/admin.php +++ b/modules/contact-form/admin.php @@ -696,7 +696,7 @@ function grunion_ajax_spam() { */ $subject = apply_filters( 'contact_form_subject', $content_fields['_feedback_subject'], $content_fields['_feedback_all_fields'] ); - wp_mail( $to, $subject, $message, $headers ); + Grunion_Contact_Form::wp_mail( $to, $subject, $message, $headers ); } } elseif( $_POST['make_it'] == 'publish' ) { if ( ! current_user_can($post_type_object->cap->delete_post, $post_id) ) { diff --git a/modules/contact-form/grunion-contact-form.php b/modules/contact-form/grunion-contact-form.php index 9c858a4ef4f84..51faeb92df5e9 100644 --- a/modules/contact-form/grunion-contact-form.php +++ b/modules/contact-form/grunion-contact-form.php @@ -2150,8 +2150,6 @@ function process_submission() { wp_schedule_event( time() + 250, 'daily', 'grunion_scheduled_delete' ); } - add_filter( 'wp_mail_content_type', __CLASS__ . '::get_mail_content_type' ); - add_action( 'phpmailer_init', __CLASS__ . '::add_plain_text_alternative' ); if ( $is_spam !== true && /** @@ -2166,7 +2164,7 @@ function process_submission() { */ true === apply_filters( 'grunion_should_send_email', true, $post_id ) ) { - wp_mail( $to, "{$spam}{$subject}", $message, $headers ); + self::wp_mail( $to, "{$spam}{$subject}", $message, $headers ); } elseif ( true === $is_spam && /** @@ -2180,10 +2178,8 @@ function process_submission() { */ apply_filters( 'grunion_still_email_spam', false ) == true ) { // don't send spam by default. Filterable. - wp_mail( $to, "{$spam}{$subject}", $message, $headers ); + self::wp_mail( $to, "{$spam}{$subject}", $message, $headers ); } - remove_filter( 'wp_mail_content_type', __CLASS__ . '::get_mail_content_type' ); - remove_action( 'phpmailer_init', __CLASS__ . '::add_plain_text_alternative' ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return self::success_message( $post_id, $this ); @@ -2217,6 +2213,29 @@ function process_submission() { exit; } + /** + * Wrapper for wp_mail() that enables HTML messages with text alternatives + * + * @param string|array $to Array or comma-separated list of email addresses to send message. + * @param string $subject Email subject. + * @param string $message Message contents. + * @param string|array $headers Optional. Additional headers. + * @param string|array $attachments Optional. Files to attach. + * + * @return bool Whether the email contents were sent successfully. + */ + public static function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { + add_filter( 'wp_mail_content_type', __CLASS__ . '::get_mail_content_type' ); + add_action( 'phpmailer_init', __CLASS__ . '::add_plain_text_alternative' ); + + $result = wp_mail( $to, $subject, $message, $headers, $attachments ); + + remove_filter( 'wp_mail_content_type', __CLASS__ . '::get_mail_content_type' ); + remove_action( 'phpmailer_init', __CLASS__ . '::add_plain_text_alternative' ); + + return $result; + } + /** * Add a display name part to an email address *