Skip to content

Commit

Permalink
Merge pull request #60 from SparkPost/issue-59
Browse files Browse the repository at this point in the history
Fix ReplyTo for latest wordpress
  • Loading branch information
rajumsys authored Aug 23, 2016
2 parents 0bb2bb2 + 029eac8 commit 200d9d1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
37 changes: 35 additions & 2 deletions mailer.http.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,12 @@ protected function get_request_headers($hide_api_key = false)
}

/**
* Returns the list of Reply-To headers
* Returns the list of Reply-To recipients
* For WordPress version below 4.6
* @return array
* TODO Remove this when wordpress does not support version below 4.6
*/
protected function get_reply_to()
protected function parse_reply_to_from_custom_header()
{
$replyTos = array();
foreach ($this->CustomHeader as $header) { // wp_mail sets Reply-To as custom header (does not use phpmailer->addReplyTo)
Expand All @@ -271,6 +273,37 @@ protected function get_reply_to()
return implode(',', $replyTos);
}

/**
* Returns list of Reply-To recipients
* For WordPress 4.6 and above
* @return array Formatted list of reply tos
*/
protected function parse_reply_to()
{
$replyTos = array();
foreach ($this->ReplyTo as $reply_to) {
$name = $reply_to[1];
$email = $reply_to[0];
if(empty($name)) {
$replyTos[] = $email;
} else {
$replyTos[] = sprintf('%s <%s>', $name, $email);
}
}

return implode(',', $replyTos);
}

protected function get_reply_to()
{
$wp_version = get_bloginfo('version');
if(version_compare($wp_version, '4.6') == -1) { // if lower than 4.6
return $this->parse_reply_to_from_custom_header();
} else {
return $this->parse_reply_to();
}
}

protected function build_recipient($email, $name = '', $header_to = '') {
$recipient = array(
'address' => array(
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: sparkpost, rajuru
Tags: sparkpost, smtp, wp_mail, mail, email
Requires at least: 4.0
Tested up to: 4.4.2
Stable tag: 2.4.0
Tested up to: 4.6
Stable tag: 2.4.1
License: GPLv2 or later

Send all your email from WordPress through SparkPost, the most advanced email delivery service.
Expand Down Expand Up @@ -47,6 +47,9 @@ Visit our [support site](https://support.sparkpost.com/) for help.

== Changelog ==

= 2.4.1=
- Fix Reply-To header issue with WordPress 4.6

= 2.4.0 =
- Add supports for CC and BCC using HTTP API

Expand Down
2 changes: 1 addition & 1 deletion wordpress-sparkpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Plugin Name: SparkPost
Plugin URI: http://sparkpost.com/
Description: Send all your email from Wordpress through SparkPost, the world's most advanced email delivery service.
Version: 2.4.0
Version: 2.4.1
Author: SparkPost
Author URI: http://sparkpost.com
License: GPLv2 or later
Expand Down

0 comments on commit 200d9d1

Please sign in to comment.