Version Description
Download this release
Release Info
Developer | Sky Bolt |
Plugin | WP-SCSS |
Version | 2.1.1 |
Comparing to | |
See all releases |
Code changes from version 2.0.1 to 2.1.1
- class/class-wp-scss.php +13 -10
- options.php +54 -12
- readme.md +141 -0
- readme.txt +1 -1
- wp-scss.php +34 -34
class/class-wp-scss.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
4 |
use ScssPhp\ScssPhp\Compiler;
|
5 |
|
6 |
class Wp_Scss {
|
@@ -25,11 +26,11 @@ class Wp_Scss {
|
|
25 |
*/
|
26 |
public function __construct ($scss_dir, $css_dir, $compile_method, $sourcemaps) {
|
27 |
global $scssc;
|
28 |
-
$this->scss_dir
|
29 |
-
$this->css_dir
|
30 |
-
$this->compile_method
|
31 |
-
$this->compile_errors
|
32 |
-
$scssc
|
33 |
|
34 |
$scssc->setFormatter( $compile_method );
|
35 |
$scssc->setImportPaths( $this->scss_dir );
|
@@ -157,7 +158,8 @@ class Wp_Scss {
|
|
157 |
* @return bool - true if compiling is needed
|
158 |
*/
|
159 |
public function needs_compiling() {
|
160 |
-
|
|
|
161 |
return true;
|
162 |
}
|
163 |
|
@@ -208,12 +210,13 @@ class Wp_Scss {
|
|
208 |
* @param $css_folder - directory from theme root. We need this passed in separately
|
209 |
* so it can be used in a url, not path
|
210 |
*/
|
211 |
-
public function enqueue_files($css_folder) {
|
212 |
|
|
|
213 |
foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) {
|
214 |
if ( pathinfo($stylesheet->getFilename(), PATHINFO_EXTENSION) == 'css' ) {
|
215 |
$name = $stylesheet->getBasename('.css') . '-style';
|
216 |
-
$uri =
|
217 |
$ver = $stylesheet->getMTime();
|
218 |
|
219 |
|
1 |
<?php
|
2 |
+
//Required to use get_home_path()
|
3 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
4 |
+
include_once(WPSCSS_PLUGIN_DIR . '/scssphp/scss.inc.php');
|
5 |
use ScssPhp\ScssPhp\Compiler;
|
6 |
|
7 |
class Wp_Scss {
|
26 |
*/
|
27 |
public function __construct ($scss_dir, $css_dir, $compile_method, $sourcemaps) {
|
28 |
global $scssc;
|
29 |
+
$this->scss_dir = $scss_dir;
|
30 |
+
$this->css_dir = $css_dir;
|
31 |
+
$this->compile_method = $compile_method;
|
32 |
+
$this->compile_errors = array();
|
33 |
+
$scssc = new Compiler();
|
34 |
|
35 |
$scssc->setFormatter( $compile_method );
|
36 |
$scssc->setImportPaths( $this->scss_dir );
|
158 |
* @return bool - true if compiling is needed
|
159 |
*/
|
160 |
public function needs_compiling() {
|
161 |
+
global $wpscss_settings;
|
162 |
+
if (defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE || $wpscss_settings['always_recompile'] === "1") {
|
163 |
return true;
|
164 |
}
|
165 |
|
210 |
* @param $css_folder - directory from theme root. We need this passed in separately
|
211 |
* so it can be used in a url, not path
|
212 |
*/
|
213 |
+
public function enqueue_files($base_folder_path, $css_folder) {
|
214 |
|
215 |
+
$relative_path = explode(get_home_path(), $base_folder_path)[1];
|
216 |
foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) {
|
217 |
if ( pathinfo($stylesheet->getFilename(), PATHINFO_EXTENSION) == 'css' ) {
|
218 |
$name = $stylesheet->getBasename('.css') . '-style';
|
219 |
+
$uri = '/'.$relative_path.$css_folder.$stylesheet->getFilename();
|
220 |
$ver = $stylesheet->getMTime();
|
221 |
|
222 |
|
options.php
CHANGED
@@ -78,9 +78,27 @@ class Wp_Scss_Settings
|
|
78 |
'wpscss_options' // Page
|
79 |
);
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
add_settings_field(
|
82 |
'wpscss_scss_dir', // ID
|
83 |
-
'
|
84 |
array( $this, 'input_text_callback' ), // Callback
|
85 |
'wpscss_options', // Page
|
86 |
'wpscss_paths_section', // Section
|
@@ -117,14 +135,14 @@ class Wp_Scss_Settings
|
|
117 |
array( // args
|
118 |
'name' => 'compiling_options',
|
119 |
'type' => apply_filters( 'wp_scss_compiling_modes',
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
)
|
129 |
)
|
130 |
);
|
@@ -184,6 +202,24 @@ class Wp_Scss_Settings
|
|
184 |
)
|
185 |
);
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
}
|
188 |
|
189 |
/**
|
@@ -210,7 +246,7 @@ class Wp_Scss_Settings
|
|
210 |
* Print the Section text
|
211 |
*/
|
212 |
public function print_paths_info() {
|
213 |
-
print '
|
214 |
}
|
215 |
public function print_compile_info() {
|
216 |
print 'Choose how you would like SCSS and source maps to be compiled and how you would like the plugin to handle errors';
|
@@ -249,9 +285,15 @@ class Wp_Scss_Settings
|
|
249 |
*/
|
250 |
public function input_checkbox_callback( $args ) {
|
251 |
$this->options = get_option( 'wpscss_options' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
-
$html = '<input type="checkbox" id="' . esc_attr( $args['name'] ) . '" name="wpscss_options[' . esc_attr( $args['name'] ) . ']" value="1"' . checked( 1, isset( $this->options[esc_attr( $args['name'] )] ) ? $this->options[esc_attr( $args['name'] )] : 0, false ) . '/>';
|
254 |
-
$html .= '<label for="' . esc_attr( $args['name'] ) . '"></label>';
|
255 |
|
256 |
echo $html;
|
257 |
}
|
78 |
'wpscss_options' // Page
|
79 |
);
|
80 |
|
81 |
+
add_settings_field(
|
82 |
+
'wpscss_base_folder', // ID
|
83 |
+
'Base Location', // Title
|
84 |
+
array( $this, 'input_select_callback' ), // Callback
|
85 |
+
'wpscss_options', // Page
|
86 |
+
'wpscss_paths_section', // Section
|
87 |
+
array( // args
|
88 |
+
'name' => 'base_compiling_folder',
|
89 |
+
'type' => apply_filters( 'wp_scss_base_compiling_modes',
|
90 |
+
array(
|
91 |
+
get_stylesheet_directory() => 'Current theme',
|
92 |
+
wp_get_upload_dir()['basedir'] => 'Uploads directory',
|
93 |
+
WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin',
|
94 |
+
)
|
95 |
+
)
|
96 |
+
)
|
97 |
+
);
|
98 |
+
|
99 |
add_settings_field(
|
100 |
'wpscss_scss_dir', // ID
|
101 |
+
'SCSS Location', // Title
|
102 |
array( $this, 'input_text_callback' ), // Callback
|
103 |
'wpscss_options', // Page
|
104 |
'wpscss_paths_section', // Section
|
135 |
array( // args
|
136 |
'name' => 'compiling_options',
|
137 |
'type' => apply_filters( 'wp_scss_compiling_modes',
|
138 |
+
array(
|
139 |
+
'ScssPhp\ScssPhp\Formatter\Expanded' => 'Expanded',
|
140 |
+
'ScssPhp\ScssPhp\Formatter\Nested' => 'Nested',
|
141 |
+
'ScssPhp\ScssPhp\Formatter\Compressed' => 'Compressed',
|
142 |
+
'ScssPhp\ScssPhp\Formatter\Compact' => 'Compact',
|
143 |
+
'ScssPhp\ScssPhp\Formatter\Crunched' => 'Crunched',
|
144 |
+
'ScssPhp\ScssPhp\Formatter\Debug' => 'Debug'
|
145 |
+
)
|
146 |
)
|
147 |
)
|
148 |
);
|
202 |
)
|
203 |
);
|
204 |
|
205 |
+
// Development options
|
206 |
+
add_settings_section(
|
207 |
+
'wpscss_development_section', // ID
|
208 |
+
'Development Settings', // Title
|
209 |
+
'', // Callback
|
210 |
+
'wpscss_options' // Page
|
211 |
+
);
|
212 |
+
|
213 |
+
add_settings_field(
|
214 |
+
'wpscss_scss_always_recompile', // ID
|
215 |
+
'Always Recompile', // Title
|
216 |
+
array( $this, 'input_checkbox_callback' ), // Callback
|
217 |
+
'wpscss_options', // Page
|
218 |
+
'wpscss_development_section', // Section
|
219 |
+
array( // args
|
220 |
+
'name' => 'always_recompile',
|
221 |
+
)
|
222 |
+
);
|
223 |
}
|
224 |
|
225 |
/**
|
246 |
* Print the Section text
|
247 |
*/
|
248 |
public function print_paths_info() {
|
249 |
+
print 'Location of your SCSS/CSS folders. Folders must be nested under your <b>Base Location</b> and start with <code>/</code>.</br>Examples: <code>/custom-scss/</code> and <code>/custom-css/</code>';
|
250 |
}
|
251 |
public function print_compile_info() {
|
252 |
print 'Choose how you would like SCSS and source maps to be compiled and how you would like the plugin to handle errors';
|
285 |
*/
|
286 |
public function input_checkbox_callback( $args ) {
|
287 |
$this->options = get_option( 'wpscss_options' );
|
288 |
+
$html = "";
|
289 |
+
if($args['name'] == 'always_recompile' && defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE){
|
290 |
+
$html .= '<input type="checkbox" id="' . esc_attr( $args['name'] ) . '" name="wpscss_options[' . esc_attr( $args['name'] ) . ']" value="1"' . checked( 1, isset( $this->options[esc_attr( $args['name'] )] ) ? $this->options[esc_attr( $args['name'] )] : 1, false ) . ' disabled=disabled/>';
|
291 |
+
$html .= '<label for="' . esc_attr( $args['name'] ) . '">Currently overwritten by constant <code>WP_SCSS_ALWAYS_RECOMPILE</code></label>';
|
292 |
+
}else{
|
293 |
+
$html .= '<input type="checkbox" id="' . esc_attr( $args['name'] ) . '" name="wpscss_options[' . esc_attr( $args['name'] ) . ']" value="1"' . checked( 1, isset( $this->options[esc_attr( $args['name'] )] ) ? $this->options[esc_attr( $args['name'] )] : 0, false ) . '/>';
|
294 |
+
$html .= '<label for="' . esc_attr( $args['name'] ) . '"></label>';
|
295 |
+
}
|
296 |
|
|
|
|
|
297 |
|
298 |
echo $html;
|
299 |
}
|
readme.md
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# WP-SCSS
|
2 |
+
#### A lightweight SCSS compiler for Wordpress.
|
3 |
+
|
4 |
+
Compiles .scss files on your wordpress install using [scssphp](https://github.com/scssphp/scssphp). Includes settings page for configuring directories, error reporting, compiling options, and auto enqueuing.
|
5 |
+
|
6 |
+
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.
|
7 |
+
|
8 |
+
## Settings
|
9 |
+
|
10 |
+
#### Directories
|
11 |
+
Directories are defined relative to your `base compile folder` which defaults to the theme folder. Alternatly you can choose the uploads directory or plugin directory. They must be separate from one another, so you cannot define the root folder to compile into itself.
|
12 |
+
|
13 |
+
Ideally you should setup a scss folder and a css folder within your theme. This will ensure the most accurate compiling.
|
14 |
+
|
15 |
+
library
|
16 |
+
|-css
|
17 |
+
| --style.css
|
18 |
+
| --ie.css
|
19 |
+
|-scss
|
20 |
+
| --style.scss
|
21 |
+
| --ie.scss
|
22 |
+
|
23 |
+
#### Compiling Mode
|
24 |
+
Compiling comes in five modes:
|
25 |
+
|
26 |
+
* Expanded - Full open css. One line per property. Brackets close on their own line.
|
27 |
+
* Nested - Lightly compressed css. Brackets close with css block. Indents to match scss nesting.
|
28 |
+
* Compressed - More compressed css. Entire rule block on one line. No indentation.
|
29 |
+
* Compact - Removes all line breaks, unnecessary whitespace, and single-line comments.
|
30 |
+
* Crunched - Same as Compressed, but also removes multi-line comments.
|
31 |
+
|
32 |
+
See examples of each in [scssphp's documentation](http://scssphp.github.io/scssphp)
|
33 |
+
|
34 |
+
#### Source Map Mode
|
35 |
+
Source maps come in three modes:
|
36 |
+
|
37 |
+
* None - No source map will be generated.
|
38 |
+
* Inline - A source map will be generated in the compiled CSS file.
|
39 |
+
* File - A source map will be generated as a standalone file in the compiled CSS directory.
|
40 |
+
|
41 |
+
#### Error Display
|
42 |
+
'Show in Header' will post a message on the front end when errors have occured. This helps debug as you write your scss.
|
43 |
+
|
44 |
+
If you're working on a live/production site, you can send errors to a log. This will create a log file in your scss directory and print errors there as they occur. Just keep an eye on it, because the css will not be updated until errors have been resolved.
|
45 |
+
|
46 |
+
#### Enqueuing
|
47 |
+
The plugin can automatically add your css files to the header for you. This option will [enqueue](http://codex.wordpress.org/Function_Reference/wp_enqueue_style) all files found in the css directory defined in the settings. Keep this in mind if you have other non-compiled css files in this folder. The plugin will add them to the header, just don't reenque them somewhere else.
|
48 |
+
|
49 |
+
Also keep in mind, that if you disable this plugin it can no longer enqueue files for you.
|
50 |
+
|
51 |
+
## Directions
|
52 |
+
*This plugin requires at least php 5.6 to work.*
|
53 |
+
|
54 |
+
#### Importing Subfiles
|
55 |
+
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.
|
56 |
+
|
57 |
+
When importing in your scss file, you can leave off the underscore.
|
58 |
+
|
59 |
+
@import 'subfile';
|
60 |
+
|
61 |
+
#### Setting Variables via PHP
|
62 |
+
You can set SCSS variables in your theme or plugin by using the wp_scss_variables filter.
|
63 |
+
|
64 |
+
function wp_scss_set_variables(){
|
65 |
+
$variables = array(
|
66 |
+
'black' => '#000',
|
67 |
+
'white' => '#fff'
|
68 |
+
);
|
69 |
+
return $variables;
|
70 |
+
}
|
71 |
+
add_filter('wp_scss_variables','wp_scss_set_variables');
|
72 |
+
|
73 |
+
#### Always Recompile
|
74 |
+
During development it's sometimes useful to force stylesheet compilation on every page load. Especially on hosts where filemtime() is not updating consistently.
|
75 |
+
|
76 |
+
You can tell the plugin to always recompile in the plugin options page or by adding the following constant to your wp-config.php or functions.php file.
|
77 |
+
|
78 |
+
define('WP_SCSS_ALWAYS_RECOMPILE', true);
|
79 |
+
|
80 |
+
#### Compass Support
|
81 |
+
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.
|
82 |
+
|
83 |
+
compass / frameworks / compass / stylesheets /
|
84 |
+
@import 'compass';
|
85 |
+
|
86 |
+
Alternatively, you can include [Bourbon](https://github.com/thoughtbot/bourbon) in a similar fashion.
|
87 |
+
|
88 |
+
#### .sass Support
|
89 |
+
This plugin will only work with .scss format.
|
90 |
+
|
91 |
+
## Changelog
|
92 |
+
* 2.1.1
|
93 |
+
* Bug fixes after merging 2.0.2 and 2.1.0 defaults worked, but new options did not. [Shadoath](https://github.com/ConnectThink/WP-SCSS/issues/165)
|
94 |
+
* 2.1.0
|
95 |
+
* Settings dropdown added for choosing additional base compile locations outside of current theme. Suggestion by [pixeldesignstudio ](https://github.com/ConnectThink/WP-SCSS/issues/127)
|
96 |
+
* 2.0.2
|
97 |
+
* Added option in settings to enable an 'always recompile' flag. Suggestion by [bick](https://github.com/ConnectThink/WP-SCSS/issues/151)
|
98 |
+
* 2.0.1
|
99 |
+
* Bugfix to add filter for option_wpscss_options to remove Leafo if stored in DB. Thanks to [kinsky-org](https://github.com/ConnectThink/WP-SCSS/issues/157) for pointing this out
|
100 |
+
* Saving plugin settings will update DB with correct value.
|
101 |
+
* 2.0.0
|
102 |
+
* Requires PHP 5.6
|
103 |
+
* Update src to use [ScssPHP github repo at 1.0.2](https://github.com/scssphp/scssphp/tree/1.0.2)
|
104 |
+
* Added check to make sure 'compiler' function was not already defined. [Shadoath](https://github.com/ConnectThink/WP-SCSS/pull/155)
|
105 |
+
* 1.2.6
|
106 |
+
* Create cache dir if it doesn't exist [@XNBlank](https://github.com/ConnectThink/WP-SCSS/pull/135)
|
107 |
+
* Add cache dir as default [@mhbapcc](https://github.com/ConnectThink/WP-SCSS/pull/144)
|
108 |
+
* 1.2.5
|
109 |
+
* Fix error when ".*" folders exist [@chameron](https://github.com/ConnectThink/WP-SCSS/pull/111)
|
110 |
+
* Add detailed error description for the directory settings [@andreyc0d3r](https://github.com/ConnectThink/WP-SCSS/pull/121)
|
111 |
+
* Fix on SASS compilation trigger [@fazzinipierluigi](https://github.com/ConnectThink/WP-SCSS/pull/122)
|
112 |
+
* 1.2.4
|
113 |
+
* Updated scssphp to version 0.7.5
|
114 |
+
* Added source map [@iannacone](https://github.com/ConnectThink/WP-SCSS/issues/49)
|
115 |
+
* Always define $wpscss_compiler in the global scope [@jazbek](https://github.com/ConnectThink/WP-SCSS/pull/98)
|
116 |
+
* 1.2.3
|
117 |
+
* Updated scssphp to version 0.7.2 [@hellerbenjamin](https://github.com/ConnectThink/WP-SCSS/pull/86)
|
118 |
+
* Removed depricated screen_icon()
|
119 |
+
* 1.2.2
|
120 |
+
* Updated scssphp to version 0.6.6
|
121 |
+
* 1.2.1
|
122 |
+
* Changed set version option to update if already exists
|
123 |
+
* 1.2.0
|
124 |
+
* Fixed a bug where directory inputs were not getting sanitized [@mmcev106](https://github.com/ConnectThink/WP-SCSS/pull/66)
|
125 |
+
* Made the missing directory warning also display if a specified path is a file [@mmcev106](https://github.com/ConnectThink/WP-SCSS/pull/65)
|
126 |
+
* Added /vendor to .gitignore [@mmcev106](https://github.com/ConnectThink/WP-SCSS/pull/64)
|
127 |
+
* Dont enqueue already enqueued stylesheets [@bobbysmith007](https://github.com/ConnectThink/WP-SCSS/pull/61)
|
128 |
+
* 1.1.9 - Added filter to set variables via PHP [@ohlle](https://github.com/ohlle) and option to minify CSS output [@mndewitt](https://github.com/mndewitt)
|
129 |
+
* 1.1.8 - Various improvements from pull requests by [@jbrains](https://github.com/jbrains) and [@brainfork](https://github.com/brainfork)
|
130 |
+
* 1.1.7 - Update scssphp to 0.0.12 - pull from #16 [@GabrielGil](https://github.com/GabrielGil)
|
131 |
+
* 1.1.6 - Upgraded scss.inc.php to version 0.0.10 - pull from #12 [@kirkhoff](https://github.com/kirkhoff)
|
132 |
+
* 1.1.5 - Added option to only show errors to logged in users - merge from #10 [@tolnem](https://github.com/tolnem)
|
133 |
+
* 1.1.4 - Add support for subfolders in scss directory
|
134 |
+
* 1.1.3 - Fix print bug (2) in header
|
135 |
+
* 1.1.2 - Add support for moved wp-content directory
|
136 |
+
* 1.1.1 - Catch permissions errors
|
137 |
+
* 1.0.0 - Initial Release
|
138 |
+
|
139 |
+
## License
|
140 |
+
This plugin is developed and maintained by Connect Think and contributers.
|
141 |
+
[GPL V3](http://www.gnu.org/copyleft/gpl.html)
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: connectthink
|
|
3 |
Tags: sass, scss, css
|
4 |
Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
Requires at least: 3.0.1
|
6 |
-
|
7 |
Stable tag: 2.0.1
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/copyleft/gpl.html
|
3 |
Tags: sass, scss, css
|
4 |
Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
Requires at least: 3.0.1
|
6 |
+
tested up to: 5.6.1
|
7 |
Stable tag: 2.0.1
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/copyleft/gpl.html
|
wp-scss.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WP-SCSS
|
4 |
* Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
* Description: Compiles scss files live on WordPress.
|
6 |
-
* Version: 2.
|
7 |
* Author: Connect Think
|
8 |
* Author URI: http://connectthink.com
|
9 |
* License: GPLv3
|
@@ -17,10 +17,11 @@
|
|
17 |
* b. wp-scss class - manages compiling
|
18 |
* c. options class - builds settings page
|
19 |
* 3. Registering Settings Page and Options
|
20 |
-
* 4.
|
21 |
-
* 5.
|
22 |
-
* 6.
|
23 |
-
* 7.
|
|
|
24 |
*/
|
25 |
|
26 |
|
@@ -29,9 +30,6 @@
|
|
29 |
*/
|
30 |
|
31 |
// Plugin Paths
|
32 |
-
if (!defined('WPSCSS_THEME_DIR'))
|
33 |
-
define('WPSCSS_THEME_DIR', get_stylesheet_directory());
|
34 |
-
|
35 |
if (!defined('WPSCSS_PLUGIN_NAME'))
|
36 |
define('WPSCSS_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
|
37 |
|
@@ -46,7 +44,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', '2.
|
50 |
|
51 |
// Add version to options table
|
52 |
if ( get_option( WPSCSS_VERSION_KEY ) !== false ) {
|
@@ -104,7 +102,7 @@ function wpscss_plugin_action_links($links, $file) {
|
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
-
*
|
108 |
*
|
109 |
* Correction for when Leafo is stored in DB
|
110 |
* as a value in compiling_options
|
@@ -118,7 +116,7 @@ function wpscss_plugin_db_cleanup($option_values){
|
|
118 |
}
|
119 |
|
120 |
/**
|
121 |
-
*
|
122 |
*
|
123 |
* Pull settings from options table
|
124 |
* Scrub empty fields or directories that don't exists
|
@@ -126,51 +124,53 @@ function wpscss_plugin_db_cleanup($option_values){
|
|
126 |
*/
|
127 |
|
128 |
$wpscss_options = get_option( 'wpscss_options' );
|
|
|
129 |
$scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : '';
|
130 |
$css_dir_setting = isset($wpscss_options['css_dir']) ? $wpscss_options['css_dir'] : '';
|
131 |
|
132 |
-
// Checks if directories are
|
133 |
if( $scss_dir_setting == false || $css_dir_setting == false ) {
|
134 |
function wpscss_settings_error() {
|
135 |
echo '<div class="error">
|
136 |
-
<p><strong>
|
137 |
</div>';
|
138 |
}
|
139 |
add_action('admin_notices', 'wpscss_settings_error');
|
140 |
return 0; //exits
|
141 |
|
142 |
-
// Checks if directory exists
|
143 |
-
} elseif ( !is_dir(
|
144 |
-
function
|
145 |
echo '<div class="error">
|
146 |
-
<p><strong>
|
147 |
</div>';
|
148 |
-
}
|
149 |
-
add_action('admin_notices', 'wpscss_settings_error');
|
150 |
return 0; //exits
|
151 |
-
|
152 |
-
|
|
|
|
|
153 |
echo '<div class="error">
|
154 |
-
<p><strong>
|
155 |
</div>';
|
156 |
-
}
|
157 |
-
add_action('admin_notices', 'wpscss_settings_error');
|
158 |
return 0; //exits
|
159 |
}
|
160 |
|
161 |
// Plugin Settings
|
162 |
$wpscss_settings = array(
|
163 |
-
'scss_dir'
|
164 |
-
'css_dir'
|
165 |
-
'compiling'
|
166 |
-
'
|
167 |
-
'
|
168 |
-
'
|
|
|
169 |
);
|
170 |
|
171 |
|
172 |
/**
|
173 |
-
*
|
174 |
*
|
175 |
* Passes settings to the object
|
176 |
* If needs_compiling passes, runs compile method
|
@@ -210,7 +210,7 @@ function wp_scss_compile() {
|
|
210 |
}
|
211 |
|
212 |
/**
|
213 |
-
*
|
214 |
*
|
215 |
* First block handles print errors to front end.
|
216 |
* This adds a small style block the header to help errors get noticed
|
@@ -294,13 +294,13 @@ function wpscss_handle_errors() {
|
|
294 |
|
295 |
|
296 |
/**
|
297 |
-
*
|
298 |
*/
|
299 |
|
300 |
if ( $wpscss_settings['enqueue'] == '1' ) {
|
301 |
function wpscss_enqueue_styles() {
|
302 |
global $wpscss_compiler, $wpscss_options;
|
303 |
-
$wpscss_compiler->enqueue_files($wpscss_options['css_dir']);
|
304 |
}
|
305 |
add_action('wp_enqueue_scripts', 'wpscss_enqueue_styles', 50);
|
306 |
}
|
3 |
* Plugin Name: WP-SCSS
|
4 |
* Plugin URI: https://github.com/ConnectThink/WP-SCSS
|
5 |
* Description: Compiles scss files live on WordPress.
|
6 |
+
* Version: 2.1.1
|
7 |
* Author: Connect Think
|
8 |
* Author URI: http://connectthink.com
|
9 |
* License: GPLv3
|
17 |
* b. wp-scss class - manages compiling
|
18 |
* c. options class - builds settings page
|
19 |
* 3. Registering Settings Page and Options
|
20 |
+
* 4. Read correct DB values for version 2.0.1 (Leafo => ScssPhp)
|
21 |
+
* 5. Assign plugin settings
|
22 |
+
* 6. Instantiate wp_scss object and run compiler
|
23 |
+
* 7. Handle Errors
|
24 |
+
* 8. Enqueue Styles
|
25 |
*/
|
26 |
|
27 |
|
30 |
*/
|
31 |
|
32 |
// Plugin Paths
|
|
|
|
|
|
|
33 |
if (!defined('WPSCSS_PLUGIN_NAME'))
|
34 |
define('WPSCSS_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
|
35 |
|
44 |
define('WPSCSS_VERSION_KEY', 'wpscss_version');
|
45 |
|
46 |
if (!defined('WPSCSS_VERSION_NUM'))
|
47 |
+
define('WPSCSS_VERSION_NUM', '2.1.1');
|
48 |
|
49 |
// Add version to options table
|
50 |
if ( get_option( WPSCSS_VERSION_KEY ) !== false ) {
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
+
* 4. UPDATE DATABASE VALUES
|
106 |
*
|
107 |
* Correction for when Leafo is stored in DB
|
108 |
* as a value in compiling_options
|
116 |
}
|
117 |
|
118 |
/**
|
119 |
+
* 5. PLUGIN SETTINGS
|
120 |
*
|
121 |
* Pull settings from options table
|
122 |
* Scrub empty fields or directories that don't exists
|
124 |
*/
|
125 |
|
126 |
$wpscss_options = get_option( 'wpscss_options' );
|
127 |
+
$base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? $wpscss_options['base_compiling_folder'] : get_stylesheet_directory();
|
128 |
$scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : '';
|
129 |
$css_dir_setting = isset($wpscss_options['css_dir']) ? $wpscss_options['css_dir'] : '';
|
130 |
|
131 |
+
// Checks if directories are not yet defined
|
132 |
if( $scss_dir_setting == false || $css_dir_setting == false ) {
|
133 |
function wpscss_settings_error() {
|
134 |
echo '<div class="error">
|
135 |
+
<p><strong>WP-SCSS</strong> requires both directories be specified. <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wpscss_options">Please update your settings.</a></p>
|
136 |
</div>';
|
137 |
}
|
138 |
add_action('admin_notices', 'wpscss_settings_error');
|
139 |
return 0; //exits
|
140 |
|
141 |
+
// Checks if SCSS directory exists
|
142 |
+
} elseif ( !is_dir($base_compiling_folder . $scss_dir_setting) ) {
|
143 |
+
add_action('admin_notices', function() use ($base_compiling_folder, $scss_dir_setting){
|
144 |
echo '<div class="error">
|
145 |
+
<p><strong>WP-SCSS:</strong> The SCSS directory does not exist (' . $base_compiling_folder . $scss_dir_setting . '). Please create the directory or <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wpscss_options">update your settings.</a></p>
|
146 |
</div>';
|
147 |
+
});
|
|
|
148 |
return 0; //exits
|
149 |
+
|
150 |
+
// Checks if CSS directory exists
|
151 |
+
} elseif ( !is_dir($base_compiling_folder . $css_dir_setting) ) {
|
152 |
+
add_action('admin_notices', function() use ($base_compiling_folder, $css_dir_setting){
|
153 |
echo '<div class="error">
|
154 |
+
<p><strong>WP-SCSS:</strong> The CSS directory does not exist (' . $base_compiling_folder . $css_dir_setting . '). Please create the directory or <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wpscss_options">update your settings.</a></p>
|
155 |
</div>';
|
156 |
+
});
|
|
|
157 |
return 0; //exits
|
158 |
}
|
159 |
|
160 |
// Plugin Settings
|
161 |
$wpscss_settings = array(
|
162 |
+
'scss_dir' => $base_compiling_folder . $scss_dir_setting,
|
163 |
+
'css_dir' => $base_compiling_folder . $css_dir_setting,
|
164 |
+
'compiling' => isset($wpscss_options['compiling_options']) ? $wpscss_options['compiling_options'] : 'ScssPhp\ScssPhp\Formatter\Expanded',
|
165 |
+
'always_recompile' => isset($wpscss_options['always_recompile']) ? $wpscss_options['always_recompile'] : false,
|
166 |
+
'errors' => isset($wpscss_options['errors']) ? $wpscss_options['errors'] : 'show',
|
167 |
+
'sourcemaps' => isset($wpscss_options['sourcemap_options']) ? $wpscss_options['sourcemap_options'] : 'SOURCE_MAP_NONE',
|
168 |
+
'enqueue' => isset($wpscss_options['enqueue']) ? $wpscss_options['enqueue'] : 0
|
169 |
);
|
170 |
|
171 |
|
172 |
/**
|
173 |
+
* 6. INSTANTIATE & EXECUTE COMPILER
|
174 |
*
|
175 |
* Passes settings to the object
|
176 |
* If needs_compiling passes, runs compile method
|
210 |
}
|
211 |
|
212 |
/**
|
213 |
+
* 7. HANDLE COMPILING ERRORS
|
214 |
*
|
215 |
* First block handles print errors to front end.
|
216 |
* This adds a small style block the header to help errors get noticed
|
294 |
|
295 |
|
296 |
/**
|
297 |
+
* 8. ENQUEUE STYLES
|
298 |
*/
|
299 |
|
300 |
if ( $wpscss_settings['enqueue'] == '1' ) {
|
301 |
function wpscss_enqueue_styles() {
|
302 |
global $wpscss_compiler, $wpscss_options;
|
303 |
+
$wpscss_compiler->enqueue_files($wpscss_options['base_compiling_folder'], $wpscss_options['css_dir']);
|
304 |
}
|
305 |
add_action('wp_enqueue_scripts', 'wpscss_enqueue_styles', 50);
|
306 |
}
|