Version Description
- Fixed strict standards error: redefining already defined constructor for class.
Download this release
Release Info
Developer | tiguan |
Plugin | Speed Booster Pack |
Version | 1.3 |
Comparing to | |
See all releases |
Code changes from version 1.2 to 1.3
- inc/use-google-libraries.php +188 -137
- readme.txt +20 -4
- speed-booster-pack.php +2 -2
inc/use-google-libraries.php
CHANGED
@@ -4,15 +4,18 @@
|
|
4 |
/* Author & copyright (c) 2008-2013 : Jason Penney (email : jpenney@jczorkmid.net ). General Public License v.2.0 */
|
5 |
|
6 |
|
7 |
-
if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
8 |
|
9 |
class JCP_UseGoogleLibraries {
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
public static function get_instance() {
|
14 |
-
if ( !isset( self::$instance ) ) {
|
15 |
-
self::$instance =
|
16 |
}
|
17 |
return self::$instance;
|
18 |
}
|
@@ -60,7 +63,8 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
60 |
|
61 |
/**
|
62 |
* True if using a version of WordPress that allows
|
63 |
-
* `wp_register_script` to take protocol-relative URLs,
|
|
|
64 |
*
|
65 |
* @since 1.5.2
|
66 |
*
|
@@ -83,117 +87,138 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
83 |
protected static $cache_len = 90000; // 25 hours
|
84 |
|
85 |
/**
|
86 |
-
* Message displayed and logged when a WP_Scripts has been created
|
|
|
87 |
*
|
88 |
-
* @var
|
89 |
*/
|
90 |
protected static $script_before_init_notice =
|
91 |
'Another plugin has registered or enqued a script before the "init" action. Attempting to work around it.';
|
92 |
|
93 |
/**
|
94 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
*/
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
/**
|
99 |
* PHP 5 Constructor
|
100 |
*/
|
101 |
function __construct() {
|
102 |
-
$this->jquery_tag
|
103 |
-
$this->google_scripts =
|
104 |
-
array(
|
105 |
-
// any extra scripts listed here not provided by WordPress
|
106 |
-
// or another plugin will not be registered. This list
|
107 |
-
// is just used to chancge where things load from.
|
108 |
-
|
109 |
-
// 'script-handle' => ( 'google-lib-path', 'google-file-name', 'google-combined-into')
|
110 |
-
/* jQuery */
|
111 |
-
'jquery' => array( 'jquery', 'jquery.min', '' ),
|
112 |
-
|
113 |
-
/* jQuery UI */
|
114 |
-
'jquery-ui-core' => array( 'jqueryui', 'jquery-ui.min', '' ),
|
115 |
-
'jquery-ui-accordion' => array( '', '', 'jquery-ui-core' ),
|
116 |
-
'jquery-ui-autocomplete' => array( '', '', 'jquery-ui-core' ), /* jQueri UI 1.8 */
|
117 |
-
'jquery-ui-button' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
118 |
-
'jquery-ui-datepicker' => array( '', '', 'jquery-ui-core' ),
|
119 |
-
'jquery-ui-dialog' => array( '', '', 'jquery-ui-core' ),
|
120 |
-
'jquery-ui-draggable' => array( '', '', 'jquery-ui-core' ),
|
121 |
-
'jquery-ui-droppable' => array( '', '', 'jquery-ui-core' ),
|
122 |
-
'jquery-ui-menu' => array( '', '', 'jquery-ui-core' ),
|
123 |
-
'jquery-ui-mouse' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
124 |
-
'jquery-ui-position' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
125 |
-
'jquery-ui-progressbar' => array( '', '', 'jquery-ui-core' ),
|
126 |
-
'jquery-ui-resizable' => array( '', '', 'jquery-ui-core' ),
|
127 |
-
'jquery-ui-selectable' => array( '', '', 'jquery-ui-core' ),
|
128 |
-
'jquery-ui-slider' => array( '', '', 'jquery-ui-core' ),
|
129 |
-
'jquery-ui-sortable' => array( '', '', 'jquery-ui-core' ),
|
130 |
-
'jquery-ui-tabs' => array( '', '', 'jquery-ui-core' ),
|
131 |
-
'jquery-ui-widget' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
132 |
-
|
133 |
-
/* jQuery Effects */
|
134 |
-
'jquery-effects-core' => array( '', '', 'jquery-ui-core' ),
|
135 |
-
'jquery-effects-blind' => array( '', '', 'jquery-ui-core' ),
|
136 |
-
'jquery-effects-bounce' => array( '', '', 'jquery-ui-core' ),
|
137 |
-
'jquery-effects-clip' => array( '', '', 'jquery-ui-core' ),
|
138 |
-
'jquery-effects-drop' => array( '', '', 'jquery-ui-core' ),
|
139 |
-
'jquery-effects-explode' => array( '', '', 'jquery-ui-core' ),
|
140 |
-
'jquery-effects-fade' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
141 |
-
'jquery-effects-fold' => array( '', '', 'jquery-ui-core' ),
|
142 |
-
'jquery-effects-highlight' => array( '', '', 'jquery-ui-core' ),
|
143 |
-
'jquery-effects-pulsate' => array( '', '', 'jquery-ui-core' ),
|
144 |
-
'jquery-effects-scale' => array( '', '', 'jquery-ui-core' ),
|
145 |
-
'jquery-effects-shake' => array( '', '', 'jquery-ui-core' ),
|
146 |
-
'jquery-effects-slide' => array( '', '', 'jquery-ui-core' ),
|
147 |
-
'jquery-effects-transfer' => array( '', '', 'jquery-ui-core' ),
|
148 |
-
|
149 |
-
/* prototype */
|
150 |
-
'prototype' => array( 'prototype', 'prototype', '' ),
|
151 |
-
|
152 |
-
/* scriptaculous */
|
153 |
-
'scriptaculous-root' => array( 'scriptaculous', 'scriptaculous', '' ),
|
154 |
-
'scriptaculous-builder' => array( '', '', 'scriptaculous-root' ),
|
155 |
-
'scriptaculous-effects' => array( '', '', 'scriptaculous-root' ),
|
156 |
-
'scriptaculous-dragdrop' => array( '', '', 'scriptaculous-root' ),
|
157 |
-
'scriptaculous-controls' => array( '', '', 'scriptaculous-root' ),
|
158 |
-
'scriptaculous-slider' => array( '', '', 'scriptaculous-root' ),
|
159 |
-
'scriptaculous-sound' => array( '', '', 'scriptaculous-root' ),
|
160 |
-
|
161 |
-
/* moo tools */
|
162 |
-
'mootools' => array( 'mootools', 'mootools-yui-compressed', '' ),
|
163 |
-
|
164 |
-
/* Dojo */
|
165 |
-
'dojo' => array( 'dojo', 'dojo.xd', '' ),
|
166 |
-
|
167 |
-
/* swfobject */
|
168 |
-
'swfobject' => array( 'swfobject', 'swfobject', '' ),
|
169 |
-
|
170 |
-
/* YUI */
|
171 |
-
'yui' => array( 'yui', 'build/yuiloader/yuiloader-min', '' ),
|
172 |
-
|
173 |
-
/* Ext Core */
|
174 |
-
'ext-core' => array( 'ext-core', 'ext-core', '' )
|
175 |
|
176 |
-
);
|
177 |
$this->noconflict_next = FALSE;
|
178 |
// protocol-relative URLS accepted by `wp_register_scripts`
|
179 |
// starting with version 3.5
|
180 |
-
$this->protocol_relative_supported = version_compare(
|
|
|
|
|
181 |
}
|
182 |
|
183 |
static function configure_plugin() {
|
184 |
-
add_action(
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
1000
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
global $wp_scripts;
|
198 |
if ( is_a( $wp_scripts, 'WP_Scripts' ) ) {
|
199 |
self::debug( self::$script_before_init_notice );
|
@@ -203,11 +228,14 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
203 |
}
|
204 |
|
205 |
/**
|
206 |
-
* Get markup to show error message in admin when $WP_Script
|
|
|
|
|
207 |
* @returns string markup for notice display
|
208 |
*/
|
209 |
static function script_before_init_admin_notice() {
|
210 |
-
echo '<div class="error fade"><p>Use Google Libraries: ' .
|
|
|
211 |
}
|
212 |
|
213 |
static function setup_filter() {
|
@@ -225,9 +253,9 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
225 |
static function debug( $message ) {
|
226 |
if ( WP_DEBUG !== false ) {
|
227 |
if ( is_array( $message ) || is_object( $message ) ) {
|
228 |
-
$message =
|
229 |
}
|
230 |
-
error_log(
|
231 |
}
|
232 |
}
|
233 |
|
@@ -241,12 +269,54 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
241 |
|
242 |
}
|
243 |
|
244 |
-
|
245 |
static function replace_default_scripts_action( &$scripts ) {
|
246 |
$ugl = self::get_instance();
|
247 |
$ugl->replace_default_scripts( $scripts );
|
248 |
}
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
/**
|
251 |
* Collects replacement script registration data.
|
252 |
*
|
@@ -265,13 +335,7 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
265 |
$newscripts = array();
|
266 |
$combine_ok = array();
|
267 |
|
268 |
-
|
269 |
-
// if so, we'll adjust google_scripts here
|
270 |
-
if ( $scripts->query( 'jquery-core' ) && array_key_exists( 'jquery', $this->google_scripts ) ) {
|
271 |
-
$this->google_scripts['jquery-core'] = $this->google_scripts['jquery'];
|
272 |
-
unset($this->google_scripts['jquery']);
|
273 |
-
$this->jquery_tag = 'jquery-core';
|
274 |
-
}
|
275 |
|
276 |
foreach ( $this->google_scripts as $name => $values ) {
|
277 |
if ( $script = $scripts->query( $name ) ) {
|
@@ -304,23 +368,10 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
304 |
}
|
305 |
}
|
306 |
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
// build new URL
|
312 |
-
$url = "//ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
|
313 |
-
if ( wp_remote_retrieve_response_code( wp_remote_head( "http:$url" ) ) !== 200 ) {
|
314 |
-
self::debug( "Google servers do not seem to be hosting requested version of $name (version $ver). Using version provided by WordPress." );
|
315 |
-
continue;
|
316 |
-
}
|
317 |
-
if ( ! $this->protocol_relative_supported ) {
|
318 |
-
$url = "http:$url";
|
319 |
-
}
|
320 |
-
$script->src = $url;
|
321 |
-
} else {
|
322 |
-
$script->src = "";
|
323 |
-
}
|
324 |
$newscripts[] = $script;
|
325 |
$combine_ok[] = $name;
|
326 |
}
|
@@ -381,7 +432,7 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
381 |
function replace_default_scripts( &$scripts ) {
|
382 |
$newscripts = $this->get_newscripts( $scripts );
|
383 |
foreach ( $newscripts as $script ) {
|
384 |
-
$olddata = $this->
|
385 |
$scripts->remove( $script->handle );
|
386 |
// re-register with original ver
|
387 |
$scripts->add( $script->handle, $script->src, $script->deps, $script->ver );
|
@@ -394,18 +445,18 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
394 |
}
|
395 |
|
396 |
|
397 |
-
function
|
398 |
|
399 |
-
if ( !method_exists( $dep_obj, 'add_data' ) )
|
400 |
return false;
|
401 |
|
402 |
-
if ( !isset( $dep_obj->registered[$handle] ) )
|
403 |
return false;
|
404 |
|
405 |
-
if (
|
406 |
return $dep_obj->registered[$handle]->extra;
|
407 |
|
408 |
-
if ( !method_exists( $dep_obj, 'get_data' ) )
|
409 |
return $dep_obj->registered[$handle]->extra[$data_name];
|
410 |
|
411 |
return $dep_obj->get_data( $handle, $data_name );
|
@@ -422,11 +473,11 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
422 |
function remove_ver_query( $src ) {
|
423 |
if ( $this->noconflict_next ) {
|
424 |
$this->noconflict_next = FALSE;
|
425 |
-
echo
|
426 |
}
|
427 |
if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
|
428 |
$src = remove_query_arg( 'ver', $src );
|
429 |
-
if ( strpos( $src, $this->google_scripts[$this->jquery_tag][1] .
|
430 |
$this->noconflict_next = TRUE;
|
431 |
}
|
432 |
}
|
@@ -434,8 +485,8 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
|
434 |
}
|
435 |
|
436 |
static function remove_ver_query_filter( $src ) {
|
437 |
-
$ugl =
|
438 |
return $ugl->remove_ver_query( $src );
|
439 |
}
|
440 |
}
|
441 |
-
}
|
4 |
/* Author & copyright (c) 2008-2013 : Jason Penney (email : jpenney@jczorkmid.net ). General Public License v.2.0 */
|
5 |
|
6 |
|
7 |
+
if ( ! class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
8 |
|
9 |
class JCP_UseGoogleLibraries {
|
10 |
|
11 |
+
protected static $instance;
|
12 |
+
protected static $plugin_file = __FILE__;
|
13 |
+
protected static $version = '1.6dev';
|
14 |
+
protected static $noconflict_inject = "<script type='text/javascript'>try{jQuery.noConflict();}catch(e){};</script>\n";
|
15 |
+
|
16 |
public static function get_instance() {
|
17 |
+
if ( ! isset( self::$instance ) ) {
|
18 |
+
self::$instance = new JCP_UseGoogleLibraries();
|
19 |
}
|
20 |
return self::$instance;
|
21 |
}
|
63 |
|
64 |
/**
|
65 |
* True if using a version of WordPress that allows
|
66 |
+
* `wp_register_script` to take protocol-relative URLs,
|
67 |
+
* otherwise False
|
68 |
*
|
69 |
* @since 1.5.2
|
70 |
*
|
87 |
protected static $cache_len = 90000; // 25 hours
|
88 |
|
89 |
/**
|
90 |
+
* Message displayed and logged when a WP_Scripts has been created
|
91 |
+
* before it's time
|
92 |
*
|
93 |
+
* @var str
|
94 |
*/
|
95 |
protected static $script_before_init_notice =
|
96 |
'Another plugin has registered or enqued a script before the "init" action. Attempting to work around it.';
|
97 |
|
98 |
/**
|
99 |
+
* Registry of scripts available from Google Libraries. Any extra
|
100 |
+
* scripts listed here not provided by WordPress or another plugin
|
101 |
+
* will not be registered. This list is just used to chancge where
|
102 |
+
* things load from.
|
103 |
+
*
|
104 |
+
* Entries are in the format:
|
105 |
+
* <code>
|
106 |
+
* 'script-handle' => array(
|
107 |
+
* 'google-lib-path',
|
108 |
+
* 'google-file-name',
|
109 |
+
* 'google-combined-into'
|
110 |
+
* )
|
111 |
+
* </code>
|
112 |
+
*
|
113 |
+
* @var array
|
114 |
*/
|
115 |
+
protected static $default_google_scripts = array(
|
116 |
+
/* jQuery */
|
117 |
+
'jquery' => array( 'jquery', 'jquery.min', '' ),
|
118 |
+
|
119 |
+
/* jQuery UI */
|
120 |
+
'jquery-ui-core' => array( 'jqueryui', 'jquery-ui.min', '' ),
|
121 |
+
'jquery-ui-accordion' => array( '', '', 'jquery-ui-core' ),
|
122 |
+
'jquery-ui-autocomplete' => array( '', '', 'jquery-ui-core' ), /* jQueri UI 1.8 */
|
123 |
+
'jquery-ui-button' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
124 |
+
'jquery-ui-datepicker' => array( '', '', 'jquery-ui-core' ),
|
125 |
+
'jquery-ui-dialog' => array( '', '', 'jquery-ui-core' ),
|
126 |
+
'jquery-ui-draggable' => array( '', '', 'jquery-ui-core' ),
|
127 |
+
'jquery-ui-droppable' => array( '', '', 'jquery-ui-core' ),
|
128 |
+
'jquery-ui-menu' => array( '', '', 'jquery-ui-core' ),
|
129 |
+
'jquery-ui-mouse' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
130 |
+
'jquery-ui-position' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
131 |
+
'jquery-ui-progressbar' => array( '', '', 'jquery-ui-core' ),
|
132 |
+
'jquery-ui-resizable' => array( '', '', 'jquery-ui-core' ),
|
133 |
+
'jquery-ui-selectable' => array( '', '', 'jquery-ui-core' ),
|
134 |
+
'jquery-ui-slider' => array( '', '', 'jquery-ui-core' ),
|
135 |
+
'jquery-ui-sortable' => array( '', '', 'jquery-ui-core' ),
|
136 |
+
'jquery-ui-tabs' => array( '', '', 'jquery-ui-core' ),
|
137 |
+
'jquery-ui-widget' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
138 |
+
|
139 |
+
/* jQuery Effects */
|
140 |
+
'jquery-effects-core' => array( '', '', 'jquery-ui-core' ),
|
141 |
+
'jquery-effects-blind' => array( '', '', 'jquery-ui-core' ),
|
142 |
+
'jquery-effects-bounce' => array( '', '', 'jquery-ui-core' ),
|
143 |
+
'jquery-effects-clip' => array( '', '', 'jquery-ui-core' ),
|
144 |
+
'jquery-effects-drop' => array( '', '', 'jquery-ui-core' ),
|
145 |
+
'jquery-effects-explode' => array( '', '', 'jquery-ui-core' ),
|
146 |
+
'jquery-effects-fade' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
147 |
+
'jquery-effects-fold' => array( '', '', 'jquery-ui-core' ),
|
148 |
+
'jquery-effects-highlight' => array( '', '', 'jquery-ui-core' ),
|
149 |
+
'jquery-effects-pulsate' => array( '', '', 'jquery-ui-core' ),
|
150 |
+
'jquery-effects-scale' => array( '', '', 'jquery-ui-core' ),
|
151 |
+
'jquery-effects-shake' => array( '', '', 'jquery-ui-core' ),
|
152 |
+
'jquery-effects-slide' => array( '', '', 'jquery-ui-core' ),
|
153 |
+
'jquery-effects-transfer' => array( '', '', 'jquery-ui-core' ),
|
154 |
+
|
155 |
+
/* prototype */
|
156 |
+
'prototype' => array( 'prototype', 'prototype', '' ),
|
157 |
+
|
158 |
+
/* scriptaculous */
|
159 |
+
'scriptaculous-root' => array( 'scriptaculous', 'scriptaculous', '' ),
|
160 |
+
'scriptaculous-builder' => array( '', '', 'scriptaculous-root' ),
|
161 |
+
'scriptaculous-effects' => array( '', '', 'scriptaculous-root' ),
|
162 |
+
'scriptaculous-dragdrop' => array( '', '', 'scriptaculous-root' ),
|
163 |
+
'scriptaculous-controls' => array( '', '', 'scriptaculous-root' ),
|
164 |
+
'scriptaculous-slider' => array( '', '', 'scriptaculous-root' ),
|
165 |
+
'scriptaculous-sound' => array( '', '', 'scriptaculous-root' ),
|
166 |
+
|
167 |
+
/* moo tools */
|
168 |
+
'mootools' => array( 'mootools', 'mootools-yui-compressed', '' ),
|
169 |
+
|
170 |
+
/* Dojo */
|
171 |
+
'dojo' => array( 'dojo', 'dojo.xd', '' ),
|
172 |
+
|
173 |
+
/* swfobject */
|
174 |
+
'swfobject' => array( 'swfobject', 'swfobject', '' ),
|
175 |
+
|
176 |
+
/* YUI */
|
177 |
+
'yui' => array( 'yui', 'build/yuiloader/yuiloader-min', '' ),
|
178 |
+
|
179 |
+
/* Ext Core */
|
180 |
+
'ext-core' => array( 'ext-core', 'ext-core', '' )
|
181 |
+
|
182 |
+
);
|
183 |
|
184 |
/**
|
185 |
* PHP 5 Constructor
|
186 |
*/
|
187 |
function __construct() {
|
188 |
+
$this->jquery_tag = 'jquery';
|
189 |
+
$this->google_scripts = self::$default_google_scripts;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
|
|
191 |
$this->noconflict_next = FALSE;
|
192 |
// protocol-relative URLS accepted by `wp_register_scripts`
|
193 |
// starting with version 3.5
|
194 |
+
$this->protocol_relative_supported = version_compare(
|
195 |
+
get_bloginfo( 'version' ), '3.5', '>='
|
196 |
+
);
|
197 |
}
|
198 |
|
199 |
static function configure_plugin() {
|
200 |
+
add_action(
|
201 |
+
'wp_default_scripts',
|
202 |
+
array(
|
203 |
+
'JCP_UseGoogleLibraries',
|
204 |
+
'replace_default_scripts_action',
|
205 |
+
),
|
206 |
+
1000
|
207 |
+
);
|
208 |
+
add_filter(
|
209 |
+
'script_loader_src',
|
210 |
+
array( 'JCP_UseGoogleLibraries', 'remove_ver_query_filter' ),
|
211 |
+
1000
|
212 |
+
);
|
213 |
+
add_filter(
|
214 |
+
'init',
|
215 |
+
array( 'JCP_UseGoogleLibraries', 'setup_filter' )
|
216 |
+
);
|
217 |
+
|
218 |
+
// There's a chance some plugin has called wp_enqueue_script
|
219 |
+
// outside of any hooks, which means that this plugin's
|
220 |
+
// 'wp_default_scripts' hook will never get a chance to fire.
|
221 |
+
// This tries to work around that.
|
222 |
global $wp_scripts;
|
223 |
if ( is_a( $wp_scripts, 'WP_Scripts' ) ) {
|
224 |
self::debug( self::$script_before_init_notice );
|
228 |
}
|
229 |
|
230 |
/**
|
231 |
+
* Get markup to show error message in admin when $WP_Script
|
232 |
+
* created before it's time
|
233 |
+
*
|
234 |
* @returns string markup for notice display
|
235 |
*/
|
236 |
static function script_before_init_admin_notice() {
|
237 |
+
echo '<div class="error fade"><p>Use Google Libraries: ' .
|
238 |
+
self::$script_before_init_notice . '</p></div>';
|
239 |
}
|
240 |
|
241 |
static function setup_filter() {
|
253 |
static function debug( $message ) {
|
254 |
if ( WP_DEBUG !== false ) {
|
255 |
if ( is_array( $message ) || is_object( $message ) ) {
|
256 |
+
$message = var_export( $message, true );
|
257 |
}
|
258 |
+
error_log( 'Use Google Libraries: ' . $message );
|
259 |
}
|
260 |
}
|
261 |
|
269 |
|
270 |
}
|
271 |
|
|
|
272 |
static function replace_default_scripts_action( &$scripts ) {
|
273 |
$ugl = self::get_instance();
|
274 |
$ugl->replace_default_scripts( $scripts );
|
275 |
}
|
276 |
|
277 |
+
/**
|
278 |
+
* Sometimes WordPress registes `jquery.js` as `'jquery-core'`, while
|
279 |
+
* '`jquery`' is some other script with a dependency on
|
280 |
+
* `'jquery-core'`. If '`jquery-core`' in present in `$scripts`
|
281 |
+
* this is assumed to be the case and update the registration for
|
282 |
+
* '`jquery-core`' instead.
|
283 |
+
*
|
284 |
+
* @since 1.6
|
285 |
+
*
|
286 |
+
* @param object $scripts
|
287 |
+
*/
|
288 |
+
protected function newscripts_fix_jquery_core( &$scripts ) {
|
289 |
+
// jquery may really be loaded under jquery-core
|
290 |
+
// if so, we'll adjust google_scripts here
|
291 |
+
if ( $scripts->query( 'jquery-core' ) && array_key_exists( 'jquery', $this->google_scripts ) ) {
|
292 |
+
$this->google_scripts['jquery-core'] = $this->google_scripts['jquery'];
|
293 |
+
unset( $this->google_scripts['jquery'] );
|
294 |
+
$this->jquery_tag = 'jquery-core';
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
protected function newscripts_build_url( $name, $lib, $ver, $js, $orig_url ) {
|
299 |
+
|
300 |
+
// if $lib is empty, then this script does not need to be
|
301 |
+
// exlicitly loaded when using googleapis.com, but we need to keep
|
302 |
+
// it around for dependencies
|
303 |
+
if ( $lib != '' ) {
|
304 |
+
// build new URL
|
305 |
+
$url = "//ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
|
306 |
+
$head = wp_remote_head( "http:$url" );
|
307 |
+
if ( wp_remote_retrieve_response_code( $head ) !== 200 ) {
|
308 |
+
self::debug( "Google servers do not seem to be hosting requested version of $name (version $ver). Using version provided by WordPress." );
|
309 |
+
return $orig_url;
|
310 |
+
}
|
311 |
+
if ( ! $this->protocol_relative_supported ) {
|
312 |
+
return "http:$url";
|
313 |
+
}
|
314 |
+
return $url;
|
315 |
+
} else {
|
316 |
+
return '';
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
/**
|
321 |
* Collects replacement script registration data.
|
322 |
*
|
335 |
$newscripts = array();
|
336 |
$combine_ok = array();
|
337 |
|
338 |
+
$this->newscripts_fix_jquery_core( $scripts );
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
foreach ( $this->google_scripts as $name => $values ) {
|
341 |
if ( $script = $scripts->query( $name ) ) {
|
368 |
}
|
369 |
}
|
370 |
|
371 |
+
$script->src = $this->newscripts_build_url(
|
372 |
+
$name, $lib, $ver, $js, $script->src
|
373 |
+
);
|
374 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
$newscripts[] = $script;
|
376 |
$combine_ok[] = $name;
|
377 |
}
|
432 |
function replace_default_scripts( &$scripts ) {
|
433 |
$newscripts = $this->get_newscripts( $scripts );
|
434 |
foreach ( $newscripts as $script ) {
|
435 |
+
$olddata = $this->wp_dependency_get_data( $scripts, $script->handle );
|
436 |
$scripts->remove( $script->handle );
|
437 |
// re-register with original ver
|
438 |
$scripts->add( $script->handle, $script->src, $script->deps, $script->ver );
|
445 |
}
|
446 |
|
447 |
|
448 |
+
function wp_dependency_get_data( $dep_obj, $handle, $data_name = false ) {
|
449 |
|
450 |
+
if ( ! method_exists( $dep_obj, 'add_data' ) )
|
451 |
return false;
|
452 |
|
453 |
+
if ( ! isset( $dep_obj->registered[$handle] ) )
|
454 |
return false;
|
455 |
|
456 |
+
if ( ! $data_name )
|
457 |
return $dep_obj->registered[$handle]->extra;
|
458 |
|
459 |
+
if ( ! method_exists( $dep_obj, 'get_data' ) )
|
460 |
return $dep_obj->registered[$handle]->extra[$data_name];
|
461 |
|
462 |
return $dep_obj->get_data( $handle, $data_name );
|
473 |
function remove_ver_query( $src ) {
|
474 |
if ( $this->noconflict_next ) {
|
475 |
$this->noconflict_next = FALSE;
|
476 |
+
echo self::$noconflict_inject; // xss ok
|
477 |
}
|
478 |
if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
|
479 |
$src = remove_query_arg( 'ver', $src );
|
480 |
+
if ( strpos( $src, $this->google_scripts[$this->jquery_tag][1] . '.js' ) ) {
|
481 |
$this->noconflict_next = TRUE;
|
482 |
}
|
483 |
}
|
485 |
}
|
486 |
|
487 |
static function remove_ver_query_filter( $src ) {
|
488 |
+
$ugl = self::get_instance();
|
489 |
return $ugl->remove_ver_query( $src );
|
490 |
}
|
491 |
}
|
492 |
+
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: speed, optimization, performance, speed booster, scripts to the footer, Google Libraries, CDN, defer parsing of javascript, remove query strings, GTmetrix, Google PageSpeed, YSlow
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 3.9.1
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,16 +12,29 @@ Features options to improve your website performance and get a higher score on t
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
Speed Booster Pack allows you to improve your page loading speed and get a higher score on the major speed testing services such as [GTmetrix](http://gtmetrix.com/), [Google PageSpeed](http://developers.google.com/speed/pagespeed/insights/),
|
16 |
|
17 |
-
=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
* **Moves scripts to the footer** to improve page loading speed.
|
20 |
* **Loads javascript files from Google Libraries** rather than serving them from your WordPress install directly, to reduce latency, increase parallelism and improve caching.
|
21 |
* **Defers parsing of javascript files** to reduce the initial load time of your page.
|
22 |
* **Removes query strings from static resources** to improve your speed scores.
|
23 |
* **Removes junk header tags** to clean up your WordPress Header.
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
**Page loading time** – the progress bar color will be:
|
27 |
|
@@ -50,6 +63,9 @@ For complete usage instructions visit [Plugin Documentation](http://tiguandesign
|
|
50 |
|
51 |
== Changelog ==
|
52 |
|
|
|
|
|
|
|
53 |
= 1.2 =
|
54 |
* Modified the plugin version number variable in plugin options page.
|
55 |
|
4 |
Tags: speed, optimization, performance, speed booster, scripts to the footer, Google Libraries, CDN, defer parsing of javascript, remove query strings, GTmetrix, Google PageSpeed, YSlow
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 3.9.1
|
7 |
+
Stable tag: 1.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
Speed Booster Pack allows you to improve your page loading speed and get a higher score on the major speed testing services such as [GTmetrix](http://gtmetrix.com/), [Google PageSpeed](http://developers.google.com/speed/pagespeed/insights/), [YSlow](https://developer.yahoo.com/yslow/), [Pingdom](http://tools.pingdom.com/fpt/), [Webpagetest](http://www.webpagetest.org/) or other speed testing tools.
|
16 |
|
17 |
+
= Why Site Speed Is Important =
|
18 |
+
|
19 |
+
When visitors lands on your site for the first time, you only have a 3 seconds to capture their attention and convince them to stick around. That's not convinced you? Read on:
|
20 |
+
|
21 |
+
|
22 |
+
>* Google incorporating site speed in search rankings
|
23 |
+
* 47% of online consumers expect a web page to load in 2 seconds or less
|
24 |
+
* 40% of people will abandon a site that takes more than 3 seconds to load
|
25 |
+
* 80% of online consumers are less likely to return to a slow website
|
26 |
+
|
27 |
+
= Main Plugin Features =
|
28 |
|
29 |
* **Moves scripts to the footer** to improve page loading speed.
|
30 |
* **Loads javascript files from Google Libraries** rather than serving them from your WordPress install directly, to reduce latency, increase parallelism and improve caching.
|
31 |
* **Defers parsing of javascript files** to reduce the initial load time of your page.
|
32 |
* **Removes query strings from static resources** to improve your speed scores.
|
33 |
* **Removes junk header tags** to clean up your WordPress Header.
|
34 |
+
|
35 |
+
= Page Load Stats =
|
36 |
+
|
37 |
+
Page Load Stats is a brief statistic displayed in the plugin options page. It displays your homepage loading speed (in seconds) and number of processed queries.
|
38 |
|
39 |
**Page loading time** – the progress bar color will be:
|
40 |
|
63 |
|
64 |
== Changelog ==
|
65 |
|
66 |
+
= 1.3 =
|
67 |
+
* Fixed strict standards error: redefining already defined constructor for class.
|
68 |
+
|
69 |
= 1.2 =
|
70 |
* Modified the plugin version number variable in plugin options page.
|
71 |
|
speed-booster-pack.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Speed Booster Pack
|
4 |
* Plugin URI: http://tiguandesign.com
|
5 |
* Description: Speed Booster Pack allows you to improve your page loading speed and get a higher score on the major speed testing services such as <a href="http://gtmetrix.com/">GTmetrix</a>, <a href="http://developers.google.com/speed/pagespeed/insights/">Google PageSpeed</a> or other speed testing tools.
|
6 |
-
* Version: 1.
|
7 |
* Author: Tiguan
|
8 |
* Author URI: http://themeforest.net/user/Tiguan
|
9 |
* License: GPLv2
|
@@ -38,7 +38,7 @@ $sbp_options = get_option( 'sbp_settings', 'checked' ); // retrieve the plugin s
|
|
38 |
|
39 |
define( 'SPEED_BOOSTER_PACK_RELEASE_DATE', date_i18n( 'F j, Y', '1400569200' ) ); // Defining plugin release date
|
40 |
define( 'SPEED_BOOSTER_PACK_PATH', plugin_dir_path( __FILE__ ) ); // Defining plugin dir path
|
41 |
-
define( 'SPEED_BOOSTER_PACK_VERSION', 'v1.
|
42 |
|
43 |
|
44 |
/*----------------------------------------------
|
3 |
* Plugin Name: Speed Booster Pack
|
4 |
* Plugin URI: http://tiguandesign.com
|
5 |
* Description: Speed Booster Pack allows you to improve your page loading speed and get a higher score on the major speed testing services such as <a href="http://gtmetrix.com/">GTmetrix</a>, <a href="http://developers.google.com/speed/pagespeed/insights/">Google PageSpeed</a> or other speed testing tools.
|
6 |
+
* Version: 1.3
|
7 |
* Author: Tiguan
|
8 |
* Author URI: http://themeforest.net/user/Tiguan
|
9 |
* License: GPLv2
|
38 |
|
39 |
define( 'SPEED_BOOSTER_PACK_RELEASE_DATE', date_i18n( 'F j, Y', '1400569200' ) ); // Defining plugin release date
|
40 |
define( 'SPEED_BOOSTER_PACK_PATH', plugin_dir_path( __FILE__ ) ); // Defining plugin dir path
|
41 |
+
define( 'SPEED_BOOSTER_PACK_VERSION', 'v1.3'); // Defining plugin version
|
42 |
|
43 |
|
44 |
/*----------------------------------------------
|