Make WordPress Core


Ignore:
Timestamp:
09/12/2013 06:56:20 AM (10 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r25371 r25396  
    32323232        $url = WP_SITEURL;
    32333233    } else {
     3234        // The request is for the admin
     3235        if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
     3236            $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
     3237
     3238        // The request is for a file in ABSPATH
     3239        } elseif ( dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/' == ABSPATH ) {
     3240            // Strip off any file/query params in the path
     3241            $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
     3242
     3243        } else {
     3244            if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], ABSPATH ) ) {
     3245                // Request is hitting a file inside ABSPATH
     3246                $directory = str_replace( ABSPATH, '', dirname( $_SERVER['SCRIPT_FILENAME'] ) );
     3247                // Strip off the sub directory, and any file/query paramss
     3248                $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
     3249            } else {
     3250                // Request is hitting a file above ABSPATH
     3251                $subdirectory = str_replace( dirname( $_SERVER['SCRIPT_FILENAME'] ), '', ABSPATH );
     3252                // Strip off any file/query params from the path, appending the sub directory to the install
     3253                $path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
     3254            }
     3255        }
     3256
    32343257        $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
    3235         $url = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
     3258        $url = $schema . $_SERVER['HTTP_HOST'] . $path;
    32363259    }
    32373260
Note: See TracChangeset for help on using the changeset viewer.