Scripts n Styles - Version 1.0.2

Version Description

  • Added fields for body_class and post_class
  • Merged meta boxes
  • Cleaned up code
  • Improved compatibility
  • Added Screenshot
Download this release

Release Info

Developer WraithKenny
Plugin Icon wp plugin Scripts n Styles
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

Files changed (4) hide show
  1. README.txt +20 -21
  2. screenshot-1.png +0 -0
  3. scripts-n-styles.php +141 -105
  4. uninstall.php +11 -11
README.txt CHANGED
@@ -1,16 +1,16 @@
1
  === Scripts n Styles ===
2
- Contributors: wraithkenny, touvan
3
- Tags: admin, per-page CSS styles, per-page JavaScript
 
4
  Requires at least: 3.0.1
5
- Tested up to: 3.0.1
6
- Stable tag: 1.0.1
7
-
8
- This plugin allows Admin users to individually add custom CSS and JavaScript directly to Post, Pages or any other registered custom post types.
9
 
 
10
 
11
  == Description ==
12
 
13
- This plugin allows Admin users the ability to add custom CSS (at the bottom of the 'head' tag) and JavaScript (at the bottom of the 'body' tag) directly into individual Post, Pages or any other registered custom post types.
14
 
15
  Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
16
 
@@ -21,14 +21,6 @@ A few notes about the implementation:
21
  * JavaScript is included inline, not linked, at the bottom of the `body` element with `script` tags by using `wp-footer`. If your theme doesn't have this hook, this plugin (as well as most others) won't work.
22
  * **There is no input validation.** This plugin puts exactly what you type in the meta box directly into the `html` with no error checking. You are an Admin, and we trust you to be carefull. Try not to break anything.
23
 
24
- I plan on implementing the following in future releases:
25
-
26
- * Syntax highlighting via CodeMirror or Skywriter (Bespin).
27
- * Option of including JavaScript in `wp-head` instead of `wp-footer` (Not very typical).
28
- * Ability to link .css and .js files.
29
- * Some sort of input validation.
30
- * Possibly add option to enable this functionality for Editor rolls. Admin would have to enable it **explicitly**. (Not so sure about this one. Are Editors generally trusted users?)
31
-
32
  == Installation ==
33
 
34
  This plugin does not require any special activation or template tags. Just get it from wordpress.org/extend, install and activate like normal.
@@ -45,14 +37,21 @@ Well, because plugins are supposed to, and should be expected to clean up after
45
 
46
  = Can I get around that somehow? =
47
 
48
- Sure, if you are an Admin, just go to the plugin editor and wipe out the uninstall.php (Replace everything with a space character) and then WordPress will not delete the meta data on uninstall.
49
 
50
  == Screenshots ==
51
 
52
- 1. I'll add a screenshot in the version with syntax highlighting, but for now, the plugin adds very simple Meta Boxes.
53
 
54
  == Changelog ==
55
 
 
 
 
 
 
 
 
56
  = 1.0.1 =
57
  * Some small plugin meta data updates.
58
 
@@ -61,8 +60,8 @@ Sure, if you are an Admin, just go to the plugin editor and wipe out the uninsta
61
 
62
  == Upgrade Notice ==
63
 
64
- = 1.0.1 =
65
- Some small plugin meta data updates.
66
 
67
- = 1.0 =
68
- Initial Release, there is nothing to upgrade from.
1
  === Scripts n Styles ===
2
+ Contributors: WraithKenny, Touvan
3
+ Donate link: http://wordpressfoundation.org/donate/
4
+ Tags: admin, CSS, javascript, code, custom, Style
5
  Requires at least: 3.0.1
6
+ Tested up to: 3.1.2
7
+ Stable tag: 1.0.2
 
 
8
 
9
+ This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
10
 
11
  == Description ==
12
 
