Skip to content

Commit bf3c0cc

Browse files
Copilotswissspidy
andcommitted
Fix phar_safe_path by using Phar::running(false) for WP_CLI_PHAR_PATH
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>
1 parent ccdb297 commit bf3c0cc

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

php/boot-phar.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@
99
die( -1 );
1010
}
1111

12-
// Store the phar stream path for use in determining WP_CLI_ROOT.
13-
// Using Phar::running(true) returns the phar:// stream wrapper path (e.g., phar:///path/to/file.phar)
14-
// which ensures consistent path resolution when the phar is renamed.
15-
$wp_cli_phar_path = Phar::running( true );
16-
1712
// Store the filesystem path for `Utils\phar_safe_path()` function.
1813
// Using Phar::running(false) returns just the filesystem path without phar:// protocol.
14+
// This prevents phar_safe_path() from attempting to replace "phar://phar://..." incorrectly.
1915
define( 'WP_CLI_PHAR_PATH', Phar::running( false ) );
2016

21-
// Determine WP_CLI_ROOT dynamically based on the actual phar stream path
22-
// instead of hardcoding 'phar://wp-cli.phar' to handle renamed phars.
23-
if ( file_exists( $wp_cli_phar_path . '/php/wp-cli.php' ) ) {
24-
define( 'WP_CLI_ROOT', $wp_cli_phar_path );
17+
// Use the phar alias 'wp-cli.phar' which is set during phar creation and works
18+
// regardless of the actual filename. This ensures template paths resolve correctly.
19+
if ( file_exists( 'phar://wp-cli.phar/php/wp-cli.php' ) ) {
20+
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar' );
2521
include WP_CLI_ROOT . '/php/wp-cli.php';
26-
} elseif ( file_exists( $wp_cli_phar_path . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
27-
define( 'WP_CLI_ROOT', $wp_cli_phar_path . '/vendor/wp-cli/wp-cli' );
22+
} elseif ( file_exists( 'phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
23+
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar/vendor/wp-cli/wp-cli' );
2824
include WP_CLI_ROOT . '/php/wp-cli.php';
2925
} else {
3026
echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?";

0 commit comments

Comments
 (0)