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

@wordpress/env: Allow configuration of wp-config.php constants in .wp-env.json #19972

Closed
WraithKenny opened this issue Jan 30, 2020 · 6 comments · Fixed by #20352
Closed

@wordpress/env: Allow configuration of wp-config.php constants in .wp-env.json #19972

WraithKenny opened this issue Jan 30, 2020 · 6 comments · Fixed by #20352
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] Env /packages/env [Type] Enhancement A suggestion for improvement.

Comments

@WraithKenny
Copy link

WraithKenny commented Jan 30, 2020

No description provided.

@aduth aduth added [Tool] Env /packages/env [Type] Enhancement A suggestion for improvement. labels Jan 30, 2020
@epiqueras
Copy link
Contributor

cc @noisysocks

@gziolo gziolo changed the title Package Env Feature Request Env: Make it possible to override wp-config.php with wp-env.json Feb 19, 2020
@noisysocks noisysocks changed the title Env: Make it possible to override wp-config.php with wp-env.json @wordpress/env: Allow configuration of wp-config.php constants in .wp-env.json Feb 20, 2020
@noisysocks
Copy link
Member

Yep, let's do it.

Some notes regarding implementation:

  • It must be possible to configure the WordPress debug constants, namely: WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY, and SCRIPT_DEBUG. WP_DEBUG and SCRIPT_DEBUG should be enabled by default.

  • Constants should be configurable using .wp-env.json only and not e.g. using an environment variable. This is because WordPress constants are generally a per project setting. See wp-env: Add custom port numbers to .wp-env.json #20158 (comment). Also, using JSON for this means that we can avoid issues where e.g. a constant must be true instead of "true".

  • The local wp-config.php file, if it exists, should be updated when wp-env start is ran so as to ensure that the config in wp-config.php matches the config specified in .wp-env.json. Only the constants specified in .wp-env.json should be modified: that is, any other code that is in wp-config.php should not be touched. To do this we will need to roll our own wp-config.php generation using wp config create and wp config set. Right now we are relying on the wordpress Docker image to generate the wp-config.php but this is not flexible enough to handle updates to arbitrary constants—it can only update database constants.

  • Because wp-env is a tool specifically for WordPress and config in WordPress parlance has a very specific meaning, I think we can get away with using "config" as the key in .wp-env.json.

    {
    	"themes": [
    		"../path/to/theme/dir"
    	],
    	"plugins": [
    		"../path/to/plugin/dir"
    	],
    	"config": {
    		"WP_DEBUG": true,
    		"SCRIPT_DEBUG": true,
    		"SAVEQUERIES": true,
    		"JETPACK_DEV_DEBUG": true
    	}
    }

@noisysocks noisysocks added the Needs Dev Ready for, and needs developer efforts label Feb 20, 2020
@epiqueras
Copy link
Contributor

Only the constants specified in .wp-env.json should be modified: that is, any other code that is in wp-config.php should not be touched.

Why is that necessary?

@noisysocks
Copy link
Member

If you're using a local install (e.g. "core": "~/path/to/wordpress-develop/build") you may prefer to add code or constants to the wp-config.php manually. wp-env shouldn't blow those changes away if it can help it. At any rate, wp config set handles this correctly so we get it for free.

@epiqueras
Copy link
Contributor

What about the same constants being already defined in wp-config.php, should we overwrite them?

I guess we should.

@noisysocks
Copy link
Member

Yes, I think so.

@epiqueras epiqueras removed the Needs Dev Ready for, and needs developer efforts label Feb 21, 2020
@epiqueras epiqueras self-assigned this Feb 21, 2020
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] Env /packages/env [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants