From 078d3bb3cf56665ae13e0702387d34c115e60db0 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Wed, 8 Sep 2021 09:12:48 -0400 Subject: [PATCH 01/13] Test at new arrangement of folders --- options.php | 40 +++++++++++++++++++++++++++++++++------- wp-scss.php | 12 ++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/options.php b/options.php index d406cb6..bd89779 100644 --- a/options.php +++ b/options.php @@ -76,25 +76,51 @@ public function page_init() { 'wpscss_options' // Page ); + $base_folder_options = array( + wp_get_upload_dir()['basedir'] => 'Uploads Directory', + WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin' + ); + if(get_stylesheet_directory() === get_template_directory()){ + array_unshift($base_folder_options, array(get_stylesheet_directory() => 'Current Theme')); + }else{ + array_unshift($base_folder_options, array(get_template_directory() => 'Parent Theme')); + array_unshift($base_folder_options, array(get_stylesheet_directory() => 'Child Theme')); + } + + echo $base_folder_options; + add_settings_field( 'wpscss_base_folder', // ID 'Base Location', // Title array( $this, 'input_select_callback' ), // Callback 'wpscss_options', // Page - 'wpscss_paths_section', // Section + 'wpscss_paths_section', // Section array( // args 'name' => 'base_compiling_folder', 'type' => apply_filters( 'wp_scss_base_compiling_modes', - array( - get_template_directory() => 'Parent theme', // Won't display if no parent theme as it would have duplicate keys in array - get_stylesheet_directory() => (get_stylesheet_directory() === get_template_directory() ? 'Current theme' : 'Child theme'), - wp_get_upload_dir()['basedir'] => 'Uploads directory', - WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin', - ) + $base_folder_options + // array( + // get_template_directory() => 'Parent theme', // Won't display if no parent theme as it would have duplicate keys in array + // get_stylesheet_directory() => (get_stylesheet_directory() === get_template_directory() ? 'Current theme' : 'Child theme'), + // wp_get_upload_dir()['basedir'] => 'Uploads directory', + // WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin', + // ) ) ) ); + add_settings_field( + 'Use Absolute Path', // ID + 'Use Absolute Path', // Title + array( $this, 'input_checkbox_callback' ), // Callback + 'wpscss_options', // Page + 'wpscss_paths_section', // Section + array( // args + 'name' => 'use_absolute_paths' + ) + ); + + add_settings_field( 'wpscss_scss_dir', // ID 'SCSS Location', // Title diff --git a/wp-scss.php b/wp-scss.php index 1a8bcfd..3c89096 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -130,7 +130,19 @@ function wpscss_plugin_db_cleanup($option_values){ * Assign settings via settings array to pass to object */ +// Allow current WP to keep these values don't store to db +function get_base_dir_from_name($name){ + $possible_directories = array( + 'Parent Theme' => get_template_directory(), // Won't display if no parent theme as it would have duplicate keys in array + 'Current Theme' => get_stylesheet_directory(), + 'Child Theme' => get_stylesheet_directory(), + 'Uploads Directory' => wp_get_upload_dir()['basedir'], + 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, + ); + return $possible_directories[$name]; +} $wpscss_options = get_option( 'wpscss_options' ); +// $base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? get_base_dir_from_name($wpscss_options['base_compiling_folder']) : get_stylesheet_directory(); $base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? $wpscss_options['base_compiling_folder'] : get_stylesheet_directory(); $scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : ''; $css_dir_setting = isset($wpscss_options['css_dir']) ? $wpscss_options['css_dir'] : ''; From 6b7a621741786aaac19354c4b1b87409d4936816 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Wed, 8 Sep 2021 10:16:44 -0400 Subject: [PATCH 02/13] Test v2 of baseFolder name --- options.php | 10 +++++----- wp-scss.php | 12 ++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/options.php b/options.php index bd89779..66919ce 100644 --- a/options.php +++ b/options.php @@ -77,14 +77,14 @@ public function page_init() { ); $base_folder_options = array( - wp_get_upload_dir()['basedir'] => 'Uploads Directory', - WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin' + 'Uploads Directory' => 'Uploads Directory', + 'WP-SCSS Plugin' => 'WP-SCSS Plugin' ); if(get_stylesheet_directory() === get_template_directory()){ - array_unshift($base_folder_options, array(get_stylesheet_directory() => 'Current Theme')); + $base_folder_options['Current Theme'] = 'Current Theme'; }else{ - array_unshift($base_folder_options, array(get_template_directory() => 'Parent Theme')); - array_unshift($base_folder_options, array(get_stylesheet_directory() => 'Child Theme')); + $base_folder_options['Parent Theme'] = 'Parent Theme'; + $base_folder_options['Child Theme'] = 'Child Theme'; } echo $base_folder_options; diff --git a/wp-scss.php b/wp-scss.php index 3c89096..4606810 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -131,7 +131,7 @@ function wpscss_plugin_db_cleanup($option_values){ */ // Allow current WP to keep these values don't store to db -function get_base_dir_from_name($name){ +function get_base_dir_from_name($name_or_old_path){ $possible_directories = array( 'Parent Theme' => get_template_directory(), // Won't display if no parent theme as it would have duplicate keys in array 'Current Theme' => get_stylesheet_directory(), @@ -139,9 +139,17 @@ function get_base_dir_from_name($name){ 'Uploads Directory' => wp_get_upload_dir()['basedir'], 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, ); - return $possible_directories[$name]; + $directory_path = $possible_directories[$name_or_old_path]; + if($directory_path){ + return $directory_path; + }else{ + return $name_or_old_path; + } } + $wpscss_options = get_option( 'wpscss_options' ); +$test = get_base_dir_from_name($wpscss_options['base_compiling_folder']); +echo($test); // $base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? get_base_dir_from_name($wpscss_options['base_compiling_folder']) : get_stylesheet_directory(); $base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? $wpscss_options['base_compiling_folder'] : get_stylesheet_directory(); $scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : ''; From 451c73313f31cc07d89c152690b1a1a289f1af44 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Wed, 8 Sep 2021 14:28:54 +0000 Subject: [PATCH 03/13] looks to be good --- options.php | 2 +- wp-scss.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/options.php b/options.php index 66919ce..88fe1f2 100644 --- a/options.php +++ b/options.php @@ -87,7 +87,7 @@ public function page_init() { $base_folder_options['Child Theme'] = 'Child Theme'; } - echo $base_folder_options; + /* echo var_dump($base_folder_options); */ add_settings_field( 'wpscss_base_folder', // ID diff --git a/wp-scss.php b/wp-scss.php index 4606810..600131f 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -140,6 +140,8 @@ function get_base_dir_from_name($name_or_old_path){ 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, ); $directory_path = $possible_directories[$name_or_old_path]; + echo($name_or_old_path); + echo($directory_path); if($directory_path){ return $directory_path; }else{ @@ -149,9 +151,7 @@ function get_base_dir_from_name($name_or_old_path){ $wpscss_options = get_option( 'wpscss_options' ); $test = get_base_dir_from_name($wpscss_options['base_compiling_folder']); -echo($test); -// $base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? get_base_dir_from_name($wpscss_options['base_compiling_folder']) : get_stylesheet_directory(); -$base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? $wpscss_options['base_compiling_folder'] : get_stylesheet_directory(); +$base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? get_base_dir_from_name($wpscss_options['base_compiling_folder']) : get_stylesheet_directory(); $scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : ''; $css_dir_setting = isset($wpscss_options['css_dir']) ? $wpscss_options['css_dir'] : ''; From 920bb10e8e921c339b5c5e5be31e5755bc5bb3bf Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Wed, 8 Sep 2021 14:48:26 +0000 Subject: [PATCH 04/13] Check array[key], update notices, set defaults --- options.php | 10 +--------- wp-scss.php | 17 +++++++++-------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/options.php b/options.php index 88fe1f2..223e3a2 100644 --- a/options.php +++ b/options.php @@ -87,8 +87,6 @@ public function page_init() { $base_folder_options['Child Theme'] = 'Child Theme'; } - /* echo var_dump($base_folder_options); */ - add_settings_field( 'wpscss_base_folder', // ID 'Base Location', // Title @@ -98,13 +96,7 @@ public function page_init() { array( // args 'name' => 'base_compiling_folder', 'type' => apply_filters( 'wp_scss_base_compiling_modes', - $base_folder_options - // array( - // get_template_directory() => 'Parent theme', // Won't display if no parent theme as it would have duplicate keys in array - // get_stylesheet_directory() => (get_stylesheet_directory() === get_template_directory() ? 'Current theme' : 'Child theme'), - // wp_get_upload_dir()['basedir'] => 'Uploads directory', - // WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin', - // ) + $base_folder_options ) ) ); diff --git a/wp-scss.php b/wp-scss.php index 600131f..f1abd10 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -139,18 +139,19 @@ function get_base_dir_from_name($name_or_old_path){ 'Uploads Directory' => wp_get_upload_dir()['basedir'], 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, ); - $directory_path = $possible_directories[$name_or_old_path]; - echo($name_or_old_path); - echo($directory_path); - if($directory_path){ + if(array_key_exists($name_or_old_path, $possible_directories)){ return $directory_path; }else{ + add_action('admin_notices', function(){ + echo '
+

WP-SCSS: Please save your settings to make use of the new dynamic Base Location.

+
'; + }); return $name_or_old_path; } } $wpscss_options = get_option( 'wpscss_options' ); -$test = get_base_dir_from_name($wpscss_options['base_compiling_folder']); $base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? get_base_dir_from_name($wpscss_options['base_compiling_folder']) : get_stylesheet_directory(); $scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : ''; $css_dir_setting = isset($wpscss_options['css_dir']) ? $wpscss_options['css_dir'] : ''; @@ -158,7 +159,7 @@ function get_base_dir_from_name($name_or_old_path){ // Checks if directories are not yet defined if( $scss_dir_setting == false || $css_dir_setting == false ) { function wpscss_settings_error() { - echo '
+ echo '

WP-SCSS requires both directories be specified. Please update your settings.

'; } @@ -168,7 +169,7 @@ function wpscss_settings_error() { // Checks if SCSS directory exists } elseif ( !is_dir($base_compiling_folder . $scss_dir_setting) ) { add_action('admin_notices', function() use ($base_compiling_folder, $scss_dir_setting){ - echo '
+ echo '

WP-SCSS: The SCSS directory does not exist (' . $base_compiling_folder . $scss_dir_setting . '). Please create the directory or update your settings.

'; }); @@ -177,7 +178,7 @@ function wpscss_settings_error() { // Checks if CSS directory exists } elseif ( !is_dir($base_compiling_folder . $css_dir_setting) ) { add_action('admin_notices', function() use ($base_compiling_folder, $css_dir_setting){ - echo '
+ echo '

WP-SCSS: The CSS directory does not exist (' . $base_compiling_folder . $css_dir_setting . '). Please create the directory or update your settings.

'; }); From bd7ceddda58d9b4910021ec007a951b1a5710841 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Thu, 30 Sep 2021 02:14:10 +0000 Subject: [PATCH 05/13] fix dir name return --- wp-scss.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp-scss.php b/wp-scss.php index f1abd10..a8fb319 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -140,7 +140,8 @@ function get_base_dir_from_name($name_or_old_path){ 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, ); if(array_key_exists($name_or_old_path, $possible_directories)){ - return $directory_path; + return $possible_directories[$name_or_old_path]; + /* return $directory_path; */ }else{ add_action('admin_notices', function(){ echo '
From 5eaf42df1f38a6e4c365c1fe5256937685abb2e5 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 15:40:29 -0400 Subject: [PATCH 06/13] Correct response --- wp-scss.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-scss.php b/wp-scss.php index f1abd10..e461aea 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -140,7 +140,7 @@ function get_base_dir_from_name($name_or_old_path){ 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, ); if(array_key_exists($name_or_old_path, $possible_directories)){ - return $directory_path; + return $possible_directories[$name_or_old_path]; }else{ add_action('admin_notices', function(){ echo '
From 5e074794befe8b329459610a78f72ac03d0aebbe Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 15:49:30 -0400 Subject: [PATCH 07/13] Update readme and push version to 2.4.0 --- readme.md | 3 +++ readme.txt | 2 +- wp-scss.php | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index b7e6536..4ab2379 100644 --- a/readme.md +++ b/readme.md @@ -110,6 +110,9 @@ This plugin will only work with .scss format. ## Changelog +- 2.4.0 + - Changes the base_compiling_folder to store key not path to directory [shadoath](https://github.com/ConnectThink/WP-SCSS/issues/219) + - This allows deploying from local or staging to production by not saving absolute paths in DB. - 2.3.5 - Add 'selected' to wp_kses on select() [shadoath](https://github.com/ConnectThink/WP-SCSS/issues/217) - 2.3.4 diff --git a/readme.txt b/readme.txt index d681c97..428fe7c 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Plugin URI: https://github.com/ConnectThink/WP-SCSS Requires at least: 3.0.1 Tested up to: 5.8 Requires PHP: 5.6 -Stable tag: 2.3.5 +Stable tag: 2.4.0 License: GPLv3 or later License URI: http://www.gnu.org/copyleft/gpl.html diff --git a/wp-scss.php b/wp-scss.php index e461aea..3af1265 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.3.5 + * Version: 2.4.0 * Author: Connect Think * Author URI: http://connectthink.com * License: GPLv3 @@ -130,7 +130,7 @@ function wpscss_plugin_db_cleanup($option_values){ * Assign settings via settings array to pass to object */ -// Allow current WP to keep these values don't store to db +// Use current WP functions to get directory values, only store key function get_base_dir_from_name($name_or_old_path){ $possible_directories = array( 'Parent Theme' => get_template_directory(), // Won't display if no parent theme as it would have duplicate keys in array From 050ae519e20184fba135aa553bf016e38a8d0aca Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 17:29:36 -0400 Subject: [PATCH 08/13] Better notice language when updating plugin --- wp-scss.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-scss.php b/wp-scss.php index 3af1265..1037efe 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -142,10 +142,15 @@ function get_base_dir_from_name($name_or_old_path){ if(array_key_exists($name_or_old_path, $possible_directories)){ return $possible_directories[$name_or_old_path]; }else{ + $key = array_search($name_or_old_path, $possible_directories); + $notice = '

WP-SCSS: Please save your settings'; + if($key){ + $notice += ' with the Base Location of '. $key .' specified.

'; + }else{ + $notice += ' with the correct Base Location specified.

'; + } add_action('admin_notices', function(){ - echo '
-

WP-SCSS: Please save your settings to make use of the new dynamic Base Location.

-
'; + echo '
' . $notice . '
'; }); return $name_or_old_path; } From bad7467025dda49340d9487a6e5176ff2785930d Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 17:30:31 -0400 Subject: [PATCH 09/13] Silly dots --- wp-scss.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-scss.php b/wp-scss.php index 1037efe..7fa8ad4 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -145,9 +145,9 @@ function get_base_dir_from_name($name_or_old_path){ $key = array_search($name_or_old_path, $possible_directories); $notice = '

WP-SCSS: Please save your settings'; if($key){ - $notice += ' with the Base Location of '. $key .' specified.

'; + $notice .= ' with the Base Location of '. $key .' specified.

'; }else{ - $notice += ' with the correct Base Location specified.

'; + $notice .= ' with the correct Base Location specified.

'; } add_action('admin_notices', function(){ echo '
' . $notice . '
'; From 920f40cdb150a9664560ae436b54e9ee3fbe1c60 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 17:31:40 -0400 Subject: [PATCH 10/13] Pass in --- wp-scss.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-scss.php b/wp-scss.php index 7fa8ad4..b4845e1 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -149,7 +149,7 @@ function get_base_dir_from_name($name_or_old_path){ }else{ $notice .= ' with the correct Base Location specified.

'; } - add_action('admin_notices', function(){ + add_action('admin_notices', function() use ($notice){ echo '
' . $notice . '
'; }); return $name_or_old_path; From b03daf3b6a4556d093f35ce8b8894ec359db27f8 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 21:44:06 +0000 Subject: [PATCH 11/13] Improve output for displaying needed setting change --- wp-scss.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wp-scss.php b/wp-scss.php index b4845e1..f173ed4 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -133,21 +133,25 @@ function wpscss_plugin_db_cleanup($option_values){ // Use current WP functions to get directory values, only store key function get_base_dir_from_name($name_or_old_path){ $possible_directories = array( - 'Parent Theme' => get_template_directory(), // Won't display if no parent theme as it would have duplicate keys in array - 'Current Theme' => get_stylesheet_directory(), - 'Child Theme' => get_stylesheet_directory(), 'Uploads Directory' => wp_get_upload_dir()['basedir'], 'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR, ); + // Won't display if no parent theme as it would have duplicate keys in array + if(get_stylesheet_directory() === get_template_directory()){ + $possible_directories['Current Theme'] = get_stylesheet_directory(); + }else{ + $possible_directories['Parent Theme'] = get_template_directory(); + $possible_directories['Child Theme'] = get_stylesheet_directory(); + } if(array_key_exists($name_or_old_path, $possible_directories)){ return $possible_directories[$name_or_old_path]; }else{ $key = array_search($name_or_old_path, $possible_directories); $notice = '

WP-SCSS: Please save your settings'; if($key){ - $notice .= ' with the Base Location of '. $key .' specified.

'; + $notice .= ' with the Base Location of '. $key .' specified.

'; }else{ - $notice .= ' with the correct Base Location specified.

'; + $notice .= ' with the correct Base Location specified.

'; } add_action('admin_notices', function() use ($notice){ echo '
' . $notice . '
'; From 08ef517295c3f9023311090c2200e3af7b70bb60 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 17:44:18 -0400 Subject: [PATCH 12/13] Hide field that is not yet used --- options.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/options.php b/options.php index 223e3a2..f7ba7c5 100644 --- a/options.php +++ b/options.php @@ -101,16 +101,17 @@ public function page_init() { ) ); - add_settings_field( - 'Use Absolute Path', // ID - 'Use Absolute Path', // Title - array( $this, 'input_checkbox_callback' ), // Callback - 'wpscss_options', // Page - 'wpscss_paths_section', // Section - array( // args - 'name' => 'use_absolute_paths' - ) - ); + // #TODO see if this is ever warrented + // add_settings_field( + // 'Use Absolute Path', // ID + // 'Use Absolute Path', // Title + // array( $this, 'input_checkbox_callback' ), // Callback + // 'wpscss_options', // Page + // 'wpscss_paths_section', // Section + // array( // args + // 'name' => 'use_absolute_paths' + // ) + // ); add_settings_field( From 919e140c9f6a09231df7fac75d82b69ccc57c743 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Tue, 19 Oct 2021 17:48:24 -0400 Subject: [PATCH 13/13] Version bump to 2.4.0 --- wp-scss.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-scss.php b/wp-scss.php index f173ed4..0fd72a2 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -44,7 +44,7 @@ define('WPSCSS_VERSION_KEY', 'wpscss_version'); if (!defined('WPSCSS_VERSION_NUM')) - define('WPSCSS_VERSION_NUM', '2.3.5'); + define('WPSCSS_VERSION_NUM', '2.4.0'); // Add version to options table if ( get_option( WPSCSS_VERSION_KEY ) !== false ) {