SiteOrigin CSS - Version 1.5.4

Version Description

  • 28 September 2022 =
  • Developer: Introduced definable Custom CSS file name and location using siteorigin_custom_css_file and siteorigin_css_enqueue_css.
Download this release

Release Info

Developer SiteOrigin
Plugin Icon 128x128 SiteOrigin CSS
Version 1.5.4
Comparing to
See all releases

Code changes from version 1.5.3 to 1.5.4

Files changed (3) hide show
  1. lang/so-css.pot +22 -22
  2. readme.txt +5 -2
  3. so-css.php +120 -39
lang/so-css.pot CHANGED
@@ -16,7 +16,7 @@ msgstr ""
16
  "X-Poedit-SourceCharset: UTF-8\n"
17
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
18
 
19
- #: so-css.php:3, so-css.php:457
20
  msgid "SiteOrigin CSS"
21
  msgstr ""
22
 
@@ -36,87 +36,87 @@ msgstr ""
36
  msgid "https://siteorigin.com/css/"
37
  msgstr ""
38
 
39
- #: so-css.php:264, so-css.php:264, so-css.php:303
40
  msgid "Custom CSS"
41
  msgstr ""
42
 
43
- #: so-css.php:305
44
  msgid "SiteOrigin CSS adds any custom CSS you enter here into your site's header. "
45
  msgstr ""
46
 
47
- #: so-css.php:306
48
  msgid "These changes will persist across updates so it's best to make all your changes here. "
49
  msgstr ""
50
 
51
- #: so-css.php:371
52
  msgid "Unchanged"
53
  msgstr ""
54
 
55
- #: so-css.php:372
56
  msgid "Select"
57
  msgstr ""
58
 
59
- #: so-css.php:373
60
  msgid "Select Image"
61
  msgstr ""
62
 
63
- #: so-css.php:374
64
  msgid "Are you sure you want to leave without saving?"
65
  msgstr ""
66
 
67
- #: so-css.php:443
68
  msgid "CSS Editor"
69
  msgstr ""
70
 
71
- #: so-css.php:444
72
  msgid "Support"
73
  msgstr ""
74
 
75
- #: so-css.php:446
76
  msgid "Addons"
77
  msgstr ""
78
 
79
- #: so-css.php:460
80
  msgid "Changes apply to %s and its child themes"
81
  msgstr ""
82
 
83
- #: so-css.php:461, tpl/page.php:114, tpl/page.php:144
84
  msgid "Save CSS"
85
  msgstr ""
86
 
87
- #: so-css.php:468
88
  msgid "Editing CSS for: %s"
89
  msgstr ""
90
 
91
- #: so-css.php:473
92
  msgid "Changes apply to the %s %s when the current theme is %s or its child themes"
93
  msgstr ""
94
 
95
- #: so-css.php:480
96
  msgid "Save %s CSS"
97
  msgstr ""
98
 
99
- #: so-css.php:493
100
  msgid "Revert to this revision"
101
  msgstr ""
102
 
103
- #: so-css.php:548, so-css.php:569, so-css.php:588
104
  msgid "The supplied nonce is invalid."
105
  msgstr ""
106
 
107
- #: so-css.php:549, so-css.php:570, so-css.php:589
108
  msgid "Invalid nonce."
109
  msgstr ""
110
 
111
- #: so-css.php:635
112
  msgid "%d chars"
113
  msgstr ""
114
 
115
- #: so-css.php:635
116
  msgid "Latest"
117
  msgstr ""
118
 
119
- #: so-css.php:641
120
  msgid "No revisions yet."
121
  msgstr ""
122
 
16
  "X-Poedit-SourceCharset: UTF-8\n"
17
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
18
 
19
+ #: so-css.php:3, so-css.php:534
20
  msgid "SiteOrigin CSS"
21
  msgstr ""
22
 
36
  msgid "https://siteorigin.com/css/"
37
  msgstr ""
38
 
39
+ #: so-css.php:337, so-css.php:337, so-css.php:380
40
  msgid "Custom CSS"
41
  msgstr ""
42
 
43
+ #: so-css.php:382
44
  msgid "SiteOrigin CSS adds any custom CSS you enter here into your site's header. "
45
  msgstr ""
46
 
