From 0ef060f0ca71448c7670db3f34b4a60e458808da Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Tue, 13 Jul 2021 11:38:38 -0400 Subject: [PATCH 01/11] Merge settings from database with constants Since both page-settings.php and wp-mail.php (class Postmark_Mail) need these settings a new file is created that will return an array of settings. The array of settings coming from the database is merged with the settings defined as constants, with constants taking priority. --- postmark-settings.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 postmark-settings.php diff --git a/postmark-settings.php b/postmark-settings.php new file mode 100644 index 0000000..8353af6 --- /dev/null +++ b/postmark-settings.php @@ -0,0 +1,15 @@ + defined('POSTMARK_API_KEY') ? POSTMARK_API_KEY : null, + 'stream_name' => defined('POSTMARK_STREAM_NAME') ? POSTMARK_STREAM_NAME : null, + 'sender_address' => defined('POSTMARK_SENDER_ADDRESS') ? POSTMARK_SENDER_ADDRESS : null, +); +$settings = array_merge( $settings, $settings_from_constants ); +return $settings; From ba909bbd9bd5b43cefd8a78816ec48685c7962ff Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Tue, 13 Jul 2021 11:39:39 -0400 Subject: [PATCH 02/11] Add overrideen settings property so we can show in UI --- postmark.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/postmark.php b/postmark.php index 1a39e77..60dd8d1 100644 --- a/postmark.php +++ b/postmark.php @@ -19,6 +19,13 @@ class Postmark_Mail { */ public $settings; + /** + * Overridden Settings. + * + * @var array + */ + public $overridden_settings; + /** * Last Error. * @@ -45,6 +52,7 @@ public function __construct() { add_filter( 'init', array( $this, 'init' ) ); $this->settings = $this->load_settings(); + $this->overridden_settings = include POSTMARK_DIR . '/postmark-settings.php'; } /** From e0096ba4ea823197ee52dd7a6b0299ba017db79c Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Tue, 13 Jul 2021 11:40:16 -0400 Subject: [PATCH 03/11] When sending mail, use constants if defined --- wp-mail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-mail.php b/wp-mail.php index b4fb885..aec3e0a 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -52,7 +52,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() // Compact the input, apply the filters, and extract them back out. extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); - $settings = json_decode( get_option( 'postmark_settings' ), true ); + $settings = include POSTMARK_DIR . '/postmark-settings.php'; if ( ! is_array( $attachments ) ) { $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); From 9dd25a17bffa253b265866caa21055973267df65 Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Tue, 13 Jul 2021 11:42:42 -0400 Subject: [PATCH 04/11] Show the user which settings have been overridden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the WP Dashboard, show the user if settings have been overridden by constants, but don’t show them the actual constant values. This will somehwat obfuscate the API key from the user. (Think agencies that define constants for a client using the agencies sandboxed api key.) --- page-settings.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/page-settings.php b/page-settings.php index 57e1127..6c3b3bd 100644 --- a/page-settings.php +++ b/page-settings.php @@ -42,6 +42,18 @@ + overridden_settings['api_key'] ) ) : ?> +
POSTMARK_API_KEY is defined in your wp-config.php and overrides the API Key set here.
+ + + overridden_settings['stream_name'] ) ) : ?> +
POSTMARK_STREAM_NAME is defined in your wp-config.php and overrides the Message Stream set here.
+ + + overridden_settings['sender_address'] ) ) : ?> +
POSTMARK_SENDER_ADDRESS is defined in your wp-config.php and overrides the Sender Email set here.
+ +
From abc089d5c9c4d917a5e4d47ca851f9acacbe52f6 Mon Sep 17 00:00:00 2001 From: Patrick Graham Date: Mon, 19 Jul 2021 09:17:36 -0700 Subject: [PATCH 05/11] Plugin versioning. --- postmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postmark.php b/postmark.php index 60dd8d1..230c06b 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.7 + * Version: 1.14.0 * Author: Andrew Yates & Matt Gibbs */ @@ -38,7 +38,7 @@ class Postmark_Mail { */ public function __construct() { if ( ! defined( 'POSTMARK_VERSION' ) ) { - define( 'POSTMARK_VERSION', '1.13.7' ); + define( 'POSTMARK_VERSION', '1.14.0' ); } if ( ! defined( 'POSTMARK_DIR' ) ) { From 0649d41e712fa44726aef1db5273573ad022fb3c Mon Sep 17 00:00:00 2001 From: Patrick Graham Date: Mon, 19 Jul 2021 09:19:50 -0700 Subject: [PATCH 06/11] Readme updates for v1.14.0 --- README.md | 3 +++ readme.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 01b0867..1680a9a 100755 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ 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 +### v1.14.0 +* Adds ability to override settings for environment specific Postmark plugin settings. + ### v1.13.7 * Fix limit of 500 sending logs deleted per day. diff --git a/readme.txt b/readme.txt index 46eac4f..c89d459 100644 --- a/readme.txt +++ b/readme.txt @@ -103,6 +103,9 @@ The plugin supports using the `wp_mail_from_name` filter for manually setting a 1. Postmark WP Plugin Settings screen. == Changelog == += v1.14.0 = +* Adds ability to override settings for environment specific Postmark plugin settings. + = v1.13.7 = * Fix limit of 500 sending logs deleted per day. From 08d797e4fa1b8af1fb30dd83eb8563947b4e7d25 Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Mon, 19 Jul 2021 16:42:39 -0400 Subject: [PATCH 07/11] filter the array to remove null values --- postmark-settings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/postmark-settings.php b/postmark-settings.php index 8353af6..9f2332e 100644 --- a/postmark-settings.php +++ b/postmark-settings.php @@ -11,5 +11,6 @@ 'stream_name' => defined('POSTMARK_STREAM_NAME') ? POSTMARK_STREAM_NAME : null, 'sender_address' => defined('POSTMARK_SENDER_ADDRESS') ? POSTMARK_SENDER_ADDRESS : null, ); +$settings_from_constants = array_filter($settings_from_constants); $settings = array_merge( $settings, $settings_from_constants ); return $settings; From 3e32f10d559a031ea84def0d909fdca9257424ae Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Mon, 19 Jul 2021 16:42:57 -0400 Subject: [PATCH 08/11] return an arrray so we can see real settings and overridden settings --- postmark-settings.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/postmark-settings.php b/postmark-settings.php index 9f2332e..6a4deb0 100644 --- a/postmark-settings.php +++ b/postmark-settings.php @@ -13,4 +13,7 @@ ); $settings_from_constants = array_filter($settings_from_constants); $settings = array_merge( $settings, $settings_from_constants ); -return $settings; +return array( + 'settings' => $settings, + 'settings_from_constants' => $settings_from_constants, +); From 4d71d3ec26fde8a30888adc602f967a3cc6d8e61 Mon Sep 17 00:00:00 2001 From: Tim Flight <4959691+tflight@users.noreply.github.com> Date: Mon, 19 Jul 2021 16:43:14 -0400 Subject: [PATCH 09/11] identify which settings we need to use --- postmark.php | 1 + wp-mail.php | 1 + 2 files changed, 2 insertions(+) diff --git a/postmark.php b/postmark.php index 230c06b..2762988 100644 --- a/postmark.php +++ b/postmark.php @@ -53,6 +53,7 @@ public function __construct() { $this->settings = $this->load_settings(); $this->overridden_settings = include POSTMARK_DIR . '/postmark-settings.php'; + $this->overridden_settings = $this->overridden_settings['settings_from_constants']; } /** diff --git a/wp-mail.php b/wp-mail.php index aec3e0a..5fdbb9c 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -53,6 +53,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); $settings = include POSTMARK_DIR . '/postmark-settings.php'; + $settings = $settings['settings']; if ( ! is_array( $attachments ) ) { $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); From c5138a9568be6f8e5c72274c01c564c1c7420eac Mon Sep 17 00:00:00 2001 From: Patrick Graham Date: Tue, 20 Jul 2021 14:08:07 -0700 Subject: [PATCH 10/11] Add environment variable usage info to readme. --- readme.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 083c361..99f18ca 100644 --- a/readme.txt +++ b/readme.txt @@ -59,11 +59,22 @@ Because we've been in this business for many years. We’ve been running an emai Most importantly, a great product requires great support and even better education. Our team is spread out across six time zones to offer fast support on everything from using Postmark to best practices on content and user engagement. A solid infrastructure only goes so far, that’s why improving our customer’s sending practices helps achieve incredible results - = Why aren't my HTML emails being sent? = This plugin detects HTML by checking the headers sent by other WordPress plugins. If a "text/html" content type isn't set then this plugin won't send the HTML to Postmark to be sent out only the plain text version of the email. += How do I set environment specific Postmark plugin settings? + +You can optionally set the Postmark API Token, message stream, and default sending address by adding the following to your `wp-config.php` file: + +``` +define( 'POSTMARK_API_KEY', '' ); +define( 'POSTMARK_STREAM_NAME', 'stream-name' ); +define( 'POSTMARK_SENDER_ADDRESS', 'from@example.com' ); +``` + +Setting any of these here will override what is set via the plugin's UI. + = Why are password reset links not showing in emails sent with this plugin? = There are a couple ways to resolve this issue. From 05c898c554ad5a315153e4e500e55f164593ed44 Mon Sep 17 00:00:00 2001 From: Patrick Graham Date: Tue, 20 Jul 2021 14:11:01 -0700 Subject: [PATCH 11/11] Style adherence. --- postmark-settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/postmark-settings.php b/postmark-settings.php index 6a4deb0..20512a4 100644 --- a/postmark-settings.php +++ b/postmark-settings.php @@ -7,11 +7,11 @@ $settings = json_decode( get_option( 'postmark_settings' ), true ); $settings_from_constants = array( - 'api_key' => defined('POSTMARK_API_KEY') ? POSTMARK_API_KEY : null, - 'stream_name' => defined('POSTMARK_STREAM_NAME') ? POSTMARK_STREAM_NAME : null, - 'sender_address' => defined('POSTMARK_SENDER_ADDRESS') ? POSTMARK_SENDER_ADDRESS : null, + 'api_key' => defined( 'POSTMARK_API_KEY' ) ? POSTMARK_API_KEY : null, + 'stream_name' => defined( 'POSTMARK_STREAM_NAME' ) ? POSTMARK_STREAM_NAME : null, + 'sender_address' => defined( 'POSTMARK_SENDER_ADDRESS' ) ? POSTMARK_SENDER_ADDRESS : null, ); -$settings_from_constants = array_filter($settings_from_constants); +$settings_from_constants = array_filter( $settings_from_constants ); $settings = array_merge( $settings, $settings_from_constants ); return array( 'settings' => $settings,