Skip to content

Instantly share code, notes, and snippets.

@omnp
Created October 18, 2019 04:06
Show Gist options
  • Select an option

  • Save omnp/25a2bc026c8f471fde0728e0a25fc46e to your computer and use it in GitHub Desktop.

Select an option

Save omnp/25a2bc026c8f471fde0728e0a25fc46e to your computer and use it in GitHub Desktop.
A simple WordPress plugin to automatically compile less files into css using lessphp
<?php
/**
* Plugin Name: My Test Plugin
*/
defined('ABSPATH') or die();
require_once 'lessc.inc.php';
class my_test_plugin {
private $less;
function edit_theme() {
if (!isset($this->less)) {
$this->less = new lessc;
}
$filename = $_POST['file'];
$filename = get_stylesheet_directory() .'/'. $filename;
if (pathinfo($filename, PATHINFO_EXTENSION) == 'less') {
try {
$outfilename = preg_replace('/\.less$/', '.css', $filename);
$result = $this->less->compileFile($filename, $outfilename);
}
catch (exception $e) {
echo($e->getMessage());
}
}
}
}
$my_test_plugin_ = new my_test_plugin();
add_action('wp_ajax_edit-theme-plugin-file', array($my_test_plugin_, 'edit_theme'), 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment