Version Description
- Option to show Metabox by default
- Check upgrade in more places
- Fix double Settings Message on general-options
- Fix empty post showing on usage
- Cleaned up constants (internal)
Download this release
Release Info
Developer | WraithKenny |
Plugin | Scripts n Styles |
Version | 3.0 |
Comparing to | |
See all releases |
Code changes from version 3 to 3.0
- README.txt +12 -2
- includes/class.SnS_Admin.php +203 -211
- includes/class.SnS_Admin_Meta_Box.php +13 -5
- includes/class.SnS_Form.php +27 -2
- includes/class.SnS_Global_Page.php +16 -21
- includes/class.SnS_List_Usage.php +26 -26
- includes/class.SnS_Settings_Page.php +24 -9
- includes/class.SnS_Usage_Page.php +4 -4
- scripts-n-styles.php +322 -312
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: WraithKenny, Touvan
|
|
3 |
Donate link: http://wordpressfoundation.org/donate/
|
4 |
Tags: admin, CSS, javascript, code, custom, Style
|
5 |
Requires at least: 3.2
|
6 |
-
Tested up to: 3.3-
|
7 |
-
Stable tag: 3
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
|
@@ -53,6 +53,13 @@ Sure, if you are an Admin, just go to the plugin editor and wipe out the uninsta
|
|
53 |
|
54 |
== Changelog ==
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
= 3 =
|
57 |
* AJAX Saving of Meta-box
|
58 |
* Dynamically populate the Styles Dropdown for TinyMCE
|
@@ -90,6 +97,9 @@ Sure, if you are an Admin, just go to the plugin editor and wipe out the uninsta
|
|
90 |
|
91 |
== Upgrade Notice ==
|
92 |
|
|
|
|
|
|
|
93 |
= 3 =
|
94 |
Adds new features.
|
95 |
|
3 |
Donate link: http://wordpressfoundation.org/donate/
|
4 |
Tags: admin, CSS, javascript, code, custom, Style
|
5 |
Requires at least: 3.2
|
6 |
+
Tested up to: 3.3-RC2
|
7 |
+
Stable tag: 3.0
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
|
53 |
|
54 |
== Changelog ==
|
55 |
|
56 |
+
= 3.0 =
|
57 |
+
* Option to show Metabox by default
|
58 |
+
* Check upgrade in more places
|
59 |
+
* Fix double Settings Message on general-options
|
60 |
+
* Fix empty post showing on usage
|
61 |
+
* Cleaned up constants (internal)
|
62 |
+
|
63 |
= 3 =
|
64 |
* AJAX Saving of Meta-box
|
65 |
* Dynamically populate the Styles Dropdown for TinyMCE
|
97 |
|
98 |
== Upgrade Notice ==
|
99 |
|
100 |
+
= 3.0 =
|
101 |
+
Bug fixes
|
102 |
+
|
103 |
= 3 =
|
104 |
Adds new features.
|
105 |
|
includes/class.SnS_Admin.php
CHANGED
@@ -1,212 +1,204 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Scripts n Styles Admin Class
|
4 |
-
*
|
5 |
-
* Allows WordPress admin users the ability to add custom CSS
|
6 |
-
* and JavaScript directly to individual Post, Pages or custom
|
7 |
-
* post types.
|
8 |
-
*/
|
9 |
-
|
10 |
-
require_once( 'class.SnS_Admin_Meta_Box.php' );
|
11 |
-
require_once( 'class.SnS_Settings_Page.php' );
|
12 |
-
require_once( 'class.SnS_Usage_Page.php' );
|
13 |
-
require_once( 'class.SnS_Global_Page.php' );
|
14 |
-
require_once( 'class.SnS_AJAX.php' );
|
15 |
-
require_once( 'class.SnS_Form.php' );
|
16 |
-
|
17 |
-
class SnS_Admin
|
18 |
-
{
|
19 |
-
/**#@+
|
20 |
-
* Constants
|
21 |
-
*/
|
22 |
-
const OPTION_GROUP = 'scripts_n_styles';
|
23 |
-
const MENU_SLUG = 'sns';
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
$plugin_file
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
$
|
49 |
-
$
|
50 |
-
$
|
51 |
-
|
52 |
-
|
53 |
-
if ( in_array( $menu_spot, $
|
54 |
-
else
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
$page = $_REQUEST[ 'page' ];
|
80 |
-
?>
|
81 |
-
<?php screen_icon(); ?>
|
82 |
-
<h2>Scripts n Styles</h2>
|
83 |
-
<?php
|
84 |
-
|
85 |
-
|
86 |
-
<a class="nav-tab<?php echo ( self::MENU_SLUG
|
87 |
-
<a class="nav-tab<?php echo ( self::MENU_SLUG . '
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
'
|
103 |
-
'
|
104 |
-
|
105 |
-
<
|
106 |
-
|
107 |
-
<em>
|
108 |
-
<em>
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
'<p>' . __( '
|
116 |
-
'<p>' . __( '<a href="
|
117 |
-
'<p>' . __( '<a href="
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
'
|
123 |
-
'
|
124 |
-
|
125 |
-
<
|
126 |
-
|
127 |
-
<em>
|
128 |
-
<em>
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
$options
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
'
|
153 |
-
'
|
154 |
-
'
|
155 |
-
|
156 |
-
|
157 |
-
array( 'key' => '
|
158 |
-
array( 'key' => '
|
159 |
-
array( 'key' => '
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
delete_post_meta( $post->ID, '
|
185 |
-
delete_post_meta( $post->ID, '
|
186 |
-
delete_post_meta( $post->ID, '
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
*/
|
205 |
-
static function plugin_action_links( $actions ) {
|
206 |
-
$actions[ 'settings' ] = '<a href="' . menu_page_url( SnS_Settings_Page::MENU_SLUG, false ) . '"/>Settings</a>';
|
207 |
-
return $actions;
|
208 |
-
}
|
209 |
-
|
210 |
-
}
|
211 |
-
|
212 |
?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Scripts n Styles Admin Class
|
4 |
+
*
|
5 |
+
* Allows WordPress admin users the ability to add custom CSS
|
6 |
+
* and JavaScript directly to individual Post, Pages or custom
|
7 |
+
* post types.
|
8 |
+
*/
|
9 |
+
|
10 |
+
require_once( 'class.SnS_Admin_Meta_Box.php' );
|
11 |
+
require_once( 'class.SnS_Settings_Page.php' );
|
12 |
+
require_once( 'class.SnS_Usage_Page.php' );
|
13 |
+
require_once( 'class.SnS_Global_Page.php' );
|
14 |
+
require_once( 'class.SnS_AJAX.php' );
|
15 |
+
require_once( 'class.SnS_Form.php' );
|
16 |
+
|
17 |
+
class SnS_Admin
|
18 |
+
{
|
19 |
+
/**#@+
|
20 |
+
* Constants
|
21 |
+
*/
|
22 |
+
const OPTION_GROUP = 'scripts_n_styles';
|
23 |
+
const MENU_SLUG = 'sns';
|
24 |
+
static $parent_slug = '';
|
25 |
+
/**#@-*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Initializing method.
|
29 |
+
* @static
|
30 |
+
*/
|
31 |
+
static function init() {
|
32 |
+
add_action( 'admin_menu', array( 'SnS_Admin_Meta_Box', 'init' ) );
|
33 |
+
|
34 |
+
add_action( 'admin_menu', array( __CLASS__, 'menu' ) );
|
35 |
+
|
36 |
+
add_action( 'admin_init', array( 'SnS_AJAX', 'init' ) );
|
37 |
+
|
38 |
+
$plugin_file = plugin_basename( Scripts_n_Styles::$file );
|
39 |
+
add_filter( "plugin_action_links_$plugin_file", array( __CLASS__, 'plugin_action_links') );
|
40 |
+
|
41 |
+
register_activation_hook( Scripts_n_Styles::$file, array( __CLASS__, 'upgrade' ) );
|
42 |
+
}
|
43 |
+
|
44 |
+
function menu() {
|
45 |
+
if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) ) return;
|
46 |
+
|
47 |
+
$options = get_option( 'SnS_options' );
|
48 |
+
$menu_spot = isset( $options[ 'menu_position' ] ) ? $options[ 'menu_position' ]: '';
|
49 |
+
$top_spots = array( 'menu', 'object', 'utility' );
|
50 |
+
$sub_spots = array( 'tools.php', 'options-general.php', 'themes.php' );
|
51 |
+
|
52 |
+
if ( in_array( $menu_spot, $top_spots ) ) $parent_slug = SnS_Admin::MENU_SLUG;
|
53 |
+
else if ( in_array( $menu_spot, $sub_spots ) ) $parent_slug = $menu_spot;
|
54 |
+
else $parent_slug = 'tools.php';
|
55 |
+
|
56 |
+
self::$parent_slug = $parent_slug;
|
57 |
+
|
58 |
+
switch( $menu_spot ) {
|
59 |
+
case 'menu':
|
60 |
+
add_menu_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
|
61 |
+
break;
|
62 |
+
case 'object':
|
63 |
+
add_object_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
|
64 |
+
break;
|
65 |
+
case 'utility':
|
66 |
+
add_utility_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
|
67 |
+
break;
|
68 |
+
}
|
69 |
+
SnS_Global_Page::init();
|
70 |
+
SnS_Settings_Page::init();
|
71 |
+
SnS_Usage_Page::init();
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Nav Tabs
|
76 |
+
*/
|
77 |
+
function nav() {
|
78 |
+
$options = get_option( 'SnS_options' );
|
79 |
+
$page = $_REQUEST[ 'page' ];
|
80 |
+
?>
|
81 |
+
<?php screen_icon(); ?>
|
82 |
+
<h2>Scripts n Styles</h2>
|
83 |
+
<?php if ( ! isset( $options[ 'menu_position' ] ) || 'options-general.php' != $options[ 'menu_position' ] ) settings_errors(); ?>
|
84 |
+
<?php screen_icon( 'none' ); ?>
|
85 |
+
<h3 class="nav-tab-wrapper">
|
86 |
+
<a class="nav-tab<?php echo ( self::MENU_SLUG == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG ); ?>"><?php _e( 'Global', 'scripts-n-styles' ); ?></a>
|
87 |
+
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_settings' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_settings' ); ?>"><?php _e( 'Settings', 'scripts-n-styles' ); ?></a>
|
88 |
+
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_usage' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_usage' ); ?>"><?php _e( 'Usage', 'scripts-n-styles' ); ?></a>
|
89 |
+
</h3>
|
90 |
+
<?php
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Settings Page help
|
95 |
+
*/
|
96 |
+
function help() {
|
97 |
+
global $wp_version; // Back Compat for now
|
98 |
+
if ( version_compare( $wp_version, '3.2.1', '>') ) {
|
99 |
+
$screen = get_current_screen();
|
100 |
+
if ( 'post' != $screen->id ) {
|
101 |
+
$screen->add_help_tab( array(
|
102 |
+
'title' => __( 'Scripts n Styles', 'scripts-n-styles' ),
|
103 |
+
'id' => 'scripts-n-styles',
|
104 |
+
'content' =>
|
105 |
+
'<p>' . __( '<p>In default (non MultiSite) WordPress installs, both <em>Administrators</em> and
|
106 |
+
<em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens.
|
107 |
+
Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only
|
108 |
+
<em>"Super Admin"</em> users can access either
|
109 |
+
<em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change
|
110 |
+
capabilities (specifically "unfiltered_html"),
|
111 |
+
other users can be granted access.</p>', 'scripts-n-styles' ) . '</p>'
|
112 |
+
)
|
113 |
+
);
|
114 |
+
$screen->set_help_sidebar(
|
115 |
+
'<p><strong>' . __( 'For more information:', 'scripts-n-styles' ) . '</strong></p>' .
|
116 |
+
'<p>' . __( '<a href="http://wordpress.org/extend/plugins/scripts-n-styles/faq/" target="_blank">Frequently Asked Questions</a>', 'scripts-n-styles' ) . '</p>' .
|
117 |
+
'<p>' . __( '<a href="https://github.com/unFocus/Scripts-n-Styles" target="_blank">Source on github</a>', 'scripts-n-styles' ) . '</p>' .
|
118 |
+
'<p>' . __( '<a href="http://wordpress.org/tags/scripts-n-styles" target="_blank">Support Forums</a>', 'scripts-n-styles' ) . '</p>'
|
119 |
+
);
|
120 |
+
} else {
|
121 |
+
$screen->add_help_tab( array(
|
122 |
+
'title' => __( 'Scripts n Styles', 'scripts-n-styles' ),
|
123 |
+
'id' => 'scripts-n-styles',
|
124 |
+
'content' =>
|
125 |
+
'<p>' . __( '<p>In default (non MultiSite) WordPress installs, both <em>Administrators</em> and
|
126 |
+
<em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens.
|
127 |
+
Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only
|
128 |
+
<em>"Super Admin"</em> users can access either
|
129 |
+
<em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change
|
130 |
+
capabilities (specifically "unfiltered_html"),
|
131 |
+
other users can be granted access.</p>', 'scripts-n-styles' ) . '</p>'
|
132 |
+
)
|
133 |
+
);
|
134 |
+
}
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Utility Method: Sets defaults if not previously set. Sets stored 'version' to VERSION.
|
140 |
+
*/
|
141 |
+
static function upgrade() {
|
142 |
+
$options = get_option( 'SnS_options' );
|
143 |
+
if ( ! $options ) $options = array();
|
144 |
+
$options[ 'version' ] = Scripts_n_Styles::VERSION;
|
145 |
+
update_option( 'SnS_options', $options );
|
146 |
+
|
147 |
+
/*
|
148 |
+
* upgrade proceedure
|
149 |
+
*/
|
150 |
+
$posts = get_posts(
|
151 |
+
array(
|
152 |
+
'numberposts' => -1,
|
153 |
+
'post_type' => 'any',
|
154 |
+
'post_status' => 'any',
|
155 |
+
'meta_query' => array(
|
156 |
+
'relation' => 'OR',
|
157 |
+
array( 'key' => '_SnS_scripts' ),
|
158 |
+
array( 'key' => '_SnS_styles' ),
|
159 |
+
array( 'key' => 'uFp_scripts' ),
|
160 |
+
array( 'key' => 'uFp_styles' )
|
161 |
+
)
|
162 |
+
)
|
163 |
+
);
|
164 |
+
|
165 |
+
foreach( $posts as $post) {
|
166 |
+
$styles = get_post_meta( $post->ID, '_SnS_styles', true );
|
167 |
+
if ( empty( $styles ) )
|
168 |
+
$styles = get_post_meta( $post->ID, 'uFp_styles', true );
|
169 |
+
|
170 |
+
$scripts = get_post_meta( $post->ID, '_SnS_scripts', true );
|
171 |
+
if ( empty( $scripts ) )
|
172 |
+
$scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
|
173 |
+
|
174 |
+
$SnS = array();
|
175 |
+
if ( ! empty( $styles ) )
|
176 |
+
$SnS[ 'styles' ] = $styles;
|
177 |
+
|
178 |
+
if ( ! empty( $scripts ) )
|
179 |
+
$SnS[ 'scripts' ] = $scripts;
|
180 |
+
|
181 |
+
if ( ! empty( $SnS ) )
|
182 |
+
update_post_meta( $post->ID, '_SnS', $SnS );
|
183 |
+
|
184 |
+
delete_post_meta( $post->ID, 'uFp_styles' );
|
185 |
+
delete_post_meta( $post->ID, 'uFp_scripts' );
|
186 |
+
delete_post_meta( $post->ID, '_SnS_styles' );
|
187 |
+
delete_post_meta( $post->ID, '_SnS_scripts' );
|
188 |
+
}
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Adds link to the Settings Page in the WordPress "Plugin Action Links" array.
|
194 |
+
* @param array $actions
|
195 |
+
* @return array
|
196 |
+
*/
|
197 |
+
static function plugin_action_links( $actions ) {
|
198 |
+
$actions[ 'settings' ] = '<a href="' . menu_page_url( SnS_Settings_Page::MENU_SLUG, false ) . '"/>' . __( 'Settings' ) . '</a>';
|
199 |
+
return $actions;
|
200 |
+
}
|
201 |
+
|
202 |
+
}
|
203 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
?>
|
includes/class.SnS_Admin_Meta_Box.php
CHANGED
@@ -104,7 +104,12 @@ class SnS_Admin_Meta_Box
|
|
104 |
}
|
105 |
|
106 |
static function default_hidden_meta_boxes( $hidden ) {
|
107 |
-
$
|
|
|
|
|
|
|
|
|
|
|
108 |
return $hidden;
|
109 |
}
|
110 |
|
@@ -265,7 +270,7 @@ class SnS_Admin_Meta_Box
|
|
265 |
|
266 |
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.18' );
|
267 |
wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
268 |
-
wp_enqueue_style( 'sns-meta-box-styles', plugins_url( 'css/meta-box-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ),
|
269 |
}
|
270 |
|
271 |
/**
|
@@ -328,7 +333,7 @@ class SnS_Admin_Meta_Box
|
|
328 |
//'codemirror-htmlmixed',
|
329 |
//'codemirror-php'
|
330 |
),
|
331 |
-
|
332 |
|
333 |
wp_localize_script( 'sns-meta-box-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
|
334 |
}
|
@@ -368,8 +373,11 @@ class SnS_Admin_Meta_Box
|
|
368 |
if ( isset( $styles[ 'classes_mce' ] ) && empty( $styles[ 'classes_mce' ] ) )
|
369 |
unset( $styles[ 'classes_mce' ] );
|
370 |
|
371 |
-
$SnS['scripts']
|
372 |
-
$SnS['
|
|
|
|
|
|
|
373 |
|
374 |
if ( empty( $SnS ) )
|
375 |
delete_post_meta( $post_id, '_SnS' );
|
104 |
}
|
105 |
|
106 |
static function default_hidden_meta_boxes( $hidden ) {
|
107 |
+
$options = get_option( 'SnS_options' );
|
108 |
+
if ( ! isset( $options[ 'metabox' ] ) )
|
109 |
+
$hidden[] = 'SnS_meta_box';
|
110 |
+
else if ( 'yes' == $options[ 'metabox' ] )
|
111 |
+
$hidden[] = 'SnS_meta_box';
|
112 |
+
|
113 |
return $hidden;
|
114 |
}
|
115 |
|
270 |
|
271 |
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.18' );
|
272 |
wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
273 |
+
wp_enqueue_style( 'sns-meta-box-styles', plugins_url( 'css/meta-box-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
|
274 |
}
|
275 |
|
276 |
/**
|
333 |
//'codemirror-htmlmixed',
|
334 |
//'codemirror-php'
|
335 |
),
|
336 |
+
Scripts_n_Styles::VERSION, true );
|
337 |
|
338 |
wp_localize_script( 'sns-meta-box-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
|
339 |
}
|
373 |
if ( isset( $styles[ 'classes_mce' ] ) && empty( $styles[ 'classes_mce' ] ) )
|
374 |
unset( $styles[ 'classes_mce' ] );
|
375 |
|
376 |
+
if ( empty( $scripts ) ) unset( $SnS['scripts'] );
|
377 |
+
else $SnS['scripts'] = $scripts;
|
378 |
+
|
379 |
+
if ( empty( $styles ) ) unset( $SnS['styles'] );
|
380 |
+
else $SnS['styles'] = $styles;
|
381 |
|
382 |
if ( empty( $SnS ) )
|
383 |
delete_post_meta( $post_id, '_SnS' );
|
includes/class.SnS_Form.php
CHANGED
@@ -31,6 +31,33 @@ class SnS_Form
|
|
31 |
echo $output;
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
/**
|
35 |
* Settings Page
|
36 |
* Outputs a select element for selecting options to set scripts for including.
|
@@ -127,11 +154,9 @@ class SnS_Form
|
|
127 |
* Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
|
128 |
*/
|
129 |
function page() {
|
130 |
-
SnS_Admin::upgrade_check();
|
131 |
?>
|
132 |
<div class="wrap">
|
133 |
<?php SnS_Admin::nav(); ?>
|
134 |
-
<?php settings_errors(); ?>
|
135 |
<form action="" method="post" autocomplete="off">
|
136 |
<?php settings_fields( SnS_Admin::OPTION_GROUP ); ?>
|
137 |
<?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
|
31 |
echo $output;
|
32 |
}
|
33 |
|
34 |
+
function radio( $args ) {
|
35 |
+
extract( $args );
|
36 |
+
$options = get_option( $setting );
|
37 |
+
$default = isset( $default ) ? $default : '';
|
38 |
+
$value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : $default;
|
39 |
+
$output = '<fieldset>';
|
40 |
+
if ( $legend ) {
|
41 |
+
$output .= '<legend class="screen-reader-text"><span>';
|
42 |
+
$output .= $legend;
|
43 |
+
$output .= '</span></legend>';
|
44 |
+
}
|
45 |
+
$output .= '<p>';
|
46 |
+
foreach ( $choices as $choice ) {
|
47 |
+
$output .= '<label>';
|
48 |
+
$output .= '<input type="radio"';
|
49 |
+
$output .= checked( $value, $choice, false );
|
50 |
+
$output .= ' value="' . $choice . '" name="' . $setting . '[' . $label_for . ']"> ' . $choice;
|
51 |
+
$output .= '</label>';
|
52 |
+
$output .= '<br>';
|
53 |
+
}
|
54 |
+
$output .= '</p></fieldset>';
|
55 |
+
if ( $description ) {
|
56 |
+
$output .= $description;
|
57 |
+
}
|
58 |
+
echo $output;
|
59 |
+
}
|
60 |
+
|
61 |
/**
|
62 |
* Settings Page
|
63 |
* Outputs a select element for selecting options to set scripts for including.
|
154 |
* Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
|
155 |
*/
|
156 |
function page() {
|
|
|
157 |
?>
|
158 |
<div class="wrap">
|
159 |
<?php SnS_Admin::nav(); ?>
|
|
|
160 |
<form action="" method="post" autocomplete="off">
|
161 |
<?php settings_fields( SnS_Admin::OPTION_GROUP ); ?>
|
162 |
<?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
|
includes/class.SnS_Global_Page.php
CHANGED
@@ -9,20 +9,15 @@
|
|
9 |
|
10 |
class SnS_Global_Page
|
11 |
{
|
12 |
-
/**
|
13 |
-
* Constants
|
14 |
-
*/
|
15 |
-
const OPTION_GROUP = 'scripts_n_styles';
|
16 |
-
|
17 |
/**
|
18 |
* Initializing method.
|
19 |
* @static
|
20 |
*/
|
21 |
function init() {
|
22 |
-
if ( SnS_Admin::$parent_slug == SnS_Admin::MENU_SLUG ) $menu_title = 'Global';
|
23 |
-
else $menu_title = 'Scripts n Styles';
|
24 |
|
25 |
-
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, 'Scripts n Styles', $menu_title, 'unfiltered_html', SnS_Admin::MENU_SLUG, array( 'SnS_Form', 'page' ) );
|
26 |
|
27 |
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
|
28 |
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
|
@@ -33,11 +28,11 @@ class SnS_Global_Page
|
|
33 |
function admin_enqueue_scripts() {
|
34 |
$options = get_option( 'SnS_options' );
|
35 |
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
|
36 |
-
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ),
|
37 |
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.18' );
|
38 |
wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
39 |
|
40 |
-
wp_enqueue_script( 'sns-global-page-scripts', plugins_url('js/global-page.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-css', 'codemirror-javascript' ),
|
41 |
wp_localize_script( 'sns-global-page-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
|
42 |
wp_enqueue_script( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.18' );
|
43 |
wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
@@ -50,18 +45,18 @@ class SnS_Global_Page
|
|
50 |
function admin_load() {
|
51 |
|
52 |
register_setting(
|
53 |
-
|
54 |
'SnS_options' );
|
55 |
|
56 |
add_settings_section(
|
57 |
'global',
|
58 |
-
'Global Scripts n Styles',
|
59 |
array( __CLASS__, 'global_section' ),
|
60 |
SnS_Admin::MENU_SLUG );
|
61 |
|
62 |
add_settings_field(
|
63 |
'scripts',
|
64 |
-
'<strong>Scripts:</strong> ',
|
65 |
array( 'SnS_Form', 'textarea' ),
|
66 |
SnS_Admin::MENU_SLUG,
|
67 |
'global',
|
@@ -72,11 +67,11 @@ class SnS_Global_Page
|
|
72 |
'rows' => 5,
|
73 |
'cols' => 40,
|
74 |
'style' => 'min-width: 500px; width:97%;',
|
75 |
-
'description' => '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code><script></code> tags at the bottom of the <code><body></code> element of your html.</span>'
|
76 |
) );
|
77 |
add_settings_field(
|
78 |
'styles',
|
79 |
-
'<strong>Styles:</strong> ',
|
80 |
array( 'SnS_Form', 'textarea' ),
|
81 |
SnS_Admin::MENU_SLUG,
|
82 |
'global',
|
@@ -87,11 +82,11 @@ class SnS_Global_Page
|
|
87 |
'rows' => 5,
|
88 |
'cols' => 40,
|
89 |
'style' => 'min-width: 500px; width:97%;',
|
90 |
-
'description' => '<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code><style></code> tags in the <code><head></code> element of your html.</span>'
|
91 |
) );
|
92 |
add_settings_field(
|
93 |
'scripts_in_head',
|
94 |
-
'<strong>Scripts</strong><br />(for the <code>head</code> element): ',
|
95 |
array( 'SnS_Form', 'textarea' ),
|
96 |
SnS_Admin::MENU_SLUG,
|
97 |
'global',
|
@@ -102,11 +97,11 @@ class SnS_Global_Page
|
|
102 |
'rows' => 5,
|
103 |
'cols' => 40,
|
104 |
'style' => 'min-width: 500px; width:97%;',
|
105 |
-
'description' => '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code><script></code> tags in the <code><head></code> element of your html.</span>'
|
106 |
) );
|
107 |
add_settings_field(
|
108 |
'enqueue_scripts',
|
109 |
-
'<strong>Enqueue Scripts</strong>: ',
|
110 |
array( 'SnS_Form', 'select' ),
|
111 |
SnS_Admin::MENU_SLUG,
|
112 |
'global',
|
@@ -117,7 +112,7 @@ class SnS_Global_Page
|
|
117 |
'size' => 5,
|
118 |
'style' => 'height: auto;',
|
119 |
'multiple' => true,
|
120 |
-
'show_current' => 'Currently Enqueued Scripts: '
|
121 |
) );
|
122 |
}
|
123 |
|
@@ -128,7 +123,7 @@ class SnS_Global_Page
|
|
128 |
function global_section() {
|
129 |
?>
|
130 |
<div style="max-width: 55em;">
|
131 |
-
<p
|
132 |
</div>
|
133 |
<?php
|
134 |
}
|
9 |
|
10 |
class SnS_Global_Page
|
11 |
{
|
|
|
|
|
|
|
|
|
|
|
12 |
/**
|
13 |
* Initializing method.
|
14 |
* @static
|
15 |
*/
|
16 |
function init() {
|
17 |
+
if ( SnS_Admin::$parent_slug == SnS_Admin::MENU_SLUG ) $menu_title = __( 'Global', 'scripts-n-styles' );
|
18 |
+
else $menu_title = __( 'Scripts n Styles', 'scripts-n-styles' );
|
19 |
|
20 |
+
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), $menu_title, 'unfiltered_html', SnS_Admin::MENU_SLUG, array( 'SnS_Form', 'page' ) );
|
21 |
|
22 |
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
|
23 |
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
|
28 |
function admin_enqueue_scripts() {
|
29 |
$options = get_option( 'SnS_options' );
|
30 |
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
|
31 |
+
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
|
32 |
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.18' );
|
33 |
wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
34 |
|
35 |
+
wp_enqueue_script( 'sns-global-page-scripts', plugins_url('js/global-page.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-css', 'codemirror-javascript' ), Scripts_n_Styles::VERSION, true );
|
36 |
wp_localize_script( 'sns-global-page-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
|
37 |
wp_enqueue_script( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.18' );
|
38 |
wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
45 |
function admin_load() {
|
46 |
|
47 |
register_setting(
|
48 |
+
SnS_Admin::OPTION_GROUP,
|
49 |
'SnS_options' );
|
50 |
|
51 |
add_settings_section(
|
52 |
'global',
|
53 |
+
__( 'Global Scripts n Styles', 'scripts-n-styles' ),
|
54 |
array( __CLASS__, 'global_section' ),
|
55 |
SnS_Admin::MENU_SLUG );
|
56 |
|
57 |
add_settings_field(
|
58 |
'scripts',
|
59 |
+
__( '<strong>Scripts:</strong> ', 'scripts-n-styles' ),
|
60 |
array( 'SnS_Form', 'textarea' ),
|
61 |
SnS_Admin::MENU_SLUG,
|
62 |
'global',
|
67 |
'rows' => 5,
|
68 |
'cols' => 40,
|
69 |
'style' => 'min-width: 500px; width:97%;',
|
70 |
+
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code><script></code> tags at the bottom of the <code><body></code> element of your html.</span>', 'scripts-n-styles' )
|
71 |
) );
|
72 |
add_settings_field(
|
73 |
'styles',
|
74 |
+
__( '<strong>Styles:</strong> ', 'scripts-n-styles' ),
|
75 |
array( 'SnS_Form', 'textarea' ),
|
76 |
SnS_Admin::MENU_SLUG,
|
77 |
'global',
|
82 |
'rows' => 5,
|
83 |
'cols' => 40,
|
84 |
'style' => 'min-width: 500px; width:97%;',
|
85 |
+
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code><style></code> tags in the <code><head></code> element of your html.</span>', 'scripts-n-styles' )
|
86 |
) );
|
87 |
add_settings_field(
|
88 |
'scripts_in_head',
|
89 |
+
__( '<strong>Scripts</strong><br />(for the <code>head</code> element): ', 'scripts-n-styles' ),
|
90 |
array( 'SnS_Form', 'textarea' ),
|
91 |
SnS_Admin::MENU_SLUG,
|
92 |
'global',
|
97 |
'rows' => 5,
|
98 |
'cols' => 40,
|
99 |
'style' => 'min-width: 500px; width:97%;',
|
100 |
+
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code><script></code> tags in the <code><head></code> element of your html.</span>', 'scripts-n-styles' )
|
101 |
) );
|
102 |
add_settings_field(
|
103 |
'enqueue_scripts',
|
104 |
+
__( '<strong>Enqueue Scripts</strong>: ', 'scripts-n-styles' ),
|
105 |
array( 'SnS_Form', 'select' ),
|
106 |
SnS_Admin::MENU_SLUG,
|
107 |
'global',
|
112 |
'size' => 5,
|
113 |
'style' => 'height: auto;',
|
114 |
'multiple' => true,
|
115 |
+
'show_current' => __( 'Currently Enqueued Scripts: ', 'scripts-n-styles' )
|
116 |
) );
|
117 |
}
|
118 |
|
123 |
function global_section() {
|
124 |
?>
|
125 |
<div style="max-width: 55em;">
|
126 |
+
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts and Styles registered individually.', 'scripts-n-styles' )?></p>
|
127 |
</div>
|
128 |
<?php
|
129 |
}
|
includes/class.SnS_List_Usage.php
CHANGED
@@ -17,27 +17,27 @@ class SnS_List_Usage extends WP_List_Table {
|
|
17 |
return $post->$column_name;
|
18 |
case 'script_data':
|
19 |
if ( isset( $post->sns_scripts[ 'scripts_in_head' ] ) ) {
|
20 |
-
$return .= '<div>Scripts (head)</div>';
|
21 |
}
|
22 |
if ( isset( $post->sns_scripts[ 'scripts' ] ) ) {
|
23 |
-
$return .= '<div>Scripts</div>';
|
24 |
}
|
25 |
if ( isset( $post->sns_scripts[ 'enqueue_scripts' ] ) ) {
|
26 |
-
$return .= '<div>Enqueued Scripts</div>';
|
27 |
}
|
28 |
return $return;
|
29 |
case 'style_data':
|
30 |
if ( isset( $post->sns_styles[ 'classes_mce' ] ) ) {
|
31 |
-
$return .= '<div>TinyMCE Formats</div>';
|
32 |
}
|
33 |
if ( isset( $post->sns_styles[ 'styles' ] ) ) {
|
34 |
-
$return .= '<div>Styles</div>';
|
35 |
}
|
36 |
if ( isset( $post->sns_styles[ 'classes_post' ] ) ) {
|
37 |
-
$return .= '<div>Post Classes</div>';
|
38 |
}
|
39 |
if ( isset( $post->sns_styles[ 'classes_body' ] ) ) {
|
40 |
-
$return .= '<div>Body Classes</div>';
|
41 |
}
|
42 |
return $return;
|
43 |
default:
|
@@ -50,7 +50,7 @@ class SnS_List_Usage extends WP_List_Table {
|
|
50 |
$edit_title = esc_attr( sprintf( __( 'Edit “%s”' ), $post->post_title ) );
|
51 |
|
52 |
$actions = array(
|
53 |
-
'edit' => sprintf('<a title="%s" href="%s"
|
54 |
);
|
55 |
|
56 |
$return = '<strong>';
|
@@ -72,12 +72,12 @@ class SnS_List_Usage extends WP_List_Table {
|
|
72 |
|
73 |
function get_columns() {
|
74 |
$columns = array(
|
75 |
-
'title' => 'Title',
|
76 |
-
'ID' => 'ID',
|
77 |
-
'status' => 'Status',
|
78 |
-
'post_type' => 'Post Type',
|
79 |
-
'script_data' => 'Script Data',
|
80 |
-
'style_data' => 'Style Data'
|
81 |
);
|
82 |
|
83 |
return $columns;
|
@@ -124,27 +124,27 @@ class SnS_List_Usage extends WP_List_Table {
|
|
124 |
function _post_states( $post ) {
|
125 |
$post_states = array();
|
126 |
$return = '';
|
127 |
-
if ( isset($_GET['post_status']) )
|
128 |
-
$post_status = $_GET['post_status'];
|
129 |
else
|
130 |
$post_status = '';
|
131 |
|
132 |
-
if ( !empty($post->post_password) )
|
133 |
-
$post_states['protected'] = __('Password protected');
|
134 |
if ( 'private' == $post->post_status && 'private' != $post_status )
|
135 |
-
$post_states['private'] = __('Private');
|
136 |
if ( 'draft' == $post->post_status && 'draft' != $post_status )
|
137 |
-
$post_states['draft'] = __('Draft');
|
138 |
if ( 'pending' == $post->post_status && 'pending' != $post_status )
|
139 |
/* translators: post state */
|
140 |
-
$post_states['pending'] = _x('Pending', 'post state');
|
141 |
if ( is_sticky($post->ID) )
|
142 |
-
$post_states['sticky'] = __('Sticky');
|
143 |
|
144 |
$post_states = apply_filters( 'display_post_states', $post_states );
|
145 |
|
146 |
-
if ( ! empty($post_states) ) {
|
147 |
-
$state_count = count($post_states);
|
148 |
$i = 0;
|
149 |
$return .= ' - ';
|
150 |
foreach ( $post_states as $state ) {
|
@@ -163,8 +163,8 @@ class SnS_List_Usage extends WP_List_Table {
|
|
163 |
function _add_meta_data( $posts ) {
|
164 |
foreach( $posts as $post) {
|
165 |
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
166 |
-
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
167 |
-
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
168 |
if ( ! empty( $styles ) )
|
169 |
$post->sns_styles = $styles;
|
170 |
if ( ! empty( $scripts ) )
|
17 |
return $post->$column_name;
|
18 |
case 'script_data':
|
19 |
if ( isset( $post->sns_scripts[ 'scripts_in_head' ] ) ) {
|
20 |
+
$return .= '<div>' . __( 'Scripts (head)', 'scripts-n-styles' ) . '</div>';
|
21 |
}
|
22 |
if ( isset( $post->sns_scripts[ 'scripts' ] ) ) {
|
23 |
+
$return .= '<div>' . __( 'Scripts', 'scripts-n-styles' ) . '</div>';
|
24 |
}
|
25 |
if ( isset( $post->sns_scripts[ 'enqueue_scripts' ] ) ) {
|
26 |
+
$return .= '<div>' . __( 'Enqueued Scripts', 'scripts-n-styles' ) . '</div>';
|
27 |
}
|
28 |
return $return;
|
29 |
case 'style_data':
|
30 |
if ( isset( $post->sns_styles[ 'classes_mce' ] ) ) {
|
31 |
+
$return .= '<div>' . __( 'TinyMCE Formats', 'scripts-n-styles' ) . '</div>';
|
32 |
}
|
33 |
if ( isset( $post->sns_styles[ 'styles' ] ) ) {
|
34 |
+
$return .= '<div>' . __( 'Styles', 'scripts-n-styles' ) . '</div>';
|
35 |
}
|
36 |
if ( isset( $post->sns_styles[ 'classes_post' ] ) ) {
|
37 |
+
$return .= '<div>' . __( 'Post Classes', 'scripts-n-styles' ) . '</div>';
|
38 |
}
|
39 |
if ( isset( $post->sns_styles[ 'classes_body' ] ) ) {
|
40 |
+
$return .= '<div>' . __( 'Body Classes', 'scripts-n-styles' ) . '</div>';
|
41 |
}
|
42 |
return $return;
|
43 |
default:
|
50 |
$edit_title = esc_attr( sprintf( __( 'Edit “%s”' ), $post->post_title ) );
|
51 |
|
52 |
$actions = array(
|
53 |
+
'edit' => sprintf( '<a title="%s" href="%s">%s</a>', $edit_title, $edit_link, __( 'Edit' ) ),
|
54 |
);
|
55 |
|
56 |
$return = '<strong>';
|
72 |
|
73 |
function get_columns() {
|
74 |
$columns = array(
|
75 |
+
'title' => __( 'Title' ),
|
76 |
+
'ID' => __( 'ID' ),
|
77 |
+
'status' => __( 'Status' ),
|
78 |
+
'post_type' => __( 'Post Type', 'scripts-n-styles' ),
|
79 |
+
'script_data' => __( 'Script Data', 'scripts-n-styles' ),
|
80 |
+
'style_data' => __( 'Style Data', 'scripts-n-styles' )
|
81 |
);
|
82 |
|
83 |
return $columns;
|
124 |
function _post_states( $post ) {
|
125 |
$post_states = array();
|
126 |
$return = '';
|
127 |
+
if ( isset($_GET[ 'post_status' ]) )
|
128 |
+
$post_status = $_GET[ 'post_status' ];
|
129 |
else
|
130 |
$post_status = '';
|
131 |
|
132 |
+
if ( ! empty( $post->post_password ) )
|
133 |
+
$post_states[ 'protected' ] = __( 'Password protected' );
|
134 |
if ( 'private' == $post->post_status && 'private' != $post_status )
|
135 |
+
$post_states[ 'private' ] = __( 'Private' );
|
136 |
if ( 'draft' == $post->post_status && 'draft' != $post_status )
|
137 |
+
$post_states[ 'draft' ] = __( 'Draft' );
|
138 |
if ( 'pending' == $post->post_status && 'pending' != $post_status )
|
139 |
/* translators: post state */
|
140 |
+
$post_states[ 'pending' ] = _x( 'Pending', 'post state' );
|
141 |
if ( is_sticky($post->ID) )
|
142 |
+
$post_states[ 'sticky' ] = __( 'Sticky' );
|
143 |
|
144 |
$post_states = apply_filters( 'display_post_states', $post_states );
|
145 |
|
146 |
+
if ( ! empty( $post_states ) ) {
|
147 |
+
$state_count = count( $post_states );
|
148 |
$i = 0;
|
149 |
$return .= ' - ';
|
150 |
foreach ( $post_states as $state ) {
|
163 |
function _add_meta_data( $posts ) {
|
164 |
foreach( $posts as $post) {
|
165 |
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
166 |
+
$styles = isset( $SnS[ 'styles' ] ) ? $SnS[ 'styles' ]: array();
|
167 |
+
$scripts = isset( $SnS[ 'scripts' ] ) ? $SnS[ 'scripts' ]: array();
|
168 |
if ( ! empty( $styles ) )
|
169 |
$post->sns_styles = $styles;
|
170 |
if ( ! empty( $scripts ) )
|
includes/class.SnS_Settings_Page.php
CHANGED
@@ -19,7 +19,7 @@ class SnS_Settings_Page
|
|
19 |
* @static
|
20 |
*/
|
21 |
function init() {
|
22 |
-
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, 'Scripts n Styles', 'Settings', 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
|
23 |
|
24 |
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
|
25 |
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
|
@@ -37,13 +37,13 @@ class SnS_Settings_Page
|
|
37 |
$options = get_option( 'SnS_options' );
|
38 |
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
|
39 |
|
40 |
-
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ),
|
41 |
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.18' );
|
42 |
|
43 |
foreach ( array( 'cobalt', 'default', 'eclipse', 'elegant', 'monokai', 'neat', 'night', 'rubyblue' ) as $theme )
|
44 |
wp_enqueue_style( "codemirror-$theme", plugins_url( "libraries/CodeMirror2/theme/$theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
45 |
|
46 |
-
wp_enqueue_script( 'sns-settings-page-scripts', plugins_url('js/settings-page.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-css', 'codemirror-javascript' ),
|
47 |
wp_localize_script( 'sns-settings-page-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
|
48 |
wp_enqueue_script( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.18' );
|
49 |
wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
@@ -66,7 +66,7 @@ class SnS_Settings_Page
|
|
66 |
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
67 |
*/
|
68 |
function admin_load() {
|
69 |
-
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array(),
|
70 |
|
71 |
register_setting(
|
72 |
SnS_Admin::OPTION_GROUP,
|
@@ -74,13 +74,13 @@ class SnS_Settings_Page
|
|
74 |
|
75 |
add_settings_section(
|
76 |
'settings',
|
77 |
-
'Scripts n Styles Settings',
|
78 |
array( __CLASS__, 'settings_section' ),
|
79 |
SnS_Admin::MENU_SLUG );
|
80 |
|
81 |
add_settings_field(
|
82 |
'menu_position',
|
83 |
-
'<strong>Menu Position</strong>: ',
|
84 |
array( 'SnS_Form', 'select' ),
|
85 |
SnS_Admin::MENU_SLUG,
|
86 |
'settings',
|
@@ -94,7 +94,7 @@ class SnS_Settings_Page
|
|
94 |
|
95 |
add_settings_field(
|
96 |
'cm_theme',
|
97 |
-
'<strong>CodeMirror Theme</strong>: ',
|
98 |
array( 'SnS_Form', 'select' ),
|
99 |
SnS_Admin::MENU_SLUG,
|
100 |
'settings',
|
@@ -106,9 +106,24 @@ class SnS_Settings_Page
|
|
106 |
'style' => 'height: auto;'
|
107 |
) );
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
add_settings_section(
|
110 |
'demo',
|
111 |
-
'Code Mirror Demo',
|
112 |
array( __CLASS__, 'demo_section' ),
|
113 |
SnS_Admin::MENU_SLUG );
|
114 |
}
|
@@ -120,7 +135,7 @@ class SnS_Settings_Page
|
|
120 |
function settings_section() {
|
121 |
?>
|
122 |
<div style="max-width: 55em;">
|
123 |
-
<p
|
124 |
</div>
|
125 |
<?php
|
126 |
}
|
19 |
* @static
|
20 |
*/
|
21 |
function init() {
|
22 |
+
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Settings' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
|
23 |
|
24 |
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
|
25 |
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
|
37 |
$options = get_option( 'SnS_options' );
|
38 |
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
|
39 |
|
40 |
+
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
|
41 |
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.18' );
|
42 |
|
43 |
foreach ( array( 'cobalt', 'default', 'eclipse', 'elegant', 'monokai', 'neat', 'night', 'rubyblue' ) as $theme )
|
44 |
wp_enqueue_style( "codemirror-$theme", plugins_url( "libraries/CodeMirror2/theme/$theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
45 |
|
46 |
+
wp_enqueue_script( 'sns-settings-page-scripts', plugins_url('js/settings-page.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-css', 'codemirror-javascript' ), Scripts_n_Styles::VERSION, true );
|
47 |
wp_localize_script( 'sns-settings-page-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
|
48 |
wp_enqueue_script( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.18' );
|
49 |
wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.18' );
|
66 |
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
67 |
*/
|
68 |
function admin_load() {
|
69 |
+
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array(), Scripts_n_Styles::VERSION );
|
70 |
|
71 |
register_setting(
|
72 |
SnS_Admin::OPTION_GROUP,
|
74 |
|
75 |
add_settings_section(
|
76 |
'settings',
|
77 |
+
__( 'Scripts n Styles Settings', 'scripts-n-styles' ),
|
78 |
array( __CLASS__, 'settings_section' ),
|
79 |
SnS_Admin::MENU_SLUG );
|
80 |
|
81 |
add_settings_field(
|
82 |
'menu_position',
|
83 |
+
__( '<strong>Menu Position</strong>: ', 'scripts-n-styles' ),
|
84 |
array( 'SnS_Form', 'select' ),
|
85 |
SnS_Admin::MENU_SLUG,
|
86 |
'settings',
|
94 |
|
95 |
add_settings_field(
|
96 |
'cm_theme',
|
97 |
+
__( '<strong>CodeMirror Theme</strong>: ', 'scripts-n-styles' ),
|
98 |
array( 'SnS_Form', 'select' ),
|
99 |
SnS_Admin::MENU_SLUG,
|
100 |
'settings',
|
106 |
'style' => 'height: auto;'
|
107 |
) );
|
108 |
|
109 |
+
add_settings_field(
|
110 |
+
'metabox',
|
111 |
+
__( '<strong>Hide Metabox by default</strong>: ', 'scripts-n-styles' ),
|
112 |
+
array( 'SnS_Form', 'radio' ),
|
113 |
+
SnS_Admin::MENU_SLUG,
|
114 |
+
'settings',
|
115 |
+
array(
|
116 |
+
'label_for' => 'metabox',
|
117 |
+
'setting' => 'SnS_options',
|
118 |
+
'choices' => array( 'yes', 'no' ),
|
119 |
+
'default' => 'yes',
|
120 |
+
'legend' => __( 'Hide Metabox by default', 'scripts-n-styles' ),
|
121 |
+
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">This is overridable via Screen Options on each edit screen.</span>', 'scripts-n-styles' )
|
122 |
+
) );
|
123 |
+
|
124 |
add_settings_section(
|
125 |
'demo',
|
126 |
+
__( 'Code Mirror Demo', 'scripts-n-styles' ),
|
127 |
array( __CLASS__, 'demo_section' ),
|
128 |
SnS_Admin::MENU_SLUG );
|
129 |
}
|
135 |
function settings_section() {
|
136 |
?>
|
137 |
<div style="max-width: 55em;">
|
138 |
+
<p><?php _e( 'Control how and where Scripts n Styles menus and metaboxes appear. These options are here because sometimes users really care about this stuff. Feel free to adjust to your liking. :-)', 'scripts-n-styles' ) ?></p>
|
139 |
</div>
|
140 |
<?php
|
141 |
}
|
includes/class.SnS_Usage_Page.php
CHANGED
@@ -19,7 +19,7 @@ class SnS_Usage_Page
|
|
19 |
* @static
|
20 |
*/
|
21 |
function init() {
|
22 |
-
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, 'Scripts n Styles', 'Usage', 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
|
23 |
|
24 |
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
|
25 |
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
|
@@ -42,7 +42,7 @@ class SnS_Usage_Page
|
|
42 |
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
43 |
*/
|
44 |
function admin_load() {
|
45 |
-
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array(),
|
46 |
|
47 |
add_screen_option( 'per_page', array( 'label' => __( 'Per Page' ), 'default' => 20 ) );
|
48 |
add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 );
|
@@ -51,7 +51,7 @@ class SnS_Usage_Page
|
|
51 |
|
52 |
add_settings_section(
|
53 |
'usage',
|
54 |
-
'Scripts n Styles Usage',
|
55 |
array( __CLASS__, 'usage_section' ),
|
56 |
SnS_Admin::MENU_SLUG );
|
57 |
}
|
@@ -75,7 +75,7 @@ class SnS_Usage_Page
|
|
75 |
*/
|
76 |
function usage_section() { ?>
|
77 |
<div style="max-width: 55em;">
|
78 |
-
<p
|
79 |
</div>
|
80 |
<?php
|
81 |
require_once( 'class.SnS_List_Usage.php' );
|
19 |
* @static
|
20 |
*/
|
21 |
function init() {
|
22 |
+
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Usage', 'scripts-n-styles' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
|
23 |
|
24 |
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
|
25 |
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
|
42 |
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
43 |
*/
|
44 |
function admin_load() {
|
45 |
+
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array(), Scripts_n_Styles::VERSION );
|
46 |
|
47 |
add_screen_option( 'per_page', array( 'label' => __( 'Per Page' ), 'default' => 20 ) );
|
48 |
add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 );
|
51 |
|
52 |
add_settings_section(
|
53 |
'usage',
|
54 |
+
__( 'Scripts n Styles Usage', 'scripts-n-styles' ),
|
55 |
array( __CLASS__, 'usage_section' ),
|
56 |
SnS_Admin::MENU_SLUG );
|
57 |
}
|
75 |
*/
|
76 |
function usage_section() { ?>
|
77 |
<div style="max-width: 55em;">
|
78 |
+
<p><?php _e( 'The following table shows content that utilizes Scripts n Styles.', 'scripts-n-styles' ) ?></p>
|
79 |
</div>
|
80 |
<?php
|
81 |
require_once( 'class.SnS_List_Usage.php' );
|
scripts-n-styles.php
CHANGED
@@ -1,313 +1,323 @@
|
|
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: 3
|
9 |
-
License: GPLv2 or later
|
10 |
-
Network: true
|
11 |
-
*/
|
12 |
-
|
13 |
-
/* Copyright 2010-2011 Kenneth Newman www.unfocus.com
|
14 |
-
|
15 |
-
This program is free software; you can redistribute it and/or
|
16 |
-
modify it under the terms of the GNU General Public License
|
17 |
-
as published by the Free Software Foundation; either version 2
|
18 |
-
of the License, or (at your option) any later version.
|
19 |
-
|
20 |
-
This program is distributed in the hope that it will be useful,
|
21 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
-
GNU General Public License for more details.
|
24 |
-
|
25 |
-
You should have received a copy of the GNU General Public License
|
26 |
-
along with this program; if not, write to the Free Software
|
27 |
-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
-
*/
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Scripts n Styles
|
32 |
-
*
|
33 |
-
* Allows WordPress admin users the ability to add custom CSS
|
34 |
-
* and JavaScript directly to individual Post, Pages or custom
|
35 |
-
* post types.
|
36 |
-
*
|
37 |
-
* NOTE: No user except the "Super Admin" can use this plugin in MultiSite. I'll add features for MultiSite later, perhaps the ones below...
|
38 |
-
* The "Super Admin" user has exclusive 'unfiltered_html' capabilities in MultiSite. Also, options.php checks for is_super_admin()
|
39 |
-
* so the 'manage_options' capability for blog admins is insufficient to pass the check to manage options directly.
|
40 |
-
*
|
41 |
-
* The Tentative plan is for Super Admins to create Snippets or Shortcodes approved for use by users with certain capabilities
|
42 |
-
* ('unfiltered_html' and/or 'manage_options'). The 'unfiltered_html' capability can be granted via another plugin. This plugin will
|
43 |
-
* not deal with granting any capabilities.
|
44 |
-
*
|
45 |
-
* @package Scripts_n_Styles
|
46 |
-
* @link http://www.unfocus.com/projects/scripts-n-styles/ Plugin URI
|
47 |
-
* @author unFocus Projects
|
48 |
-
* @link http://www.unfocus.com/ Author URI
|
49 |
-
* @version 3
|
50 |
-
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
51 |
-
* @copyright Copyright (c) 2010 - 2011, Kenneth Newman
|
52 |
-
*
|
53 |
-
* @todo Add Post Type Selection on Options Page? Not sure that's useful.
|
54 |
-
* @todo Add Conditional Tags support as alternative to Globally applying Scripts n Styles.
|
55 |
-
* @todo Create ability to add and register scripts and styles for enqueueing (via Options page).
|
56 |
-
* @todo Create selection on Option page of which to pick registered scripts to make available on edit screens.
|
57 |
-
* @todo Create shortcode to embed html/javascript snippets. See http://scribu.net/wordpress/optimal-script-loading.html in which this is already figured out :-)
|
58 |
-
* @todo Create shortcode registration on Options page to make those snippets available on edit screens.
|
59 |
-
* @todo Create shortcode registration of html snippets on edit screens for single use.
|
60 |
-
* @todo Add Error messaging.
|
61 |
-
* @todo Replace Multi-Select element with something better.
|
62 |
-
* @todo "Include Scripts" will be reintroduced when registering is finished.
|
63 |
-
* @todo Clean up tiny_mce_before_init in SnS_Admin_Meta_Box.
|
64 |
-
* @todo LESS.js support.
|
65 |
-
* @todo LESS.js highlighting support to CodeMirror.
|
66 |
-
* @todo Solarize theme to CodeMirror.
|
67 |
-
*/
|
68 |
-
|
69 |
-
class Scripts_n_Styles
|
70 |
-
{
|
71 |
-
/**#@+
|
72 |
-
* @static
|
73 |
-
*/
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
if ( is_admin() && ! ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) ) {
|
84 |
-
/* NOTE: Setting the DISALLOW_UNFILTERED_HTML constant to
|
85 |
-
true in the wp-config.php would effectively disable this
|
86 |
-
plugin's admin because no user would have the capability.
|
87 |
-
*/
|
88 |
-
include_once( 'includes/class.SnS_Admin.php' );
|
89 |
-
SnS_Admin::init();
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
|
94 |
-
add_filter( 'post_class', array( __CLASS__, 'post_classes' ) );
|
95 |
-
|
96 |
-
add_action( 'wp_head', array( __CLASS__, 'styles' ), 11 );
|
97 |
-
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 11 );
|
98 |
-
add_action( 'wp_head', array( __CLASS__, 'scripts_in_head' ), 11 );
|
99 |
-
add_action( 'wp_footer', array( __CLASS__, 'scripts' ), 11 );
|
100 |
-
}
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Utility Method
|
104 |
-
*/
|
105 |
-
static function get_wp_registered() {
|
106 |
-
return array(
|
107 |
-
// Starting with the list of Scripts registered by default on the Theme side (index page of twentyten).
|
108 |
-
'l10n',
|
109 |
-
'utils',
|
110 |
-
'common',
|
111 |
-
'sack',
|
112 |
-
'quicktags',
|
113 |
-
'colorpicker',
|
114 |
-
'editor',
|
115 |
-
'prototype',
|
116 |
-
'wp-ajax-response',
|
117 |
-
'autosave',
|
118 |
-
'wp-lists',
|
119 |
-
'scriptaculous-root',
|
120 |
-
'scriptaculous-builder',
|
121 |
-
'scriptaculous-dragdrop',
|
122 |
-
'scriptaculous-effects',
|
123 |
-
'scriptaculous-slider',
|
124 |
-
'scriptaculous-sound',
|
125 |
-
'scriptaculous-controls',
|
126 |
-
'scriptaculous',
|
127 |
-
'cropper',
|
128 |
-
'jquery',
|
129 |
-
'jquery-ui-core',
|
130 |
-
'jquery-ui-position',
|
131 |
-
'jquery-ui-widget',
|
132 |
-
'jquery-ui-mouse',
|
133 |
-
'jquery-ui-button',
|
134 |
-
'jquery-ui-tabs',
|
135 |
-
'jquery-ui-sortable',
|
136 |
-
'jquery-ui-draggable',
|
137 |
-
'jquery-ui-droppable',
|
138 |
-
'jquery-ui-selectable',
|
139 |
-
'jquery-ui-resizable',
|
140 |
-
'jquery-ui-dialog',
|
141 |
-
'jquery-form',
|
142 |
-
'jquery-color',
|
143 |
-
'suggest',
|
144 |
-
'schedule',
|
145 |
-
'jquery-query',
|
146 |
-
'jquery-serialize-object',
|
147 |
-
'jquery-hotkeys',
|
148 |
-
'jquery-table-hotkeys',
|
149 |
-
'thickbox',
|
150 |
-
'jcrop',
|
151 |
-
'swfobject',
|
152 |
-
'swfupload',
|
153 |
-
'swfupload-swfobject',
|
154 |
-
'swfupload-queue',
|
155 |
-
'swfupload-speed',
|
156 |
-
'swfupload-all',
|
157 |
-
'swfupload-handlers',
|
158 |
-
'comment-reply',
|
159 |
-
'json2',
|
160 |
-
'imgareaselect',
|
161 |
-
'password-strength-meter',
|
162 |
-
'user-profile',
|
163 |
-
'admin-bar',
|
164 |
-
'wplink',
|
165 |
-
'wpdialogs-popup'
|
166 |
-
);
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Theme Action: 'wp_head()'
|
171 |
-
* Outputs the globally and individually set Styles in the Theme's head element.
|
172 |
-
*/
|
173 |
-
static function styles() {
|
174 |
-
// Global
|
175 |
-
$options = get_option( 'SnS_options' );
|
176 |
-
if ( ! empty( $options ) && ! empty( $options[ 'styles' ] ) ) {
|
177 |
-
?><style type="text/css"><?php
|
178 |
-
echo $options[ 'styles' ];
|
179 |
-
?></style><?php
|
180 |
-
}
|
181 |
-
|
182 |
-
if ( ! is_singular() ) return;
|
183 |
-
// Individual
|
184 |
-
global $post;
|
185 |
-
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
186 |
-
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
187 |
-
if ( ! empty( $styles ) && ! empty( $styles[ 'styles' ] ) ) {
|
188 |
-
?><style type="text/css"><?php
|
189 |
-
echo $styles[ 'styles' ];
|
190 |
-
?></style><?php
|
191 |
-
}
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Theme Action: 'wp_footer()'
|
196 |
-
* Outputs the globally and individually set Scripts at the end of the Theme's body element.
|
197 |
-
*/
|
198 |
-
static function scripts() {
|
199 |
-
// Global
|
200 |
-
$options = get_option( 'SnS_options' );
|
201 |
-
if ( ! empty( $options ) && ! empty( $options[ 'scripts' ] ) ) {
|
202 |
-
?><script type="text/javascript"><?php
|
203 |
-
echo $options[ 'scripts' ];
|
204 |
-
?></script><?php
|
205 |
-
}
|
206 |
-
|
207 |
-
if ( ! is_singular() ) return;
|
208 |
-
// Individual
|
209 |
-
global $post;
|
210 |
-
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
211 |
-
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
212 |
-
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts' ] ) ) {
|
213 |
-
?><script type="text/javascript"><?php
|
214 |
-
echo $scripts[ 'scripts' ];
|
215 |
-
?></script><?php
|
216 |
-
}
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
* Theme Action: 'wp_head()'
|
221 |
-
* Outputs the globally and individually set Scripts in the Theme's head element.
|
222 |
-
*/
|
223 |
-
static function scripts_in_head() {
|
224 |
-
// Global
|
225 |
-
$options = get_option( 'SnS_options' );
|
226 |
-
if ( ! empty( $options ) && ! empty( $options[ 'scripts_in_head' ] ) ) {
|
227 |
-
?><script type="text/javascript"><?php
|
228 |
-
echo $options[ 'scripts_in_head' ];
|
229 |
-
?></script><?php
|
230 |
-
}
|
231 |
-
|
232 |
-
if ( ! is_singular() ) return;
|
233 |
-
// Individual
|
234 |
-
global $post;
|
235 |
-
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
236 |
-
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
237 |
-
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts_in_head' ] ) ) {
|
238 |
-
?><script type="text/javascript"><?php
|
239 |
-
echo $scripts[ 'scripts_in_head' ];
|
240 |
-
?></script><?php
|
241 |
-
}
|
242 |
-
}
|
243 |
-
|
244 |
-
/**
|
245 |
-
* Theme Filter: 'body_class()'
|
246 |
-
* Adds classes to the Theme's body tag.
|
247 |
-
* @uses self::get_styles()
|
248 |
-
* @param array $classes
|
249 |
-
* @return array $classes
|
250 |
-
*/
|
251 |
-
static function body_classes( $classes ) {
|
252 |
-
if ( ! is_singular() || is_admin() ) return $classes;
|
253 |
-
|
254 |
-
global $post;
|
255 |
-
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
256 |
-
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
257 |
-
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_body' ] ) )
|
258 |
-
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_body' ] ) );
|
259 |
-
|
260 |
-
return $classes;
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Theme Filter: 'post_class()'
|
265 |
-
* Adds classes to the Theme's post container.
|
266 |
-
* @param array $classes
|
267 |
-
* @return array $classes
|
268 |
-
*/
|
269 |
-
static function post_classes( $classes ) {
|
270 |
-
if ( ! is_singular() || is_admin() ) return $classes;
|
271 |
-
|
272 |
-
global $post;
|
273 |
-
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
274 |
-
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
275 |
-
|
276 |
-
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_post' ] ) )
|
277 |
-
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_post' ] ) );
|
278 |
-
|
279 |
-
return $classes;
|
280 |
-
}
|
281 |
-
|
282 |
-
/**
|
283 |
-
* Theme Action: 'wp_enqueue_scripts'
|
284 |
-
* Enqueues chosen Scripts.
|
285 |
-
*/
|
286 |
-
static function enqueue_scripts() {
|
287 |
-
// Global
|
288 |
-
$options = get_option( 'SnS_options' );
|
289 |
-
if ( ! isset( $options[ 'enqueue_scripts' ] ) )
|
290 |
-
$enqueue_scripts = array();
|
291 |
-
else
|
292 |
-
$enqueue_scripts = $options[ 'enqueue_scripts' ];
|
293 |
-
|
294 |
-
foreach ( $enqueue_scripts as $handle )
|
295 |
-
wp_enqueue_script( $handle );
|
296 |
-
|
297 |
-
if ( ! is_singular() ) return;
|
298 |
-
// Individual
|
299 |
-
global $post;
|
300 |
-
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
301 |
-
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
302 |
-
|
303 |
-
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
|
304 |
-
foreach ( $scripts[ 'enqueue_scripts' ] as $handle )
|
305 |
-
wp_enqueue_script( $handle );
|
306 |
-
}
|
307 |
-
}
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
?>
|
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: 3.0
|
9 |
+
License: GPLv2 or later
|
10 |
+
Network: true
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright 2010-2011 Kenneth Newman www.unfocus.com
|
14 |
+
|
15 |
+
This program is free software; you can redistribute it and/or
|
16 |
+
modify it under the terms of the GNU General Public License
|
17 |
+
as published by the Free Software Foundation; either version 2
|
18 |
+
of the License, or (at your option) any later version.
|
19 |
+
|
20 |
+
This program is distributed in the hope that it will be useful,
|
21 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
GNU General Public License for more details.
|
24 |
+
|
25 |
+
You should have received a copy of the GNU General Public License
|
26 |
+
along with this program; if not, write to the Free Software
|
27 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
+
*/
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Scripts n Styles
|
32 |
+
*
|
33 |
+
* Allows WordPress admin users the ability to add custom CSS
|
34 |
+
* and JavaScript directly to individual Post, Pages or custom
|
35 |
+
* post types.
|
36 |
+
*
|
37 |
+
* NOTE: No user except the "Super Admin" can use this plugin in MultiSite. I'll add features for MultiSite later, perhaps the ones below...
|
38 |
+
* The "Super Admin" user has exclusive 'unfiltered_html' capabilities in MultiSite. Also, options.php checks for is_super_admin()
|
39 |
+
* so the 'manage_options' capability for blog admins is insufficient to pass the check to manage options directly.
|
40 |
+
*
|
41 |
+
* The Tentative plan is for Super Admins to create Snippets or Shortcodes approved for use by users with certain capabilities
|
42 |
+
* ('unfiltered_html' and/or 'manage_options'). The 'unfiltered_html' capability can be granted via another plugin. This plugin will
|
43 |
+
* not deal with granting any capabilities.
|
44 |
+
*
|
45 |
+
* @package Scripts_n_Styles
|
46 |
+
* @link http://www.unfocus.com/projects/scripts-n-styles/ Plugin URI
|
47 |
+
* @author unFocus Projects
|
48 |
+
* @link http://www.unfocus.com/ Author URI
|
49 |
+
* @version 3.0
|
50 |
+
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
51 |
+
* @copyright Copyright (c) 2010 - 2011, Kenneth Newman
|
52 |
+
*
|
53 |
+
* @todo Add Post Type Selection on Options Page? Not sure that's useful.
|
54 |
+
* @todo Add Conditional Tags support as alternative to Globally applying Scripts n Styles.
|
55 |
+
* @todo Create ability to add and register scripts and styles for enqueueing (via Options page).
|
56 |
+
* @todo Create selection on Option page of which to pick registered scripts to make available on edit screens.
|
57 |
+
* @todo Create shortcode to embed html/javascript snippets. See http://scribu.net/wordpress/optimal-script-loading.html in which this is already figured out :-)
|
58 |
+
* @todo Create shortcode registration on Options page to make those snippets available on edit screens.
|
59 |
+
* @todo Create shortcode registration of html snippets on edit screens for single use.
|
60 |
+
* @todo Add Error messaging.
|
61 |
+
* @todo Replace Multi-Select element with something better.
|
62 |
+
* @todo "Include Scripts" will be reintroduced when registering is finished.
|
63 |
+
* @todo Clean up tiny_mce_before_init in SnS_Admin_Meta_Box.
|
64 |
+
* @todo LESS.js support.
|
65 |
+
* @todo LESS.js highlighting support to CodeMirror.
|
66 |
+
* @todo Solarize theme to CodeMirror.
|
67 |
+
*/
|
68 |
+
|
69 |
+
class Scripts_n_Styles
|
70 |
+
{
|
71 |
+
/**#@+
|
72 |
+
* @static
|
73 |
+
*/
|
74 |
+
const VERSION = '3.0';
|
75 |
+
static $file = __FILE__;
|
76 |
+
/**#@-*/
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
|
80 |
+
* @static
|
81 |
+
*/
|
82 |
+
static function init() {
|
83 |
+
if ( is_admin() && ! ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) ) {
|
84 |
+
/* NOTE: Setting the DISALLOW_UNFILTERED_HTML constant to
|
85 |
+
true in the wp-config.php would effectively disable this
|
86 |
+
plugin's admin because no user would have the capability.
|
87 |
+
*/
|
88 |
+
include_once( 'includes/class.SnS_Admin.php' );
|
89 |
+
SnS_Admin::init();
|
90 |
+
}
|
91 |
+
add_action( 'plugins_loaded', array( __CLASS__, 'upgrade_check' ) );
|
92 |
+
|
93 |
+
add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
|
94 |
+
add_filter( 'post_class', array( __CLASS__, 'post_classes' ) );
|
95 |
+
|
96 |
+
add_action( 'wp_head', array( __CLASS__, 'styles' ), 11 );
|
97 |
+
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 11 );
|
98 |
+
add_action( 'wp_head', array( __CLASS__, 'scripts_in_head' ), 11 );
|
99 |
+
add_action( 'wp_footer', array( __CLASS__, 'scripts' ), 11 );
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Utility Method
|
104 |
+
*/
|
105 |
+
static function get_wp_registered() {
|
106 |
+
return array(
|
107 |
+
// Starting with the list of Scripts registered by default on the Theme side (index page of twentyten).
|
108 |
+
'l10n',
|
109 |
+
'utils',
|
110 |
+
'common',
|
111 |
+
'sack',
|
112 |
+
'quicktags',
|
113 |
+
'colorpicker',
|
114 |
+
'editor',
|
115 |
+
'prototype',
|
116 |
+
'wp-ajax-response',
|
117 |
+
'autosave',
|
118 |
+
'wp-lists',
|
119 |
+
'scriptaculous-root',
|
120 |
+
'scriptaculous-builder',
|
121 |
+
'scriptaculous-dragdrop',
|
122 |
+
'scriptaculous-effects',
|
123 |
+
'scriptaculous-slider',
|
124 |
+
'scriptaculous-sound',
|
125 |
+
'scriptaculous-controls',
|
126 |
+
'scriptaculous',
|
127 |
+
'cropper',
|
128 |
+
'jquery',
|
129 |
+
'jquery-ui-core',
|
130 |
+
'jquery-ui-position',
|
131 |
+
'jquery-ui-widget',
|
132 |
+
'jquery-ui-mouse',
|
133 |
+
'jquery-ui-button',
|
134 |
+
'jquery-ui-tabs',
|
135 |
+
'jquery-ui-sortable',
|
136 |
+
'jquery-ui-draggable',
|
137 |
+
'jquery-ui-droppable',
|
138 |
+
'jquery-ui-selectable',
|
139 |
+
'jquery-ui-resizable',
|
140 |
+
'jquery-ui-dialog',
|
141 |
+
'jquery-form',
|
142 |
+
'jquery-color',
|
143 |
+
'suggest',
|
144 |
+
'schedule',
|
145 |
+
'jquery-query',
|
146 |
+
'jquery-serialize-object',
|
147 |
+
'jquery-hotkeys',
|
148 |
+
'jquery-table-hotkeys',
|
149 |
+
'thickbox',
|
150 |
+
'jcrop',
|
151 |
+
'swfobject',
|
152 |
+
'swfupload',
|
153 |
+
'swfupload-swfobject',
|
154 |
+
'swfupload-queue',
|
155 |
+
'swfupload-speed',
|
156 |
+
'swfupload-all',
|
157 |
+
'swfupload-handlers',
|
158 |
+
'comment-reply',
|
159 |
+
'json2',
|
160 |
+
'imgareaselect',
|
161 |
+
'password-strength-meter',
|
162 |
+
'user-profile',
|
163 |
+
'admin-bar',
|
164 |
+
'wplink',
|
165 |
+
'wpdialogs-popup'
|
166 |
+
);
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Theme Action: 'wp_head()'
|
171 |
+
* Outputs the globally and individually set Styles in the Theme's head element.
|
172 |
+
*/
|
173 |
+
static function styles() {
|
174 |
+
// Global
|
175 |
+
$options = get_option( 'SnS_options' );
|
176 |
+
if ( ! empty( $options ) && ! empty( $options[ 'styles' ] ) ) {
|
177 |
+
?><style type="text/css"><?php
|
178 |
+
echo $options[ 'styles' ];
|
179 |
+
?></style><?php
|
180 |
+
}
|
181 |
+
|
182 |
+
if ( ! is_singular() ) return;
|
183 |
+
// Individual
|
184 |
+
global $post;
|
185 |
+
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
186 |
+
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
187 |
+
if ( ! empty( $styles ) && ! empty( $styles[ 'styles' ] ) ) {
|
188 |
+
?><style type="text/css"><?php
|
189 |
+
echo $styles[ 'styles' ];
|
190 |
+
?></style><?php
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Theme Action: 'wp_footer()'
|
196 |
+
* Outputs the globally and individually set Scripts at the end of the Theme's body element.
|
197 |
+
*/
|
198 |
+
static function scripts() {
|
199 |
+
// Global
|
200 |
+
$options = get_option( 'SnS_options' );
|
201 |
+
if ( ! empty( $options ) && ! empty( $options[ 'scripts' ] ) ) {
|
202 |
+
?><script type="text/javascript"><?php
|
203 |
+
echo $options[ 'scripts' ];
|
204 |
+
?></script><?php
|
205 |
+
}
|
206 |
+
|
207 |
+
if ( ! is_singular() ) return;
|
208 |
+
// Individual
|
209 |
+
global $post;
|
210 |
+
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
211 |
+
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
212 |
+
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts' ] ) ) {
|
213 |
+
?><script type="text/javascript"><?php
|
214 |
+
echo $scripts[ 'scripts' ];
|
215 |
+
?></script><?php
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Theme Action: 'wp_head()'
|
221 |
+
* Outputs the globally and individually set Scripts in the Theme's head element.
|
222 |
+
*/
|
223 |
+
static function scripts_in_head() {
|
224 |
+
// Global
|
225 |
+
$options = get_option( 'SnS_options' );
|
226 |
+
if ( ! empty( $options ) && ! empty( $options[ 'scripts_in_head' ] ) ) {
|
227 |
+
?><script type="text/javascript"><?php
|
228 |
+
echo $options[ 'scripts_in_head' ];
|
229 |
+
?></script><?php
|
230 |
+
}
|
231 |
+
|
232 |
+
if ( ! is_singular() ) return;
|
233 |
+
// Individual
|
234 |
+
global $post;
|
235 |
+
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
236 |
+
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
237 |
+
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts_in_head' ] ) ) {
|
238 |
+
?><script type="text/javascript"><?php
|
239 |
+
echo $scripts[ 'scripts_in_head' ];
|
240 |
+
?></script><?php
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Theme Filter: 'body_class()'
|
246 |
+
* Adds classes to the Theme's body tag.
|
247 |
+
* @uses self::get_styles()
|
248 |
+
* @param array $classes
|
249 |
+
* @return array $classes
|
250 |
+
*/
|
251 |
+
static function body_classes( $classes ) {
|
252 |
+
if ( ! is_singular() || is_admin() ) return $classes;
|
253 |
+
|
254 |
+
global $post;
|
255 |
+
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
256 |
+
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
257 |
+
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_body' ] ) )
|
258 |
+
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_body' ] ) );
|
259 |
+
|
260 |
+
return $classes;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Theme Filter: 'post_class()'
|
265 |
+
* Adds classes to the Theme's post container.
|
266 |
+
* @param array $classes
|
267 |
+
* @return array $classes
|
268 |
+
*/
|
269 |
+
static function post_classes( $classes ) {
|
270 |
+
if ( ! is_singular() || is_admin() ) return $classes;
|
271 |
+
|
272 |
+
global $post;
|
273 |
+
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
274 |
+
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
|
275 |
+
|
276 |
+
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_post' ] ) )
|
277 |
+
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_post' ] ) );
|
278 |
+
|
279 |
+
return $classes;
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Theme Action: 'wp_enqueue_scripts'
|
284 |
+
* Enqueues chosen Scripts.
|
285 |
+
*/
|
286 |
+
static function enqueue_scripts() {
|
287 |
+
// Global
|
288 |
+
$options = get_option( 'SnS_options' );
|
289 |
+
if ( ! isset( $options[ 'enqueue_scripts' ] ) )
|
290 |
+
$enqueue_scripts = array();
|
291 |
+
else
|
292 |
+
$enqueue_scripts = $options[ 'enqueue_scripts' ];
|
293 |
+
|
294 |
+
foreach ( $enqueue_scripts as $handle )
|
295 |
+
wp_enqueue_script( $handle );
|
296 |
+
|
297 |
+
if ( ! is_singular() ) return;
|
298 |
+
// Individual
|
299 |
+
global $post;
|
300 |
+
$SnS = get_post_meta( $post->ID, '_SnS', true );
|
301 |
+
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
|
302 |
+
|
303 |
+
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
|
304 |
+
foreach ( $scripts[ 'enqueue_scripts' ] as $handle )
|
305 |
+
wp_enqueue_script( $handle );
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Utility Method: Compares VERSION to stored 'version' value.
|
311 |
+
*/
|
312 |
+
static function upgrade_check() {
|
313 |
+
$options = get_option( 'SnS_options' );
|
314 |
+
if ( ! isset( $options[ 'version' ] ) || version_compare( self::VERSION, $options[ 'version' ], '>' ) ) {
|
315 |
+
include_once( 'includes/class.SnS_Admin.php' );
|
316 |
+
SnS_Admin::upgrade();
|
317 |
+
}
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
+
Scripts_n_Styles::init();
|
322 |
+
|
323 |
?>
|