diff --git a/CHANGELOG.md b/CHANGELOG.md index 544a0fe..bcd528a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +1.8.8 (2022-12-11) +- Fixed bug when `$to` override in the `wp_mail` function + 1.8.7 (2022-11-12) - Fixed bug when field `Override "From" Details` was not updated diff --git a/includes/wp-mail-api.php b/includes/wp-mail-api.php index 53cd139..3781235 100644 --- a/includes/wp-mail-api.php +++ b/includes/wp-mail-api.php @@ -112,13 +112,6 @@ function mg_mutate_to_rcpt_vars_cb($to_addrs) if (!function_exists('wp_mail')) { function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { - // Compact the input, apply the filters, and extract them back out - $extractData = apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')); - if (!is_array($extractData)) { - $extractData = (array)$extractData; - } - extract($extractData, EXTR_OVERWRITE); - $mailgun = get_option('mailgun'); $region = (defined('MAILGUN_REGION') && MAILGUN_REGION) ? MAILGUN_REGION : $mailgun['region']; $apiKey = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $mailgun['apiKey']; @@ -129,10 +122,41 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) } // If a region is not set via defines or through the options page, default to US region. - if (!((bool)$region)) { + if (!($region)) { error_log('[Mailgun] No region configuration was found! Defaulting to US region.'); $region = 'us'; } + + // Respect WordPress core filters + $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); + + if ( isset( $atts['to'] ) ) { + $to = $atts['to']; + } + + if ( ! is_array( $to ) ) { + $to = explode( ',', $to ); + } + + if ( isset( $atts['subject'] ) ) { + $subject = $atts['subject']; + } + + if ( isset( $atts['message'] ) ) { + $message = $atts['message']; + } + + if ( isset( $atts['headers'] ) ) { + $headers = $atts['headers']; + } + + if ( isset( $atts['attachments'] ) ) { + $attachments = $atts['attachments']; + } + + if (!is_array($attachments)) { + $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); + } if (!is_array($attachments)) { $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); @@ -256,7 +280,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) } elseif (is_array($body['o:tag'])) { $body['o:tag'] = array_merge($body['o:tag'], $tags); } else { - $body['o:tag'] .= ',' . $tags; + $body['o:tag'] .= ',' . implode(',', $tags); } } diff --git a/mailgun.php b/mailgun.php index 4cda4c2..2e2342e 100755 --- a/mailgun.php +++ b/mailgun.php @@ -3,7 +3,7 @@ * Plugin Name: Mailgun * Plugin URI: http://wordpress.org/extend/plugins/mailgun/ * Description: Mailgun integration for WordPress - * Version: 1.8.7 + * Version: 1.8.8 * Tested up to: 6.1 * Author: Mailgun * Author URI: http://www.mailgun.com/ diff --git a/readme.md b/readme.md index 8d64a0b..e1172bb 100755 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev Tags: mailgun, smtp, http, api, mail, email Requires at least: 3.3 Tested up to: 6.1 -Stable tag: 1.8.7 +Stable tag: 1.8.8 Requires PHP: 5.6 License: GPLv2 or later @@ -130,6 +130,9 @@ MAILGUN_FROM_ADDRESS Type: string == Changelog == += 1.8.8 (2022-12-11): = +- Fixed bug when `$to` override in the `wp_mail` function + = 1.8.7 (2022-11-12): = - Fixed bug when field `Override "From" Details` was not updated diff --git a/readme.txt b/readme.txt index 6d4629b..991703f 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev Tags: mailgun, smtp, http, api, mail, email Requires at least: 4.4 Tested up to: 6.1 -Stable tag: 1.8.7 +Stable tag: 1.8.8 Requires PHP: 5.6 License: GPLv2 or later