#20449 closed defect (bug) (fixed)
get_home_path() error on windows with different home and site_url values
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 3.5 | Priority: | normal |
| Severity: | normal | Version: | 3.3.1 |
| Component: | Permalinks | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
get_home_path() was always returning a root directory reference '/'
Environment:
IIS 7.5, FCGI, PHP 5.3.10, WP 3.3.1
Walking through
I'll just run through what's happening to the values below:
// for ref, script_filename is
//$_SERVER["SCRIPT_FILENAME"] = 'D:\root\vhosts\site\httpdocs\wp\wp-admin\options-permalink.php'
function get_home_path() {
$home = get_option( 'home' );
// $home='http://site.com'
$siteurl = get_option( 'siteurl' );
// $siteurl = 'http://site.com/wp'
if ( $home != '' && $home != $siteurl ) {
$wp_path_rel_to_home = str_replace($home, '', $siteurl);
// $wp_path_rel_to_home = '/wp'
$pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home);
// $pos = FALSE
$home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos);
// $home_path = ''
$home_path = trailingslashit( $home_path );
// $home_path = '/'
} else {
$home_path = ABSPATH;
}
return $home_path;
// returns '/'
}
Suggest adding the following line
$wp_path_rel_to_home = str_replace('/', DIRECTORY_SEPARATOR, $wp_path_rel_to_home);
Diff:
--- a/wp/wp-admin/includes/file.php
+++ b/wp/wp-admin/includes/file.php
@@ -81,6 +81,7 @@ function get_home_path() {
$siteurl = get_option( 'siteurl' );
if ( $home != '' && $home != $siteurl ) {
$wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */
+ $wp_path_rel_to_home = str_replace('/', DIRECTORY_SEPARATOR, $wp_path_rel_to_home); // replaces url slashs with backslashes when needed
$pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home);
$home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos);
$home_path = trailingslashit( $home_path );
--
Attachments (4)
Change History (18)
#4
@
14 years ago
- Owner set to dd32
- Resolution set to fixed
- Status changed from new to closed
In [21224]:
#5
@
13 years ago
If on D:\root\vhosts\site\httpdocs\wp\wp-admin\options-permalink.php with a subfolder install ($wp_path_rel_to_home = '/wp') the desired result is D:\root\vhosts\site\httpdocs\ but we get D:\root\vhosts\site\httpdocs\wp\
This causes the .htaccess file to be written to the WordPress Address rather then the Site Address.
The strripos hits the wp in wp-admin so in the special case that the subfolder is wp (like Mark's skeleton) this patch doesn't work well.
Should this be reopened, or a new ticket?
#8
@
13 years ago
#18768 is the reason for the strripos instead of stripos. We probably need something more complicated then just the first or last occurrence.
#9
@
13 years ago
20449.2.patch uses trailingslashit on $wp_path_rel_to_home (to search against a directory), which prevents /wp/ from matching /wp.dev or /wp-admin etc.
#10
@
13 years ago
Tested 20449.2.patch, looks good to me.
For some reason,
$_SERVER['SCRIPT_FILENAME']contains forward slashes on my Windows install:So the bug didn't reproduce as is.
ABSPATHcontains backslashes though:The patch also handles #10447.