-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add guards before preprocessors fns declarations
- Loading branch information
1 parent
46d2fc4
commit 0c1b4f0
Showing
2 changed files
with
116 additions
and
104 deletions.
There are no files selected for viewing
110 changes: 58 additions & 52 deletions
110
projects/packages/jetpack-mu-wpcom/src/features/custom-css/custom-css/preprocessors.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,76 @@ | ||
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
|
||
/** | ||
* CSS preprocessor registration. | ||
* | ||
* To add a new preprocessor (or replace an existing one), hook into the | ||
* jetpack_custom_css_preprocessors filter and add an entry to the array | ||
* that is passed in. | ||
* | ||
* Format is: | ||
* $preprocessors[ UNIQUE_KEY ] => array( 'name' => 'Processor name', 'callback' => [processing function] ); | ||
* | ||
* The callback function accepts a single string argument (non-CSS markup) and returns a string (CSS). | ||
* | ||
* @param array $preprocessors The list of preprocessors added thus far. | ||
* @return array | ||
*/ | ||
function jetpack_register_css_preprocessors( $preprocessors ) { | ||
$preprocessors['less'] = array( | ||
'name' => 'LESS', | ||
'callback' => 'jetpack_less_css_preprocess', | ||
); | ||
if ( ! function_exists( 'jetpack_register_css_preprocessors' ) ) { | ||
/** | ||
* CSS preprocessor registration. | ||
* | ||
* To add a new preprocessor (or replace an existing one), hook into the | ||
* jetpack_custom_css_preprocessors filter and add an entry to the array | ||
* that is passed in. | ||
* | ||
* Format is: | ||
* $preprocessors[ UNIQUE_KEY ] => array( 'name' => 'Processor name', 'callback' => [processing function] ); | ||
* | ||
* The callback function accepts a single string argument (non-CSS markup) and returns a string (CSS). | ||
* | ||
* @param array $preprocessors The list of preprocessors added thus far. | ||
* @return array | ||
*/ | ||
function jetpack_register_css_preprocessors( $preprocessors ) { | ||
$preprocessors['less'] = array( | ||
'name' => 'LESS', | ||
'callback' => 'jetpack_less_css_preprocess', | ||
); | ||
|
||
$preprocessors['sass'] = array( | ||
'name' => 'Sass (SCSS Syntax)', | ||
'callback' => 'jetpack_sass_css_preprocess', | ||
); | ||
$preprocessors['sass'] = array( | ||
'name' => 'Sass (SCSS Syntax)', | ||
'callback' => 'jetpack_sass_css_preprocess', | ||
); | ||
|
||
return $preprocessors; | ||
return $preprocessors; | ||
} | ||
} | ||
|
||
add_filter( 'jetpack_custom_css_preprocessors', 'jetpack_register_css_preprocessors' ); | ||
|
||
/** | ||
* Compile less prepocessors? | ||
* | ||
* @param string $less - less. | ||
*/ | ||
function jetpack_less_css_preprocess( $less ) { | ||
require_once __DIR__ . '/preprocessors/lessc.inc.php'; | ||
if ( ! function_exists( 'jetpack_less_css_preprocess' ) ) { | ||
/** | ||
* Compile less prepocessors? | ||
* | ||
* @param string $less - less. | ||
*/ | ||
function jetpack_less_css_preprocess( $less ) { | ||
require_once __DIR__ . '/preprocessors/lessc.inc.php'; | ||
|
||
$compiler = new lessc(); | ||
$compiler = new lessc(); | ||
|
||
// Don't try to load from the filesystem. | ||
$compiler->setImportDir( array() ); | ||
// Don't try to load from the filesystem. | ||
$compiler->setImportDir( array() ); | ||
|
||
try { | ||
return $compiler->compile( $less ); | ||
} catch ( Exception $e ) { | ||
return $less; | ||
try { | ||
return $compiler->compile( $less ); | ||
} catch ( Exception $e ) { | ||
return $less; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Compile sass prepocessors? | ||
* | ||
* @param string $sass - sass. | ||
*/ | ||
function jetpack_sass_css_preprocess( $sass ) { | ||
$compiler = new ScssPhp\ScssPhp\Compiler(); | ||
if ( ! function_exists( 'jetpack_sass_css_preprocess' ) ) { | ||
/** | ||
* Compile sass prepocessors? | ||
* | ||
* @param string $sass - sass. | ||
*/ | ||
function jetpack_sass_css_preprocess( $sass ) { | ||
$compiler = new ScssPhp\ScssPhp\Compiler(); | ||
|
||
// Don't try to load from the filesystem. | ||
$compiler->setImportPaths( array() ); | ||
// Don't try to load from the filesystem. | ||
$compiler->setImportPaths( array() ); | ||
|
||
try { | ||
return $compiler->compileString( $sass )->getCss(); | ||
} catch ( Exception $e ) { | ||
return $sass; | ||
try { | ||
return $compiler->compileString( $sass )->getCss(); | ||
} catch ( Exception $e ) { | ||
return $sass; | ||
} | ||
} | ||
} |
110 changes: 58 additions & 52 deletions
110
projects/plugins/jetpack/modules/custom-css/custom-css/preprocessors.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,76 @@ | ||
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
|
||
/** | ||
* CSS preprocessor registration. | ||
* | ||
* To add a new preprocessor (or replace an existing one), hook into the | ||
* jetpack_custom_css_preprocessors filter and add an entry to the array | ||
* that is passed in. | ||
* | ||
* Format is: | ||
* $preprocessors[ UNIQUE_KEY ] => array( 'name' => 'Processor name', 'callback' => [processing function] ); | ||
* | ||
* The callback function accepts a single string argument (non-CSS markup) and returns a string (CSS). | ||
* | ||
* @param array $preprocessors The list of preprocessors added thus far. | ||
* @return array | ||
*/ | ||
function jetpack_register_css_preprocessors( $preprocessors ) { | ||
$preprocessors['less'] = array( | ||
'name' => 'LESS', | ||
'callback' => 'jetpack_less_css_preprocess', | ||
); | ||
if ( ! function_exists( 'jetpack_register_css_preprocessors' ) ) { | ||
/** | ||
* CSS preprocessor registration. | ||
* | ||
* To add a new preprocessor (or replace an existing one), hook into the | ||
* jetpack_custom_css_preprocessors filter and add an entry to the array | ||
* that is passed in. | ||
* | ||
* Format is: | ||
* $preprocessors[ UNIQUE_KEY ] => array( 'name' => 'Processor name', 'callback' => [processing function] ); | ||
* | ||
* The callback function accepts a single string argument (non-CSS markup) and returns a string (CSS). | ||
* | ||
* @param array $preprocessors The list of preprocessors added thus far. | ||
* @return array | ||
*/ | ||
function jetpack_register_css_preprocessors( $preprocessors ) { | ||
$preprocessors['less'] = array( | ||
'name' => 'LESS', | ||
'callback' => 'jetpack_less_css_preprocess', | ||
); | ||
|
||
$preprocessors['sass'] = array( | ||
'name' => 'Sass (SCSS Syntax)', | ||
'callback' => 'jetpack_sass_css_preprocess', | ||
); | ||
$preprocessors['sass'] = array( | ||
'name' => 'Sass (SCSS Syntax)', | ||
'callback' => 'jetpack_sass_css_preprocess', | ||
); | ||
|
||
return $preprocessors; | ||
return $preprocessors; | ||
} | ||
} | ||
|
||
add_filter( 'jetpack_custom_css_preprocessors', 'jetpack_register_css_preprocessors' ); | ||
|
||
/** | ||
* Compile less prepocessors? | ||
* | ||
* @param string $less - less. | ||
*/ | ||
function jetpack_less_css_preprocess( $less ) { | ||
require_once __DIR__ . '/preprocessors/lessc.inc.php'; | ||
if ( ! function_exists( 'jetpack_less_css_preprocess' ) ) { | ||
/** | ||
* Compile less prepocessors? | ||
* | ||
* @param string $less - less. | ||
*/ | ||
function jetpack_less_css_preprocess( $less ) { | ||
require_once __DIR__ . '/preprocessors/lessc.inc.php'; | ||
|
||
$compiler = new lessc(); | ||
$compiler = new lessc(); | ||
|
||
// Don't try to load from the filesystem. | ||
$compiler->setImportDir( array() ); | ||
// Don't try to load from the filesystem. | ||
$compiler->setImportDir( array() ); | ||
|
||
try { | ||
return $compiler->compile( $less ); | ||
} catch ( Exception $e ) { | ||
return $less; | ||
try { | ||
return $compiler->compile( $less ); | ||
} catch ( Exception $e ) { | ||
return $less; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Compile sass prepocessors? | ||
* | ||
* @param string $sass - sass. | ||
*/ | ||
function jetpack_sass_css_preprocess( $sass ) { | ||
$compiler = new ScssPhp\ScssPhp\Compiler(); | ||
if ( ! function_exists( 'jetpack_sass_css_preprocess' ) ) { | ||
/** | ||
* Compile sass prepocessors? | ||
* | ||
* @param string $sass - sass. | ||
*/ | ||
function jetpack_sass_css_preprocess( $sass ) { | ||
$compiler = new ScssPhp\ScssPhp\Compiler(); | ||
|
||
// Don't try to load from the filesystem. | ||
$compiler->setImportPaths( array() ); | ||
// Don't try to load from the filesystem. | ||
$compiler->setImportPaths( array() ); | ||
|
||
try { | ||
return $compiler->compileString( $sass )->getCss(); | ||
} catch ( Exception $e ) { | ||
return $sass; | ||
try { | ||
return $compiler->compileString( $sass )->getCss(); | ||
} catch ( Exception $e ) { | ||
return $sass; | ||
} | ||
} | ||
} |