-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Env: ensure correct port setting on related wp-config params #22559
Env: ensure correct port setting on related wp-config params #22559
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! This mostly makes sense to me.
Looking at line 83 in this same file, where we set --url=localhost:${ port }
, do we need to update that to use the specified site url? (not sure how that mechanism works?
for ( let [ key, value ] of Object.entries( config.config ) ) { | ||
// Ensure correct port setting from config when configure WP urls. | ||
if ( key === 'WP_SITEURL' || key === 'WP_HOME' ) { | ||
const url = new URL( value ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think there's ever a possibility that WP_SITEURL
would already include the port number? If so, should we still override it? (Honestly not sure what the expected behavior would be in this case.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi noahtallen, thanks for the quick reply and your suggestions.
In fact I thought about similar things also and was not shure if the code change goes to the right direction.
I think the install setup, meaning '--url=localhost:${port} should stay as is. This is the WP default written to the database for home and siteurl option. And the port already comes from the config setting provided by the json files. So everything should be fine, or? By default no WP_HOME and WP_SITEURL is set inside wp-config.php. As far as I know it is common usage to rewrite this setting via wp-config.php if needed, and the database fallback is allways available if no WP_HOME or WP_SITEURL is set.
Rewriting the port setting if already set in WP_HOME or WP_SITEURL maybe can be problematic? I am not realy shure either. In fact these params are used to write out urls in the html pages. And it has to be the provided ports because docker maps only these ports to the containers.
Currently these port settings (if set in the WP_HOME and WP_SITEURL) would be configured for both instances, WordPress and also testsWordPress, which never can be correct, or?
Alternatively the rewrite only could be done when no port is set in the URL parameters (suggesting the author did not want to configure port 80 or port 443).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought about some placeholder in the config param. Could it be a sollution? If an config author writes out the placeholder in the WP_HOME or WP_SITEURL parameter, it will be replaced with the port setting, otherwise nothing happens. Something like
{
"config": {
"WP_HOME": "http://some.domain:${port}",
"WP_SITEURL": "http://some.domain:${port}",
}
}
and in wordpress.js then
value = value.replace(/\$\{port\}/, port);
This should be backward compatible also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewriting the port setting if already set in WP_HOME or WP_SITEURL maybe can be problematic
Yeah, exposing docker on the same port is definitely a requirement.
I just thought about some placeholder in the config param
Neat idea! My only concern about it is that I don't know how useful it would be outside of this use case, and it doesn't seem like we really need it that much anyways.
would be configured for both instances, WordPress and also testsWordPress, which never can be correct
True. This will be resolved by #22568. At least, a user could theoretically set it differently for each environment then.
for ( const [ key, value ] of Object.entries( config.config ) ) { | ||
for ( let [ key, value ] of Object.entries( config.config ) ) { | ||
// Ensure correct port setting from config when configure WP urls. | ||
if ( key === 'WP_SITEURL' || key === 'WP_HOME' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should introduce a separate function for "merging" or "overriding" values in the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. Especially for deep merging of .wp-env.json and .wp-env.override.json objects this would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at adding a separate function in #22568 (for some different config values) so we can probably skip it here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a fine way to fix it for now :) I'll integrate it a bit more into my changes in #22568
If |
Description
Hi, I like the usage of wp-env for setting up a development environment for WordPress.
I recogniced when I configure WP_HOME and/or WP_SITEURL as property in the config prop of .wp-env.json or .wp-env.override.json the setting is not correctly propagated to the resulting wp-config.php.
That is because the port property setting in .wp-env.json or .wp-env.override.json is independend from WP_HOME and WP_SITEURL configuration but needs to be merged in the resulting parameters injected in wp-config.php.
I added a code block in env/lib/wordpress.js which modifies the value given to the docker-compose command so that the correct port setting is ensured.
How has this been tested?
All existing tests pass. Beside this it is an open question for me right now. Maybe I have not yet fully understood how the testing environment is used testing the wp-env stuff. There are no tests for setting wp-config.php config items right now as far as I can see. If you have any advice I would appreciate it.
I just tested by running the setup scripts and checking the resulting dev environment.
Example of test setup:
.wp-env.json:
.wp-env.overide.json:
Expected for WordPress in wp-config.php
Expected for tests-WordPress in wp-config.php
but originally for both got
Types of changes
Bug fix
Checklist: