Fix phar path resolution when renamed from wp-cli.phar#872
Draft
Fix phar path resolution when renamed from wp-cli.phar#872
Conversation
Replace hardcoded 'phar://wp-cli.phar' with dynamic Phar::running(false) to correctly handle renamed phar files. This ensures WP_CLI_ROOT always points to the actual phar stream path, fixing template path resolution when the phar is not named 'wp-cli.phar'. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Use Phar::running(true) for WP_CLI_ROOT (returns phar:// stream path) and Phar::running(false) for WP_CLI_PHAR_PATH (returns filesystem path). This ensures proper path resolution in phar_safe_path() function. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wp-config.mustache file not found in phar
Fix phar path resolution when renamed from wp-cli.phar
Feb 15, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This comment was marked as resolved.
This comment was marked as resolved.
Keep WP_CLI_ROOT using the hardcoded alias 'phar://wp-cli.phar' to ensure template paths resolve correctly. Only change WP_CLI_PHAR_PATH to use Phar::running(false) which returns the filesystem path without phar:// protocol, preventing phar_safe_path() from creating malformed paths. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Author
... Fixed in bf3c0cc. The issue was that I changed both Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix phar path resolution when phar file is not named "wp-cli.phar"
Problem
When running
wp config create --path=subfolder ...with a phar file named something other than "wp-cli.phar" (e.g., "wp"), the path resolution fails with a malformed path error.Root Cause
In the original code,
WP_CLI_PHAR_PATHwas set usingPhar::running(true)which returns"phar:///path/to/file.phar". Whenphar_safe_path()attempted to normalize paths, it tried to replace"phar://phar:///path/to/file.phar/"with"phar://", creating a malformed search string with doublephar://prefixes.Solution
Changed
WP_CLI_PHAR_PATHto usePhar::running(false)which returns the filesystem path without thephar://protocol (e.g.,"/path/to/file.phar"). This allowsphar_safe_path()to correctly search for"phar:///path/to/file.phar/"when normalizing paths.Kept
WP_CLI_ROOTusing the hardcoded alias'phar://wp-cli.phar'(set during phar creation) to ensure all template paths resolve correctly regardless of the actual phar filename.Changes Made
Original prompt
This section details on the original issue you should resolve
<issue_title>wp-config.mustache is not a file in phar</issue_title>
<issue_description>## Bug Report
Describe the current, buggy behavior
When wp-cli.phar is renamed to wp and moved into a path location, --path option seems to have conflict with wp create command. This has been reported before (#31)
Describe how other contributors can replicate this bug
However, with just a cd to the subfolder, it works just fine:
Also, if I rename wp to wp-cli.phar, it works:
Describe what you would expect as the correct outcome
Let us know what environment you are running this on