13
+ This plugin allows Admin users the ability to add custom CSS (at the bottom of the `head` tag) and JavaScript (at the bottom of the `body` tag) directly into individual Post, Pages or any other registered custom post types. You can also add classes to the body tag and the post container (if your theme supports `body_class()` and `post_class()` functions).
14
 
15
  Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
16
 
21
  * JavaScript is included inline, not linked, at the bottom of the `body` element with `script` tags by using `wp-footer`. If your theme doesn't have this hook, this plugin (as well as most others) won't work.
22
  * **There is no input validation.** This plugin puts exactly what you type in the meta box directly into the `html` with no error checking. You are an Admin, and we trust you to be carefull. Try not to break anything.
23
 
 
 
 
 
 
 
 
 
24
  == Installation ==
25
 
26
  This plugin does not require any special activation or template tags. Just get it from wordpress.org/extend, install and activate like normal.
37
 
38
  = Can I get around that somehow? =
39
 
40
+ Sure, if you are an Admin, just go to the plugin editor and wipe out the `uninstall.php` (Replace everything with a space character) and then WordPress will not delete the meta data on uninstall.
41
 
42
  == Screenshots ==
43
 
44
+ 1. The New and Improved Meta Box.
45
 
46
  == Changelog ==
47
 
48
+ = 1.0.2 =
49
+ * Added fields for body_class and post_class
50
+ * Merged meta boxes
51
+ * Cleaned up code
52
+ * Improved compatibility
53
+ * Added Screenshot
54
+
55
  = 1.0.1 =
56
  * Some small plugin meta data updates.
57
 
60
 
61
  == Upgrade Notice ==
62
 
63
+ = 1.0.2 =
64
+ Minor update. Adds a few new features.
65
 
