Skip to content

Commit 154f2a2

Browse files
Copilotswissspidy
andcommitted
Simplify path logic and add clarifying comments
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 37a6c47 commit 154f2a2

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/Core_Command.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,18 +699,24 @@ function wp_new_blog_notification() {
699699
// wp_guess_url() to construct incorrect URLs.
700700
$url_parts = Utils\parse_url( $assoc_args['url'] );
701701
$path = isset( $url_parts['path'] ) ? $url_parts['path'] : '/';
702-
// Ensure path ends with index.php for proper WordPress URL detection
703-
if ( '/' === $path || '' === $path ) {
702+
703+
// Ensure path represents a PHP script for proper WordPress URL detection.
704+
// If the path doesn't already end with a file (no extension in basename),
705+
// append '/index.php' to represent the WordPress entry point.
706+
$path = rtrim( $path, '/' );
707+
if ( empty( $path ) ) {
704708
$path = '/index.php';
705-
} elseif ( '/' === substr( $path, -1 ) ) {
706-
$path .= 'index.php';
707709
} elseif ( false === strpos( basename( $path ), '.' ) ) {
708-
// If path doesn't end with / and has no extension, add /index.php
709-
$path = rtrim( $path, '/' ) . '/index.php';
710+
// Path doesn't end with a file, append /index.php
711+
$path .= '/index.php';
710712
}
713+
711714
$_SERVER['PHP_SELF'] = $path;
712715
$_SERVER['SCRIPT_NAME'] = $path;
713-
// Set SCRIPT_FILENAME to the actual WordPress index.php path if it exists
716+
717+
// Set SCRIPT_FILENAME to the actual WordPress index.php if available.
718+
// This is optional and only set when ABSPATH is defined and index.php exists.
719+
// If not set, WordPress can still function using PHP_SELF and SCRIPT_NAME.
714720
if ( defined( 'ABSPATH' ) && file_exists( ABSPATH . 'index.php' ) ) {
715721
$_SERVER['SCRIPT_FILENAME'] = ABSPATH . 'index.php';
716722
}

0 commit comments

Comments
 (0)