Simple Custom CSS and JS - Version 3.0

Version Description

  • 04/12/2016
  • Feature: create the Web Designer role
  • Feature: allow Custom Codes to be managed only by users with the right capabilities
Download this release

Release Info

Developer diana_burduja
Plugin Icon 128x128 Simple Custom CSS and JS
Version 3.0
Comparing to
See all releases

Code changes from version 2.10 to 3.0

custom-css-js.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Simple Custom CSS and JS
4
  * Plugin URI: https://wordpress.org/plugins/custom-css-js/
5
  * Description: Easily add Custom CSS or JS to your website with an awesome editor.
6
- * Version: 2.10
7
  * Author: Diana Burduja
8
  * Author URI: https://www.silkypress.com/
9
  * License: GPL2
@@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
15
  }
16
 
17
  if ( ! class_exists( 'CustomCSSandJS' ) ) :
18
- define( 'CCJ_VERSION', '2.10' );
19
  /**
20
  * Main CustomCSSandJS Class
21
  *
@@ -72,6 +72,7 @@ final class CustomCSSandJS {
72
  $this->upload_dir = $wp_upload_dir['basedir'] . '/custom-css-js';
73
  $this->upload_url = $wp_upload_dir['baseurl'] . '/custom-css-js';
74
  if ( is_admin() ) {
 
75
  include_once( 'includes/admin-screens.php' );
76
  include_once( 'includes/admin-addons.php' );
77
  include_once( 'includes/admin-warnings.php' );
@@ -190,45 +191,153 @@ final class CustomCSSandJS {
190
  */
191
  public function register_post_type() {
192
  $labels = array(
193
- 'name' => _x( 'Custom Code', 'post type general name'),
194
- 'singular_name' => _x( 'Custom Code', 'post type singular name'),
195
- 'menu_name' => _x( 'Custom CSS & JS', 'admin menu'),
196
- 'name_admin_bar' => _x( 'Custom Code', 'add new on admin bar'),
197
- 'add_new' => _x( 'Add Custom Code', 'add new'),
198
- 'add_new_item' => __( 'Add Custom Code'),
199
- 'new_item' => __( 'New Custom Code'),
200
- 'edit_item' => __( 'Edit Custom Code'),
201
- 'view_item' => __( 'View Custom Code'),
202
- 'all_items' => __( 'All Custom Code'),
203
- 'search_items' => __( 'Search Custom Code'),
204
- 'parent_item_colon' => __( 'Parent Custom Code:'),
205
- 'not_found' => __( 'No Custom Code found.'),
206
- 'not_found_in_trash' => __( 'No Custom Code found in Trash.')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  );
208
 
209
  $args = array(
210
- 'labels' => $labels,
211
- 'description' => __( 'Custom CSS and JS code' ),
212
- 'public' => false,
213
- 'publicly_queryable' => false,
214
- 'show_ui' => true,
215
- 'show_in_menu' => true,
216
- 'menu_position' => 100,
217
- 'menu_icon' => 'dashicons-plus-alt',
218
- 'query_var' => false,
219
- 'rewrite' => array( 'slug' => 'custom-css-js' ),
220
- 'capability_type' => 'post',
221
- 'has_archive' => true,
222
- 'hierarchical' => false,
223
- 'exclude_from_search' => true,
224
- 'menu_position' => null,
225
- 'can_export' => false,
226
- 'supports' => array( 'title' )
 
227
  );
228
 
229
  register_post_type( 'custom-css-js', $args );
230
  }
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
 
233
  }
234
 
@@ -258,3 +367,5 @@ function custom_css_js_plugin_action_links( $links ) {
258
 
259
  }
260
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'custom_css_js_plugin_action_links' );
 
 
3
  * Plugin Name: Simple Custom CSS and JS
4
  * Plugin URI: https://wordpress.org/plugins/custom-css-js/
5
  * Description: Easily add Custom CSS or JS to your website with an awesome editor.
6
+ * Version: 3.0
7
  * Author: Diana Burduja
8
  * Author URI: https://www.silkypress.com/
9
  * License: GPL2
15
  }
16
 
17
  if ( ! class_exists( 'CustomCSSandJS' ) ) :
18
+ define( 'CCJ_VERSION', '3.0' );
19
  /**
20
  * Main CustomCSSandJS Class
21
  *
72
  $this->upload_dir = $wp_upload_dir['basedir'] . '/custom-css-js';
73
  $this->upload_url = $wp_upload_dir['baseurl'] . '/custom-css-js';
74
  if ( is_admin() ) {
75
+ add_action('admin_init', array($this, 'create_roles'));
76
  include_once( 'includes/admin-screens.php' );
77
  include_once( 'includes/admin-addons.php' );
78
  include_once( 'includes/admin-warnings.php' );
191
  */
