What is the best practice for checking your environment with PHP in context of Trellis / Bedrock?

I’m configuring Mergebot and it requires me to add 4 lines of code to WP Config. However, two are for Production while two are for Development.

I know I can use PHP to check which environment I’m in, but I’m wondering if there is a best practice for this that already exists in the context of Trellis / Bedrock, such as a constant variable?

Thank you for your time!

Use Bedrock’s specific env configs? https://github.com/roots/bedrock/tree/master/config/environments

3 Likes

Thanks.

I also discovered WP_ENV worked as well.

End result in site/config/application.php:
if ( WP_ENV == 'production' ) { } elseif ( WP_ENV == 'development' ) { }

Thank you for the swift reply!

Env config files are the proper way to do this. They are loaded based on WP_ENV.

3 Likes

Hey, is there a way to check the environment in JS?
I have a function which, inside has a variable which needs updating depending on the environment.

Found a solution, am now doing PHP conditionals in setup.php and passing the data to my JS script with: wp_localize_script

1 Like