roborourke / wp-less

Provides a LESS compiler compatible with wp_enqueue_style() for rapid CSS development in themes and plugins.
MIT License
217 stars 55 forks source link

Fix assumption that stylesheet is in content directory #35

Closed Rarst closed 10 years ago

Rarst commented 11 years ago

parse_stylesheet() currently assumes that stylesheet resides in content directory tree. This is typical, but not guaranteed since WP themes and plugins can be decoupled from that directory by configuration, as well as completely arbitrary styles can be enqueued.

list( $less_path, $query_string ) = explode( '?', str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $src ) );

Since stylesheet registration only captures URL, we need to:

scottsweb commented 11 years ago

I have had troubles with this line of code when using a multisite network with mapped domains. I use the old method from an earlier version of the plugin:

preg_match( "/^(.*?\/wp-content\/)([^\?]+)(.*)$/", $src, $src_bits );
$less_path = WP_CONTENT_DIR . '/' . $src_bits[ 2 ]; 
if (isset($src_bits[ 3 ])) { $query_string = str_replace('?', '', $src_bits[3]); }

Which whilst not as neat seems to be more robust.

roborourke commented 11 years ago

Cheers Scott,

Nice when my dodgy coding habits are vindicated! Multisite is something I've not looked into enough with this plugin yet so thanks for the heads up. The difficulty is making it work as a theme library but also as a plugin in its own right.

Robert O'Rourke sanchothefat.com +44 7816 329424

scottsweb commented 11 years ago

Hi Robert , No problem. I came across it a little while back when testing a multisite setup with my theme framework and seeing this bug report reminded me of it. I think its will be almost impossible to create a plugin that works in all environments. It becomes even more complicated when people start rewriting urls to asset files, moving wp-content and using CDNs etc etc. I am always happy to take what you have all expertly put together here and tweak it a little to fit my needs.

I have spent some time today trying to get the latest lessphp and wp-less integrated into my framework but I still have issues with the latest version of less-php (0.3.8) so have backed out of it again. It seems to not play nicely with the semantic grid system so hoping to see an update on it soon.