192
  public function register_post_type() {
193
  $labels = array(
194
+ 'name' => _x( 'Custom Code', 'post type general name'),
195
+ 'singular_name' => _x( 'Custom Code', 'post type singular name'),
196
+ 'menu_name' => _x( 'Custom CSS & JS', 'admin menu'),
197
+ 'name_admin_bar' => _x( 'Custom Code', 'add new on admin bar'),
198
+ 'add_new' => _x( 'Add Custom Code', 'add new'),
199
+ 'add_new_item' => __( 'Add Custom Code'),
200
+ 'new_item' => __( 'New Custom Code'),
201
+ 'edit_item' => __( 'Edit Custom Code'),
202
+ 'view_item' => __( 'View Custom Code'),
203
+ 'all_items' => __( 'All Custom Code'),
204
+ 'search_items' => __( 'Search Custom Code'),
205
+ 'parent_item_colon' => __( 'Parent Custom Code:'),
206
+ 'not_found' => __( 'No Custom Code found.'),
207
+ 'not_found_in_trash' => __( 'No Custom Code found in Trash.')
208
+ );
209
+
210
+ $capability_type = 'custom_css';
211
+ $capabilities = array(
212
+ 'edit_post' => "edit_{$capability_type}",
213
+ 'read_post' => "read_{$capability_type}",
214
+ 'delete_post' => "delete_{$capability_type}",
215
+ 'edit_posts' => "edit_{$capability_type}s",
216
+ 'edit_others_posts' => "edit_others_{$capability_type}s",
217
+ 'publish_posts' => "publish_{$capability_type}s",
218
+ 'read' => "read",
219
+ 'delete_posts' => "delete_{$capability_type}s",
220
+ 'delete_published_posts' => "delete_published_{$capability_type}s",
221
+ 'delete_others_posts' => "delete_others_{$capability_type}s",
222
+ 'edit_published_posts' => "edit_published_{$capability_type}s",
223
+ 'create_posts' => "edit_{$capability_type}s",
224
  );
225
 
226
  $args = array(
227
+ 'labels' => $labels,
228
+ 'description' => __( 'Custom CSS and JS code' ),
229
+ 'public' => false,
230
+ 'publicly_queryable' => false,
231
+ 'show_ui' => true,
232
+ 'show_in_menu' => true,
233
+ 'menu_position' => 100,
234
+ 'menu_icon' => 'dashicons-plus-alt',
235
+ 'query_var' => false,
236
+ 'rewrite' => array( 'slug' => 'custom-css-js' ),
237
+ 'capability_type' => $capability_type,
238
+ 'capabilities' => $capabilities,
239
+ 'has_archive' => true,
240
+ 'hierarchical' => false,
241
+ 'exclude_from_search' => true,
242
+ 'menu_position' => null,
243
+ 'can_export' => false,
244
+ 'supports' => array( 'title' )
245
  );
246
 
247
  register_post_type( 'custom-css-js', $args );
248
  }
249
 
250
+
251
+ /**
252
+ * Create roles and capabilities.
253
+ */
254
+ function create_roles() {
255
+ global $wp_roles;
256
+
257
+
258
+ if ( !current_user_can('update_plugins') )
259
+ return;
260
+
261
+ if ( ! class_exists( 'WP_Roles' ) ) {
262
+ return;
263
+ }
264
+
265
+ if ( ! isset( $wp_roles ) ) {
266
+ $wp_roles = new WP_Roles();
267
+ }
268
+
269
+ if ( isset($wp_roles->roles['css_js_designer']))
270
+ return;
271
+
272
+ // Add Web Designer role
273
+ add_role( 'css_js_designer', __( 'Web Designer'), array(
274
+ 'level_9' => true,
275
+ 'level_8' => true,
276
+ 'level_7' => true,
277
+ 'level_6' => true,
278
+ 'level_5' => true,
279
+ 'level_4' => true,
280
+ 'level_3' => true,
281
+ 'level_2' => true,
282
+ 'level_1' => true,
283
+ 'level_0' => true,
284
+ 'read' => true,
285
+ 'read_private_pages' => true,
286
+ 'read_private_posts' => true,
287
+ 'edit_users' => true,
288
+ 'edit_posts' => true,
289
+ 'edit_pages' => true,
290
+ 'edit_published_posts' => true,
291
+ 'edit_published_pages' => true,
292
+ 'edit_private_pages' => true,
293
+ 'edit_private_posts' => true,
294
+ 'edit_others_posts' => true,
295
+ 'edit_others_pages' => true,
296
+ 'publish_posts' => true,
297
+ 'publish_pages' => true,
298
+ 'delete_posts' => true,
299
+ 'delete_pages' => true,
300
+ 'delete_private_pages' => true,
301
+ 'delete_private_posts' => true,
302
+ 'delete_published_pages' => true,
303
+ 'delete_published_posts' => true,
304
+ 'delete_others_posts' => true,
305
+ 'delete_others_pages' => true,
306
+ 'manage_categories' => true,
307
+ 'moderate_comments' => true,
308
+ 'unfiltered_html' => true,
309
+ 'upload_files' => true,
310
+ ) );
311
+
312
+ $capabilities = array();
313
+
314
+ $capability_types = array( 'custom_css' );
315
+
316
+ foreach ( $capability_types as $capability_type ) {
317
+
318
+ $capabilities[ $capability_type ] = array(
319
+ // Post type
320
+ "edit_{$capability_type}",
321
+ "read_{$capability_type}",
322
+ "delete_{$capability_type}",
323
+ "edit_{$capability_type}s",
324
+ "edit_others_{$capability_type}s",
325
+ "publish_{$capability_type}s",
326
+ "delete_{$capability_type}s",
327
+ "delete_published_{$capability_type}s",
328
+ "delete_others_{$capability_type}s",
329
+ "edit_published_{$capability_type}s",
330
+ );
331
+ }
332
+
333
+ foreach ( $capabilities as $cap_group ) {
334
+ foreach ( $cap_group as $cap ) {
335
+ $wp_roles->add_cap( 'css_js_designer', $cap );
336
+ $wp_roles->add_cap( 'administrator', $cap );
337
+ }
338
+ }
339
+ }
340
+
341
 
342
  }
343
 
367
 
368
  }
369
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'custom_css_js_plugin_action_links' );
370
+
371
+
includes/admin-notices.php CHANGED
@@ -44,7 +44,7 @@ class CustomCSSandJS_Notices {
44
 
45
  if ( !isset($screen->post_type) || $screen->post_type !== 'custom-css-js' )
46
  return;
47
-
48
  if ( ! $notice = $this->choose_notice() )
49
  return;
50
 
@@ -86,18 +86,18 @@ class CustomCSSandJS_Notices {
86
  $days_passed = ceil( ( $now - $this->activation_time ) / 86400 );
87
 
88
  switch ( $days_passed ) {
89
- case 1 : return '1_day';
90
- case 2 : return '2_day';
91
- case 3 : break; //return '3_day';
 
92
  case 4 : break;
93
  case 5 : break;
94
- case 6 : break;
95
- case 7 : break; // return '7_day';
96
  case 8 : break;
97
  case 9 : break;
98
  case 10 : break;
99
- case 11 : break;
100
- case 12 : break; //return '12_day';
101
  }
102
  }
103
 
44
 
45
  if ( !isset($screen->post_type) || $screen->post_type !== 'custom-css-js' )
46
  return;
47
+
48
  if ( ! $notice = $this->choose_notice() )
49
  return;
50
 
86
  $days_passed = ceil( ( $now - $this->activation_time ) / 86400 );
87
 
88
  switch ( $days_passed ) {
89
+ case 0 : return '1_day';
90
+ case 1 : return '2_day';
91
+ case 2 : break; //return '3_day';
92
+ case 3 : break;
93
  case 4 : break;
94
  case 5 : break;
95
+ case 6 : break; // return '7_day';
96
+ case 7 : break;
97
  case 8 : break;
98
  case 9 : break;
99
  case 10 : break;
100
+ case 11 : break; //return '12_day';
 
101
  }
102
  }
103
 
includes/admin-screens.php CHANGED
@@ -89,16 +89,17 @@ class CustomCSSandJS_Admin {
89
  $menu_slug = 'edit.php?post_type=custom-css-js';
90
  $submenu_slug = 'post-new.php?post_type=custom-css-js';
91
 
 
 
92
  $title = __('Add Custom CSS');
93
- add_submenu_page( $menu_slug, $title, $title, 'manage_options', $submenu_slug .'&language=css');
94
 
95
  $title = __('Add Custom JS');
96
- add_submenu_page( $menu_slug, $title, $title, 'manage_options', $submenu_slug . '&language=js');
97
 
98
  $title = __('Add Custom HTML');
99
- add_submenu_page( $menu_slug, $title, $title, 'manage_options', $submenu_slug . '&language=html');
100
 
101
- remove_submenu_page( $menu_slug, $submenu_slug);
102
  }
103
 
104
 
89
  $menu_slug = 'edit.php?post_type=custom-css-js';
90
  $submenu_slug = 'post-new.php?post_type=custom-css-js';
91
 
92
+ remove_submenu_page( $menu_slug, $submenu_slug);
93
+
94
  $title = __('Add Custom CSS');
95
+ add_submenu_page( $menu_slug, $title, $title, 'publish_custom_csss', $submenu_slug .'&language=css');
96
 
97
  $title = __('Add Custom JS');
98
+ add_submenu_page( $menu_slug, $title, $title, 'publish_custom_csss', $submenu_slug . '&language=js');
99
 
100
  $title = __('Add Custom HTML');
101
+ add_submenu_page( $menu_slug, $title, $title, 'publish_custom_csss', $submenu_slug . '&language=html');
102
 
 
103
  }
104
 
105
 
readme.txt CHANGED
@@ -6,7 +6,7 @@ Email: diana@burduja.eu
6
  Tags: CSS, JS, javascript, custom CSS, custom JS, custom style, site css, add style, customize theme, custom code, external css, css3, style, styles, stylesheet, theme, editor, design, admin
7
  Requires at least: 3.0.1
8
  Tested up to: 4.7
9
- Stable tag: 2.10
10
  License: GPLv3
11
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
12
 
@@ -24,46 +24,6 @@ Customize your WordPress site's appearance by easily adding custom CSS and JS co
24
  * Add as many codes as you want
25
  * Keep your changes also when you change the theme
26
 
