From f0e78ed150799f721cfd76db786fb6e74ee9066a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:11:01 +0000 Subject: [PATCH 1/4] Initial plan From fecd3fe535a82df81cc30396ab5aab7a2855d755 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:16:24 +0000 Subject: [PATCH 2/4] 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> --- php/boot-phar.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/php/boot-phar.php b/php/boot-phar.php index e5f94a262..de58d26fe 100644 --- a/php/boot-phar.php +++ b/php/boot-phar.php @@ -12,11 +12,15 @@ // Store the path to the Phar early on for `Utils\phar-safe-path()` function. define( 'WP_CLI_PHAR_PATH', Phar::running( true ) ); -if ( file_exists( 'phar://wp-cli.phar/php/wp-cli.php' ) ) { - define( 'WP_CLI_ROOT', 'phar://wp-cli.phar' ); +// Determine WP_CLI_ROOT dynamically based on the actual phar path +// instead of hardcoding 'phar://wp-cli.phar' to handle renamed phars. +// Use Phar::running(false) to get the phar stream path (e.g., phar:///path/to/file.phar) +// instead of the filesystem path, ensuring consistency when the phar is renamed. +if ( file_exists( Phar::running( false ) . '/php/wp-cli.php' ) ) { + define( 'WP_CLI_ROOT', Phar::running( false ) ); include WP_CLI_ROOT . '/php/wp-cli.php'; -} elseif ( file_exists( 'phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) { - define( 'WP_CLI_ROOT', 'phar://wp-cli.phar/vendor/wp-cli/wp-cli' ); +} elseif ( file_exists( Phar::running( false ) . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) { + define( 'WP_CLI_ROOT', Phar::running( false ) . '/vendor/wp-cli/wp-cli' ); include WP_CLI_ROOT . '/php/wp-cli.php'; } else { echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?"; From ccdb297c598c2a9698914ecc64c4505d83d350ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:21:16 +0000 Subject: [PATCH 3/4] Correctly use Phar::running() parameters for path resolution 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> --- php/boot-phar.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/php/boot-phar.php b/php/boot-phar.php index de58d26fe..38f5f8fc0 100644 --- a/php/boot-phar.php +++ b/php/boot-phar.php @@ -9,18 +9,22 @@ die( -1 ); } -// Store the path to the Phar early on for `Utils\phar-safe-path()` function. -define( 'WP_CLI_PHAR_PATH', Phar::running( true ) ); +// Store the phar stream path for use in determining WP_CLI_ROOT. +// Using Phar::running(true) returns the phar:// stream wrapper path (e.g., phar:///path/to/file.phar) +// which ensures consistent path resolution when the phar is renamed. +$wp_cli_phar_path = Phar::running( true ); -// Determine WP_CLI_ROOT dynamically based on the actual phar path +// Store the filesystem path for `Utils\phar_safe_path()` function. +// Using Phar::running(false) returns just the filesystem path without phar:// protocol. +define( 'WP_CLI_PHAR_PATH', Phar::running( false ) ); + +// Determine WP_CLI_ROOT dynamically based on the actual phar stream path // instead of hardcoding 'phar://wp-cli.phar' to handle renamed phars. -// Use Phar::running(false) to get the phar stream path (e.g., phar:///path/to/file.phar) -// instead of the filesystem path, ensuring consistency when the phar is renamed. -if ( file_exists( Phar::running( false ) . '/php/wp-cli.php' ) ) { - define( 'WP_CLI_ROOT', Phar::running( false ) ); +if ( file_exists( $wp_cli_phar_path . '/php/wp-cli.php' ) ) { + define( 'WP_CLI_ROOT', $wp_cli_phar_path ); include WP_CLI_ROOT . '/php/wp-cli.php'; -} elseif ( file_exists( Phar::running( false ) . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) { - define( 'WP_CLI_ROOT', Phar::running( false ) . '/vendor/wp-cli/wp-cli' ); +} elseif ( file_exists( $wp_cli_phar_path . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) { + define( 'WP_CLI_ROOT', $wp_cli_phar_path . '/vendor/wp-cli/wp-cli' ); include WP_CLI_ROOT . '/php/wp-cli.php'; } else { echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?"; From bf3c0ccc7459ac7d4d17a02a0ebc0f9c8c0b56f3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:53:39 +0000 Subject: [PATCH 4/4] 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> --- php/boot-phar.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/php/boot-phar.php b/php/boot-phar.php index 38f5f8fc0..a708cac62 100644 --- a/php/boot-phar.php +++ b/php/boot-phar.php @@ -9,22 +9,18 @@ die( -1 ); } -// Store the phar stream path for use in determining WP_CLI_ROOT. -// Using Phar::running(true) returns the phar:// stream wrapper path (e.g., phar:///path/to/file.phar) -// which ensures consistent path resolution when the phar is renamed. -$wp_cli_phar_path = Phar::running( true ); - // Store the filesystem path for `Utils\phar_safe_path()` function. // Using Phar::running(false) returns just the filesystem path without phar:// protocol. +// This prevents phar_safe_path() from attempting to replace "phar://phar://..." incorrectly. define( 'WP_CLI_PHAR_PATH', Phar::running( false ) ); -// Determine WP_CLI_ROOT dynamically based on the actual phar stream path -// instead of hardcoding 'phar://wp-cli.phar' to handle renamed phars. -if ( file_exists( $wp_cli_phar_path . '/php/wp-cli.php' ) ) { - define( 'WP_CLI_ROOT', $wp_cli_phar_path ); +// Use the phar alias 'wp-cli.phar' which is set during phar creation and works +// regardless of the actual filename. This ensures template paths resolve correctly. +if ( file_exists( 'phar://wp-cli.phar/php/wp-cli.php' ) ) { + define( 'WP_CLI_ROOT', 'phar://wp-cli.phar' ); include WP_CLI_ROOT . '/php/wp-cli.php'; -} elseif ( file_exists( $wp_cli_phar_path . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) { - define( 'WP_CLI_ROOT', $wp_cli_phar_path . '/vendor/wp-cli/wp-cli' ); +} elseif ( file_exists( 'phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) { + define( 'WP_CLI_ROOT', 'phar://wp-cli.phar/vendor/wp-cli/wp-cli' ); include WP_CLI_ROOT . '/php/wp-cli.php'; } else { echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?";