From 7cb8eec7a25c4925ef68251d7107c618688d8348 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Sat, 30 Jan 2021 11:11:49 -0700 Subject: [PATCH] Add check for 'compiler' function --- class/class-wp-scss.php | 64 +++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/class/class-wp-scss.php b/class/class-wp-scss.php index b644c44..2abe4e7 100644 --- a/class/class-wp-scss.php +++ b/class/class-wp-scss.php @@ -58,40 +58,48 @@ public function compile() { //Compiler - Takes scss $in and writes compiled css to $out file // catches errors and puts them the object's compiled_errors property - function compiler($in, $out, $instance) { - global $scssc, $cache; + if (function_exists( 'compiler' )) { + function compiler($in, $out, $instance) { + global $scssc, $cache; - if (!file_exists($cache)) { - mkdir($cache, 0644); - } - if (is_writable($cache)) { - try { - $map = basename($out) . '.map'; - $scssc->setSourceMap(constant('Leafo\ScssPhp\Compiler::' . $instance->sourcemaps)); - $scssc->setSourceMapOptions(array( - 'sourceMapWriteTo' => $instance->css_dir . $map, // absolute path to a file to write the map to - 'sourceMapURL' => $map, // url of the map - 'sourceMapBasepath' => rtrim(ABSPATH, '/'), // base path for filename normalization - 'sourceRoot' => '/', // This value is prepended to the individual entries in the 'source' field. - )); - - $css = $scssc->compile(file_get_contents($in), $in); - - file_put_contents($cache.basename($out), $css); - } catch (Exception $e) { + if (!file_exists($cache)) { + mkdir($cache, 0644); + } + if (is_writable($cache)) { + try { + $map = basename($out) . '.map'; + $scssc->setSourceMap(constant('Leafo\ScssPhp\Compiler::' . $instance->sourcemaps)); + $scssc->setSourceMapOptions(array( + 'sourceMapWriteTo' => $instance->css_dir . $map, // absolute path to a file to write the map to + 'sourceMapURL' => $map, // url of the map + 'sourceMapBasepath' => rtrim(ABSPATH, '/'), // base path for filename normalization + 'sourceRoot' => '/', // This value is prepended to the individual entries in the 'source' field. + )); + + $css = $scssc->compile(file_get_contents($in), $in); + + file_put_contents($cache.basename($out), $css); + } catch (Exception $e) { + $errors = array ( + 'file' => basename($in), + 'message' => $e->getMessage(), + ); + array_push($instance->compile_errors, $errors); + } + } else { $errors = array ( - 'file' => basename($in), - 'message' => $e->getMessage(), + 'file' => $cache, + 'message' => "File Permission Error, permission denied. Please make the cache directory writable." ); array_push($instance->compile_errors, $errors); } - } else { - $errors = array ( - 'file' => $cache, - 'message' => "File Permission Error, permission denied. Please make the cache directory writable." - ); - array_push($instance->compile_errors, $errors); } + }else{ + $errors = array ( + 'file' => 'SCSS compiler', + 'message' => "Compile Error, function does not exist." + ); + array_push($instance->compile_errors, $errors); } $input_files = array();