LESS Compiler PHP with WordPress 4.0.1 and Bootstrap 3

I’m trying to add a php-compiler in my new WordPress Theme. Therefore I followed this Tutorial: http://www.tailored4wp.com/how-to-use-less-auto-compiler-in-your-next-wordpress-project-quick-tip-361/

My functions.php

Read More
/**
* LESS Compiler.
*/
function autoCompileLess() {

    // include lessc.inc
    require_once( get_template_directory().'/less/lessc.inc.php' );

    // input and output location
    $inputFile = get_template_directory().'/less/bootstrap.less';
    $outputFile = get_template_directory().'/css/bootstrap_less.css';

    // load the cache
    $cacheFile = $inputFile.".cache";

    if (file_exists($cacheFile)) {
        $cache = unserialize(file_get_contents($cacheFile));
    } else {
        $cache = $inputFile;
    }

    $less = new lessc;
    // create a new cache object, and compile
    $newCache = $less->cachedCompile($cache);

    // output a LESS file, and cache file only if it has been modified since last compile
    if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
        file_put_contents($cacheFile, serialize($newCache));
        file_put_contents($outputFile, $newCache['compiled']);
    }
}
/**
 * Enqueue scripts and styles.
 */
function scripts() {

    wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap_less.css' ); 
}
add_action( 'wp_enqueue_scripts', 'scripts' );

If I change some less files, there won’t be any file in output-directory. (I set the right permissions)

And if I add

if(is_user_logged_in()) {
add_action(‘init’, ‘autoCompileLess’);
}

…/wp-admin will show a blank page with no code in it. What’s wrong?

********EDIT*************

I copied the Theme to XAMPP Installation and got these Errors:

Fatal error: Uncaught exception ‘Exception’ with message ‘parse error:
failed at &:extend(.clearfix all);
D:xampphtdocswordpress/wp-content/themes/templateName/less/mixins/grid.less
on line 11′ in
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php:3460
Stack trace: #0
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php(2273):
lessc_parser->throwError() #1
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php(121):
lessc_parser->parse(‘// Grid system?…’) #2
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php(753):
lessc->tryImport(Array, Object(stdClass), Object(stdClass)) #3
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php(162):
lessc->compileProp(Array, Object(stdClass), Object(stdClass)) #4
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php(147):
lessc->compileImportedProps(Array, Object(stdClass), Object(stdClass),
Object(lessc_parser), ‘D:xampphtdocs…’) #5
D:xampphtdocswordpressw in
D:xampphtdocswordpresswp-contentthemestemplateNamelesslessc.inc.php
on line 3460

Related posts

Leave a Reply

1 comment

  1. I found a solution, based on Bass Jobsons comments, thanks to Bass Jobson:

    Leafo/lessphp is not compatible to Bootstrap 3.1.1 and it seems not to be actively developed anymore. So I changed to oyejorge/lessphp.

    https://github.com/oyejorge/less.php/

    Transitioning from Leafo/lessphp

    Projects looking for an easy transition from leafo/lessphp can use the
    lessc.inc.php adapter. To use, Download the less.php source code and
    unzip the files into your project so that the new ‘lessc.inc.php’
    replaces the existing ‘lessc.inc.php’.

    Note, the ‘setPreserveComments’ will no longer have any effect on the
    compiled less.