Closed pravdomil closed 9 years ago
Well I got with your snippet: cannot access protected property wplessplugin::$compiler
@Pravdomil so instead of $WPLess->compiler
use the public method $WPLess->getCompiler()
. I reckon it is not documented but this is something you can look out by browsing the Plugin.php
class.
OK, thanks for support.
The last issue, if I switched to oyejorge less compiler and use $WPLess->getCompiler->setFormatter it doesn't work.
In lessc->compileFile function is Less_Parser always loaded with no args so compression cannot be applied. I found workaround for it:
// turn on compression for oyejorge less compiler
add_action('wp-less_compiler_construct_pre', function($compiler) {
Less_Parser::$options['compress'] = true;
});
I use it here https://github.com/Pravdomil/wp-pravdomil/blob/master/less.php#L26
Well, setFormatter
exists in oyejorge flavour of wp-less: https://github.com/oyejorge/less.php/blob/master/lessc.inc.php#L38
Your workaround seems legit, it seems to be enabled if the compressed
formatter is used (cf. https://github.com/oyejorge/less.php/blob/master/lessc.inc.php#L81)
I download the latest version from https://wordpress.org/plugins/wp-less/ and it seems that oyejorge library is older then master on Github. Comparing compileFile function.
wp-less/vendor/oyejorge/less.php/lessc.inc.php: 127
$parser = new Less_Parser();
$parser->SetImportDirs($this->getImportDirs());
if( count( $this->registeredVars ) ) $parser->ModifyVars( $this->registeredVars );
$parser->parseFile($fname);
$out = $parser->getCss();
https://github.com/oyejorge/less.php/blob/master/lessc.inc.php#L141
$parser = new Less_Parser($this->getOptions());
$parser->SetImportDirs($this->getImportDirs());
if( count( $this->registeredVars ) ) $parser->ModifyVars( $this->registeredVars );
foreach ($this->libFunctions as $name => $func) {
$parser->registerFunction($name, $func);
}
$parser->parseFile($fname);
$out = $parser->getCss();
I'm right?
Yep you are right. Bundled versions were out of date, released as v1.7.6
. Give it a try and let us know :-)
I think that it will work, can you please update the oyejorge compiler? Can I help you some how?
After that, we can use this snippet for compressed output:
add_filter('wp_less_compiler', function() { return 'less.php'; } );
add_action('wp-less_init', function($WPLess) {
$WPLess->getCompiler()->setFormatter('compressed');
} );
@Pravdomil I updated both of them (leafo/lessphp bumped from 0.4
to 0.5
). Cf. https://plugins.trac.wordpress.org/changeset/1241501/wp-less#file1
Great, now the compression works perfectly with both compilers.
I would recommend to use oyejorge library since it's official php less compiler and more up to date, what do you think?
It would be just a matter of changing the default value for the filter (to less.php
): https://github.com/oncletom/wp-less/blob/master/lib/Plugin.class.php#L68
Feel free to open a PR for this :-)
You can hook on
wp-less_init
and do something like:Otherwise please provide more ample reasons than a pretty much impolite please merge.