diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index 281d7261f04c4..a3ccdb00e7cf0 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Enhancement - Removed the need for quotation marks when passing options to `wp-env run`. +- Setting a `config` key to `null` will prevent adding the constant to `wp-config.php` even if a default value is defined by `wp-env`. ## 4.7.0 (2022-05-18) diff --git a/packages/env/README.md b/packages/env/README.md index 25836f74aa691..311db067fed9f 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -518,6 +518,8 @@ WP_HOME: 'http://localhost', On the test instance, all of the above are still defined, but `WP_DEBUG` and `SCRIPT_DEBUG` are set to false. +These can be overridden by setting a value within the `config` configuration. Setting it to `null` will prevent the constant being defined entirely. + Additionally, the values referencing a URL include the specified port for the given environment. So if you set `testsPort: 3000, port: 2000`, `WP_HOME` (for example) will be `http://localhost:3000` on the tests instance and `http://localhost:2000` on the development instance. ### Examples diff --git a/packages/env/lib/wordpress.js b/packages/env/lib/wordpress.js index 7473bc1c6d030..133524bd72bfe 100644 --- a/packages/env/lib/wordpress.js +++ b/packages/env/lib/wordpress.js @@ -64,6 +64,11 @@ async function configureWordPress( environment, config, spinner ) { for ( let [ key, value ] of Object.entries( config.env[ environment ].config ) ) { + // Allow the configuration to skip a default constant by specifying it as null. + if ( null === value ) { + continue; + } + // Add quotes around string values to work with multi-word strings better. value = typeof value === 'string' ? `"${ value }"` : value; setupCommands.push(