Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mailgun/wordpress-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-mykhailenko committed Dec 14, 2022
2 parents 915109d + 82c0bcd commit 577a190
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
42 changes: 33 additions & 9 deletions includes/wp-mail-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 577a190

Please sign in to comment.