WP Add Custom CSS - Version 1.0.0

Version Description

  • Added support for custom post types
Download this release

Release Info

Developer danieledesantis
Plugin Icon 128x128 WP Add Custom CSS
Version 1.0.0
Comparing to
See all releases

Code changes from version 0.9.7 to 1.0.0

Files changed (2) hide show
  1. readme.txt +17 -6
  2. wordpress-add-custom-css.php +46 -6
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WP Add Custom CSS ===
2
  Contributors: danieledesantis
3
- Tags: css, custom css, stylesheet, custom stylesheet, single post css, site css, single page css
4
  Requires at least: 4.0
5
- Tested up to: 4.4
6
- Stable tag: 0.9.7
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -11,11 +11,11 @@ Add custom css to the whole website and to specific posts and pages.
11
 
12
  == Description ==
13
 
14
- WP Add Custom CSS allows you to add custom CSS to the whole website and to individual posts and pages.
15
- The CSS rules applied to the whole website will override the default stylesheets of your theme and plugins, while the CSS rules applied to specific pages and posts will override the main stylesheet too.
16
 
17
  You can edit the main stylesheet from the the "Add custom CSS" settings page.
18
- The plugin also creates a new "Custom CSS" box in the editing area to add custom CSS to specific posts and pages.
19
 
20
  Available languages:
21
 
@@ -46,6 +46,10 @@ Once the plugin is installed and activated, from your dashboard navigate to "Add
46
 
47
  Once the plugin is installed and activated, you will find a new box called "Custom CSS" in your post/page editing area.
48
 
 
 
 
 
49
  = The "Custom CSS" box is not displaying, why? =
50
 
51
  Click on the "Screen option" link from your post/page editing area and be sure the "Custom CSS" option is checked.
@@ -55,9 +59,13 @@ Click on the "Screen option" link from your post/page editing area and be sure t
55
  1. Add custom CSS to the whole website.
56
  2. Add custom CSS to specific posts.
57
  3. Add custom CSS to specific pages.
 
58
 
59
  == Changelog ==
60
 
 
 
 
61
  = 0.9.7 =
62
  * Fixed minor bug
63
 
@@ -85,6 +93,9 @@ Click on the "Screen option" link from your post/page editing area and be sure t
85
 
86
  == Upgrade Notice ==
87
 
 
 
 
88
  = 0.9.7 =
89
  * Fixed minor bug
90
 
1
  === WP Add Custom CSS ===
2
  Contributors: danieledesantis
3
+ Tags: css, custom css, style, styles, stylesheet, custom stylesheet, single post css, site css, single page css, custom post type css, product css
4
  Requires at least: 4.0
5
+ Tested up to: 4.6
6
+ Stable tag: 1.0.0
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
11
 
12
  == Description ==
13
 
14
+ WP Add Custom CSS allows you to add **custom CSS** to the **whole website** and to **individual posts, pages and custom post types** (such as **Woocommerce products**).
15
+ The CSS rules applied to the whole website will override the default stylesheets of your theme and plugins, while the CSS rules applied to specific pages, posts or custom post types will override the main stylesheet too.
16
 
17
  You can edit the main stylesheet from the the "Add custom CSS" settings page.
18
+ The plugin also creates a new "Custom CSS" box in the editing area to **add custom CSS to specific posts, pages and custom post types**.
19
 
20
  Available languages:
21
 
46
 
47
  Once the plugin is installed and activated, you will find a new box called "Custom CSS" in your post/page editing area.
48
 
49
+ = How do I apply custom CSS to a specific custom post type? =
50
+
51
+ Once the plugin is installed and activated, from your dashboard navigate to "Add custom CSS", check the desired custom post types and save. You will find a new box called "Custom CSS" in your custom post type editing area.
52
+
53
  = The "Custom CSS" box is not displaying, why? =
54
 
55
  Click on the "Screen option" link from your post/page editing area and be sure the "Custom CSS" option is checked.
59
  1. Add custom CSS to the whole website.
60
  2. Add custom CSS to specific posts.
61
  3. Add custom CSS to specific pages.
62
+ 4. Add custom CSS to specific custom post types (such as Woocommerce products).
63
 
64
  == Changelog ==
65
 
66
+ = 1.0.0 =
67
+ * Added support for custom post types
68
+
69
  = 0.9.7 =
70
  * Fixed minor bug
71
 
93
 
94
  == Upgrade Notice ==
95
 
96
+ = 1.0.0 =
97
+ * Added support for custom post types
98
+
99
  = 0.9.7 =
100
  * Fixed minor bug
101
 
wordpress-add-custom-css.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: WP Add Custom CSS
4
  Plugin URI: http://www.danieledesantis.net
5
- Description: Add custom css to the whole website and to specific posts and pages.
6
- Version: 0.9.7
7
  Author: Daniele De Santis
8
  Author URI: http://www.danieledesantis.net
9
  Text Domain: wp-add-custom-css
@@ -12,7 +12,7 @@ License: GPL2
12
  */
13
 
14
  /*
15
- Copyright 2014 Daniele De Santis (email : hello@danieledesantis.net)
16
 
17
  This program is free software; you can redistribute it and/or modify
18
  it under the terms of the GNU General Public License, version 2, as
@@ -57,7 +57,11 @@ if(!class_exists('Wpacc'))
57
  }
58
 
59
  public function add_meta_box( $post_type ) {
60
- $post_types = array('post', 'page');
 
 
 
 
61
  if ( in_array( $post_type, $post_types )) {
62
  add_meta_box('wp_add_custom_css', __( 'Custom CSS', 'wp-add-custom-css' ), array( $this, 'render_meta_box_content' ), $post_type, 'advanced', 'high');
63
  }
@@ -121,6 +125,22 @@ if(!class_exists('Wpacc'))
121
  echo '<textarea name="wpacc_settings[main_custom_style]" style="width:100%; min-height:300px;">' . $custom_rules . '</textarea>';
122
  }
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  public function init_settings() {
125
  register_setting(
126
  'wpacc_group',
@@ -139,6 +159,19 @@ if(!class_exists('Wpacc'))
139
  'wp-add-custom-css_settings',
140
  'wpacc_main_style'
141
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
 
144
  public function delete_options() {
@@ -181,7 +214,15 @@ if(!class_exists('Wpacc'))
181
 
182
  public function single_custom_css() {
183
  if ( is_single() || is_page() ) {
184
- global $post;
 
 
 
 
 
 
 
 
185
  $single_custom_css = get_post_meta( $post->ID, '_single_add_custom_css', true );
186
  if ( $single_custom_css !== '' ) {
187
  $single_custom_css = str_replace ( '&gt;' , '>' , $single_custom_css );
@@ -209,5 +250,4 @@ if(isset($wpacc)) {
209
  }
210
  add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wpacc_settings_link');
211
  }
212
-
213
  ?>
2
  /*
3
  Plugin Name: WP Add Custom CSS
4
  Plugin URI: http://www.danieledesantis.net
5
+ Description: Add custom css to the whole website and to specific posts, pages and custom post types.
6
+ Version: 1.0.0
7
  Author: Daniele De Santis
8
  Author URI: http://www.danieledesantis.net
9
  Text Domain: wp-add-custom-css
12
  */
13
 
14
  /*
15
+ Copyright 2014-2016 Daniele De Santis (email : hello@danieledesantis.net)
16
 
17
  This program is free software; you can redistribute it and/or modify
18
  it under the terms of the GNU General Public License, version 2, as
57
  }
58
 
59
  public function add_meta_box( $post_type ) {
60
+ $this->options = get_option( 'wpacc_settings' );
61
+ $post_types = array('post', 'page');
62
+ if ( isset($this->options['selected_post_types']) ) {
63
+ $post_types = array_merge( $post_types, $this->options['selected_post_types'] );
64
+ }
65
  if ( in_array( $post_type, $post_types )) {
66
  add_meta_box('wp_add_custom_css', __( 'Custom CSS', 'wp-add-custom-css' ), array( $this, 'render_meta_box_content' ), $post_type, 'advanced', 'high');
67
  }
125
  echo '<textarea name="wpacc_settings[main_custom_style]" style="width:100%; min-height:300px;">' . $custom_rules . '</textarea>';
126
  }
127
 
128
+ public function print_section_2_info() {
129
+ echo __('Enable page specific CSS for the post types below.', 'wp-add-custom-css');
130
+ }
131
+
132
+ public function post_types_checkboxes() {
133
+ $available_post_types = get_post_types( array('public' => true, '_builtin' => false), 'objects' );
134
+ foreach ( $available_post_types as $post_type ) {
135
+ if ( isset( $this->options['selected_post_types'] ) ) {
136
+ $checked = in_array( $post_type->name, $this->options['selected_post_types'] ) ? ' checked' : '';
137
+ } else {
138
+ $checked = '';
139
+ }
140
+ echo '<div style="margin-bottom:10px"><input type="checkbox" name="wpacc_settings[selected_post_types][]" value="' . $post_type->name . '"' . $checked . '>' . $post_type->label . '</div>'; // output checkbox
141
+ }
142
+ }
143
+
144
  public function init_settings() {
145
  register_setting(
146
  'wpacc_group',
159
  'wp-add-custom-css_settings',
160
  'wpacc_main_style'
161
  );
162
+ add_settings_section(
163
+ 'wpacc_post_types',
164
+ __('Post types', 'wp-add-custom-css'),
165
+ array( $this, 'print_section_2_info' ),
166
+ 'wp-add-custom-css_settings'
167
+ );
168
+ add_settings_field(
169
+ 'selected_post_types',
170
+ __('Available post types', 'wp-add-custom-css'),
171
+ array( $this, 'post_types_checkboxes' ),
172
+ 'wp-add-custom-css_settings',
173
+ 'wpacc_post_types'
174
+ );
175
  }
176
 
177
  public function delete_options() {
214
 
215
  public function single_custom_css() {
216
  if ( is_single() || is_page() ) {
217
+ global $post;
218
+ $enabled_post_types = array('post', 'page');
219
+ $this->options = get_option( 'wpacc_settings' );
220
+ if ( isset($this->options['selected_post_types']) ) {
221
+ $enabled_post_types = array_merge( $enabled_post_types, $this->options['selected_post_types'] );
222
+ }
223
+ if ( ! in_array( $post->post_type, $enabled_post_types )) {
224
+ return;
225
+ }
226
  $single_custom_css = get_post_meta( $post->ID, '_single_add_custom_css', true );
227
  if ( $single_custom_css !== '' ) {
228
  $single_custom_css = str_replace ( '&gt;' , '>' , $single_custom_css );
250
  }
251
  add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wpacc_settings_link');
252
  }
 
253
  ?>