Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment based settings #71

Closed
pgraham3 opened this issue Nov 23, 2020 · 5 comments
Closed

Environment based settings #71

pgraham3 opened this issue Nov 23, 2020 · 5 comments

Comments

@pgraham3
Copy link
Contributor

pgraham3 commented Nov 23, 2020

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 #69

@tflight
Copy link
Contributor

tflight commented Jul 1, 2021

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
Copy link
Contributor Author

pgraham3 commented Jul 5, 2021

@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
Copy link
Contributor

tflight commented Jul 5, 2021

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
Copy link
Contributor Author

pgraham3 commented Jul 5, 2021

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

@kenwiesner
Copy link

kenwiesner commented Jul 12, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants