Roots Discourse

Best practice for wp_options as .env key value

Totally new to Bedrock. I am running just Bedrock, with a self-coded theme on Laravel Forge.

I want to set a serialised key’s value in the wp_optionsDB table using the .env variable. For example in staging:


Then depending on the environment, set the wp_option to reflect that setting.

I tried conditionally running a wp cli command:
wp patch update woocommerce_stripe_settings testmode yes

But this feels wrong and I wasn’t sure when that command should be run? Maybe after_theme_switch action or maybe on the deploy script in in Laravel Forge?

Can anyone tell me how to handle this?

Ive taken a quick look and it doesn’t look like there’s a hook to enable the testmode, but you could always hook into pre_options_{$option} and modify the output based on your env setting.

Also, I don’t think the dot env file is the best place for it, the config/environment.php is.

Okay thanks for tip. It’s going to get a bit messy with the 21 serialised key-values but i guess thats okay.

Is the general rule to keep sensitive credentials in .env and commit the non-sensitive stuff in the config/environment.php? if they are your own plugins.

This topic was automatically closed after 42 days. New replies are no longer allowed.