Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#48099 closed defect (bug) (duplicate)

get_stylesheet_directory() and get_template_directory() are front-slashed even in Windows environment

Reported by: kestutisit's profile KestutisIT Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: Cc:

Description

So, despite that DIRECTORY_SEPARATOR PHP constant is correct if Windows OS environment (for i.e. XAMPP), and is \, WordPress returns paths url-like - /.
So we have to run a replacements in our UI_Routing class to have a correct paths, despite the fact that Windows recognizes both, the paths are looking strange when they have some chars forward-slashed, and some - back-slashed.

<?php
$currentThemePath = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), get_stylesheet_directory());
$parentThemePath = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), get_stylesheet_directory());
$uiPathInCurrentTheme = $currentThemePath.DIRECTORY_SEPARATOR.$this->themeUI_FolderName.DIRECTORY_SEPARATOR;
$uiPathInParentTheme = $parentThemePath.DIRECTORY_SEPARATOR.$this->themeUI_FolderName.DIRECTORY_SEPARATOR;

Change History (5)

#1 @KestutisIT
5 years ago

*On line no. 4 there had to be get_template_directory() used instead.

#2 @jrf
5 years ago

despite the fact that Windows recognizes both, the paths are looking strange

That kind of sums it up. This is working perfectly fine. The fact that it looks strange is irrelevant.

Suggested solution: won't fix

#3 @knutsp
5 years ago

  • Focuses template coding-standards removed
  • Keywords close added
  • Summary changed from get_stylesheet_directory() and get_stylesheet_directory() are front-slashed even in Windows environment to get_stylesheet_directory() and get_template_directory() are front-slashed even in Windows environment
  • Version 5.2.3 deleted

#4 @KestutisIT
5 years ago

I'm not sure, but there may be a reason to fix this as well, as something just got fixed for URLS for Windows. Why don't fix this as well, @SergeyBiryukov : [46473]

Last edited 5 years ago by SergeyBiryukov (previous) (diff)

#5 @SergeyBiryukov
5 years ago

  • Keywords needs-patch close removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the ticket!

[46473] fixes a regression introduced in [45971], which is not the case here.

Using DIRECTORY_SEPARATOR in core has been discussed several times before, most recently in #28811 and #29726. Since Windows recognizes both types of slashes, there is no strong reason for changing this if nothing is broken.

Anywhere in core where a path needs to be compared, wp_normalize_path() should be used.

Note: See TracTickets for help on using tickets.