WordPress.org

Make WordPress Core

Ticket #15838: 15838.patch

File 15838.patch, 1.6 KB (added by kurtpayne, 3 years ago)

Accounting for differences between ABSPATH and $_SERVERDOCUMENT_ROOT? and caching return value

  • wp-admin/includes/file.php

     
    7777 * @return string Full filesystem path to the root of the WordPress installation 
    7878 */ 
    7979function get_home_path() { 
     80        static $home_path = ''; 
     81        if ( strlen($home_path) ) 
     82                return $home_path; 
     83 
    8084        $home = get_option( 'home' ); 
    8185        $siteurl = get_option( 'siteurl' ); 
    8286        if ( $home != '' && $home != $siteurl ) { 
     
    8791        } else { 
    8892                $home_path = ABSPATH; 
    8993        } 
     94         
     95        if ( 0 !== strpos($home_path, $_SERVER['DOCUMENT_ROOT']) ) { 
     96 
     97                // This means that apache and php disagree about the filesystem root 
     98                // We should trust document root, but it could look like this: 
     99                // Document root:  /var/chroot/home/html 
     100                // PHP Root:       /home/html/ 
     101                // WordPress Root: /home/html/blog 
     102                // These three need to be combined 
     103 
     104                $segment1 = realpath($_SERVER['DOCUMENT_ROOT']); 
     105                if ( empty($segment1) ) 
     106                        $segment1 = $_SERVER['DOCUMENT_ROOT']; // realpath failed for some reason 
     107 
     108                $segment2 = realpath(ABSPATH); 
     109                $_segment2 = $segment2; // Temp copy 
     110                while ( strlen( $_segment2 ) && substr( $segment1 , 0 - strlen( $_segment2 ) ) != $_segment2 ) 
     111                        $_segment2 = substr( $_segment2, 0, -1 ); // PHP root part 
     112                 
     113                $segment1 = str_replace($_segment2, '', $segment1); // Doc root part             
     114                $segment3 = str_replace($_segment2, '', $segment2); // WordPress dir part 
     115                $home_path = trailingslashit($segment1 . $_segment2 . $segment3); // Combined 
     116        } 
    90117 
    91118        return $home_path; 
    92119}