66
+ = 1.0.1 =
67
+ Some small plugin meta data updates.
screenshot-1.png ADDED
Binary file
scripts-n-styles.php CHANGED
@@ -1,106 +1,142 @@
1
- <?php
2
- /*
3
- Plugin Name: Scripts n Styles
4
- Plugin URI: http://www.unfocus.com/projects/scripts-n-styles/
5
- Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
6
- Author: unFocus Projects
7
- Author URI: http://www.unfocus.com/
8
- Version: 1.0.1
9
- License: GPL2
10
- */
11
-
12
- if ( !function_exists( 'add_action' ) ) {
13
- header( 'Status: 403 Forbidden' );
14
- header( 'HTTP/1.1 403 Forbidden' );
15
- exit();
16
- }
17
-
18
- if ( !class_exists( 'Scripts_n_Styles' ) ) {
19
-
20
- /**
21
- * @package Scripts_n_Styles
22
- * @version 1.0
23
- */
24
- class Scripts_n_Styles
25
- {
26
- const PREFIX = 'uFp_';
27
- function Scripts_n_Styles() {
28
- if ( is_admin() ) {
29
- add_action( 'add_meta_boxes', array( &$this, 'add' ));
30
- add_action( 'save_post', array( &$this, 'save_styles' ));
31
- add_action( 'save_post', array( &$this, 'save_scripts' ));
32
- }
33
- add_action( 'wp_head',array( &$this, 'styles' ));
34
- add_action( 'wp_footer',array( &$this, 'scripts' ));
35
- }
36
- function add() {
37
- if ( current_user_can( 'manage_options' ) ) {
38
- $registered_post_types = get_post_types();
39
- $post_type_defaults = array( 'mediapage', 'attachment', 'revision', 'nav_menu_item');
40
- $post_types = array_diff( $registered_post_types, $post_type_defaults );
41
- foreach ($post_types as $post_type ) {
42
- add_meta_box( self::PREFIX.'styles', 'Styles', array( &$this, 'styles_meta_box'), $post_type, 'normal', 'high' );
43
- add_meta_box( self::PREFIX.'scripts', 'Scripts', array(&$this, 'scripts_meta_box'), $post_type, 'normal', 'high' );
44
- }
45
- }
46
- }
47
- function styles_meta_box( $post ) {
48
- $value = get_post_meta( $post->ID, self::PREFIX.'styles', true ); ?>
49
- <input type="hidden" name="<?= self::PREFIX ?>styles_noncename" id="<?= self::PREFIX ?>styles_noncename" value="<?= wp_create_nonce( self::PREFIX.'styles' ) ?>" />
50
- <textarea name="<?= self::PREFIX ?>styles" id="<?= self::PREFIX ?>styles" rows="5" cols="30" style="width:100%;"><?php echo @ $value[ 'styles' ] ?></textarea>
51
- <?php
52
- }
53
- function scripts_meta_box( $post ) {
54
- $value = get_post_meta( $post->ID, self::PREFIX.'scripts', true ); ?>
55
- <input type="hidden" name="<?= self::PREFIX ?>scripts_noncename" id="<?= self::PREFIX ?>scripts_noncename" value="<?= wp_create_nonce( self::PREFIX.'scripts' ) ?>" />
56
- <textarea name="<?= self::PREFIX ?>scripts" id="<?= self::PREFIX ?>scripts" rows="5" cols="30" style="width:100%;"><?php echo @ $value[ 'scripts' ]; ?></textarea>
57
- <?php
58
- }
59
- function save_scripts( $post_id ) {
60
- if ( current_user_can( 'manage_options' ) ) {
61
- if ( !wp_verify_nonce( @$_POST[ self::PREFIX.'scripts_noncename' ], self::PREFIX.'scripts' ))
62
- return $post_id;
63
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
64
- return $post_id;
65
-
66
- $meta[ 'scripts' ] = $_POST[ self::PREFIX.'scripts' ];
67
- update_post_meta( $post_id, self::PREFIX.'scripts', $meta );
68
- }
69
- }
70
- function save_styles( $post_id ) {
71
- if ( current_user_can( 'manage_options' ) ) {
72
- if ( !wp_verify_nonce( @$_POST[ self::PREFIX.'styles_noncename' ], self::PREFIX.'styles' ) )
73
- return $post_id;
74
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
75
- return $post_id;
76
-
77
- $meta[ 'styles' ] = $_POST[ self::PREFIX.'styles' ];
78
- update_post_meta( $post_id, self::PREFIX.'styles', $meta );
79
- }
80
- }
81
- function styles() {
82
- if ( is_page() || is_single() ) {
83
- global $post;
84
- $styles = get_post_meta( $post->ID, self::PREFIX.'styles', true );
85
- if ( !empty( $styles ) ) { ?>
86
- <style type="text/css">
87
- <?php echo $styles[ 'styles' ]; ?>
88
- </style>
89
- <?php }
90
- }
91
- }
92
- function scripts() {
93
- if ( is_page() || is_single() ) {
94
- global $post;
95
- $scripts = get_post_meta( $post->ID , self::PREFIX.'scripts', true );
96
- if ( !empty( $scripts ) ) { ?>
97
- <script type="text/javascript">
98
- <?php echo $scripts[ 'scripts' ]; ?>
99
- </script>
100
- <?php }
101
- }
102
- }
103
- }
104
- $uFp_SnS = new Scripts_n_Styles;
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: Scripts n Styles
4
+ Plugin URI: http://www.unfocus.com/projects/scripts-n-styles/
5
+ Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
6
+ Author: unFocus Projects
7
+ Author URI: http://www.unfocus.com/
8
+ Version: 1.0.2
9
+ License: GPL2
10
+ */
11
+ /* Copyright 2010 Ken Newman www.unfocus.com
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License, version 2, as
15
+ published by the Free Software Foundation.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+
27
+ if ( !function_exists( 'add_action' ) ) {
28
+ header( 'Status: 403 Forbidden' );
29
+ header( 'HTTP/1.1 403 Forbidden' );
30
+ exit();
31
+ }
32
+
33
+ if ( !class_exists( 'Scripts_n_Styles' ) ) {
34
+
35
+ /**
36
+ * @package Scripts_n_Styles
37
+ * @version 1.0.2
38
+ */
39
+ class Scripts_n_Styles
40
+ {
41
+ const PREFIX = 'uFp_';
42
+ function Scripts_n_Styles() {
43
+ if ( is_admin() ) {
44
+ add_action( 'add_meta_boxes', array( &$this, 'add' ));
45
+ add_action( 'save_post', array( &$this, 'save' ));
46
+ }
47
+
48
+ add_filter('body_class', array( &$this, 'body_classes' ));
49
+ add_filter('post_class', array( &$this, 'post_classes' ));
50
+
51
+ add_action( 'wp_head',array( &$this, 'styles' ));
52
+ add_action( 'wp_footer',array( &$this, 'scripts' ));
53
+ }
54
+ function add() {
55
+ if ( current_user_can( 'manage_options' ) ) {
56
+ $registered_post_types = get_post_types();
57
+ $post_type_defaults = array( 'mediapage', 'attachment', 'revision', 'nav_menu_item');
58
+ $post_types = array_diff( $registered_post_types, $post_type_defaults );
59
+ foreach ($post_types as $post_type ) {
60
+ add_meta_box( self::PREFIX.'meta_box', 'Scripts n Styles', array( &$this, 'meta_box'), $post_type, 'normal', 'high' );
61
+ }
62
+ }
63
+ }
64
+ function meta_box( $post ) {
65
+ $styles = get_post_meta( $post->ID, self::PREFIX.'styles', true );
66
+ $scripts = get_post_meta( $post->ID, self::PREFIX.'scripts', true );
67
+ ?>
68
+ <input type="hidden" name="<?php echo self::PREFIX ?>scripts_n_styles_noncename" id="<?php echo self::PREFIX ?>scripts_n_styles_noncename" value="<?php echo wp_create_nonce( self::PREFIX.'scripts_n_styles' ) ?>" />
69
+ <p style="margin-top:1.5em">
70
+ <label style="font-weight:bold;" for="<?php echo self::PREFIX ?>scripts">Scripts: </label>
71
+ <textarea class="code" name="<?php echo self::PREFIX ?>scripts" id="<?php echo self::PREFIX ?>scripts" rows="5" cols="40" style="width:98%;"><?php echo @ $scripts[ 'scripts' ]; ?></textarea>
72
+ <em>This code will be included <strong>verbatim</strong> in the &lt;script> tags at the end of your page's (or post's) &lt;body> tag.</em></p>
73
+
74
+ <p style="margin-top:1.5em">
75
+ <label style="font-weight:bold;" for="<?php echo self::PREFIX ?>scripts">Styles: </label>
76
+ <textarea class="code" name="<?php echo self::PREFIX ?>styles" id="<?php echo self::PREFIX ?>styles" rows="5" cols="40" style="width:98%;"><?php echo @ $styles[ 'styles' ] ?></textarea>
77
+ <em>This code will be included <strong>verbatim</strong> in the &lt;style> tags in the &lt;head> tag of your page (or post).</em></p>
78
+
79
+ <p style="margin-top:1.5em">
80
+ <strong>Classes: </strong></p>
81
+ <p><label style="width:15%; min-width:85px; display: inline-block;" for="<?php echo self::PREFIX ?>classes_body">body_class(): </label><input style="width:84%;" name="<?php echo self::PREFIX ?>classes_body" id="<?php echo self::PREFIX ?>classes_body" value="<?php echo @ $styles[ 'classes_body' ]; ?>" type="text" class="code" /></p>
82
+ <p><label style="width:15%; min-width:85px; display: inline-block;" for="<?php echo self::PREFIX ?>classes_post">post_class(): </label><input style="width:84%;" name="<?php echo self::PREFIX ?>classes_post" id="<?php echo self::PREFIX ?>classes_post" value="<?php echo @ $styles[ 'classes_post' ]; ?>" type="text" class="code" /></p>
83
+ <p><em>These <strong>space separated</strong> class names will be pushed into the body_class() or post_class() function (provided your theme uses these functions).</em></p>
84
+ <?php
85
+ }
86
+ function save( $post_id ) {
87
+ if ( current_user_can( 'manage_options' ) ) {
88
+ if ( !wp_verify_nonce( @$_POST[ self::PREFIX.'scripts_n_styles_noncename' ], self::PREFIX.'scripts_n_styles' ))
89
+ return $post_id;
90
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
91
+ return $post_id;
92
+
93
+ $scripts[ 'scripts' ] = $_POST[ self::PREFIX.'scripts' ];
94
+ $styles[ 'styles' ] = $_POST[ self::PREFIX.'styles' ];
95
+ $styles[ 'classes_body' ] = $_POST[ self::PREFIX.'classes_body' ];
96
+ $styles[ 'classes_post' ] = $_POST[ self::PREFIX.'classes_post' ];
97
+ update_post_meta( $post_id, self::PREFIX.'scripts', $scripts );
98
+ update_post_meta( $post_id, self::PREFIX.'styles', $styles );
99
+ }
100
+ }
101
+ function styles() {
102
+ if ( is_page() || is_single() ) {
103
+ global $post;
104
+ $meta = get_post_meta( $post->ID, self::PREFIX.'styles', true );
105
+ if ( !empty( $meta ) ) { ?>
106
+ <style type="text/css">
107
+ <?php echo $meta[ 'styles' ]; ?>
108
+ </style>
109
+ <?php }
110
+ }
111
+ }
112
+ function scripts() {
113
+ if ( is_page() || is_single() ) {
114
+ global $post;
115
+ $meta = get_post_meta( $post->ID , self::PREFIX.'scripts', true );
116
+ if ( !empty( $meta ) ) { ?>
117
+ <script type="text/javascript">
118
+ <?php echo $meta[ 'scripts' ]; ?>
119
+ </script>
120
+ <?php }
121
+ }
122
+ }
123
+ function body_classes( $classes ) {
124
+ global $post;
125
+ $meta = get_post_meta( $post->ID , self::PREFIX.'styles', true );
126
+ if ( !empty( $meta ) && !empty( $meta['classes_body'] ) ) {
127
+ $classes[] = $meta['classes_body'];
128
+ }
129
+ return $classes;
130
+ }
131
+ function post_classes( $classes ) {
132
+ global $post;
133
+ $meta = get_post_meta( $post->ID , self::PREFIX.'styles', true );
134
+ if ( !empty( $meta ) && !empty( $meta['classes_post'] ) ) {
135
+ $classes[] = $meta['classes_post'];
136
+ }
137
+ return $classes;
138
+ }
139
+ }
140
+ $uFp_SnS = new Scripts_n_Styles;
141
+ }
142
  ?>
uninstall.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
3
- exit();
4
- $get_posts_args = array('numberposts' => -1,
5
- 'post_type' => 'any',
6
- 'post_status' => 'any' );
7
- $all_posts = get_posts( $get_posts_args );
8
- foreach( $all_posts as $postinfo) {
9
- delete_post_meta($postinfo->ID, 'uFp_scripts');
10
- delete_post_meta($postinfo->ID, 'uFp_styles');
11
- }
12
  ?>
1
+ <?php
2
+ if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
3
+ exit();
4
+ $get_posts_args = array('numberposts' => -1,
5
+ 'post_type' => 'any',
6
+ 'post_status' => 'any' );
7
+ $all_posts = get_posts( $get_posts_args );
8
+ foreach( $all_posts as $postinfo) {
9
+ delete_post_meta($postinfo->ID, 'uFp_scripts');
10
+ delete_post_meta($postinfo->ID, 'uFp_styles');
11
+ }
12
  ?>