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

Built from https://develop.svn.wordpress.org/trunk@25396


git-svn-id: http://core.svn.wordpress.org/trunk@25327 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-09-12 06:57:09 +00:00
parent 6744355f70
commit 641d3b2560
4 changed files with 32 additions and 15 deletions

View File

@ -55,6 +55,9 @@ wp_load_translations_early();
// Turn register_globals off.
wp_unregister_GLOBALS();
// Standardize $_SERVER variables across setups.
wp_fix_server_vars();
require_once(ABSPATH . WPINC . '/compat.php');
require_once(ABSPATH . WPINC . '/class-wp-error.php');
require_once(ABSPATH . WPINC . '/formatting.php');
@ -198,12 +201,11 @@ switch($step) {
if ( ! $no_api ) {
require_once( ABSPATH . WPINC . '/class-http.php' );
require_once( ABSPATH . WPINC . '/http.php' );
wp_fix_server_vars();
/**#@+
* @ignore
*/
function get_bloginfo() {
return ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . str_replace( $_SERVER['PHP_SELF'], '/wp-admin/setup-config.php', '' ) );
return wp_guess_url();
}
/**#@-*/
$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );

View File

@ -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, '/');

View File

@ -445,12 +445,12 @@ function wp_not_installed() {
if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) )
wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
} elseif ( ! is_blog_installed() && false === strpos( $_SERVER['PHP_SELF'], 'install.php' ) && !defined( 'WP_INSTALLING' ) ) {
$link = wp_guess_url() . '/wp-admin/install.php';
require( ABSPATH . WPINC . '/kses.php' );
require( ABSPATH . WPINC . '/pluggable.php' );
require( ABSPATH . WPINC . '/formatting.php' );
$link = wp_guess_url() . '/wp-admin/install.php';
wp_redirect( $link );
die();
}

View File

@ -50,15 +50,7 @@ if ( file_exists( ABSPATH . 'wp-config.php') ) {
require_once( ABSPATH . WPINC . '/functions.php' );
// Set a path for the link to the installer
if ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false ) {
$path = 'setup-config.php';
} elseif ( file_exists( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/wp-admin/setup-config.php' ) ) {
$path = 'wp-admin/setup-config.php';
} else {
// WordPress files are in a sub directory, and the user is hitting the index.php in the parent directory
$path = str_replace( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/', '', dirname( __FILE__ ) . '/wp-admin/setup-config.php' );
}
$path = wp_guess_url() . '/wp-admin/setup-config.php';
// Die with an error message
$die = __( "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started." ) . '</p>';