Skip to content

Commit

Permalink
Merge pull request #162 from ConnectThink/always-recompile-setting
Browse files Browse the repository at this point in the history
Always recompile setting
  • Loading branch information
shadoath authored Feb 13, 2021
2 parents 42b2e8b + fea472a commit b861221
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
18 changes: 10 additions & 8 deletions class/class-wp-scss.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
Expand Down Expand Up @@ -157,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) {
global $always_recompile;
if (defined('WP_SCSS_ALWAYS_RECOMPILE') && WP_SCSS_ALWAYS_RECOMPILE || $always_recompile) {
return true;
}

Expand Down
28 changes: 26 additions & 2 deletions options.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@ public function page_init()
)
);

// Development options
add_settings_section(
'wpscss_development_section', // ID
'Development Settings', // Title
'', // 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_development_section', // Section
array( // args
'name' => 'always_recompile',
)
);
}

/**
Expand Down Expand Up @@ -249,9 +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 .= '<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/>';
$html .= '<label for="' . esc_attr( $args['name'] ) . '">Currently overwritten by constant <code>WP_SCSS_ALWAYS_RECOMPILE</code></label>';
}else{
$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 ) . '/>';
$html .= '<label for="' . esc_attr( $args['name'] ) . '"></label>';
}

$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 ) . '/>';
$html .= '<label for="' . esc_attr( $args['name'] ) . '"></label>';

echo $html;
}
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 10 additions & 8 deletions wp-scss.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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
);


Expand All @@ -181,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']
);

Expand Down

0 comments on commit b861221

Please sign in to comment.