Skip to content

Commit 7b95397

Browse files
authored
Merge pull request #219 from ConnectThink/sb-use-wp-compiling-folder
Use WP variables for path to base compiling folder
2 parents 4b1101e + 919e140 commit 7b95397

4 files changed

Lines changed: 66 additions & 14 deletions

File tree

options.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,44 @@ public function page_init() {
7676
'wpscss_options' // Page
7777
);
7878

79+
$base_folder_options = array(
80+
'Uploads Directory' => 'Uploads Directory',
81+
'WP-SCSS Plugin' => 'WP-SCSS Plugin'
82+
);
83+
if(get_stylesheet_directory() === get_template_directory()){
84+
$base_folder_options['Current Theme'] = 'Current Theme';
85+
}else{
86+
$base_folder_options['Parent Theme'] = 'Parent Theme';
87+
$base_folder_options['Child Theme'] = 'Child Theme';
88+
}
89+
7990
add_settings_field(
8091
'wpscss_base_folder', // ID
8192
'Base Location', // Title
8293
array( $this, 'input_select_callback' ), // Callback
8394
'wpscss_options', // Page
84-
'wpscss_paths_section', // Section
95+
'wpscss_paths_section', // Section
8596
array( // args
8697
'name' => 'base_compiling_folder',
8798
'type' => apply_filters( 'wp_scss_base_compiling_modes',
88-
array(
89-
get_template_directory() => 'Parent theme', // Won't display if no parent theme as it would have duplicate keys in array
90-
get_stylesheet_directory() => (get_stylesheet_directory() === get_template_directory() ? 'Current theme' : 'Child theme'),
91-
wp_get_upload_dir()['basedir'] => 'Uploads directory',
92-
WPSCSS_PLUGIN_DIR => 'WP-SCSS Plugin',
93-
)
99+
$base_folder_options
94100
)
95101
)
96102
);
97103

104+
// #TODO see if this is ever warrented
105+
// add_settings_field(
106+
// 'Use Absolute Path', // ID
107+
// 'Use Absolute Path', // Title
108+
// array( $this, 'input_checkbox_callback' ), // Callback
109+
// 'wpscss_options', // Page
110+
// 'wpscss_paths_section', // Section
111+
// array( // args
112+
// 'name' => 'use_absolute_paths'
113+
// )
114+
// );
115+
116+
98117
add_settings_field(
99118
'wpscss_scss_dir', // ID
100119
'SCSS Location', // Title

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ This plugin will only work with .scss format.
110110

111111
## Changelog
112112

113+
- 2.4.0
114+
- Changes the base_compiling_folder to store key not path to directory [shadoath](https://github.com/ConnectThink/WP-SCSS/issues/219)
115+
- This allows deploying from local or staging to production by not saving absolute paths in DB.
113116
- 2.3.5
114117
- Add 'selected' to wp_kses on select() [shadoath](https://github.com/ConnectThink/WP-SCSS/issues/217)
115118
- 2.3.4

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Plugin URI: https://github.com/ConnectThink/WP-SCSS
55
Requires at least: 3.0.1
66
Tested up to: 5.8
77
Requires PHP: 5.6
8-
Stable tag: 2.3.5
8+
Stable tag: 2.4.0
99
License: GPLv3 or later
1010
License URI: http://www.gnu.org/copyleft/gpl.html
1111

wp-scss.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WP-SCSS
44
* Plugin URI: https://github.com/ConnectThink/WP-SCSS
55
* Description: Compiles scss files live on WordPress.
6-
* Version: 2.3.5
6+
* Version: 2.4.0
77
* Author: Connect Think
88
* Author URI: http://connectthink.com
99
* License: GPLv3
@@ -44,7 +44,7 @@
4444
define('WPSCSS_VERSION_KEY', 'wpscss_version');
4545

4646
if (!defined('WPSCSS_VERSION_NUM'))
47-
define('WPSCSS_VERSION_NUM', '2.3.5');
47+
define('WPSCSS_VERSION_NUM', '2.4.0');
4848

4949
// Add version to options table
5050
if ( get_option( WPSCSS_VERSION_KEY ) !== false ) {
@@ -130,15 +130,45 @@ function wpscss_plugin_db_cleanup($option_values){
130130
* Assign settings via settings array to pass to object
131131
*/
132132

133+
// Use current WP functions to get directory values, only store key
134+
function get_base_dir_from_name($name_or_old_path){
135+
$possible_directories = array(
136+
'Uploads Directory' => wp_get_upload_dir()['basedir'],
137+
'WP-SCSS Plugin' => WPSCSS_PLUGIN_DIR,
138+
);
139+
// Won't display if no parent theme as it would have duplicate keys in array
140+
if(get_stylesheet_directory() === get_template_directory()){
141+
$possible_directories['Current Theme'] = get_stylesheet_directory();
142+
}else{
143+
$possible_directories['Parent Theme'] = get_template_directory();
144+
$possible_directories['Child Theme'] = get_stylesheet_directory();
145+
}
146+
if(array_key_exists($name_or_old_path, $possible_directories)){
147+
return $possible_directories[$name_or_old_path];
148+
}else{
149+
$key = array_search($name_or_old_path, $possible_directories);
150+
$notice = '<p><strong>WP-SCSS:</strong> <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wpscss_options">Please save your settings</a>';
151+
if($key){
152+
$notice .= ' with the Base Location of <b>'. $key .'</b> specified.</p>';
153+
}else{
154+
$notice .= ' with the <b>correct</b> Base Location specified.</p>';
155+
}
156+
add_action('admin_notices', function() use ($notice){
157+
echo '<div class="notice notice-info">' . $notice . '</div>';
158+
});
159+
return $name_or_old_path;
160+
}
161+
}
162+
133163
$wpscss_options = get_option( 'wpscss_options' );
134-
$base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? $wpscss_options['base_compiling_folder'] : get_stylesheet_directory();
164+
$base_compiling_folder = isset($wpscss_options['base_compiling_folder']) ? get_base_dir_from_name($wpscss_options['base_compiling_folder']) : get_stylesheet_directory();
135165
$scss_dir_setting = isset($wpscss_options['scss_dir']) ? $wpscss_options['scss_dir'] : '';
136166
$css_dir_setting = isset($wpscss_options['css_dir']) ? $wpscss_options['css_dir'] : '';
137167

138168
// Checks if directories are not yet defined
139169
if( $scss_dir_setting == false || $css_dir_setting == false ) {
140170
function wpscss_settings_error() {
141-
echo '<div class="error">
171+
echo '<div class="notice notice-error">
142172
<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>
143173
</div>';
144174
}
@@ -148,7 +178,7 @@ function wpscss_settings_error() {
148178
// Checks if SCSS directory exists
149179
} elseif ( !is_dir($base_compiling_folder . $scss_dir_setting) ) {
150180
add_action('admin_notices', function() use ($base_compiling_folder, $scss_dir_setting){
151-
echo '<div class="error">
181+
echo '<div class="notice notice-error">
152182
<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>
153183
</div>';
154184
});
@@ -157,7 +187,7 @@ function wpscss_settings_error() {
157187
// Checks if CSS directory exists
158188
} elseif ( !is_dir($base_compiling_folder . $css_dir_setting) ) {
159189
add_action('admin_notices', function() use ($base_compiling_folder, $css_dir_setting){
160-
echo '<div class="error">
190+
echo '<div class="notice notice-error">
161191
<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>
162192
</div>';
163193
});

0 commit comments

Comments
 (0)