ActiveCampaign / postmark-wordpress

The Official Postmark Wordpress Plugin
GNU General Public License v2.0
17 stars 16 forks source link

Environment based settings #71

Closed pgraham3 closed 3 years ago

pgraham3 commented 4 years ago

b2bdd wrote:

I think it would be great to be able to have different settings for different environments (local/staging/production), OR be able to override the plugin settings using a definition in the wp-config.php file. Please see https://make.wordpress.org/core/2020/07/24/new-wp_get_environment_type-function-in-wordpress-5-5/ for info about the recently added wp function to get the environment type constant.

I often have to copy production sites to a local environment to work on them and if they have postmark installed it can lead to weird emails being sent to clients. I'd like to be able to just have a custom definition to send all emails to myself on development environments.

Topic Link: https://wordpress.org/support/topic/feature-request-support-for-environment-types-override-in-wp-config/

Potentially related to https://github.com/wildbit/postmark-wordpress/issues/69

tflight commented 3 years ago

Hi @pgraham3,

I've been wanting something similar. With today's announcement of Sandbox mode it becomes even more useful. I'd be happy to work on a PR for this. I was thinking of an approach like this:

https://wpmailsmtp.com/docs/how-to-secure-smtp-settings-by-using-constants/

Basically check for the existence of constants in wp-config.php and do an array_merge() on them inside of load_settings with the constants overriding anything coming from get_option(). If the setting is detected in a constant, make the field in the dash board read-only. Keep the original value in options to fall back to if the constants are removed from wp-config.php. This would allow you to place Sandbox keys in wp-config.php for local/staging environments.

A downside to this approach is It wouldn't use the WordPress environment setting. If that was to be used then you would need to store two sets of settings, one for Sandbox and one for Production. I'd be happy to look at a PR taking that route too.

Both of those things could be implemented as well... Check for sandbox and production constants in wp-config.php and override anything coming from your stored settings.

pgraham3 commented 3 years ago

@tflight I like this idea/approach as well! Thanks for the offer to work on a PR for it. Happy to review it when it is ready.

tflight commented 3 years ago

Great, I'll get a PR soon. It looks like this repo is a version behind what is in the Plugins directory, so maybe you can get this repo up to date first?

pgraham3 commented 3 years ago

All set! Should have parity with the WordPress repo's trunk now.

kenwiesner commented 3 years ago

Been looking for a solution like this for a LONG time. We are a web hosting agency and having this functionality would allow us to ditch SendGrid and move to Postmark for our outbound transactional notifications from WordPress. It would be great if there was a way to have an environmental var that could completely hide the plugin. Customers do dumb things. :)

Glad to help test this out!