Skip to content

Commit 87e014a

Browse files
committed
Account for Windows and CLI instances in wp_guess_url(). Props SergeyBiryukov. See #25317
git-svn-id: https://develop.svn.wordpress.org/trunk@25436 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 64eec20 commit 87e014a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/wp-includes/functions.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,26 +3233,31 @@ function wp_guess_url() {
32333233
if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
32343234
$url = WP_SITEURL;
32353235
} else {
3236+
$abspath_fix = str_replace( '\\', '/', ABSPATH );
3237+
$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
3238+
32363239
// The request is for the admin
32373240
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
32383241
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
32393242

32403243
// The request is for a file in ABSPATH
3241-
} elseif ( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/' == ABSPATH ) {
3244+
} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
32423245
// Strip off any file/query params in the path
32433246
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
32443247

32453248
} else {
3246-
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], ABSPATH ) ) {
3249+
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
32473250
// Request is hitting a file inside ABSPATH
3248-
$directory = str_replace( ABSPATH, '', dirname( $_SERVER['SCRIPT_FILENAME'] ) );
3251+
$directory = str_replace( ABSPATH, '', $script_filename_dir );
32493252
// Strip off the sub directory, and any file/query paramss
32503253
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
3251-
} else {
3254+
} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
32523255
// Request is hitting a file above ABSPATH
3253-
$subdirectory = str_replace( dirname( $_SERVER['SCRIPT_FILENAME'] ), '', ABSPATH );
3256+
$subdirectory = str_replace( $script_filename_dir, '', $abspath_fix );
32543257
// Strip off any file/query params from the path, appending the sub directory to the install
32553258
$path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
3259+
} else {
3260+
$path = $_SERVER['REQUEST_URI'];
32563261
}
32573262
}
32583263

0 commit comments

Comments
 (0)