Version Description
- Added option to only show errors to logged in users
Download this release
Release Info
Developer | connectthink |
Plugin | WP-SCSS |
Version | 1.1.5 |
Comparing to | |
See all releases |
Code changes from version 1.1.3 to 1.1.5
- class/class-wp-scss.php +34 -34
- options.php +2 -1
- readme.txt +16 -10
- wp-scss.php +55 -48
class/class-wp-scss.php
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
-
<?php
|
2 |
|
3 |
class Wp_Scss {
|
4 |
/**
|
5 |
* Compiling preferences properites
|
6 |
-
*
|
7 |
* @var string
|
8 |
* @access public
|
9 |
*/
|
10 |
public $scss_dir, $css_dir, $compile_method, $scssc, $compile_errors;
|
11 |
-
|
12 |
|
13 |
/**
|
14 |
* Set values for Wp_Scss::properties
|
15 |
-
*
|
16 |
* @param string scss_dir - path to source directory for scss files
|
17 |
* @param string css_dir - path to output directory for css files
|
18 |
* @param string method - type of compile (compressed, expanded, etc)
|
19 |
-
*
|
20 |
* @var object scssc - instantiate the compiling object.
|
21 |
*
|
22 |
* @var array compile_errors - catches errors from compile
|
@@ -29,35 +29,35 @@ class Wp_Scss {
|
|
29 |
global $scssc;
|
30 |
$scssc = new scssc();
|
31 |
$scssc->setFormatter($compile_method);
|
32 |
-
$scssc->setImportPaths($scss_dir);
|
33 |
|
34 |
$this->compile_errors = array();
|
35 |
}
|
36 |
|
37 |
-
/**
|
38 |
* METHOD COMPILE
|
39 |
* Loops through scss directory and compilers files that end
|
40 |
* with .scss and do not have '_' in front.
|
41 |
*
|
42 |
-
* @function compiler - passes input content through scssphp,
|
43 |
* puts compiled css into cache file
|
44 |
*
|
45 |
* @var array input_files - array of .scss files with no '_' in front
|
46 |
* @var array sdir_arr - an array of all the files in the scss directory
|
47 |
-
*
|
48 |
-
* @return nothing - Puts successfully compiled css into apporpriate location
|
49 |
* Puts error in 'compile_errors' property
|
50 |
* @access public
|
51 |
*/
|
52 |
public function compile() {
|
53 |
global $scssc, $cache;
|
54 |
$cache = WPSCSS_PLUGIN_DIR . '/cache/';
|
55 |
-
|
56 |
//Compiler - Takes scss $in and writes compiled css to $out file
|
57 |
// catches errors and puts them the object's compiled_errors property
|
58 |
-
function compiler($in, $out, $instance) {
|
59 |
-
global $scssc, $cache;
|
60 |
-
|
61 |
if (is_writable($cache)) {
|
62 |
try {
|
63 |
$css = $scssc->compile(file_get_contents($in));
|
@@ -78,27 +78,27 @@ class Wp_Scss {
|
|
78 |
}
|
79 |
}
|
80 |
|
81 |
-
$input_files = array();
|
82 |
// Loop through directory and get .scss file that do not start with '_'
|
83 |
foreach(new DirectoryIterator($this->scss_dir) as $file) {
|
84 |
if (substr($file, 0, 1) != "_" && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'scss') {
|
85 |
array_push($input_files, $file->getFilename());
|
86 |
}
|
87 |
}
|
88 |
-
|
89 |
// For each input file, find matching css file and compile
|
90 |
foreach ($input_files as $scss_file) {
|
91 |
$input = $this->scss_dir.$scss_file;
|
92 |
$outputName = preg_replace("/\.[^$]*/",".css", $scss_file);
|
93 |
$output = $this->css_dir.$outputName;
|
94 |
-
|
95 |
compiler($input, $output, $this);
|
96 |
}
|
97 |
|
98 |
if (count($this->compile_errors) < 1) {
|
99 |
if ( is_writable($this->css_dir) ) {
|
100 |
foreach (new DirectoryIterator($cache) as $cache_file) {
|
101 |
-
if ( pathinfo($cache_file->getFilename(), PATHINFO_EXTENSION) == 'css') {
|
102 |
file_put_contents($this->css_dir.$cache_file, file_get_contents($cache.$cache_file));
|
103 |
unlink($cache.$cache_file->getFilename()); // Delete file on successful write
|
104 |
}
|
@@ -111,10 +111,10 @@ class Wp_Scss {
|
|
111 |
array_push($this->compile_errors, $errors);
|
112 |
}
|
113 |
}
|
114 |
-
}
|
115 |
|
116 |
|
117 |
-
/**
|
118 |
* METHOD NEEDS_COMPILING
|
119 |
* Gets the most recently modified file in the scss directory
|
120 |
* and compares that do the most recently modified css file.
|
@@ -126,60 +126,60 @@ class Wp_Scss {
|
|
126 |
*
|
127 |
* @var array sdir_arr - scss directory files
|
128 |
* @var array cdir_arr - css directory files
|
129 |
-
*
|
130 |
* @var string latest_scss - file mod time of the most recent file change
|
131 |
* @var string latest_css - file mod time of the most recent file change
|
132 |
-
*
|
133 |
* @return bool - true if compiling is needed
|
134 |
*/
|
135 |
public function needs_compiling() {
|
136 |
$latest_scss = 0;
|
137 |
$latest_css = 0;
|
138 |
|
139 |
-
foreach ( new
|
140 |
if (pathinfo($sfile->getFilename(), PATHINFO_EXTENSION) == 'scss') {
|
141 |
$file_time = $sfile->getMTime();
|
142 |
|
143 |
if ( (int) $file_time > $latest_scss) {
|
144 |
-
$latest_scss = $file_time;
|
145 |
}
|
146 |
}
|
147 |
}
|
148 |
|
149 |
-
foreach ( new
|
150 |
if (pathinfo($cfile->getFilename(), PATHINFO_EXTENSION) == 'css') {
|
151 |
$file_time = $cfile->getMTime();
|
152 |
-
|
153 |
if ( (int) $file_time > $latest_css) {
|
154 |
-
$latest_css = $file_time;
|
155 |
}
|
156 |
}
|
157 |
}
|
158 |
-
|
159 |
if ($latest_scss > $latest_css) {
|
160 |
return true;
|
161 |
} else {
|
162 |
-
return false;
|
163 |
}
|
164 |
}
|
165 |
|
166 |
-
/**
|
167 |
* METHOD ENQUEUE STYLES
|
168 |
* Enqueues all styles in the css directory.
|
169 |
*
|
170 |
* @param $css_folder - directory from theme root. We need this passed in separately
|
171 |
-
* so it can be used in a url, not path
|
172 |
*/
|
173 |
public function enqueue_files($css_folder) {
|
174 |
-
|
175 |
foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) {
|
176 |
if ( pathinfo($stylesheet->getFilename(), PATHINFO_EXTENSION) == 'css' ) {
|
177 |
$name = $stylesheet->getBasename('.css') . '-style';
|
178 |
$uri = get_stylesheet_directory_uri().$css_folder.$stylesheet->getFilename();
|
179 |
$ver = $stylesheet->getMTime();
|
180 |
|
181 |
-
|
182 |
-
wp_register_style(
|
183 |
$name,
|
184 |
$uri,
|
185 |
array(),
|
1 |
+
<?php
|
2 |
|
3 |
class Wp_Scss {
|
4 |
/**
|
5 |
* Compiling preferences properites
|
6 |
+
*
|
7 |
* @var string
|
8 |
* @access public
|
9 |
*/
|
10 |
public $scss_dir, $css_dir, $compile_method, $scssc, $compile_errors;
|
11 |
+
|
12 |
|
13 |
/**
|
14 |
* Set values for Wp_Scss::properties
|
15 |
+
*
|
16 |
* @param string scss_dir - path to source directory for scss files
|
17 |
* @param string css_dir - path to output directory for css files
|
18 |
* @param string method - type of compile (compressed, expanded, etc)
|
19 |
+
*
|
20 |
* @var object scssc - instantiate the compiling object.
|
21 |
*
|
22 |
* @var array compile_errors - catches errors from compile
|
29 |
global $scssc;
|
30 |
$scssc = new scssc();
|
31 |
$scssc->setFormatter($compile_method);
|
32 |
+
$scssc->setImportPaths($scss_dir);
|
33 |
|
34 |
$this->compile_errors = array();
|
35 |
}
|
36 |
|
37 |
+
/**
|
38 |
* METHOD COMPILE
|
39 |
* Loops through scss directory and compilers files that end
|
40 |
* with .scss and do not have '_' in front.
|
41 |
*
|
42 |
+
* @function compiler - passes input content through scssphp,
|
43 |
* puts compiled css into cache file
|
44 |
*
|
45 |
* @var array input_files - array of .scss files with no '_' in front
|
46 |
* @var array sdir_arr - an array of all the files in the scss directory
|
47 |
+
*
|
48 |
+
* @return nothing - Puts successfully compiled css into apporpriate location
|
49 |
* Puts error in 'compile_errors' property
|
50 |
* @access public
|
51 |
*/
|
52 |
public function compile() {
|
53 |
global $scssc, $cache;
|
54 |
$cache = WPSCSS_PLUGIN_DIR . '/cache/';
|
55 |
+
|
56 |
//Compiler - Takes scss $in and writes compiled css to $out file
|
57 |
// catches errors and puts them the object's compiled_errors property
|
58 |
+
function compiler($in, $out, $instance) {
|
59 |
+
global $scssc, $cache;
|
60 |
+
|
61 |
if (is_writable($cache)) {
|
62 |
try {
|
63 |
$css = $scssc->compile(file_get_contents($in));
|
78 |
}
|
79 |
}
|
80 |
|
81 |
+
$input_files = array();
|
82 |
// Loop through directory and get .scss file that do not start with '_'
|
83 |
foreach(new DirectoryIterator($this->scss_dir) as $file) {
|
84 |
if (substr($file, 0, 1) != "_" && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'scss') {
|
85 |
array_push($input_files, $file->getFilename());
|
86 |
}
|
87 |
}
|
88 |
+
|
89 |
// For each input file, find matching css file and compile
|
90 |
foreach ($input_files as $scss_file) {
|
91 |
$input = $this->scss_dir.$scss_file;
|
92 |
$outputName = preg_replace("/\.[^$]*/",".css", $scss_file);
|
93 |
$output = $this->css_dir.$outputName;
|
94 |
+
|
95 |
compiler($input, $output, $this);
|
96 |
}
|
97 |
|
98 |
if (count($this->compile_errors) < 1) {
|
99 |
if ( is_writable($this->css_dir) ) {
|
100 |
foreach (new DirectoryIterator($cache) as $cache_file) {
|
101 |
+
if ( pathinfo($cache_file->getFilename(), PATHINFO_EXTENSION) == 'css') {
|
102 |
file_put_contents($this->css_dir.$cache_file, file_get_contents($cache.$cache_file));
|
103 |
unlink($cache.$cache_file->getFilename()); // Delete file on successful write
|
104 |
}
|
111 |
array_push($this->compile_errors, $errors);
|
112 |
}
|
113 |
}
|
114 |
+
}
|
115 |
|
116 |
|
117 |
+
/**
|
118 |
* METHOD NEEDS_COMPILING
|
119 |
* Gets the most recently modified file in the scss directory
|
120 |
* and compares that do the most recently modified css file.
|
126 |
*
|
127 |
* @var array sdir_arr - scss directory files
|
128 |
* @var array cdir_arr - css directory files
|
129 |
+
*
|
130 |
* @var string latest_scss - file mod time of the most recent file change
|
131 |
* @var string latest_css - file mod time of the most recent file change
|
132 |
+
*
|
133 |
* @return bool - true if compiling is needed
|
134 |
*/
|
135 |
public function needs_compiling() {
|
136 |
$latest_scss = 0;
|
137 |
$latest_css = 0;
|
138 |
|
139 |
+
foreach ( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->scss_dir)) as $sfile ) {
|
140 |
if (pathinfo($sfile->getFilename(), PATHINFO_EXTENSION) == 'scss') {
|
141 |
$file_time = $sfile->getMTime();
|
142 |
|
143 |
if ( (int) $file_time > $latest_scss) {
|
144 |
+
$latest_scss = $file_time;
|
145 |
}
|
146 |
}
|
147 |
}
|
148 |
|
149 |
+
foreach ( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->css_dir)) as $cfile ) {
|
150 |
if (pathinfo($cfile->getFilename(), PATHINFO_EXTENSION) == 'css') {
|
151 |
$file_time = $cfile->getMTime();
|
152 |
+
|
153 |
if ( (int) $file_time > $latest_css) {
|
154 |
+
$latest_css = $file_time;
|
155 |
}
|
156 |
}
|
157 |
}
|
158 |
+
|
159 |
if ($latest_scss > $latest_css) {
|
160 |
return true;
|
161 |
} else {
|
162 |
+
return false;
|
163 |
}
|
164 |
}
|
165 |
|
166 |
+
/**
|
167 |
* METHOD ENQUEUE STYLES
|
168 |
* Enqueues all styles in the css directory.
|
169 |
*
|
170 |
* @param $css_folder - directory from theme root. We need this passed in separately
|
171 |
+
* so it can be used in a url, not path
|
172 |
*/
|
173 |
public function enqueue_files($css_folder) {
|
174 |
+
|
175 |
foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) {
|
176 |
if ( pathinfo($stylesheet->getFilename(), PATHINFO_EXTENSION) == 'css' ) {
|
177 |
$name = $stylesheet->getBasename('.css') . '-style';
|
178 |
$uri = get_stylesheet_directory_uri().$css_folder.$stylesheet->getFilename();
|
179 |
$ver = $stylesheet->getMTime();
|
180 |
|
181 |
+
|
182 |
+
wp_register_style(
|
183 |
$name,
|
184 |
$uri,
|
185 |
array(),
|
options.php
CHANGED
@@ -218,6 +218,7 @@ class Wp_Scss_Settings
|
|
218 |
|
219 |
$html = '<select id="errors" name="wpscss_options[errors]">';
|
220 |
$html .= '<option value="show"' . selected( $this->options['errors'], 'show', false) . '>Show in Header</option>';
|
|
|
221 |
$html .= '<option value="log"' . selected( $this->options['errors'], 'hide', false) . '>Print to Log</option>';
|
222 |
$html .= '</select>';
|
223 |
|
@@ -230,7 +231,7 @@ class Wp_Scss_Settings
|
|
230 |
function enqueue_callback() {
|
231 |
$this->options = get_option( 'wpscss_options' );
|
232 |
|
233 |
-
$html = '<input type="checkbox" id="enqueue" name="wpscss_options[enqueue]" value="1"' . checked( 1, $this->options['enqueue'], false ) . '/>';
|
234 |
$html .= '<label for="enqueue"></label>';
|
235 |
|
236 |
echo $html;
|
218 |
|
219 |
$html = '<select id="errors" name="wpscss_options[errors]">';
|
220 |
$html .= '<option value="show"' . selected( $this->options['errors'], 'show', false) . '>Show in Header</option>';
|
221 |
+
$html .= '<option value="show-logged-in"' . selected( $this->options['errors'], 'show-logged-in', false) . '>Show to Logged In Users</option>';
|
222 |
$html .= '<option value="log"' . selected( $this->options['errors'], 'hide', false) . '>Print to Log</option>';
|
223 |
$html .= '</select>';
|
224 |
|
231 |
function enqueue_callback() {
|
232 |
$this->options = get_option( 'wpscss_options' );
|
233 |
|
234 |
+
$html = '<input type="checkbox" id="enqueue" name="wpscss_options[enqueue]" value="1"' . checked( 1, isset($this->options['enqueue']) ? $this->options['enqueue'] : 0, false ) . '/>';
|
235 |
$html .= '<label for="enqueue"></label>';
|
236 |
|
237 |
echo $html;
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: sass, scss, css
|
|
4 |
Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 3.8
|
7 |
-
Stable tag: 1.1.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/copyleft/gpl.html
|
10 |
|
@@ -14,7 +14,7 @@ Compiles .scss files to .css and enqueues them.
|
|
14 |
|
15 |
Compiles .scss files on your wordpress install using [lefo's scssphp](https://github.com/leafo/scssphp). Includes settings page for configuring directories, error reporting, compiling options, and auto enqueuing.
|
16 |
|
17 |
-
The plugin only compiles when changes have been made to the scss files. Compiles are made to the matching css file, so disabling this plugin will not take down your stylesheets. In the instance where a matching css file does not exist yet, the plugin will create the appropriate css file in the css directory.
|
18 |
|
19 |
[Get detailed instructions on github](https://github.com/ConnectThink/WP-SCSS)
|
20 |
|
@@ -28,32 +28,32 @@ The plugin only compiles when changes have been made to the scss files. Compiles
|
|
28 |
|
29 |
= Can I use a child theme? =
|
30 |
|
31 |
-
Yes, absolutely. Make sure you define your directories relative to your child theme and that your child theme is active. Otherwise you'll see an error regarding missing directories.
|
32 |
|
33 |
= How do I @import subfiles =
|
34 |
|
35 |
You can import other scss files into parent files and compile them into a single css file. To do this, use @import as normal in your scss file. All imported file names *must* start with an underscore. Otherwise they will be compiled into their own css file.
|
36 |
|
37 |
When importing in your scss file, you can leave off the underscore.
|
38 |
-
|
39 |
> `@import 'subfile';`
|
40 |
-
|
41 |
|
42 |
-
|
|
|
43 |
Currently there isn't a way to fully support [compass](https://github.com/chriseppstein/compass) with a php compiler. If you want limited support, you can manually import the compass framework. You'll need both the _compass.scss and compass directory.
|
44 |
-
|
45 |
-
|
46 |
> `compass / frameworks / compass / stylesheets /
|
47 |
|
48 |
> `@import 'compass';`
|
49 |
|
50 |
|
51 |
-
Alternatively, you can include [Bourbon](https://github.com/thoughtbot/bourbon) in a similar fashion.
|
52 |
|
53 |
= Can I use .sass syntax with this Plugin? =
|
54 |
This plugin will only work with .scss format.
|
55 |
|
56 |
-
= It's not updating my css, what's happening? =
|
57 |
Do you have errors printing to the front end? If not, check your log file in your scss directory. The css will not be updated if there are errors in your sass file(s).
|
58 |
|
59 |
Make sure your directories are properly defined in the settings. Paths are defined from the root of the theme.
|
@@ -62,6 +62,12 @@ Make sure your directories are properly defined in the settings. Paths are defin
|
|
62 |
If you are having issues with the plugin, create an issue on [github](https://github.com/ConnectThink/WP-SCSS), and we'll do our best to help.
|
63 |
|
64 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
= 1.1.3 =
|
66 |
* Hotfix for a accidental character
|
67 |
|
4 |
Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 3.8
|
7 |
+
Stable tag: 1.1.5
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/copyleft/gpl.html
|
10 |
|
14 |
|
15 |
Compiles .scss files on your wordpress install using [lefo's scssphp](https://github.com/leafo/scssphp). Includes settings page for configuring directories, error reporting, compiling options, and auto enqueuing.
|
16 |
|
17 |
+
The plugin only compiles when changes have been made to the scss files. Compiles are made to the matching css file, so disabling this plugin will not take down your stylesheets. In the instance where a matching css file does not exist yet, the plugin will create the appropriate css file in the css directory.
|
18 |
|
19 |
[Get detailed instructions on github](https://github.com/ConnectThink/WP-SCSS)
|
20 |
|
28 |
|
29 |
= Can I use a child theme? =
|
30 |
|
31 |
+
Yes, absolutely. Make sure you define your directories relative to your child theme and that your child theme is active. Otherwise you'll see an error regarding missing directories.
|
32 |
|
33 |
= How do I @import subfiles =
|
34 |
|
35 |
You can import other scss files into parent files and compile them into a single css file. To do this, use @import as normal in your scss file. All imported file names *must* start with an underscore. Otherwise they will be compiled into their own css file.
|
36 |
|
37 |
When importing in your scss file, you can leave off the underscore.
|
38 |
+
|
39 |
> `@import 'subfile';`
|
|
|
40 |
|
41 |
+
|
42 |
+
= Does this plugin support Compass? =
|
43 |
Currently there isn't a way to fully support [compass](https://github.com/chriseppstein/compass) with a php compiler. If you want limited support, you can manually import the compass framework. You'll need both the _compass.scss and compass directory.
|
44 |
+
|
45 |
+
|
46 |
> `compass / frameworks / compass / stylesheets /
|
47 |
|
48 |
> `@import 'compass';`
|
49 |
|
50 |
|
51 |
+
Alternatively, you can include [Bourbon](https://github.com/thoughtbot/bourbon) in a similar fashion.
|
52 |
|
53 |
= Can I use .sass syntax with this Plugin? =
|
54 |
This plugin will only work with .scss format.
|
55 |
|
56 |
+
= It's not updating my css, what's happening? =
|
57 |
Do you have errors printing to the front end? If not, check your log file in your scss directory. The css will not be updated if there are errors in your sass file(s).
|
58 |
|
59 |
Make sure your directories are properly defined in the settings. Paths are defined from the root of the theme.
|
62 |
If you are having issues with the plugin, create an issue on [github](https://github.com/ConnectThink/WP-SCSS), and we'll do our best to help.
|
63 |
|
64 |
== Changelog ==
|
65 |
+
= 1.1.5 =
|
66 |
+
* Added option to only show errors to logged in users
|
67 |
+
|
68 |
+
= 1.1.4 =
|
69 |
+
* Add suport for subfolders in scss directory
|
70 |
+
|
71 |
= 1.1.3 =
|
72 |
* Hotfix for a accidental character
|
73 |
|
wp-scss.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
<?php
|
2 |
/**
|
3 |
* Plugin Name: WP-SCSS
|
4 |
* Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
* Description: Compiles scss files live on wordpress.
|
6 |
-
* Version: 1.1.
|
7 |
* Author: Connect Think
|
8 |
* Author URI: http://connectthink.com
|
9 |
* License: GPLv3
|
@@ -21,7 +21,7 @@
|
|
21 |
* 5. Instantiate wp_scss object and run compiler
|
22 |
* 6. Handle Errors
|
23 |
* 7. Enqueue Styles
|
24 |
-
*/
|
25 |
|
26 |
|
27 |
/*
|
@@ -46,7 +46,7 @@ if (!defined('WPSCSS_VERSION_KEY'))
|
|
46 |
define('WPSCSS_VERSION_KEY', 'wpscss_version');
|
47 |
|
48 |
if (!defined('WPSCSS_VERSION_NUM'))
|
49 |
-
define('WPSCSS_VERSION_NUM', '1.1.');
|
50 |
|
51 |
// Add version to options table
|
52 |
add_option(WPSCSS_VERSION_KEY, WPSCSS_VERSION_NUM);
|
@@ -54,8 +54,8 @@ add_option(WPSCSS_VERSION_KEY, WPSCSS_VERSION_NUM);
|
|
54 |
|
55 |
/*
|
56 |
* 2. REQUIRE DEPENDANCIES
|
57 |
-
*
|
58 |
-
* scssphp - scss compiler
|
59 |
* class-wp-scss
|
60 |
* options.php - settings for plugin page
|
61 |
*/
|
@@ -67,9 +67,9 @@ include_once WPSCSS_PLUGIN_DIR . '/options.php'; // Options page class
|
|
67 |
|
68 |
/**
|
69 |
* 3. REGISTER SETTINGS
|
70 |
-
*
|
71 |
* Instantiate Options Page
|
72 |
-
* Create link on plugin page to settings page
|
73 |
*/
|
74 |
|
75 |
if( is_admin() ) {
|
@@ -93,9 +93,9 @@ function wpscss_plugin_action_links($links, $file) {
|
|
93 |
}
|
94 |
|
95 |
|
96 |
-
/**
|
97 |
* 4. PLUGIN SETTINGS
|
98 |
-
*
|
99 |
* Pull settings from options table
|
100 |
* Scrub empty fields or directories that don't exists
|
101 |
* Assign settings via settings array to pass to object
|
@@ -105,7 +105,7 @@ $wpscss_options = get_option( 'wpscss_options' );
|
|
105 |
$scss_dir_setting = $wpscss_options['scss_dir'];
|
106 |
$css_dir_setting = $wpscss_options['css_dir'];
|
107 |
|
108 |
-
// Checks if directories are empty
|
109 |
if( $scss_dir_setting == false || $css_dir_setting == false ) {
|
110 |
function wpscss_settings_error() {
|
111 |
echo '<div class="error">
|
@@ -130,9 +130,9 @@ if( $scss_dir_setting == false || $css_dir_setting == false ) {
|
|
130 |
$wpscss_settings = array(
|
131 |
'scss_dir' => WPSCSS_THEME_DIR . $scss_dir_setting,
|
132 |
'css_dir' => WPSCSS_THEME_DIR . $css_dir_setting,
|
133 |
-
'compiling' => $wpscss_options['compiling_options'],
|
134 |
'errors' => $wpscss_options['errors'],
|
135 |
-
'enqueue' => $wpscss_options['enqueue']
|
136 |
);
|
137 |
|
138 |
|
@@ -158,55 +158,62 @@ if ( $wpscss_compiler->needs_compiling() ) {
|
|
158 |
/**
|
159 |
* 6. HANDLE COMPILING ERRORS
|
160 |
*
|
161 |
-
* First block handles print errors to front end.
|
162 |
* This adds a small style block the header to help errors get noticed
|
163 |
*
|
164 |
-
* Second block handles print errors to log file.
|
165 |
-
* After the file gets over 1MB it does a purge and deletes the first
|
166 |
-
* half of entries in the file.
|
167 |
*/
|
168 |
$log_file = $wpscss_compiler->scss_dir.'error_log.log';
|
169 |
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
echo '<div class="scss_errors"><pre>';
|
173 |
echo '<h6 style="margin: 15px 0;">Sass Compiling Error</h6>';
|
174 |
-
|
175 |
-
foreach( $
|
176 |
echo '<p class="sass_error">';
|
177 |
-
echo '<strong>'. $error['file'] .'</strong> <br/><em>"'. $error['message'] .'"</em>';
|
178 |
echo '<p class="sass_error">';
|
179 |
}
|
180 |
|
181 |
echo '</pre></div>';
|
182 |
|
183 |
-
function wpscss_error_styles() {
|
184 |
-
echo
|
185 |
-
'<style>
|
186 |
-
.scss_errors {
|
187 |
-
position: fixed;
|
188 |
-
top: 0px;
|
189 |
-
z-index: 99999;
|
190 |
-
width: 100%;
|
191 |
-
}
|
192 |
-
.scss_errors pre {
|
193 |
-
background: #f5f5f5;
|
194 |
-
border-left: 5px solid #DD3D36;
|
195 |
-
box-shadow: 0 2px 3px rgba(51,51,51, .4);
|
196 |
-
color: #666;
|
197 |
-
font-family: monospace;
|
198 |
-
font-size: 14px;
|
199 |
-
margin: 20px 0;
|
200 |
-
overflow: auto;
|
201 |
-
padding: 20px;
|
202 |
-
white-space: pre;
|
203 |
-
white-space: pre-wrap;
|
204 |
-
word-wrap: break-word;
|
205 |
-
}
|
206 |
-
</style>';
|
207 |
-
}
|
208 |
add_action('wp_print_styles', 'wpscss_error_styles');
|
|
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
} else { // Hide errors and print them to a log file.
|
211 |
foreach ($wpscss_compiler->compile_errors as $error) {
|
212 |
$error_string = date('m/d/y g:i:s', time()) .': ';
|
@@ -235,7 +242,7 @@ if ( file_exists($log_file) ) {
|
|
235 |
if ( $wpscss_settings['enqueue'] == '1' ) {
|
236 |
function wpscss_enqueue_styles() {
|
237 |
global $wpscss_compiler, $wpscss_options;
|
238 |
-
$wpscss_compiler->enqueue_files($wpscss_options['css_dir']);
|
239 |
}
|
240 |
add_action('wp_enqueue_scripts', 'wpscss_enqueue_styles', 50);
|
241 |
}
|
1 |
+
<?php
|
2 |
/**
|
3 |
* Plugin Name: WP-SCSS
|
4 |
* Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
* Description: Compiles scss files live on wordpress.
|
6 |
+
* Version: 1.1.5
|
7 |
* Author: Connect Think
|
8 |
* Author URI: http://connectthink.com
|
9 |
* License: GPLv3
|
21 |
* 5. Instantiate wp_scss object and run compiler
|
22 |
* 6. Handle Errors
|
23 |
* 7. Enqueue Styles
|
24 |
+
*/
|
25 |
|
26 |
|
27 |
/*
|
46 |
define('WPSCSS_VERSION_KEY', 'wpscss_version');
|
47 |
|
48 |
if (!defined('WPSCSS_VERSION_NUM'))
|
49 |
+
define('WPSCSS_VERSION_NUM', '1.1.5');
|
50 |
|
51 |
// Add version to options table
|
52 |
add_option(WPSCSS_VERSION_KEY, WPSCSS_VERSION_NUM);
|
54 |
|
55 |
/*
|
56 |
* 2. REQUIRE DEPENDANCIES
|
57 |
+
*
|
58 |
+
* scssphp - scss compiler
|
59 |
* class-wp-scss
|
60 |
* options.php - settings for plugin page
|
61 |
*/
|
67 |
|
68 |
/**
|
69 |
* 3. REGISTER SETTINGS
|
70 |
+
*
|
71 |
* Instantiate Options Page
|
72 |
+
* Create link on plugin page to settings page
|
73 |
*/
|
74 |
|
75 |
if( is_admin() ) {
|
93 |
}
|
94 |
|
95 |
|
96 |
+
/**
|
97 |
* 4. PLUGIN SETTINGS
|
98 |
+
*
|
99 |
* Pull settings from options table
|
100 |
* Scrub empty fields or directories that don't exists
|
101 |
* Assign settings via settings array to pass to object
|
105 |
$scss_dir_setting = $wpscss_options['scss_dir'];
|
106 |
$css_dir_setting = $wpscss_options['css_dir'];
|
107 |
|
108 |
+
// Checks if directories are empty
|
109 |
if( $scss_dir_setting == false || $css_dir_setting == false ) {
|
110 |
function wpscss_settings_error() {
|
111 |
echo '<div class="error">
|
130 |
$wpscss_settings = array(
|
131 |
'scss_dir' => WPSCSS_THEME_DIR . $scss_dir_setting,
|
132 |
'css_dir' => WPSCSS_THEME_DIR . $css_dir_setting,
|
133 |
+
'compiling' => $wpscss_options['compiling_options'],
|
134 |
'errors' => $wpscss_options['errors'],
|
135 |
+
'enqueue' => isset($wpscss_options['enqueue']) ? $wpscss_options['enqueue'] : 0
|
136 |
);
|
137 |
|
138 |
|
158 |
/**
|
159 |
* 6. HANDLE COMPILING ERRORS
|
160 |
*
|
161 |
+
* First block handles print errors to front end.
|
162 |
* This adds a small style block the header to help errors get noticed
|
163 |
*
|
164 |
+
* Second block handles print errors to log file.
|
165 |
+
* After the file gets over 1MB it does a purge and deletes the first
|
166 |
+
* half of entries in the file.
|
167 |
*/
|
168 |
$log_file = $wpscss_compiler->scss_dir.'error_log.log';
|
169 |
|
170 |
+
function wpscss_error_styles() {
|
171 |
+
echo
|
172 |
+
'<style>
|
173 |
+
.scss_errors {
|
174 |
+
position: fixed;
|
175 |
+
top: 0px;
|
176 |
+
z-index: 99999;
|
177 |
+
width: 100%;
|
178 |
+
}
|
179 |
+
.scss_errors pre {
|
180 |
+
background: #f5f5f5;
|
181 |
+
border-left: 5px solid #DD3D36;
|
182 |
+
box-shadow: 0 2px 3px rgba(51,51,51, .4);
|
183 |
+
color: #666;
|
184 |
+
font-family: monospace;
|
185 |
+
font-size: 14px;
|
186 |
+
margin: 20px 0;
|
187 |
+
overflow: auto;
|
188 |
+
padding: 20px;
|
189 |
+
white-space: pre;
|
190 |
+
white-space: pre-wrap;
|
191 |
+
word-wrap: break-word;
|
192 |
+
}
|
193 |
+
</style>';
|
194 |
+
}
|
195 |
+
|
196 |
+
function wpscss_settings_show_errors($errors) {
|
197 |
echo '<div class="scss_errors"><pre>';
|
198 |
echo '<h6 style="margin: 15px 0;">Sass Compiling Error</h6>';
|
199 |
+
|
200 |
+
foreach( $errors as $error) {
|
201 |
echo '<p class="sass_error">';
|
202 |
+
echo '<strong>'. $error['file'] .'</strong> <br/><em>"'. $error['message'] .'"</em>';
|
203 |
echo '<p class="sass_error">';
|
204 |
}
|
205 |
|
206 |
echo '</pre></div>';
|
207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
add_action('wp_print_styles', 'wpscss_error_styles');
|
209 |
+
}
|
210 |
|
211 |
+
// Show to logged in users: All the methods for checking user login are set up later in the WP flow, so this only checks that there is a cookie
|
212 |
+
if ( !is_admin() && $wpscss_settings['errors'] === 'show-logged-in' && !empty($_COOKIE[LOGGED_IN_COOKIE]) && count($wpscss_compiler->compile_errors) > 0) {
|
213 |
+
wpscss_settings_show_errors($wpscss_compiler->compile_errors);
|
214 |
+
// Show in the header to anyone
|
215 |
+
} else if ( !is_admin() && $wpscss_settings['errors'] === 'show' && count($wpscss_compiler->compile_errors) > 0) {
|
216 |
+
wpscss_settings_show_errors($wpscss_compiler->compile_errors);
|
217 |
} else { // Hide errors and print them to a log file.
|
218 |
foreach ($wpscss_compiler->compile_errors as $error) {
|
219 |
$error_string = date('m/d/y g:i:s', time()) .': ';
|
242 |
if ( $wpscss_settings['enqueue'] == '1' ) {
|
243 |
function wpscss_enqueue_styles() {
|
244 |
global $wpscss_compiler, $wpscss_options;
|
245 |
+
$wpscss_compiler->enqueue_files($wpscss_options['css_dir']);
|
246 |
}
|
247 |
add_action('wp_enqueue_scripts', 'wpscss_enqueue_styles', 50);
|
248 |
}
|