From ec61f8a987e38ba71e84eb666a2bac36da04791f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:13:07 +0000 Subject: [PATCH 1/6] Initial plan From 37a6c47d3d58d9357d4f7b6690d8527d34b1c4e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:18:53 +0000 Subject: [PATCH 2/6] Fix incorrect home/siteurl when wp-cli runs from root filesystem Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/core-install.feature | 48 +++++++++++++++++++++++++++++++++++ src/Core_Command.php | 23 +++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/features/core-install.feature b/features/core-install.feature index 4b3b74c5..1ce1b76c 100644 --- a/features/core-install.feature +++ b/features/core-install.feature @@ -177,6 +177,54 @@ Feature: Install WordPress core """ And the return code should be 0 + Scenario: Verify correct siteurl and home when URL has no path + Given an empty directory + And WP files + And wp-config.php + And a database + + When I run `wp core install --url=example.com --title=Test --admin_user=wpcli --admin_email=wpcli@example.org --admin_password=password --skip-email` + Then STDOUT should contain: + """ + Success: WordPress installed successfully. + """ + + When I run `wp option get home` + Then STDOUT should be: + """ + http://example.com + """ + + When I run `wp option get siteurl` + Then STDOUT should be: + """ + http://example.com + """ + + Scenario: Verify correct siteurl and home when URL has a path + Given an empty directory + And WP files + And wp-config.php + And a database + + When I run `wp core install --url=example.com/subdir --title=Test --admin_user=wpcli --admin_email=wpcli@example.org --admin_password=password --skip-email` + Then STDOUT should contain: + """ + Success: WordPress installed successfully. + """ + + When I run `wp option get home` + Then STDOUT should be: + """ + http://example.com/subdir + """ + + When I run `wp option get siteurl` + Then STDOUT should be: + """ + http://example.com/subdir + """ + @less-than-php-7 Scenario: Install WordPress with locale set to de_DE on WP < 4.0 Given an empty directory diff --git a/src/Core_Command.php b/src/Core_Command.php index ae1c7397..4ce38808 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -691,6 +691,29 @@ function wp_new_blog_notification() { // which is normally a runtime argument if ( isset( $assoc_args['url'] ) ) { WP_CLI::set_url( $assoc_args['url'] ); + + // Fix $_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME'] to prevent incorrect + // URL detection by WordPress during installation. When WP-CLI is executed from + // the root of the filesystem (e.g., /wp), these variables contain the WP-CLI + // executable path rather than the WordPress installation path, which causes + // wp_guess_url() to construct incorrect URLs. + $url_parts = Utils\parse_url( $assoc_args['url'] ); + $path = isset( $url_parts['path'] ) ? $url_parts['path'] : '/'; + // Ensure path ends with index.php for proper WordPress URL detection + if ( '/' === $path || '' === $path ) { + $path = '/index.php'; + } elseif ( '/' === substr( $path, -1 ) ) { + $path .= 'index.php'; + } elseif ( false === strpos( basename( $path ), '.' ) ) { + // If path doesn't end with / and has no extension, add /index.php + $path = rtrim( $path, '/' ) . '/index.php'; + } + $_SERVER['PHP_SELF'] = $path; + $_SERVER['SCRIPT_NAME'] = $path; + // Set SCRIPT_FILENAME to the actual WordPress index.php path if it exists + if ( defined( 'ABSPATH' ) && file_exists( ABSPATH . 'index.php' ) ) { + $_SERVER['SCRIPT_FILENAME'] = ABSPATH . 'index.php'; + } } $public = true; From 154f2a2f4fbf694a3765a73f5a79b3e501c83fb8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:22:07 +0000 Subject: [PATCH 3/6] Simplify path logic and add clarifying comments Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Command.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Core_Command.php b/src/Core_Command.php index 4ce38808..6b2341dd 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -699,18 +699,24 @@ function wp_new_blog_notification() { // wp_guess_url() to construct incorrect URLs. $url_parts = Utils\parse_url( $assoc_args['url'] ); $path = isset( $url_parts['path'] ) ? $url_parts['path'] : '/'; - // Ensure path ends with index.php for proper WordPress URL detection - if ( '/' === $path || '' === $path ) { + + // Ensure path represents a PHP script for proper WordPress URL detection. + // If the path doesn't already end with a file (no extension in basename), + // append '/index.php' to represent the WordPress entry point. + $path = rtrim( $path, '/' ); + if ( empty( $path ) ) { $path = '/index.php'; - } elseif ( '/' === substr( $path, -1 ) ) { - $path .= 'index.php'; } elseif ( false === strpos( basename( $path ), '.' ) ) { - // If path doesn't end with / and has no extension, add /index.php - $path = rtrim( $path, '/' ) . '/index.php'; + // Path doesn't end with a file, append /index.php + $path .= '/index.php'; } + $_SERVER['PHP_SELF'] = $path; $_SERVER['SCRIPT_NAME'] = $path; - // Set SCRIPT_FILENAME to the actual WordPress index.php path if it exists + + // Set SCRIPT_FILENAME to the actual WordPress index.php if available. + // This is optional and only set when ABSPATH is defined and index.php exists. + // If not set, WordPress can still function using PHP_SELF and SCRIPT_NAME. if ( defined( 'ABSPATH' ) && file_exists( ABSPATH . 'index.php' ) ) { $_SERVER['SCRIPT_FILENAME'] = ABSPATH . 'index.php'; } From 6573b48265bae21117cedb319954488f66636570 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:23:12 +0000 Subject: [PATCH 4/6] Use pathinfo() and trailingslashit() for safer path handling Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Core_Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core_Command.php b/src/Core_Command.php index 6b2341dd..220f810c 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -706,7 +706,7 @@ function wp_new_blog_notification() { $path = rtrim( $path, '/' ); if ( empty( $path ) ) { $path = '/index.php'; - } elseif ( false === strpos( basename( $path ), '.' ) ) { + } elseif ( '' === pathinfo( $path, PATHINFO_EXTENSION ) ) { // Path doesn't end with a file, append /index.php $path .= '/index.php'; } @@ -717,8 +717,8 @@ function wp_new_blog_notification() { // Set SCRIPT_FILENAME to the actual WordPress index.php if available. // This is optional and only set when ABSPATH is defined and index.php exists. // If not set, WordPress can still function using PHP_SELF and SCRIPT_NAME. - if ( defined( 'ABSPATH' ) && file_exists( ABSPATH . 'index.php' ) ) { - $_SERVER['SCRIPT_FILENAME'] = ABSPATH . 'index.php'; + if ( defined( 'ABSPATH' ) && file_exists( Utils\trailingslashit( ABSPATH ) . 'index.php' ) ) { + $_SERVER['SCRIPT_FILENAME'] = Utils\trailingslashit( ABSPATH ) . 'index.php'; } } From 659b2c36631022a31c083ea5f56b2b7bd7f9c346 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 4 Feb 2026 14:25:10 -0500 Subject: [PATCH 5/6] Update src/Core_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Core_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core_Command.php b/src/Core_Command.php index 220f810c..e9ee83e9 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -717,7 +717,7 @@ function wp_new_blog_notification() { // Set SCRIPT_FILENAME to the actual WordPress index.php if available. // This is optional and only set when ABSPATH is defined and index.php exists. // If not set, WordPress can still function using PHP_SELF and SCRIPT_NAME. - if ( defined( 'ABSPATH' ) && file_exists( Utils\trailingslashit( ABSPATH ) . 'index.php' ) ) { + if ( file_exists( Utils\trailingslashit( ABSPATH ) . 'index.php' ) ) { $_SERVER['SCRIPT_FILENAME'] = Utils\trailingslashit( ABSPATH ) . 'index.php'; } } From f7506a39e8df78248ef7e5f3f985f4dc5bc1dc56 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:30:16 +0000 Subject: [PATCH 6/6] Add test scenario simulating root filesystem WP-CLI location Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/core-install.feature | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/features/core-install.feature b/features/core-install.feature index 1ce1b76c..360ee168 100644 --- a/features/core-install.feature +++ b/features/core-install.feature @@ -225,6 +225,39 @@ Feature: Install WordPress core http://example.com/subdir """ + Scenario: Install with simulated root filesystem WP-CLI executable location + Given an empty directory + And WP files + And wp-config.php + And a database + And a problematic-server-vars.php file: + """ +