Created
October 18, 2019 04:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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