[wp-trac] [WordPress Trac] #32519: Enqueueing styles with directory separator

WordPress Trac noreply at wordpress.org
Thu May 28 12:11:00 UTC 2015


#32519: Enqueueing styles with directory separator
---------------------------+-----------------------------
 Reporter:  doecode        |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Script Loader  |    Version:  4.2
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Before running a specific task all my assets are within a directory called
 "tmp". To get the right directory for enqueuing styles I'm using the
 following function:

 {{{
 function asset_path($dir = '') {
     $path = '/';
     if(locate_template('tmp')) {
         $path .= 'tmp/';
     }
     $path .= 'assets' . '/';
     $path .= $dir . '/';

     return $path;
 }
 }}}

 So `wp_enqueue_style('vendor', get_template_directory_uri() .
 asset_path('vendor') . 'vendor.css')` works fine. If I change the
 `asset_path` function to

 {{{
 if( ! defined('DS') ? define('DS', DIRECTORY_SEPARATOR) : null);

 function asset_path($dir = '') {
     $path = DS;
     if(locate_template('tmp')) {
         $path .= 'tmp' . DS;
     }
     $path .= 'assets' . DS;
     $path .= $dir . DS;
     return $path;
 }
 }}}

 it doesn't work anymore, since it seems that WordPress replaces the "\"
 (currently working on Windows OS) with "". So my request looks like
 `...wp-content/themes/boilerplatetmpassetsvendorvendor.css?ver=4.1.4 `.

 I didn't find anything related to this behaviour, hence I'm assuming it's
 a bug.

 Another strange behaviour is that if I use the hardcoded directory
 separators and try to find out if the target exists with
 {{{
 if(locate_template(get_template_directory_uri() . asset_path('vendor') .
 'vendor.css'))
 // ...
 }

 wp_enqueue_style('vendor', get_template_directory_uri() .
 asset_path('vendor') . 'vendor.css');
 }}}
 the condition fails - but enqueuing succeeds.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32519>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list