Skip to content

Commit fecd3fe

Browse files
Copilotswissspidy
andcommitted
Fix phar path resolution by using Phar::running(false) for WP_CLI_ROOT
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>
1 parent f0e78ed commit fecd3fe

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

php/boot-phar.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
// Store the path to the Phar early on for `Utils\phar-safe-path()` function.
1313
define( 'WP_CLI_PHAR_PATH', Phar::running( true ) );
1414

15-
if ( file_exists( 'phar://wp-cli.phar/php/wp-cli.php' ) ) {
16-
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar' );
15+
// Determine WP_CLI_ROOT dynamically based on the actual phar path
16+
// instead of hardcoding 'phar://wp-cli.phar' to handle renamed phars.
17+
// Use Phar::running(false) to get the phar stream path (e.g., phar:///path/to/file.phar)
18+
// instead of the filesystem path, ensuring consistency when the phar is renamed.
19+
if ( file_exists( Phar::running( false ) . '/php/wp-cli.php' ) ) {
20+
define( 'WP_CLI_ROOT', Phar::running( false ) );
1721
include WP_CLI_ROOT . '/php/wp-cli.php';
18-
} elseif ( file_exists( 'phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
19-
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar/vendor/wp-cli/wp-cli' );
22+
} elseif ( file_exists( Phar::running( false ) . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
23+
define( 'WP_CLI_ROOT', Phar::running( false ) . '/vendor/wp-cli/wp-cli' );
2024
include WP_CLI_ROOT . '/php/wp-cli.php';
2125
} else {
2226
echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?";

0 commit comments

Comments
 (0)