2

Whilst writing some code that backs-up a plugin, I hit a problem with 'the wrong kind of directory slash' on my windows dev environment.

Tracking it through I find in default-constants.php:91

define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );

which is based on the following in default-constants.php:46

define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );

and hence to the config file definition...

define('ABSPATH', dirname(__FILE__) . '/');

So my question is:

Q. Why are both ABSPATH and WP_CONTENT_DIR, which are intrinsically file system specific (ie can't be interpreted for URL's), definied using explicit forward slashes, rather than PHP's own DIRECTORY_SEPARATOR ?

2 Answers 2

5

The forward slash works on every operating system supported by PHP. Yes, on Windows too. It is also more readable and easier to type, so there is no need to use the constant.

See the tickets #20849 and #15598 for related discussion on Trac.

1

It is an constant, only a string. For the separator / have PHP an constant. Also, this is WordPress, differently are stupid ;-)

2
  • Indeed. My question is why doesn't the WordPress code use the PHP constant instead of using a hardcoded slash which isn't always right (depending on what platform the code is running on). Apr 17, 2012 at 23:15
  • I think th php constant dont work on all systems and have different problems.
    – bueltge
    Apr 18, 2012 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.