PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.4.5
Jetpack – WP Security, Backup, Speed, & Growth v13.4.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / custom-css / custom-css / preprocessors.php
preprocessors.php
71 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 /**
4 * CSS preprocessor registration.
5 *
6 * To add a new preprocessor (or replace an existing one), hook into the
7 * jetpack_custom_css_preprocessors filter and add an entry to the array
8 * that is passed in.
9 *
10 * Format is:
11 * $preprocessors[ UNIQUE_KEY ] => array( 'name' => 'Processor name', 'callback' => [processing function] );
12 *
13 * The callback function accepts a single string argument (non-CSS markup) and returns a string (CSS).
14 *
15 * @param array $preprocessors The list of preprocessors added thus far.
16 * @return array
17 */
18 function jetpack_register_css_preprocessors( $preprocessors ) {
19 $preprocessors['less'] = array(
20 'name' => 'LESS',
21 'callback' => 'jetpack_less_css_preprocess',
22 );
23
24 $preprocessors['sass'] = array(
25 'name' => 'Sass (SCSS Syntax)',
26 'callback' => 'jetpack_sass_css_preprocess',
27 );
28
29 return $preprocessors;
30 }
31
32 add_filter( 'jetpack_custom_css_preprocessors', 'jetpack_register_css_preprocessors' );
33
34 /**
35 * Compile less prepocessors?
36 *
37 * @param string $less - less.
38 */
39 function jetpack_less_css_preprocess( $less ) {
40 require_once __DIR__ . '/preprocessors/lessc.inc.php';
41
42 $compiler = new lessc();
43
44 // Don't try to load from the filesystem.
45 $compiler->setImportDir( array() );
46
47 try {
48 return $compiler->compile( $less );
49 } catch ( Exception $e ) {
50 return $less;
51 }
52 }
53
54 /**
55 * Compile sass prepocessors?
56 *
57 * @param string $sass - sass.
58 */
59 function jetpack_sass_css_preprocess( $sass ) {
60 $compiler = new ScssPhp\ScssPhp\Compiler();
61
62 // Don't try to load from the filesystem.
63 $compiler->setImportPaths( array() );
64
65 try {
66 return $compiler->compileString( $sass )->getCss();
67 } catch ( Exception $e ) {
68 return $sass;
69 }
70 }
71