-
Notifications
You must be signed in to change notification settings - Fork 56
Fix incorrect home/siteurl when WP-CLI runs from root filesystem #307
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Pull request overview
Fixes malformed home/siteurl values during wp core install when WP-CLI is executed from the filesystem root by ensuring WordPress’s URL guessing logic sees server paths that reflect the --url value.
Changes:
- Override
$_SERVER['PHP_SELF']/$_SERVER['SCRIPT_NAME'](and conditionally$_SERVER['SCRIPT_FILENAME']) during installation based on the parsed--urlpath. - Normalize URL paths to an
index.php-style script path for WordPress’s install-time URL detection. - Add Behat coverage for installs with
--urlvalues with and without a path component.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Core_Command.php |
Adjusts server superglobals during install so WP’s wp_guess_url() derives the correct base URL. |
features/core-install.feature |
Adds scenarios asserting home/siteurl values for URLs with and without a path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Fix "core install" URL when wp-cli is executed from root filesystem
Resolves the issue where
wp core installdefines incorrect home and siteurl values when WP-CLI is executed from the root of the filesystem.Problem
When WP-CLI phar is located at the root of the filesystem (e.g.,
/wp) and WordPress is installed at a different path (e.g.,/home/customer/website), thewp core installcommand sets incorrecthomeandsiteurlvalues. Instead of using the URL provided via the--urlparameter (e.g.,https://website.domain.tld), it produces malformed URLs likehttps://website.domain.tldhome/customer/website.Root Cause
WordPress's internal URL detection functions (like
wp_guess_url()) use$_SERVER['PHP_SELF']and$_SERVER['SCRIPT_NAME']to determine the script path. When WP-CLI is executed from/wp, these variables contain/wp(the path to the WP-CLI phar) rather than the WordPress installation path, which causes incorrect URL construction duringwp_install().Solution
Before calling
wp_install(), the fix sets$_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'], and$_SERVER['SCRIPT_FILENAME']to match the URL path provided via the--urlparameter instead of the WP-CLI executable location.Changes
do_install()method inCore_Command.phpto set proper$_SERVERvariablespathinfo()for secure file extension detectionUtils\trailingslashit()for safe path constructiondefined('ABSPATH')check--requirefileTesting
example.com) and with paths (example.com/subdir)--requireto set problematic$_SERVERvalueswp core multisite-install(which callsdo_install())Security
pathinfo()instead of string matching for robust file extension detectionUtils\trailingslashit()for safe path construction to prevent path traversal issuesOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.