wp-less
wp-less copied to clipboard
Unable to use raw filepath with `wp_enqueue_style('foo', get_stylesheet_directory().'bar.less')`
When attempting to enqueue a LESS stylesheet with the wp_enqueue_style('foo', get_stylesheet_directory().'bar.less')
method, I'm getting a PHP error as follows:
PHP Warning: filemtime(): stat failed for /Applications/MAMP/htdocs/mysite.com/content/Applications/MAMP/htdocs/mysite.com/content/themes/my_theme/assets/less/bar.less
I'm pretty sure there is a conflict between some folder / WordPress structural re-writes that I'm doing and the expected schema of the plugin - notice how (the above error is being thrown from local development in MAMP) the filepath is duplicated above: /Applications/MAMP/htdocs/mysite.com/content/Applications/MAMP/htdocs/mysite.com...
Any idea how to make that filepath for wp_enqueue_style()
absolute? Note that my other enqueue style calls are working fine for other CSS and JS, only the one for the .less file as directed through this plugin is causing a problem.
Note also that I'm using WordPress Multisite with a child theme, and Mark Jaquith's WP-Stack: https://github.com/markjaquith/WP-Stack
I had the same issue and had to do the following using a multisite install with the roots theme:
wp_enqueue_style('roots_app', '/..'.get_template_directory_uri() . '/assets/css/app.less', false);
// Load app.css from child theme
if (is_child_theme()) {
wp_enqueue_style('roots_child', '/..'.get_stylesheet_directory_uri() . '/assets/css/app.less', false);
}
It works, but there is something funky going on with the paths to images and such referenced in the less file. I am not sure if it is this, or the fact that roots changes the upload directory to be outside of the wp-content directory
Hello,
I've been told about this issue and it's worth investigating it.
By the way, sorry for the delay of answer: I wanted to bring in a decent answer and I've been focused on other topics these days (like you know, relocating, preparing a conference and so on).
So it would mean that multisite alter the behavior of get_stylesheet_directory()
? Could you write me down the returned value of this function in your theme used in the multisite?
Thanks :-)
I found that adding this line to line 87 in my Stylesheet.class.php did the trick
$this->source_path = preg_replace('/wp-content\/wp-content/', 'wp-content', $this->source_path);
It is actually the theme I am using that is creating relative paths see https://github.com/retlehs/roots/blob/master/lib/cleanup.php#L140
The output for get_stylesheet_directory_uri() is relative from the install directory like /wp-content/themes/roots/, while get_stylesheet_directory() returns from the root like /users/wilsonwc/public_html/wp-content/themes/roots.
In the configure_path function in Stylesheet.class.php the /wp-content/ directory was getting duplicated when I used get_stylesheet_directory_uri(), so I couldn't find the file.
Just wanted to add that I had the same problem here using Ben Word's Roots theme. The problem boils down to the 'root-relative-urls' feature being enabled. This can be disabled by commenting out the relevant line in the themes config.php.
You can find more info about root-relative-urls here: http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
What I don't like is these themes/plugins are loading stuff using a non-recommended way, thus generating such edge cases elsewhere, like in WP-LESS for example. They then just expect than everything works with relative paths… which can't be possible.
@wilsonwc thanks for hinting the solution. I'd just like to have something generic and not related to any theme vendor. I've tried to make this plugin quite agnostic in its choice and behaviour so as should be its bugfix solutions ;-) Then, @thewebists, what is doing Roots theme? Is the fix of @wilsonwc working for you?