27
- = Frequently Asked Questions =
28
-
29
- * **What if I want to add multiple external CSS codes?**
30
- If you write multiple codes of the same type (for example: two external CSS codes), then all of them will be printed one after another
31
-
32
- * **Will this plugin affect the loading time?**
33
- When you click the `Save` button the codes will be cached in files, so there are no tedious database queries.
34
-
35
- * **Does the plugin modify the code I write in the editor?**
36
- No, the code is printed exactly as in the editor. It is not modified/checked/validated in any way. You take the full responsability for what is written in there.
37
-
38
- * **My code doesn't show on the website**
39
- Try one of the following:
40
- 1. If you are using any caching plugin (like "W3 Total Cache" or "WP Fastest Cache"), then don't forget to delete the cache before seing the code printed on the website.
41
- 2. Make sure the code is in **Published** state (not **Draft** or **in Trash**).
42
- 3. Check if the `wp-content/uploads/custom-css-js` folder exists and is writable
43
-
44
- * **Does it work with a Multisite Network?**
45
- Yes.
46
-
47
- * **What if I change the theme?**
48
- The CSS and JS are independent of the theme and they will persist through a theme change. This is particularly useful if you apply CSS and JS for modifying a plugin's output.
49
-
50
- * **Can I use a CSS preprocesor like LESS or Sass?**
51
- For the moment only plain CSS is supported, but you can check out the [Pro version](https://www.silkypress.com/simple-custom-css-js-pro/?utm_source=wordpress&utm_campaign=ccj_free&utm_medium=banner) in case you need a CSS preprocessor.
52
-
53
- * **Can I upload images for use with my CSS?**
54
- Yes. You can upload an image to your Media Library, then refer to it by its direct URL from within the CSS stylesheet. For example:
55
- `div#content {
56
- background-image: url('http://example.com/wp-content/uploads/2015/12/image.jpg');
57
- }`
58
-
59
- * **Can I use CSS rules like @import and @font-face?**
60
- Yes.
61
-
62
- * **CSS Help.**
63
- If you are just starting with CSS, then here you'll find some resources:
64
- * [codecademy.com - Learn HTML & CSS](https://www.codecademy.com/learn/web)
65
- * [Wordpress.org - Finding Your CSS Styles](https://codex.wordpress.org/Finding_Your_CSS_Styles)
66
-
67
  == Installation ==
68
 
69
  * From the WP admin panel, click "Plugins" -> "Add new".
@@ -93,16 +53,54 @@ OR...
93
  = Requirements =
94
  PHP >= 5.3
95
 
96
- = Browser requirements =
97
  * Firefox - version 4 and up
98
  * Chrome - any version
99
  * Safari - version 5.2 and up
100
  * Internet Explorer - version 8 and up
101
  * Opera - version 9 and up
102
 
103
- = Small incompatibilities =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  * If the [qTranslate X](https://wordpress.org/plugins/qtranslate-x/) plugin is adding some `[:]` or `[:en]` characters to your code, then you need to remove the `custom-css-js` post type from the qTranslate settings. Check out [this screenshot](https://www.silkypress.com/wp-content/uploads/2016/08/ccj_qtranslate_compatibility.png) on how to do that.
105
 
 
 
106
  == Screenshots ==
107
 
108
  1. Manage Custom Codes
@@ -115,6 +113,11 @@ $. Add/Edit HTML
115
 
116
  == Changelog ==
117
 
 
 
 
 
 
118
  = 2.10 =
119
  * 02/05/2016
120
  * Feature: circumvent external file caching by adding a GET parameter
6
  Tags: CSS, JS, javascript, custom CSS, custom JS, custom style, site css, add style, customize theme, custom code, external css, css3, style, styles, stylesheet, theme, editor, design, admin
7
  Requires at least: 3.0.1
8
  Tested up to: 4.7
9
+ Stable tag: 3.0
10
  License: GPLv3
11
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
12
 
24
  * Add as many codes as you want
25
  * Keep your changes also when you change the theme
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  == Installation ==
28
 
29
  * From the WP admin panel, click "Plugins" -> "Add new".
53
  = Requirements =
54
  PHP >= 5.3
55
 
56
+ **Browser requirements**
57
  * Firefox - version 4 and up
58
  * Chrome - any version
59
  * Safari - version 5.2 and up
60
  * Internet Explorer - version 8 and up
61
  * Opera - version 9 and up
62
 
63
+ = What if I want to add multiple external CSS codes? =
64
+ If you write multiple codes of the same type (for example: two external CSS codes), then all of them will be printed one after another
65
+
66
+ = Will this plugin affect the loading time? =
67
+ When you click the `Save` button the codes will be cached in files, so there are no tedious database queries.
68
+
69
+ = Does the plugin modify the code I write in the editor? =
70
+ No, the code is printed exactly as in the editor. It is not modified/checked/validated in any way. You take the full responsability for what is written in there.
71
+
72
+ = My code doesn't show on the website =
73
+ Try one of the following:
74
+ 1. If you are using any caching plugin (like "W3 Total Cache" or "WP Fastest Cache"), then don't forget to delete the cache before seing the code printed on the website.
75
+ 2. Make sure the code is in **Published** state (not **Draft** or **in Trash**).
76
+ 3. Check if the `wp-content/uploads/custom-css-js` folder exists and is writable
77
+
78
+ = Does it work with a Multisite Network? =
79
+ Yes.
80
+
81
+ = What if I change the theme? =
82
+ The CSS and JS are independent of the theme and they will persist through a theme change. This is particularly useful if you apply CSS and JS for modifying a plugin's output.
83
+
84
+ = Can I use a CSS preprocesor like LESS or Sass? =
85
+ For the moment only plain CSS is supported, but you can check out the [Pro version](https://www.silkypress.com/simple-custom-css-js-pro/?utm_source=wordpress&utm_campaign=ccj_free&utm_medium=banner) in case you need a CSS preprocessor.
86
+
87
+ = Can I upload images for use with my CSS? =
88
+ Yes. You can upload an image to your Media Library, then refer to it by its direct URL from within the CSS stylesheet. For example:
89
+ `div#content {
90
+ background-image: url('http://example.com/wp-content/uploads/2015/12/image.jpg');
91
+ }`
92
+
93
+ = Can I use CSS rules like @import and @font-face? =
94
+ Yes.
95
+
96
+ = Who can publish/edit/delete Custom Codes? =
97
+ By default only the Administrator will be able to publish/edit/delete Custom Codes. Check out [this article](https://www.silkypress.com/simple_custom_css_js/user-capabilities-simple-custom-css-js-plugin/) for more details on roles and user capabilities customizations.
98
+
99
+ = Compatibility with qTranslate X plugin =
100
  * If the [qTranslate X](https://wordpress.org/plugins/qtranslate-x/) plugin is adding some `[:]` or `[:en]` characters to your code, then you need to remove the `custom-css-js` post type from the qTranslate settings. Check out [this screenshot](https://www.silkypress.com/wp-content/uploads/2016/08/ccj_qtranslate_compatibility.png) on how to do that.
101
 
102
+
103
+
104
  == Screenshots ==
105
 
106
  1. Manage Custom Codes
113
 
114
  == Changelog ==
115
 
116
+ = 3.0 =
117
+ * 04/12/2016
118
+ * Feature: create the Web Designer role
119
+ * Feature: allow Custom Codes to be managed only by users with the right capabilities
120
+
121
  = 2.10 =
122
  * 02/05/2016
123
  * Feature: circumvent external file caching by adding a GET parameter
screenshot-1.jpg DELETED
Binary file
screenshot-2.jpg DELETED
Binary file
screenshot-3.jpg DELETED
Binary file
screenshot-4.jpg DELETED
Binary file