47
+ #: so-css.php:383
48
  msgid "These changes will persist across updates so it's best to make all your changes here. "
49
  msgstr ""
50
 
51
+ #: so-css.php:448
52
  msgid "Unchanged"
53
  msgstr ""
54
 
55
+ #: so-css.php:449
56
  msgid "Select"
57
  msgstr ""
58
 
59
+ #: so-css.php:450
60
  msgid "Select Image"
61
  msgstr ""
62
 
63
+ #: so-css.php:451
64
  msgid "Are you sure you want to leave without saving?"
65
  msgstr ""
66
 
67
+ #: so-css.php:520
68
  msgid "CSS Editor"
69
  msgstr ""
70
 
71
+ #: so-css.php:521
72
  msgid "Support"
73
  msgstr ""
74
 
75
+ #: so-css.php:523
76
  msgid "Addons"
77
  msgstr ""
78
 
79
+ #: so-css.php:537
80
  msgid "Changes apply to %s and its child themes"
81
  msgstr ""
82
 
83
+ #: so-css.php:538, tpl/page.php:114, tpl/page.php:144
84
  msgid "Save CSS"
85
  msgstr ""
86
 
87
+ #: so-css.php:545
88
  msgid "Editing CSS for: %s"
89
  msgstr ""
90
 
91
+ #: so-css.php:550
92
  msgid "Changes apply to the %s %s when the current theme is %s or its child themes"
93
  msgstr ""
94
 
95
+ #: so-css.php:557
96
  msgid "Save %s CSS"
97
  msgstr ""
98
 
99
+ #: so-css.php:570
100
  msgid "Revert to this revision"
101
  msgstr ""
102
 
103
+ #: so-css.php:625, so-css.php:646, so-css.php:665
104
  msgid "The supplied nonce is invalid."
105
  msgstr ""
106
 
107
+ #: so-css.php:626, so-css.php:647, so-css.php:666
108
  msgid "Invalid nonce."
109
  msgstr ""
110
 
111
+ #: so-css.php:716
112
  msgid "%d chars"
113
  msgstr ""
114
 
115
+ #: so-css.php:716
116
  msgid "Latest"
117
  msgstr ""
118
 
119
+ #: so-css.php:722
120
  msgid "No revisions yet."
121
  msgstr ""
122
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Tags: css, visual css, css editor, design, customize
3
  Requires at least: 3.9
4
  Tested up to: 6.0
5
- Stable tag: 1.5.3
6
- Build time: 2022-05-25T19:48:01+02:00
7
  License: GPLv2 or later
8
  Contributors: gpriday, alexgso
9
  Donate link: https://siteorigin.com/downloads/premium/
@@ -71,6 +71,9 @@ SiteOrigin Premium includes access to our professional email support service, pe
71
 
72
  == Changelog ==
73
 
 
 
 
74
  = 1.5.3 - 25 May 2022 =
75
  * Updated WordPress `Tested up to` tag.
76
 
2
  Tags: css, visual css, css editor, design, customize
3
  Requires at least: 3.9
4
  Tested up to: 6.0
5
+ Stable tag: 1.5.4
6
+ Build time: 2022-09-28T21:43:08+02:00
7
  License: GPLv2 or later
8
  Contributors: gpriday, alexgso
9
  Donate link: https://siteorigin.com/downloads/premium/
71
 
72
  == Changelog ==
73
 
74
+ = 1.5.4 - 28 September 2022 =
75
+ * Developer: Introduced definable Custom CSS file name and location using `siteorigin_custom_css_file` and `siteorigin_css_enqueue_css`.
76
+
77
  = 1.5.3 - 25 May 2022 =
78
  * Updated WordPress `Tested up to` tag.
79
 
so-css.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: SiteOrigin CSS
4
  Description: An advanced CSS editor from SiteOrigin.
5
- Version: 1.5.3
6
  Author: SiteOrigin
7
  Author URI: https://siteorigin.com
8
  Plugin URI: https://siteorigin.com/css/
@@ -14,7 +14,7 @@ Text Domain: so-css
14
  // Handle the legacy CSS editor that came with SiteOrigin themes
15
  include plugin_dir_path( __FILE__ ) . 'inc/legacy.php';
16
 
17
- define( 'SOCSS_VERSION', '1.5.3' );
18
  define( 'SOCSS_JS_SUFFIX', '.min' );
19
 
20
  /**
@@ -23,6 +23,7 @@ define( 'SOCSS_JS_SUFFIX', '.min' );
23
  class SiteOrigin_CSS {
24
  private $theme;
25
  private $snippet_paths;
 
26
 
27
  function __construct() {
28
  $this->theme = basename( get_template_directory() );
@@ -89,13 +90,52 @@ class SiteOrigin_CSS {
89
  */
90
  function get_custom_css( $theme, $post_id = null ) {
91
  $css_key = 'siteorigin_custom_css[' . $theme . ']';
92
- if ( empty( $post_id ) ) {
93
- return get_option( $css_key, '' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  }
95
 
96
- return get_post_meta( $post_id, $css_key, true );
97
  }
98
-
99
  /**
100
  * Save custom CSS for a given theme and post id combination.
101
  *
@@ -122,7 +162,26 @@ class SiteOrigin_CSS {
122
 
123
  return add_post_meta( $post_id, $css_key, $custom_css );
124
  }
125
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  /**
127
  * Save custom CSS for a given theme and post id combination to a file in the uploads directory to allow for caching.
128
  *
@@ -133,20 +192,23 @@ class SiteOrigin_CSS {
133
  function save_custom_css_file( $custom_css, $theme, $post_id = null ) {
134
  if ( WP_Filesystem() ) {
135
  global $wp_filesystem;
136
- $upload_dir = wp_upload_dir();
137
- $upload_dir_path = $upload_dir['basedir'] . '/so-css/';
138
-
139
- if ( ! $wp_filesystem->is_dir( $upload_dir_path ) ) {
140
- $wp_filesystem->mkdir( $upload_dir_path );
141
- }
142
-
143
- $css_file_name = 'so-css-' . $theme . ( ! empty( $post_id ) ? '_' . $post_id : '' );
144
- $css_file_path = $upload_dir_path . $css_file_name . '.css';
145
-
146
- if ( file_exists( $css_file_path ) ) {
147
- $wp_filesystem->delete( $css_file_path );
 
 
 
148
  }
149
-
150
  $wp_filesystem->put_contents(
151
  $css_file_path,
152
  $custom_css
@@ -227,21 +289,32 @@ class SiteOrigin_CSS {
227
  *
228
  */
229
  function enqueue_custom_css( $theme, $post_id = null ) {
230
-
231
- $upload_dir = wp_upload_dir();
232
- $upload_dir_path = $upload_dir['basedir'] . '/so-css/';
233
-
234
  $css_id = $theme . ( ! empty( $post_id ) ? '_' . $post_id : '' );
235
- $css_file_name = 'so-css-' . $css_id;
236
- $css_file_path = $upload_dir_path . $css_file_name . '.css';
237
-
238
- if ( empty( $_GET['so_css_preview'] ) && ! is_admin() && file_exists( $css_file_path ) ) {
239
- wp_enqueue_style(
240
- 'so-css-' . $css_id,
241
- set_url_scheme( $upload_dir['baseurl'] . '/so-css/' . $css_file_name . '.css' ),
242
- array(),
243
- $this->get_latest_revision_timestamp()
244
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  } else {
246
  $custom_css = $this->get_custom_css( $theme, $post_id );
247
  // We just need to enqueue a dummy style
@@ -273,8 +346,12 @@ class SiteOrigin_CSS {
273
  $custom_css = self::sanitize_css( filter_input( INPUT_POST, 'siteorigin_custom_css' ) );
274
  $socss_post_id = filter_input( INPUT_GET, 'socss_post_id', FILTER_VALIDATE_INT );
275
 
276
- $current = $this->get_custom_css( $this->theme, $socss_post_id );
277
- $this->save_custom_css( $custom_css, $this->theme, $socss_post_id );
 
 
 
 
278
 
279
  // If this has changed, then add a revision.
280
  if ( $current != $custom_css ) {
@@ -594,9 +671,13 @@ class SiteOrigin_CSS {
594
  if ( current_user_can( 'edit_theme_options' ) && isset( $_POST['css'] ) ) {
595
  // Sanitize CSS input. Should keep most tags, apart from script and style tags.
596
  $custom_css = self::sanitize_css( stripslashes( $_POST['css'] ) );
597
-
598
- $current = $this->get_custom_css( $this->theme );
599
- $this->save_custom_css( $custom_css, $this->theme );
 
 
 
 
600
 
601
  // If this has changed, then add a revision.
602
  if ( $current != $custom_css ) {
2
  /*
3
  Plugin Name: SiteOrigin CSS
4
  Description: An advanced CSS editor from SiteOrigin.
5
+ Version: 1.5.4
6
  Author: SiteOrigin
7
  Author URI: https://siteorigin.com
8
  Plugin URI: https://siteorigin.com/css/
14
  // Handle the legacy CSS editor that came with SiteOrigin themes
15
  include plugin_dir_path( __FILE__ ) . 'inc/legacy.php';
16
 
17
+ define( 'SOCSS_VERSION', '1.5.4' );
18
  define( 'SOCSS_JS_SUFFIX', '.min' );
19
 
20
  /**
23
  class SiteOrigin_CSS {
24
  private $theme;
25
  private $snippet_paths;
26
+ private $css_file;
27
 
28
  function __construct() {
29
  $this->theme = basename( get_template_directory() );
90
  */
91
  function get_custom_css( $theme, $post_id = null ) {
92
  $css_key = 'siteorigin_custom_css[' . $theme . ']';
93
+ if ( empty( $post_id ) && WP_Filesystem() ) {
94
+ $custom_css_file = apply_filters( 'siteorigin_custom_css_file', false );
95
+ if (
96
+ ! empty( $custom_css_file ) &&
97
+ ! empty( $custom_css_file['file'] )
98
+ ) {
99
+ // Did we previously load the CSS file? If not, load it.
100
+ if ( empty( $this->css_file ) || isset( $_POST['siteorigin_custom_css'] ) ) {
101
+ global $wp_filesystem;
102
+
103
+ // If custom file doesn't exist, create it.
104
+ if ( ! $wp_filesystem->exists( $custom_css_file['file'] ) ) {
105
+ $wp_filesystem->touch( $custom_css_file['file'] );
106
+ }
107
+
108
+ if ( empty( get_option( 'siteorigin_custom_file' ) ) ) {
109
+ update_option( 'siteorigin_custom_file', true, true );
110
+ }
111
+
112
+ if ( $wp_filesystem->is_writable( $custom_css_file['file'] ) ) {
113
+ $this->css_file = $wp_filesystem->get_contents( $custom_css_file['file'] );
114
+ }
115
+ }
116
+ return $this->css_file;
117
+ } elseif ( ! empty( get_option( 'siteorigin_custom_file' ) ) ) {
118
+ // If the custom file filter was previously active we need to
119
+ // generate the global CSS file to avoid no CSS outputting
120
+ // without modification.
121
+ delete_option( 'siteorigin_custom_file', true );
122
+ $css_file_path = $this->get_css_file_name( $theme );
123
+
124
+ global $wp_filesystem;
125
+ $wp_filesystem->put_contents(
126
+ $css_file_path,
127
+ get_option( $css_key, '' )
128
+ );
129
+ }
130
+ }
131
+
132
+ if ( ! empty( $post_id ) ) {
133
+ return get_post_meta( $post_id, $css_key, true );
134
  }
135
 
136
+ return get_option( $css_key, '' );
137
  }
138
+
139
  /**
140
  * Save custom CSS for a given theme and post id combination.
141
  *
162
 
163
  return add_post_meta( $post_id, $css_key, $custom_css );
164
  }
165
+
166
+ /**
167
+ * Returns the file name of the CSS file we're editing.
168
+ *
169
+ * @param $theme
170
+ * @param null $post_id
171
+ */
172
+ function get_css_file_name( $theme, $post_id = null ) {
173
+ global $wp_filesystem;
174
+ $upload_dir = wp_upload_dir();
175
+ $upload_dir_path = $upload_dir['basedir'] . '/so-css/';
176
+
177
+ if ( ! $wp_filesystem->is_dir( $upload_dir_path ) ) {
178
+ $wp_filesystem->mkdir( $upload_dir_path );
179
+ }
180
+
181
+ $css_file_name = 'so-css-' . $theme . ( ! empty( $post_id ) ? '_' . $post_id : '' );
182
+ return $upload_dir_path . $css_file_name . '.css';
183
+ }
184
+
185
  /**
186
  * Save custom CSS for a given theme and post id combination to a file in the uploads directory to allow for caching.
187
  *
192
  function save_custom_css_file( $custom_css, $theme, $post_id = null ) {
193
  if ( WP_Filesystem() ) {
194
  global $wp_filesystem;
195
+ $css_file_path = apply_filters( 'siteorigin_custom_css_file', false );
196
+
197
+ if (
198
+ empty( $css_file_path ) ||
199
+ empty( $css_file_path['file'] ) ||
200
+ ! $wp_filesystem->is_writable( $css_file_path['file'] )
201
+ ) {
202
+ $css_file_path = $this->get_css_file_name( $theme, $post_id );
203
+
204
+ if ( file_exists( $css_file_path ) ) {
205
+ $wp_filesystem->delete( $css_file_path );
206
+ }
207
+ } else {
208
+ $css_file_path = $css_file_path['file'];
209
+ $this->css_file = $custom_css;
210
  }
211
+
212
  $wp_filesystem->put_contents(
213
  $css_file_path,
214
  $custom_css
289
  *
290
  */
291
  function enqueue_custom_css( $theme, $post_id = null ) {
 
 
 
 
292
  $css_id = $theme . ( ! empty( $post_id ) ? '_' . $post_id : '' );
293
+ if (
294
+ empty( $_GET['so_css_preview'] ) &&
295
+ ! is_admin() &&
296
+ apply_filters( 'siteorigin_css_enqueue_css', true )
297
+ ) {
298
+ $custom_css_file = apply_filters( 'siteorigin_custom_css_file', array() );
299
+ if ( ! empty( $post_id ) || empty( $custom_css_file ) ) {
300
+ $upload_dir = wp_upload_dir();
301
+ $upload_dir_path = $upload_dir['basedir'] . '/so-css/';
302
+ $css_file_name = 'so-css-' . $css_id;
303
+ $css_file_path = $upload_dir_path . $css_file_name . '.css';
304
+ $css_file_url = $upload_dir['baseurl'] . '/so-css/' . $css_file_name . '.css';
305
+ } elseif ( isset( $custom_css_file['url'] ) ) {
306
+ $css_file_path = $custom_css_file['file'];
307
+ $css_file_url = $custom_css_file['url'];
308
+ }
309
+
310
+ if ( ! empty( $css_file_path ) && file_exists( $css_file_path ) ) {
311
+ wp_enqueue_style(
312
+ 'so-css-' . $css_id,
313
+ set_url_scheme( $css_file_url ),
314
+ array(),
315
+ $this->get_latest_revision_timestamp()
316
+ );
317
+ }
318
  } else {
319
  $custom_css = $this->get_custom_css( $theme, $post_id );
320
  // We just need to enqueue a dummy style
346
  $custom_css = self::sanitize_css( filter_input( INPUT_POST, 'siteorigin_custom_css' ) );
347
  $socss_post_id = filter_input( INPUT_GET, 'socss_post_id', FILTER_VALIDATE_INT );
348
 
349
+ if ( empty( $this->css_file ) ) {
350
+ $current = $this->get_custom_css( $this->theme, $socss_post_id );
351
+ $this->save_custom_css( $custom_css, $this->theme, $socss_post_id );
352
+ } else {
353
+ $current = $this->css_file;
354
+ }
355
 
356
  // If this has changed, then add a revision.
357
  if ( $current != $custom_css ) {
671
  if ( current_user_can( 'edit_theme_options' ) && isset( $_POST['css'] ) ) {
672
  // Sanitize CSS input. Should keep most tags, apart from script and style tags.
673
  $custom_css = self::sanitize_css( stripslashes( $_POST['css'] ) );
674
+
675
+ if ( empty( $this->css_file ) ) {
676
+ $current = $this->get_custom_css( $this->theme );
677
+ $this->save_custom_css( $custom_css, $this->theme );
678
+ } else {
679
+ $current = $this->css_file;
680
+ }
681
 
682
  // If this has changed, then add a revision.
683
  if ( $current != $custom_css ) {