Skip to content

Commit

Permalink
improve readme and add option to compress css
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Feb 22, 2021
1 parent 2e068a2 commit 3e30fd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ wp_enqueue_less provides a function to enqueue less stylesheets in WordPress.

### Composer

Composer is the best way to install wp_enqueue_less so you get updates in the future easily.
Composer is the best way to install wp_enqueue_less, so you get updates in the future easily.

```
composer require ed-itsolutions/wp_enqueue_less
```

and then in your `functions.php` of `plugin.php`
and then in your `functions.php` or `plugin.php`

```php
require_once('vendor/autoload.php');
Expand All @@ -29,7 +29,7 @@ In your normal `wp_enqueue_scripts` action simply call `wp_enqueue_less`
`wp_enqueue_less` takes 3 arguments.

- _key_ - The key name to use for this stylesheet.
- _filePath_ - The on disk path to the .less file.
- _filePath_ - The on-disk path to the .less file.
- _variables_ - A key->value array of variables to be passed to the less compiler.

```php
Expand All @@ -49,4 +49,12 @@ wp_enqueue_less will:
- Compile this less file and write the output to `/wp-content/uploads/less/key-hash.css` (this can be changed with the filter `wp_enqueue_less_css_dir`).
- Record the current hashes of all the less files used and the variables into the database.
- On the next call if none of the hashes have changed it will skip parsing.
- On a daily basis it will clean out its directory of everything but the current hash version of the stylesheet.
- On a daily basis it will clean out its directory of everything but the current hash version of the stylesheet.

### Filters

|Filter|Default|Purpose|
|:-----|:------|:------|
|wp_enqueue_less_css_url|`wp_upload_dir()['baseurl'] . '/less'`|The URL of the directory the compiled css is served from.|
|wp_enqueue_less_css_dir|`wp_upload_dir()['basedir'] . '/less'`|The on-disk directory to serve compiled css from.|
|wp_enqueue_less_compress|`true`|Should wp_enqueue_less compress the outputted css|
4 changes: 3 additions & 1 deletion wp_enqueue_less.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function wp_enqueue_less($key, $file, $variables){

if(function_exists('add_action')){
add_action('wp_enqueue_less_compile', function($details, $variables){
$parser = new Less_Parser();
$parser = new Less_Parser(array(
'compress' => apply_filters('wp_enqueue_less_compress', true)
));
$parser->parseFile($details->file, get_template_directory_uri());
$parser->ModifyVars($variables);
$css = $parser->getCss();
Expand Down

0 comments on commit 3e30fd3

Please sign in to comment.