WP Staging logo and Post SMTP Logo floating in night sky over mountain

WP Staging + Post SMTP LOG ONLY Mode

WP Staging is a great plugin for creating a Wordpress staging site from a production site. Post SMTP is my favorite plugin for Wordpress email because of features like email logging and connecting to external email senders.

However, the two plugins have a feature that is incompatible when it comes to disabling outgoing email, so I created a must-use Wordpress plugin that allows Post SMTP to continue handling outgoing email, but puts it into Log Only mode only if it’s running on the staging site.

Installation

This is a must-use plugin. It cannot be installed the normal way.

  1. Download plugin ZIP above.
  2. Unzip it locally.
  3. Upload the PHP plugin file to your main Wordpress site under the /wp-content/mu-plugins/ folder.

That’s it. When you use WP Staging to create a staging site, it will copy this file to the staging site and there it will force Post SMTP to be in log only mode – no need to mess with settings.

The Incompatibility Issue

The issue I ran into in using WP Staging alongside Post SMTP was that every time I updated my staging site, I had to quickly go to the Post SMTP settings > Advanced and switch Delivery Mode to Log Only.

This is both tedious and runs risks…

On certain sites, especially those with built-in CRMs, we have automations that could inadvertently run on the staging site and send email to real-life contacts. No good!

WP Staging has a feature that will disable email on the staging site, however this setting takes over the wp_mail function, disallowing Post SMTP from logging outgoing email. And if you actually need to simulate and test outgoing emails, this setup doesn’t work.

My Solution

If Staging Then Post SMTP Delivery Mode →Log Only

The must-use plugin I wrote can be installed on the production site and it will copy to the staging site when it is updated.

The file name of the plugin should not be changed, as must-use plugins are loaded alphabetically, and we need WP Staging’s must-use plugin (WP Staging Optimizer) to initialize first.

My plugin does the following:

  • test if the current site is a staging site; if true:
    • test if constant POST_SMTP_RUN_MODE has already been defined; if not:
      • set the POST_SMTP_RUN_MODE constant to log_only

If you wind up using this, I’d like to hear about it. Drop a comment 🙂


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *