mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Fix wp_guess_url() to work in every scenario I could find, allows us to use it to determine the correct path to the WordPress Site URL before installation for install.php and setup-config.php redirects. Fixes #24480 Fixes #16884
git-svn-id: https://develop.svn.wordpress.org/trunk@25396 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -3231,8 +3231,31 @@ function wp_guess_url() {
|
||||
if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
|
||||
$url = WP_SITEURL;
|
||||
} else {
|
||||
// The request is for the admin
|
||||
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
|
||||
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
|
||||
|
||||
// The request is for a file in ABSPATH
|
||||
} elseif ( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/' == ABSPATH ) {
|
||||
// Strip off any file/query params in the path
|
||||
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
|
||||
|
||||
} else {
|
||||
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], ABSPATH ) ) {
|
||||
// Request is hitting a file inside ABSPATH
|
||||
$directory = str_replace( ABSPATH, '', dirname( $_SERVER['SCRIPT_FILENAME'] ) );
|
||||
// Strip off the sub directory, and any file/query paramss
|
||||
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
|
||||
} else {
|
||||
// Request is hitting a file above ABSPATH
|
||||
$subdirectory = str_replace( dirname( $_SERVER['SCRIPT_FILENAME'] ), '', ABSPATH );
|
||||
// Strip off any file/query params from the path, appending the sub directory to the install
|
||||
$path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
|
||||
}
|
||||
}
|
||||
|
||||
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
|
||||
$url = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
|
||||
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
|
||||
}
|
||||
|
||||
return rtrim($url, '/');
|
||||
|
||||
Reference in New Issue
Block a user