WP Add Custom CSS - Version 0.9

Version Description

  • First release
Download this release

Release Info

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

Version 0.9

css/custom-css.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ header("Content-type: text/css");
3
+ $custom_css = get_option('wpacc_settings');
4
+ echo esc_attr($custom_css['main_custom_style']);
5
+ ?>
images/icon.png ADDED
Binary file
languages/en.mo ADDED
Binary file
languages/en.po ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Wordpress Add Custom CSS\n"
4
+ "POT-Creation-Date: 2014-10-04 16:46+0100\n"
5
+ "PO-Revision-Date: 2014-10-04 16:46+0100\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "Language: en\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.3\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-KeywordsList: __;_e\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: ../wordpress-add-custom-css.php:62
20
+ msgid "Custom CSS"
21
+ msgstr ""
22
+
23
+ #: ../wordpress-add-custom-css.php:88
24
+ msgid "Add custom CSS rules for this "
25
+ msgstr ""
26
+
27
+ #: ../wordpress-add-custom-css.php:101
28
+ msgid "Wordpress Add Custom CSS"
29
+ msgstr ""
30
+
31
+ #: ../wordpress-add-custom-css.php:105
32
+ msgid "Save"
33
+ msgstr ""
34
+
35
+ #: ../wordpress-add-custom-css.php:107
36
+ msgid "Credits"
37
+ msgstr ""
38
+
39
+ #: ../wordpress-add-custom-css.php:109
40
+ msgid "\"WP Add Custom CSS\" is a plugin by"
41
+ msgstr ""
42
+
43
+ #: ../wordpress-add-custom-css.php:116
44
+ msgid "Write here the CSS rules you want to apply to the whole website."
45
+ msgstr ""
46
+
47
+ #: ../wordpress-add-custom-css.php:202
48
+ msgid "Settings"
49
+ msgstr ""
languages/en.pot ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Wordpress Add Custom CSS\n"
4
+ "POT-Creation-Date: 2014-10-04 16:46+0100\n"
5
+ "PO-Revision-Date: 2014-10-04 16:46+0100\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "Language: en\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.3\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-KeywordsList: __;_e\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: ../wordpress-add-custom-css.php:62
20
+ msgid "Custom CSS"
21
+ msgstr ""
22
+
23
+ #: ../wordpress-add-custom-css.php:88
24
+ msgid "Add custom CSS rules for this "
25
+ msgstr ""
26
+
27
+ #: ../wordpress-add-custom-css.php:101
28
+ msgid "Wordpress Add Custom CSS"
29
+ msgstr ""
30
+
31
+ #: ../wordpress-add-custom-css.php:105
32
+ msgid "Save"
33
+ msgstr ""
34
+
35
+ #: ../wordpress-add-custom-css.php:107
36
+ msgid "Credits"
37
+ msgstr ""
38
+
39
+ #: ../wordpress-add-custom-css.php:109
40
+ msgid "\"WP Add Custom CSS\" is a plugin by"
41
+ msgstr ""
42
+
43
+ #: ../wordpress-add-custom-css.php:116
44
+ msgid "Write here the CSS rules you want to apply to the whole website."
45
+ msgstr ""
46
+
47
+ #: ../wordpress-add-custom-css.php:202
48
+ msgid "Settings"
49
+ msgstr ""
readme.txt ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.0
6
+ Stable tag: 0.9
7
+ License: GPLv2
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ 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
+ == Installation ==
21
+
22
+ = Automatic installation =
23
+
24
+ 1. Go to Plugins > Add New > Upload and select the .zip file from your hard disk
25
+ 2. Click the "Install now" button
26
+ 3. Activate the plugin through the 'Plugins' menu in WordPress
27
+
28
+ = Manual installation =
29
+
30
+ 1. Upload the plugin folder to the `/wp-content/plugins/` directory via ftp
31
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
32
+
33
+ == Frequently Asked Questions ==
34
+
35
+ = How do I apply custom CSS to the whole website? =
36
+
37
+ Once the plugin is installed and activated, from your dashboard navigate to "Add custom CSS", and write the CSS rules in the textarea.
38
+
39
+ = How do I apply custom CSS to a specific post or page? =
40
+
41
+ Once the plugin is installed and activated, you will find a new box called "Custom CSS" in your post/page editing area.
42
+
43
+ = The "Custom CSS" box is not displaying, why? =
44
+
45
+ Click on the "Screen option" link from your post/page editing area and be sure the "Custom CSS" option is checked.
46
+
47
+ == Screenshots ==
48
+
49
+ 1. Add custom CSS to the whole website.
50
+ 2. Add custom CSS to specific posts.
51
+ 3. Add custom CSS to specific pages.
52
+
53
+ == Changelog ==
54
+
55
+ = 0.9 =
56
+ * First release
wordpress-add-custom-css.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
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
+ Author: Daniele De Santis
8
+ Author URI: http://www.danieledesantis.net
9
+ Text Domain: wp-add-custom-css
10
+ Domain Path: /languages/
11
+ 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
19
+ published by the Free Software Foundation.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
+ */
30
+
31
+ if (!defined('ABSPATH')) die ('No direct access allowed');
32
+
33
+ if(!class_exists('Wpacc'))
34
+ {
35
+ class Wpacc
36
+ {
37
+ private $options;
38
+
39
+ public function __construct() {
40
+ add_action('admin_menu', array($this, 'add_menu'));
41
+ add_action( 'admin_init', array( $this, 'init_settings' ) );
42
+ add_action( 'add_meta_boxes', array($this, 'add_meta_box' ) );
43
+ add_action( 'save_post', array( $this, 'single_save' ) );
44
+ add_action('init', array($this, 'init'));
45
+ add_filter('query_vars', array($this, 'add_wp_var'));
46
+ add_action( 'wp_enqueue_scripts', array($this, 'add_custom_css'), 999 );
47
+ add_action('wp_head', array($this, 'single_custom_css'));
48
+ }
49
+
50
+ public function init() {
51
+ load_plugin_textdomain( 'wp-add-custom-css', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
52
+ }
53
+
54
+ public static function uninstall() {
55
+ self::delete_options();
56
+ self::delete_custom_meta();
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
+ }
64
+ }
65
+
66
+ public function single_save( $post_id ) {
67
+ if ( ! isset( $_POST['wp_add_custom_css_box_nonce'] ) || ! wp_verify_nonce( $_POST['wp_add_custom_css_box_nonce'], 'single_add_custom_css_box' ) ) {
68
+ return;
69
+ }
70
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
71
+ return;
72
+ }
73
+ if ( 'page' == $_POST['post_type'] ) {
74
+ if ( ! current_user_can( 'edit_page', $post_id ) )
75
+ return;
76
+ } else {
77
+ if ( ! current_user_can( 'edit_post', $post_id ) )
78
+ return;
79
+ }
80
+
81
+ $single_custom_css = sanitize_text_field( $_POST['single_custom_css'] );
82
+ update_post_meta( $post_id, '_single_add_custom_css', $single_custom_css );
83
+ }
84
+
85
+ public function render_meta_box_content( $post ) {
86
+ wp_nonce_field( 'single_add_custom_css_box', 'wp_add_custom_css_box_nonce' );
87
+ $single_custom_css = get_post_meta( $post->ID, '_single_add_custom_css', true );
88
+ echo '<p>'. __( 'Add custom CSS rules for this ' . $post->post_type, 'wp-add-custom-css' ) . '</p> ';
89
+ echo '<textarea id="single_custom_css" name="single_custom_css" style="min-height:200px;">' . esc_attr( $single_custom_css ) . '</textarea>';
90
+ }
91
+
92
+ public function add_menu() {
93
+ global $wpacc_settings_page;
94
+ $wpacc_settings_page = add_menu_page('Wordpress Add Custom CSS', 'Add Custom CSS', 'manage_options', 'wp-add-custom-css_settings', array($this, 'create_settings_page'), plugin_dir_url( __FILE__ ) . '/images/icon.png');
95
+ }
96
+
97
+ public function create_settings_page() {
98
+ $this->options = get_option( 'wpacc_settings' );
99
+ ?>
100
+ <div class="wrap">
101
+ <h2><?php echo __('Wordpress Add Custom CSS', 'wp-add-custom-css'); ?></h2>
102
+ <form id="worpress_custom_css_form" method="post" action="options.php">
103
+ <?php settings_fields( 'wpacc_group' ); ?>
104
+ <?php do_settings_sections( 'wp-add-custom-css_settings' ); ?>
105
+ <?php submit_button( __('Save', 'wp-add-custom-css') ); ?>
106
+ </form>
107
+ <h3><?php echo __('Credits', 'wp-add-custom-css'); ?></h3>
108
+ <ul>
109
+ <li><?php echo __('"WP Add Custom CSS" is a plugin by', 'wp-add-custom-css'); ?> <a href="http://www.danieledesantis.net/" target="_blank" title="Daniele De Santis">Daniele De Santis</a></li>
110
+ </ul>
111
+ </div>
112
+ <?php
113
+ }
114
+
115
+ public function print_section_info() {
116
+ echo __('Write here the CSS rules you want to apply to the whole website.', 'wp-add-custom-css');
117
+ }
118
+
119
+ public function main_css_input() {
120
+ printf(
121
+ '<textarea name="wpacc_settings[main_custom_style]" style="min-height:300px;">%s</textarea>',
122
+ isset( $this->options['main_custom_style'] ) ? esc_attr( $this->options['main_custom_style'] ) : ''
123
+ );
124
+ }
125
+
126
+ public function init_settings() {
127
+ register_setting(
128
+ 'wpacc_group',
129
+ 'wpacc_settings'
130
+ );
131
+ add_settings_section(
132
+ 'wpacc_main_style',
133
+ 'Main CSS',
134
+ array( $this, 'print_section_info' ),
135
+ 'wp-add-custom-css_settings'
136
+ );
137
+ add_settings_field(
138
+ 'main_custom_style',
139
+ 'CSS rules',
140
+ array( $this, 'main_css_input' ),
141
+ 'wp-add-custom-css_settings',
142
+ 'wpacc_main_style'
143
+ );
144
+ }
145
+
146
+ public function delete_options() {
147
+ unregister_setting(
148
+ 'wpacc_group',
149
+ 'wpacc_settings'
150
+ );
151
+ delete_option('wpacc_settings');
152
+ }
153
+
154
+ public function delete_custom_meta() {
155
+ delete_post_meta_by_key('_single_add_custom_css');
156
+ }
157
+
158
+ public static function add_wp_var($public_query_vars) {
159
+ $public_query_vars[] = 'display_custom_css';
160
+ return $public_query_vars;
161
+ }
162
+
163
+ public static function display_custom_css(){
164
+ $display_css = get_query_var('display_custom_css');
165
+ if ($display_css == 'css'){
166
+ include_once (plugin_dir_path( __FILE__ ) . '/css/custom-css.php');
167
+ exit;
168
+ }
169
+ }
170
+
171
+ public function add_custom_css() {
172
+ $this->options = get_option( 'wpacc_settings' );
173
+ if ( isset($this->options['main_custom_style']) && $this->options['main_custom_style'] != '') {
174
+ wp_register_style( 'wp-add-custom-css', get_bloginfo('url') . '?display_custom_css=css' );
175
+ wp_enqueue_style( 'wp-add-custom-css' );
176
+ }
177
+ }
178
+
179
+ public function single_custom_css() {
180
+ if ( is_single() || is_page() ) {
181
+ global $post;
182
+ $single_custom_css = get_post_meta( $post->ID, '_single_add_custom_css', true );
183
+ if ( $single_custom_css !== '' ) {
184
+ $output = "<style type=\"text/css\">" . $single_custom_css . "</style>\n";
185
+ }
186
+ echo $output;
187
+ }
188
+ }
189
+
190
+
191
+ }
192
+ }
193
+
194
+ if(class_exists('Wpacc')) {
195
+ add_action('template_redirect', array('Wpacc', 'display_custom_css'));
196
+ register_uninstall_hook(__FILE__, array('Wpacc', 'uninstall'));
197
+ $wpacc = new Wpacc();
198
+ }
199
+
200
+ if(isset($wpacc)) {
201
+ function wpacc_settings_link($links) {
202
+ $settings_link = '<a href="admin.php?page=wp-add-custom-css_settings">' . __('Settings', 'wp-add-custom-css') . '</a>';
203
+ array_unshift($links, $settings_link);
204
+ return $links;
205
+ }
206
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wpacc_settings_link');
207
+ }
208
+
209
+ ?>