From d11ddcc17e124a714d3dcb39ee3e981c6e167517 Mon Sep 17 00:00:00 2001 From: Patrick Graham Date: Mon, 22 Mar 2021 09:41:33 -0700 Subject: [PATCH] Support wp_mail_from hook to set From address. https://github.com/wildbit/postmark-wordpress/issues/48 --- README.md | 2 ++ postmark.php | 4 ++-- readme.txt | 2 ++ wp-mail.php | 10 +++++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57aeb17..6658fb0 100755 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ The plugin supports using the `wp_mail_from_name` filter for manually setting a [Can I use the Postmark for WordPress plugin with Divi contact forms?](https://postmarkapp.com/support/article/1128-can-i-use-the-postmark-for-wordpress-plugin-with-divi-contact-forms) ## Changelog +### v.1.14.0 +* Support using wp_mail_from hook to set From address. Overriding From address via header still has priority. ### v1.13.4 * Handle special characters in site titles for test emails. diff --git a/postmark.php b/postmark.php index 5a26ef0..0990e62 100644 --- a/postmark.php +++ b/postmark.php @@ -3,7 +3,7 @@ * Plugin Name: Postmark (Official) * Plugin URI: https://postmarkapp.com/ * Description: Overrides wp_mail to send emails through Postmark - * Version: 1.13.4 + * Version: 1.14.0 * Author: Andrew Yates & Matt Gibbs */ @@ -31,7 +31,7 @@ class Postmark_Mail { */ public function __construct() { if ( ! defined( 'POSTMARK_VERSION' ) ) { - define( 'POSTMARK_VERSION', '1.13.4' ); + define( 'POSTMARK_VERSION', '1.14.0' ); } if ( ! defined( 'POSTMARK_DIR' ) ) { diff --git a/readme.txt b/readme.txt index f2bd7ee..61f2b09 100644 --- a/readme.txt +++ b/readme.txt @@ -103,6 +103,8 @@ The plugin supports using the `wp_mail_from_name` filter for manually setting a 1. Postmark WP Plugin Settings screen. == Changelog == += v.1.14.0 = +* Support using wp_mail_from hook to set From address. Overriding From address via header still has priority. = v1.13.4 = * Handle special characters in site titles for test emails. diff --git a/wp-mail.php b/wp-mail.php index 0fe2dec..200e6d7 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -149,9 +149,17 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ================================================== */ - // Allow overriding the From address when specified in the headers. + // Default From address specified in plugin settings. $from = $settings['sender_address']; + // Allow overriding the From address when specified via wp_mail_from hook. + $from_email = apply_filters( 'wp_mail_from', $from_email ); + + if ( isset( $from_email ) ) { + $from = $from_email; + } + + // Allow overriding the From address when specified via header. if ( isset( $recognized_headers['From'] ) ) { $from = $recognized_headers['From']; }