From d8406d4614866ec74d1b8f421f82e95cb2f1ff66 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 9 Feb 2021 08:34:12 -0700 Subject: [PATCH 1/5] Add setting to always recompile --- class/class-wp-scss.php | 15 ++++++++------- options.php | 23 +++++++++++++++++++++++ wp-scss.php | 13 +++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/class/class-wp-scss.php b/class/class-wp-scss.php index 6f2721d..98bd6bb 100644 --- a/class/class-wp-scss.php +++ b/class/class-wp-scss.php @@ -23,13 +23,14 @@ class Wp_Scss { * * @var array compile_errors - catches errors from compile */ - public function __construct ($scss_dir, $css_dir, $compile_method, $sourcemaps) { + public function __construct ($scss_dir, $css_dir, $compile_method, $always_recompile, $sourcemaps) { global $scssc; - $this->scss_dir = $scss_dir; - $this->css_dir = $css_dir; - $this->compile_method = $compile_method; - $this->compile_errors = array(); - $scssc = new Compiler(); + $this->scss_dir = $scss_dir; + $this->css_dir = $css_dir; + $this->compile_method = $compile_method; + $this->always_recompile = $always_recompile; + $this->compile_errors = array(); + $scssc = new Compiler(); $scssc->setFormatter( $compile_method ); $scssc->setImportPaths( $this->scss_dir ); @@ -157,7 +158,7 @@ function compiler($in, $out, $instance) { * @return bool - true if compiling is needed */ public function needs_compiling() { - if (defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE) { + if (defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE || $instance->always_recompile) { return true; } diff --git a/options.php b/options.php index da54309..77642d8 100644 --- a/options.php +++ b/options.php @@ -184,6 +184,26 @@ public function page_init() ) ); + // Developer options + add_settings_section( + 'wpscss_developer_section', // ID + 'Developer Settings', // Title + array( $this, 'print_developer_info' ), // Callback + 'wpscss_options' // Page + ); + + add_settings_field( + 'wpscss_scss_always_recompile', // ID + 'Always Recompile', // Title + array( $this, 'input_checkbox_callback' ), // Callback + 'wpscss_options', // Page + 'wpscss_developer_section', // Section + array( // args + 'name' => 'always_recompile', + ) + ); + + } /** @@ -218,6 +238,9 @@ public function print_compile_info() { public function print_enqueue_info() { print 'WP-SCSS can enqueue your css stylesheets in the header automatically.'; } + public function print_developer_info() { + print 'Quickly change developer settings. Best not to use on production websites.'; + } /** * Text Fields' Callback diff --git a/wp-scss.php b/wp-scss.php index 9084077..dc7d010 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -160,12 +160,13 @@ function wpscss_settings_error() { // Plugin Settings $wpscss_settings = array( - 'scss_dir' => WPSCSS_THEME_DIR . $scss_dir_setting, - 'css_dir' => WPSCSS_THEME_DIR . $css_dir_setting, - 'compiling' => isset($wpscss_options['compiling_options']) ? $wpscss_options['compiling_options'] : 'ScssPhp\ScssPhp\Formatter\Expanded', - 'errors' => isset($wpscss_options['errors']) ? $wpscss_options['errors'] : 'show', - 'sourcemaps' => isset($wpscss_options['sourcemap_options']) ? $wpscss_options['sourcemap_options'] : 'SOURCE_MAP_NONE', - 'enqueue' => isset($wpscss_options['enqueue']) ? $wpscss_options['enqueue'] : 0 + 'scss_dir' => WPSCSS_THEME_DIR . $scss_dir_setting, + 'css_dir' => WPSCSS_THEME_DIR . $css_dir_setting, + 'compiling' => isset($wpscss_options['compiling_options']) ? $wpscss_options['compiling_options'] : 'ScssPhp\ScssPhp\Formatter\Expanded', + 'always_recompile' => isset($wpscss_options['always_recompile']) ? $wpscss_options['always_recompile'] : false + 'errors' => isset($wpscss_options['errors']) ? $wpscss_options['errors'] : 'show', + 'sourcemaps' => isset($wpscss_options['sourcemap_options']) ? $wpscss_options['sourcemap_options'] : 'SOURCE_MAP_NONE', + 'enqueue' => isset($wpscss_options['enqueue']) ? $wpscss_options['enqueue'] : 0 ); From 9019e3814ad98cdc3198f5edc7b52798ccb8617c Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 9 Feb 2021 09:09:26 -0700 Subject: [PATCH 2/5] Corrections to always recompile --- class/class-wp-scss.php | 5 +++-- wp-scss.php | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/class/class-wp-scss.php b/class/class-wp-scss.php index 98bd6bb..05f138b 100644 --- a/class/class-wp-scss.php +++ b/class/class-wp-scss.php @@ -10,7 +10,7 @@ class Wp_Scss { * @var string * @access public */ - public $scss_dir, $css_dir, $compile_method, $scssc, $compile_errors, $sourcemaps; + public $scss_dir, $css_dir, $compile_method, $always_recompile, $scssc, $compile_errors, $sourcemaps; /** * Set values for Wp_Scss::properties @@ -158,7 +158,8 @@ function compiler($in, $out, $instance) { * @return bool - true if compiling is needed */ public function needs_compiling() { - if (defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE || $instance->always_recompile) { + global $always_recompile; + if (defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE || $always_recompile) { return true; } diff --git a/wp-scss.php b/wp-scss.php index dc7d010..87d5491 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -163,10 +163,10 @@ function wpscss_settings_error() { 'scss_dir' => WPSCSS_THEME_DIR . $scss_dir_setting, 'css_dir' => WPSCSS_THEME_DIR . $css_dir_setting, 'compiling' => isset($wpscss_options['compiling_options']) ? $wpscss_options['compiling_options'] : 'ScssPhp\ScssPhp\Formatter\Expanded', - 'always_recompile' => isset($wpscss_options['always_recompile']) ? $wpscss_options['always_recompile'] : false - 'errors' => isset($wpscss_options['errors']) ? $wpscss_options['errors'] : 'show', + 'always_recompile' => isset($wpscss_options['always_recompile']) ? $wpscss_options['always_recompile'] : false, + 'errors' => isset($wpscss_options['errors']) ? $wpscss_options['errors'] : 'show', 'sourcemaps' => isset($wpscss_options['sourcemap_options']) ? $wpscss_options['sourcemap_options'] : 'SOURCE_MAP_NONE', - 'enqueue' => isset($wpscss_options['enqueue']) ? $wpscss_options['enqueue'] : 0 + 'enqueue' => isset($wpscss_options['enqueue']) ? $wpscss_options['enqueue'] : 0 ); @@ -182,6 +182,7 @@ function wpscss_settings_error() { $wpscss_settings['scss_dir'], $wpscss_settings['css_dir'], $wpscss_settings['compiling'], + $wpscss_settings['always_recompile'], $wpscss_settings['sourcemaps'] ); From 5fd08b543f22b4d47fcd309fb2d2ec04b3e3e3d3 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Fri, 12 Feb 2021 10:06:00 -0700 Subject: [PATCH 3/5] Disabled checkbox for always recompile --- options.php | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/options.php b/options.php index 77642d8..cfd12f6 100644 --- a/options.php +++ b/options.php @@ -192,16 +192,29 @@ public function page_init() 'wpscss_options' // Page ); - add_settings_field( - 'wpscss_scss_always_recompile', // ID - 'Always Recompile', // Title - array( $this, 'input_checkbox_callback' ), // Callback - 'wpscss_options', // Page - 'wpscss_developer_section', // Section - array( // args - 'name' => 'always_recompile', - ) - ); + if(WP_SCSS_ALWAYS_RECOMPILE){ + add_settings_field( + 'wpscss_scss_always_recompile', // ID + 'Always Recompile (disabled by WP_SCSS_ALWAYS_RECOMPILE)', // Title + array( $this, 'input_checkbox_disabled_callback' ), // Callback + 'wpscss_options', // Page + 'wpscss_developer_section', // Section + array( // args + 'name' => 'always_recompile', + ) + ); + }else{ + add_settings_field( + 'wpscss_scss_always_recompile', // ID + 'Always Recompile', // Title + array( $this, 'input_checkbox_callback' ), // Callback + 'wpscss_options', // Page + 'wpscss_developer_section', // Section + array( // args + 'name' => 'always_recompile', + ) + ); + } } @@ -278,4 +291,14 @@ public function input_checkbox_callback( $args ) { echo $html; } + + public function input_checkbox_disabled_callback( $args ) { + $this->options = get_option( 'wpscss_options' ); + + $html = ''; + $html .= ''; + + echo $html; + } } From 1479f4341bf8d5d52f3ccd81cf0b98c59455a3d2 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Fri, 12 Feb 2021 22:10:15 +0000 Subject: [PATCH 4/5] One checkbox to rule them ... Control recompile settings --- options.php | 68 ++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/options.php b/options.php index cfd12f6..b3142d1 100644 --- a/options.php +++ b/options.php @@ -184,39 +184,24 @@ public function page_init() ) ); - // Developer options + // Development options add_settings_section( - 'wpscss_developer_section', // ID - 'Developer Settings', // Title - array( $this, 'print_developer_info' ), // Callback - 'wpscss_options' // Page + 'wpscss_development_section', // ID + 'Development Settings', // Title + '', // Callback + 'wpscss_options' // Page ); - if(WP_SCSS_ALWAYS_RECOMPILE){ - add_settings_field( - 'wpscss_scss_always_recompile', // ID - 'Always Recompile (disabled by WP_SCSS_ALWAYS_RECOMPILE)', // Title - array( $this, 'input_checkbox_disabled_callback' ), // Callback - 'wpscss_options', // Page - 'wpscss_developer_section', // Section - array( // args - 'name' => 'always_recompile', - ) - ); - }else{ - add_settings_field( - 'wpscss_scss_always_recompile', // ID - 'Always Recompile', // Title - array( $this, 'input_checkbox_callback' ), // Callback - 'wpscss_options', // Page - 'wpscss_developer_section', // Section - array( // args - 'name' => 'always_recompile', - ) - ); - } - - + add_settings_field( + 'wpscss_scss_always_recompile', // ID + 'Always Recompile', // Title + array( $this, 'input_checkbox_callback' ), // Callback + 'wpscss_options', // Page + 'wpscss_development_section', // Section + array( // args + 'name' => 'always_recompile', + ) + ); } /** @@ -251,9 +236,6 @@ public function print_compile_info() { public function print_enqueue_info() { print 'WP-SCSS can enqueue your css stylesheets in the header automatically.'; } - public function print_developer_info() { - print 'Quickly change developer settings. Best not to use on production websites.'; - } /** * Text Fields' Callback @@ -285,19 +267,15 @@ public function input_select_callback( $args ) { */ public function input_checkbox_callback( $args ) { $this->options = get_option( 'wpscss_options' ); + $html = ""; + if($args['name'] == 'always_recompile' && defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE){ + $html .= 'options[esc_attr( $args['name'] )] ) ? $this->options[esc_attr( $args['name'] )] : 1, false ) . ' disabled=disabled/>'; + $html .= ''; + }else{ + $html .= 'options[esc_attr( $args['name'] )] ) ? $this->options[esc_attr( $args['name'] )] : 0, false ) . '/>'; + $html .= ''; + } - $html = 'options[esc_attr( $args['name'] )] ) ? $this->options[esc_attr( $args['name'] )] : 0, false ) . '/>'; - $html .= ''; - - echo $html; - } - - public function input_checkbox_disabled_callback( $args ) { - $this->options = get_option( 'wpscss_options' ); - - $html = ''; - $html .= ''; echo $html; } From fea472acc8e59ed988abc47e7991753686e9ebd9 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Fri, 12 Feb 2021 17:24:47 -0700 Subject: [PATCH 5/5] Version bump and readme update --- readme.md | 2 ++ wp-scss.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 0b92a60..d44bd5d 100644 --- a/readme.md +++ b/readme.md @@ -91,6 +91,8 @@ Alternatively, you can include [Bourbon](https://github.com/thoughtbot/bourbon) This plugin will only work with .scss format. ## Changelog +* 2.0.2 + * Added option in settings to enable an 'always recompile' flag. Suggestion by [bick](https://github.com/ConnectThink/WP-SCSS/issues/151) * 2.0.1 * 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 * Saving plugin settings will update DB with correct value. diff --git a/wp-scss.php b/wp-scss.php index 87d5491..3dbc2ae 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -3,7 +3,7 @@ * Plugin Name: WP-SCSS * Plugin URI: https://github.com/ConnectThink/WP-SCSS * Description: Compiles scss files live on WordPress. - * Version: 2.0.1 + * Version: 2.0.2 * Author: Connect Think * Author URI: http://connectthink.com * License: GPLv3 @@ -46,7 +46,7 @@ define('WPSCSS_VERSION_KEY', 'wpscss_version'); if (!defined('WPSCSS_VERSION_NUM')) - define('WPSCSS_VERSION_NUM', '2.0.1'); + define('WPSCSS_VERSION_NUM', '2.0.2'); // Add version to options table if ( get_option( WPSCSS_VERSION_KEY ) !== false ) {