env: Add support for dynamic URLs and allow setting WP_HOME and WP_SITEURL via env variables#71028
Conversation
- This commits adds support dynamically defining urls which is useful when using reverse proxy like ngrok, localtunnel etc - This is enabled by default and can be disabled by using WP_ENV_DYNAMIC_URLS_ENABLED=false when using wp-env start - This commits also add support settings WP_HOME and WP_SITEURL via env variables
|
UPDATE: fixed the issue by changing the env from |
- changed WP_HOME env to WP_ENV_HOMEURL to prevent conflict with WP_ENV_HOME - updated start cmd to reflect env value
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @apeatling, @jdmwood. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
WP_HOME and WP_SITEURL via env variablesWP_HOME and WP_SITEURL via env variables
What?
Closes #23947, #65008
Why?
Currently the wp-env site is set to localhost address, so trying to map the site to the likes of an ngrok external domain just results in a redirect back to localhost.(#23947)
This PR adds support for that by dynamically defining the
WP_HOMEandWP_SITEURLvia the snippet sent by @glendaviesnz.Alongside this PR also adds support for setting
WP_HOMEandWP_SITEURLvia env variables to allow for cases where the url is generated dynamically like gitpod.How?
This PR solves this by adding
WP_ENV_DYNAMIC_URLS_ENABLEDenv var ( default to true ) which enables dynamically defining WP_HOME and WP_SITEURL constants.This PR also adds
WP_ENV_HOMEURL,WP_ENV_SITEURLfor development environment andWP_ENV_TESTS_HOMEURL,WP_ENV_TESTS_SITEURLfor tests environment.to disable dynamically defining , pass
WP_ENV_DYNAMIC_URLS_ENABLED=falsewhen running wp-env start.Testing Instructions
_npm run wp-env start -- --updateScreenshots or screencast
npm run wp-env start -- --update
WP_ENV_DYNAMIC_URLS_ENABLED=false npm run wp-env start -- --update
WP_ENV_SITEURL & WP_ENV_HOMEURL support