Version Description
- massive Massive MASSIVE rewrite of Async JavaScript!!!
- Now includes a setup Wizard, Status page, Settings page and a help page.
- Communicates directly with GTmetrix (account required)
Download this release
Release Info
Developer | cloughit |
Plugin | Async JavaScript |
Version | 2.17.04.25 |
Comparing to | |
See all releases |
Code changes from version 1.17.02.06 to 2.17.04.25
- async-javascript.php +1224 -170
- css/admin.css +88 -14
- css/admin.min.css +1 -1
- images/finger_point_out_punch_hole_400_clr_17860.png +0 -0
- images/loading.gif +0 -0
- images/not_available.jpg +0 -0
- images/number-block-eight.jpg +0 -0
- images/number-block-five.jpg +0 -0
- images/number-block-four.jpg +0 -0
- images/number-block-nine.jpg +0 -0
- images/number-block-one.jpg +0 -0
- images/number-block-seven.jpg +0 -0
- images/number-block-six.jpg +0 -0
- images/number-block-three.jpg +0 -0
- images/number-block-two.jpg +0 -0
- images/number_five_break_hole_150_clr_18842.gif +0 -0
- images/number_four_break_hole_150_clr_18840.gif +0 -0
- images/number_one_break_hole_150_clr_18741.gif +0 -0
- images/number_three_break_hole_150_clr_18837.gif +0 -0
- images/number_two_break_hole_150_clr_18753.gif +0 -0
- images/stick_figure_panicking_150_clr_13267.gif +0 -0
- js/admin.js +278 -31
- js/admin.min.js +1 -1
- lib/gtmetrix/class.Services_WTF_Test.php +468 -0
- readme.txt +55 -20
async-javascript.php
CHANGED
@@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
4 |
Plugin Name: Async JavaScript
|
5 |
Plugin URI: https://cloughit.com.au/product/async-javascript/
|
6 |
Description: Async JavaScript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
|
7 |
-
Version:
|
8 |
Author: Clough I.T. Solutions
|
9 |
Author URI: http://www.cloughit.com.au/
|
10 |
Text Domain: async-javascript
|
@@ -14,16 +14,15 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
14 |
/**
|
15 |
* aj_admin_init()
|
16 |
*
|
17 |
-
*
|
18 |
*
|
19 |
-
* @param n/a
|
20 |
-
* @return n/a
|
21 |
*/
|
22 |
add_action( 'admin_init', 'aj_admin_init' );
|
23 |
function aj_admin_init() {
|
24 |
define( 'AJ_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
25 |
define( 'AJ_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
26 |
-
define( 'AJ_VERSION', '
|
|
|
27 |
wp_register_style(
|
28 |
'aj_admin_styles',
|
29 |
plugins_url( '/css/admin.min.css', __FILE__ )
|
@@ -35,25 +34,146 @@ function aj_admin_init() {
|
|
35 |
array( 'jquery' ),
|
36 |
time()
|
37 |
);
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
register_setting( 'aj_options', 'aj_autoptimize_enabled' );
|
46 |
-
register_setting( 'aj_options', 'aj_autoptimize_method' );
|
47 |
-
$autoptimize_enabled = get_option( 'autoptimize_enabled' );
|
48 |
-
$aj_autoptimize_enabled = get_option( 'aj_autoptimize_enabled' );
|
49 |
}
|
50 |
/**
|
51 |
-
*
|
52 |
*
|
53 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
*
|
55 |
-
* @param n/a
|
56 |
-
* @return n/a
|
57 |
*/
|
58 |
add_action( 'admin_notices', 'async_javascript_upgrade_notice' );
|
59 |
function async_javascript_upgrade_notice() {
|
@@ -85,10 +205,8 @@ function async_javascript_upgrade_notice() {
|
|
85 |
/**
|
86 |
* async_javascript_menu()
|
87 |
*
|
88 |
-
*
|
89 |
*
|
90 |
-
* @param n/a
|
91 |
-
* @return n/a
|
92 |
*/
|
93 |
add_action( 'admin_menu', 'async_javascript_menu' );
|
94 |
function async_javascript_menu() {
|
@@ -105,159 +223,715 @@ function async_javascript_menu() {
|
|
105 |
/**
|
106 |
* async_javascript_admin()
|
107 |
*
|
108 |
-
*
|
109 |
*
|
110 |
-
* @param n/a
|
111 |
-
* @return n/a
|
112 |
*/
|
113 |
function async_javascript_admin() {
|
114 |
// load settings from database
|
|
|
|
|
115 |
?>
|
116 |
-
<div class="wrap">
|
117 |
-
|
118 |
-
<
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
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 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
?>
|
207 |
-
<
|
208 |
<?php
|
209 |
}
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
</div>
|
237 |
<?php
|
238 |
}
|
239 |
/**
|
240 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
*
|
242 |
-
*
|
243 |
*
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
*
|
249 |
*/
|
250 |
add_filter( 'script_loader_tag', 'async_js', 10, 3 );
|
251 |
function async_js( $tag, $handle, $src ) {
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
262 |
if ( is_array( $array_exclusions ) && !empty( $array_exclusions ) ) {
|
263 |
foreach ( $array_exclusions as $exclusion ) {
|
@@ -281,36 +955,416 @@ function async_js( $tag, $handle, $src ) {
|
|
281 |
return $tag;
|
282 |
}
|
283 |
return $tag;
|
284 |
-
}
|
285 |
/**
|
286 |
* my_autoptimize_defer()
|
287 |
*
|
288 |
* Adds support for Autoptimize plugin. Adds 'async' attribute to '<script>' tasks called via autoptimize_filter_js_defer filter
|
289 |
* Autoptimize: https://wordpress.org/plugins/autoptimize/
|
290 |
*
|
291 |
-
* @param string $defer current value of $defer as passed to function
|
292 |
-
* @return string 'async' attribute
|
293 |
*/
|
294 |
add_filter( 'autoptimize_filter_js_defer', 'my_autoptimize_defer', 11 );
|
295 |
function my_autoptimize_defer( $defer ) {
|
296 |
-
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
|
297 |
-
|
298 |
-
$
|
299 |
-
|
300 |
-
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? true : false;
|
301 |
-
$aj_autoptimize_enabled = ( isset( $_GET['aj_autoptimize_enabled'] ) && $_GET['aj_autoptimize_enabled'] == 1 ) ? true : $aj_autoptimize_enabled;
|
302 |
-
$aj_autoptimize_method = ( get_option( 'aj_autoptimize_method' ) != 'async' ) ? 'defer' : 'async';
|
303 |
-
$aj_autoptimize_method = ( isset( $_GET['aj_autoptimize_method'] ) ) ? $_GET['aj_autoptimize_method'] : $aj_autoptimize_method;
|
304 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
305 |
if ( false !== $aj_autoptimize_enabled ) {
|
306 |
return " " . $aj_autoptimize_method . "='" . $aj_autoptimize_method . "' ";
|
307 |
}
|
308 |
}
|
309 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
add_action( 'wp_ajax_async_javascript_dismiss_upgrade', 'async_javascript_dismiss_upgrade' );
|
311 |
function async_javascript_dismiss_upgrade() {
|
312 |
$notice_id = isset( $_REQUEST['notice_id'] ) && $_REQUEST['notice_id'] != '' ? $_REQUEST['notice_id'] : '';
|
313 |
update_option( 'aj_upgrade_notice', $notice_id );
|
314 |
die();
|
315 |
}
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
Plugin Name: Async JavaScript
|
5 |
Plugin URI: https://cloughit.com.au/product/async-javascript/
|
6 |
Description: Async JavaScript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
|
7 |
+
Version: 2.17.04.25
|
8 |
Author: Clough I.T. Solutions
|
9 |
Author URI: http://www.cloughit.com.au/
|
10 |
Text Domain: async-javascript
|
14 |
/**
|
15 |
* aj_admin_init()
|
16 |
*
|
17 |
+
* Register admin stylesheets and javascripts
|
18 |
*
|
|
|
|
|
19 |
*/
|
20 |
add_action( 'admin_init', 'aj_admin_init' );
|
21 |
function aj_admin_init() {
|
22 |
define( 'AJ_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
23 |
define( 'AJ_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
24 |
+
define( 'AJ_VERSION', '2.17.04.25' );
|
25 |
+
require_once( AJ_PLUGIN_DIR . 'lib/gtmetrix/class.Services_WTF_Test.php' );
|
26 |
wp_register_style(
|
27 |
'aj_admin_styles',
|
28 |
plugins_url( '/css/admin.min.css', __FILE__ )
|
34 |
array( 'jquery' ),
|
35 |
time()
|
36 |
);
|
37 |
+
$aj_localize = array(
|
38 |
+
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
39 |
+
'siteurl' => get_site_url(),
|
40 |
+
'pluginurl' => AJ_PLUGIN_URL,
|
41 |
+
'ajadminurl' => admin_url( 'options-general.php?page=async-javascript' )
|
42 |
+
);
|
43 |
+
wp_localize_script( 'aj_admin_scripts', 'aj_localize_admin', $aj_localize );
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
/**
|
46 |
+
* register_aj_dashboard_widget()
|
47 |
*
|
48 |
+
* Register dashboard widget
|
49 |
+
*
|
50 |
+
*/
|
51 |
+
add_action( 'wp_dashboard_setup', 'register_aj_dashboard_widget' );
|
52 |
+
function register_aj_dashboard_widget() {
|
53 |
+
global $wp_meta_boxes;
|
54 |
+
wp_add_dashboard_widget(
|
55 |
+
'aj_dashboard_widget',
|
56 |
+
'Async JavaScript',
|
57 |
+
'aj_dashboard_widget'
|
58 |
+
);
|
59 |
+
$dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
|
60 |
+
$my_widget = array( 'aj_dashboard_widget' => $dashboard['aj_dashboard_widget'] );
|
61 |
+
unset( $dashboard['aj_dashboard_widget'] );
|
62 |
+
$sorted_dashboard = array_merge( $my_widget, $dashboard );
|
63 |
+
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
|
64 |
+
}
|
65 |
+
/**
|
66 |
+
* aj_dashboard_widget()
|
67 |
+
*
|
68 |
+
* Dashboard widget
|
69 |
+
*
|
70 |
+
*/
|
71 |
+
function aj_dashboard_widget() {
|
72 |
+
$site_url = trailingslashit( get_site_url() );
|
73 |
+
$aj_gtmetrix_username = get_option( 'aj_gtmetrix_username', '' );
|
74 |
+
$aj_gtmetrix_api_key = get_option( 'aj_gtmetrix_api_key', '' );
|
75 |
+
$aj_gtmetrix_server = get_option( 'aj_gtmetrix_server', '' );
|
76 |
+
$aj_enabled = ( get_option( 'aj_enabled', 0 ) == 1 ) ? 'Enabled' : 'Disabled';
|
77 |
+
$aj_method = ( get_option( 'aj_method', 'async' ) == 'async' ) ? 'Async' : 'Defer';
|
78 |
+
$aj_jquery = get_option( 'aj_jquery', 'async' );
|
79 |
+
$aj_jquery = ( $aj_jquery == 'same ' ) ? get_option( 'aj_method', 'async' ) : $aj_jquery;
|
80 |
+
$aj_jquery = ( $aj_jquery == 'async' ) ? 'Async' : ( $aj_jquery == 'defer' ) ? 'Defer' : 'Excluded';
|
81 |
+
$aj_exclusions = get_option( 'aj_exclusions', '' );
|
82 |
+
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? 'Enabled' : 'Disabled';
|
83 |
+
$aj_autoptimize_method = ( get_option( 'aj_autoptimize_method' ) == 'async' ) ? 'Async' : 'Defer';
|
84 |
+
?>
|
85 |
+
<div class="wrap aj">
|
86 |
+
<h3>Async JavaScript Status</h3>
|
87 |
+
<ul>
|
88 |
+
<li><strong>Status:</strong> <?php echo $aj_enabled; ?></li>
|
89 |
+
<?php
|
90 |
+
if ( $aj_enabled == 'Enabled' ) {
|
91 |
+
?>
|
92 |
+
<li><strong>Method:</strong> <?php echo $aj_method; ?></li>
|
93 |
+
<li><strong>jQuery:</strong> <?php echo $aj_jquery; ?></li>
|
94 |
+
<li><strong>Exclusions:</strong> <?php echo $aj_exclusions; ?></li>
|
95 |
+
<?php
|
96 |
+
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
|
97 |
+
?>
|
98 |
+
<li><strong>Autoptimize Status:</strong> <?php echo $aj_autoptimize_enabled; ?></li>
|
99 |
+
<?php
|
100 |
+
if ( $aj_autoptimize_enabled == 'Enabled' ) {
|
101 |
+
?>
|
102 |
+
<li><strong>Autoptimize Method:</strong> <?php echo $aj_autoptimize_method; ?></li>
|
103 |
+
<?php
|
104 |
+
}
|
105 |
+
} else {
|
106 |
+
?>
|
107 |
+
<li>Autoptimize not installed or activated.</li>
|
108 |
+
<?php
|
109 |
+
}
|
110 |
+
}
|
111 |
+
?>
|
112 |
+
</ul>
|
113 |
+
<hr />
|
114 |
+
<h3>Latest GTmetrix Results</h3>
|
115 |
+
<?php
|
116 |
+
$aj_gtmetrix_results = get_option( 'aj_gtmetrix_results', array() );
|
117 |
+
if ( isset( $aj_gtmetrix_results['latest'] ) ) {
|
118 |
+
$latest = $aj_gtmetrix_results['latest'];
|
119 |
+
//$screenshot = $latest['results']['report_url'] . '/screenshot.jpg';
|
120 |
+
$screenshot = $latest['screenshot'];
|
121 |
+
$pagespeed = $latest['results']['pagespeed_score'];
|
122 |
+
$yslow = $latest['results']['yslow_score'];
|
123 |
+
$pr = round( 255 * ( 1 - ( $pagespeed / 100 ) ), 0 );
|
124 |
+
$yr = round( 255 * ( 1 - ( $yslow / 100 ) ), 0 );
|
125 |
+
$pg = round( 255 * ( $pagespeed / 100 ), 0 );
|
126 |
+
$yg = round( 255 * ( $yslow / 100 ), 0 );
|
127 |
+
$pagespeed_style = ' style="color: rgb(' . $pr . ',' . $pg . ',0 )"';
|
128 |
+
$yslow_style = ' style="color: rgb(' . $yr . ',' . $yg . ',0 )"';
|
129 |
+
$flt = number_format( ( float )$latest['results']['fully_loaded_time'] / 1000, 2, '.', '' );
|
130 |
+
$tps = number_format( ( float )$latest['results']['page_bytes'] / 1024, 0, '.', '' );
|
131 |
+
$requests = $latest['results']['page_elements'];
|
132 |
+
$report = $latest['results']['report_url'];
|
133 |
+
$report_url = '<a href="' . $report . '" target="_blank">' . $report . '</a>';
|
134 |
+
?>
|
135 |
+
<p id="aj_latest_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
136 |
+
<table id="aj_latest_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
137 |
+
<tr>
|
138 |
+
<td scope="row" align="center"><img src="data:image/jpeg;base64,<?php echo $screenshot; ?>" class="aj_latest_screenshot aj_gtmetrix_screenshot_dashboard">
|
139 |
+
<td scope="row" align="center">
|
140 |
+
<h3>PageSpeed Score</h3>
|
141 |
+
<span class="aj_latest_pagespeed aj_gtmetrix_result"<?php echo $pagespeed_style; ?>><?php echo $pagespeed; ?>%</span>
|
142 |
+
</td>
|
143 |
+
<td scope="row" align="center">
|
144 |
+
<h3>YSlow Score</h3>
|
145 |
+
<span class="aj_latest_yslow aj_gtmetrix_result"<?php echo $yslow_style; ?>><?php echo $yslow; ?>%</span>
|
146 |
+
</td>
|
147 |
+
</tr>
|
148 |
+
<tr>
|
149 |
+
<td scope="row" align="center">
|
150 |
+
<h3>Fully Loaded Time</h3>
|
151 |
+
<span class="aj_latest_flt aj_gtmetrix_result"><?php echo $flt; ?>s</span>
|
152 |
+
</td>
|
153 |
+
<td scope="row" align="center">
|
154 |
+
<h3>Total Page Size</h3>
|
155 |
+
<span class="aj_latest_tps aj_gtmetrix_result"><?php echo $tps; ?>KB</span>
|
156 |
+
</td>
|
157 |
+
<td scope="row" align="center">
|
158 |
+
<h3>Requests</h3>
|
159 |
+
<span class="aj_latest_requests aj_gtmetrix_result"><?php echo $requests; ?></span>
|
160 |
+
</td>
|
161 |
+
</tr>
|
162 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_latest_report"><?php echo $report_url; ?></span></td></tr>
|
163 |
+
</table>
|
164 |
+
<?php
|
165 |
+
}
|
166 |
+
?>
|
167 |
+
<p>Please click on the Settings button below to generate a new GTmetrix Report.</p>
|
168 |
+
<p><button data-id="aj_goto_settings" class="aj_steps_button">Settings</button></p>
|
169 |
+
</div>
|
170 |
+
<?php
|
171 |
+
}
|
172 |
+
/**
|
173 |
+
* async_javascript_upgrade_notice()
|
174 |
+
*
|
175 |
+
* Show notices
|
176 |
*
|
|
|
|
|
177 |
*/
|
178 |
add_action( 'admin_notices', 'async_javascript_upgrade_notice' );
|
179 |
function async_javascript_upgrade_notice() {
|
205 |
/**
|
206 |
* async_javascript_menu()
|
207 |
*
|
208 |
+
* Register admin menu
|
209 |
*
|
|
|
|
|
210 |
*/
|
211 |
add_action( 'admin_menu', 'async_javascript_menu' );
|
212 |
function async_javascript_menu() {
|
223 |
/**
|
224 |
* async_javascript_admin()
|
225 |
*
|
226 |
+
* Admin page
|
227 |
*
|
|
|
|
|
228 |
*/
|
229 |
function async_javascript_admin() {
|
230 |
// load settings from database
|
231 |
+
$tabs = array( 'wizard', 'status', 'settings', 'help' );
|
232 |
+
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'wizard';
|
233 |
?>
|
234 |
+
<div class="wrap aj">
|
235 |
+
<div id="aj_notification"></div>
|
236 |
+
<h2>Welcome to Async JavaScript</h2>
|
237 |
+
<h2 class="nav-tab-wrapper">
|
238 |
+
<?php
|
239 |
+
foreach ($tabs as $tab ) {
|
240 |
+
$active = $active_tab == $tab ? 'nav-tab-active' : '';
|
241 |
+
echo '<a href="?page=async-javascript&tab=' . $tab . '" class="nav-tab ' . $active . '">' . ucfirst( $tab ) . '</a>';
|
242 |
+
}
|
243 |
+
?>
|
244 |
+
</h2>
|
245 |
+
<?php
|
246 |
+
if ( $active_tab == 'wizard' ) {
|
247 |
+
$site_url = trailingslashit( get_site_url() );
|
248 |
+
$aj_gtmetrix_username = get_option( 'aj_gtmetrix_username', '' );
|
249 |
+
$aj_gtmetrix_api_key = get_option( 'aj_gtmetrix_api_key', '' );
|
250 |
+
$aj_gtmetrix_server = get_option( 'aj_gtmetrix_server', '' );
|
251 |
+
if ( $aj_gtmetrix_username != '' && $aj_gtmetrix_api_key != '' ) {
|
252 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
253 |
+
$status = $test->status();
|
254 |
+
$credits = $status['api_credits'];
|
255 |
+
} else {
|
256 |
+
$credits = 'N/A';
|
257 |
+
}
|
258 |
+
?>
|
259 |
+
<table class="form-table" width="100%" cellpadding="10">
|
260 |
+
<tr id="aj_intro">
|
261 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/finger_point_out_punch_hole_400_clr_17860.png" title="Async JavaScript" alt="Async JavaScript" class="aj_step_img"></td>
|
262 |
+
<td scope="row" align="left" style="vertical-align: top !important;">
|
263 |
+
<h3>Async JavaScript</h3>
|
264 |
+
<?php echo about_aj(); ?>
|
265 |
+
</td>
|
266 |
+
</tr>
|
267 |
+
<tr id="aj_step1">
|
268 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/number_one_break_hole_150_clr_18741.gif" title="Step 1" alt="GTmetrix API Key" class="aj_step_img"></td>
|
269 |
+
<td scope="row" align="left" style="vertical-align: top !important;">
|
270 |
+
<h3>Step 1: GTmetrix API Key</h3>
|
271 |
+
<p>If you haven't already done so, grab an API Key from GTmetrix so that Async JavaScript can obtain your PageSpeed / YSlow results. Here's how:</p>
|
272 |
+
<ol>
|
273 |
+
<li>Navigate to <a href="https://gtmetrix.com/api/" target="_blank">https://gtmetrix.com/api/</a> (link opens in a new tab)</li>
|
274 |
+
<li>If you do not already have an account with GTmetrix, go ahead and sign up (it's FREE!).</li>
|
275 |
+
<li>Log in to your GTmetrix account.</li>
|
276 |
+
<li>If you haven't yet generated your API Key, click on <strong>Generate API Key</strong></li>
|
277 |
+
<li>Copy your Username and API Key into the fields below:<br /><input type="text" id="aj_gtmetrix_username" value="<?php echo $aj_gtmetrix_username; ?>" placeholder="GTmetrix Username"><input type="text" id="aj_gtmetrix_api_key" value="<?php echo $aj_gtmetrix_api_key; ?>" placeholder="GTmetrix API Key"></li>
|
278 |
+
<li>Select the desired server.<br />
|
279 |
+
<select id="aj_gtmetrix_server">
|
280 |
+
<?php
|
281 |
+
$gtmetrix_locations = array(
|
282 |
+
'Vancouver, Canada' => 1,
|
283 |
+
'London, United Kingdom' => 2,
|
284 |
+
'Sydney, Australia' => 3,
|
285 |
+
'Dallas, United States' => 4,
|
286 |
+
'Mumbai, India' => 5
|
287 |
+
);
|
288 |
+
foreach ( $gtmetrix_locations as $location => $value ) {
|
289 |
+
$selected = ( $aj_gtmetrix_server == $value ) ? ' selected="selected"' : '';
|
290 |
+
echo '<option value="' . $value . '"' . $selected . '>' . $location . '</option>';
|
291 |
+
}
|
292 |
+
?>
|
293 |
+
</select>
|
294 |
+
</li>
|
295 |
+
<li>GTmetrix Credits Available: <span class="aj_gtmetrix_credits"><?php echo $credits; ?></span></li>
|
296 |
+
</ol>
|
297 |
+
<p><strong>Please Note:</strong> By clicking the button below you acknowledge that you understand that five (5) GTmetrix API credits will be used.</p>
|
298 |
+
<p><button data-id="aj_step2" class="aj_steps_button">Proceed to Step 2</button></p>
|
299 |
+
</td>
|
300 |
+
</tr>
|
301 |
+
<tr id="aj_step2" class="aj_steps_hidden">
|
302 |
+
<td scope="row" align="center"><img src="<?php echo AJ_PLUGIN_URL; ?>images/number_two_break_hole_150_clr_18753.gif" title="Step 2" alt="Initial Test Results" class="aj_step_img"></td>
|
303 |
+
<td scope="row" align="left">
|
304 |
+
<h3>Step 2: Initial Test Results</h3>
|
305 |
+
<p>Async JavaScript will now query GTmetrix and retrieve your sites PageSpeed and YSlow scores.</p>
|
306 |
+
<p id="aj_step2_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
307 |
+
<table id="aj_step2_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
308 |
+
<tr>
|
309 |
+
<td scope="row" align="center"><img src="" class="aj_step2_screenshot aj_gtmetrix_screenshot">
|
310 |
+
<td scope="row" align="center">
|
311 |
+
<h3>PageSpeed Score</h3>
|
312 |
+
<span class="aj_step2_pagespeed aj_gtmetrix_result"></span>
|
313 |
+
</td>
|
314 |
+
<td scope="row" align="center">
|
315 |
+
<h3>YSlow Score</h3>
|
316 |
+
<span class="aj_step2_yslow aj_gtmetrix_result"></span>
|
317 |
+
</td>
|
318 |
+
<td scope="row" align="center">
|
319 |
+
<h3>Fully Loaded Time</h3>
|
320 |
+
<span class="aj_step2_flt aj_gtmetrix_result"></span>
|
321 |
+
</td>
|
322 |
+
<td scope="row" align="center">
|
323 |
+
<h3>Total Page Size</h3>
|
324 |
+
<span class="aj_step2_tps aj_gtmetrix_result"></span>
|
325 |
+
</td>
|
326 |
+
<td scope="row" align="center">
|
327 |
+
<h3>Requests</h3>
|
328 |
+
<span class="aj_step2_requests aj_gtmetrix_result"></span>
|
329 |
+
</td>
|
330 |
+
</tr>
|
331 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_step2_report"></span></td></tr>
|
332 |
+
<tr><td scope="row" align="left" colspan="6">Simulate <span class="aj_step2_gtmetrix"></span>: <a href="" class="aj_step2_url" target="_blank"></a></tr>
|
333 |
+
<p></p>
|
334 |
+
</table>
|
335 |
+
</td>
|
336 |
+
</tr>
|
337 |
+
<tr id="aj_step2b" class="aj_steps_hidden">
|
338 |
+
<td scope="row" align="center"></td>
|
339 |
+
<td scope="row" align="left">
|
340 |
+
<h3>Testing: Async</h3>
|
341 |
+
<p>Async JavaScript will now query GTmetrix and retrieve your sites PageSpeed and YSlow scores whilst simulating the JavaScript 'async' method.</p>
|
342 |
+
<p id="aj_step2b_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
343 |
+
<table id="aj_step2b_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
344 |
+
<tr>
|
345 |
+
<td scope="row" align="center"><img src="" class="aj_step2b_screenshot aj_gtmetrix_screenshot">
|
346 |
+
<td scope="row" align="center">
|
347 |
+
<h3>PageSpeed Score</h3>
|
348 |
+
<span class="aj_step2b_pagespeed aj_gtmetrix_result"></span>
|
349 |
+
</td>
|
350 |
+
<td scope="row" align="center">
|
351 |
+
<h3>YSlow Score</h3>
|
352 |
+
<span class="aj_step2b_yslow aj_gtmetrix_result"></span>
|
353 |
+
</td>
|
354 |
+
<td scope="row" align="center">
|
355 |
+
<h3>Fully Loaded Time</h3>
|
356 |
+
<span class="aj_step2b_flt aj_gtmetrix_result"></span>
|
357 |
+
</td>
|
358 |
+
<td scope="row" align="center">
|
359 |
+
<h3>Total Page Size</h3>
|
360 |
+
<span class="aj_step2b_tps aj_gtmetrix_result"></span>
|
361 |
+
</td>
|
362 |
+
<td scope="row" align="center">
|
363 |
+
<h3>Requests</h3>
|
364 |
+
<span class="aj_step2b_requests aj_gtmetrix_result"></span>
|
365 |
+
</td>
|
366 |
+
</tr>
|
367 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_step2b_report"></span></td></tr>
|
368 |
+
<tr><td scope="row" align="left" colspan="6">Simulate <span class="aj_step2b_gtmetrix"></span>: <a href="" class="aj_step2b_url" target="_blank"></a></tr>
|
369 |
+
</table>
|
370 |
+
</td>
|
371 |
+
</tr>
|
372 |
+
<tr id="aj_step2c" class="aj_steps_hidden">
|
373 |
+
<td scope="row" align="center"></td>
|
374 |
+
<td scope="row" align="left">
|
375 |
+
<h3>Testing: Defer</h3>
|
376 |
+
<p>Async JavaScript will now query GTmetrix and retrieve your sites PageSpeed and YSlow scores whilst simulating the JavaScript 'defer' method.</p>
|
377 |
+
<p id="aj_step2c_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
378 |
+
<table id="aj_step2c_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
379 |
+
<tr>
|
380 |
+
<td scope="row" align="center"><img src="" class="aj_step2c_screenshot aj_gtmetrix_screenshot">
|
381 |
+
<td scope="row" align="center">
|
382 |
+
<h3>PageSpeed Score</h3>
|
383 |
+
<span class="aj_step2c_pagespeed aj_gtmetrix_result"></span>
|
384 |
+
</td>
|
385 |
+
<td scope="row" align="center">
|
386 |
+
<h3>YSlow Score</h3>
|
387 |
+
<span class="aj_step2c_yslow aj_gtmetrix_result"></span>
|
388 |
+
</td>
|
389 |
+
<td scope="row" align="center">
|
390 |
+
<h3>Fully Loaded Time</h3>
|
391 |
+
<span class="aj_step2c_flt aj_gtmetrix_result"></span>
|
392 |
+
</td>
|
393 |
+
<td scope="row" align="center">
|
394 |
+
<h3>Total Page Size</h3>
|
395 |
+
<span class="aj_step2c_tps aj_gtmetrix_result"></span>
|
396 |
+
</td>
|
397 |
+
<td scope="row" align="center">
|
398 |
+
<h3>Requests</h3>
|
399 |
+
<span class="aj_step2c_requests aj_gtmetrix_result"></span>
|
400 |
+
</td>
|
401 |
+
</tr>
|
402 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_step2c_report"></span></td></tr>
|
403 |
+
<tr><td scope="row" align="left" colspan="6">Simulate <span class="aj_step2c_gtmetrix"></span>: <a href="" class="aj_step2c_url" target="_blank"></a></tr>
|
404 |
+
</table>
|
405 |
+
</td>
|
406 |
+
</tr>
|
407 |
+
<tr id="aj_step2d" class="aj_steps_hidden">
|
408 |
+
<td scope="row" align="center"></td>
|
409 |
+
<td scope="row" align="left">
|
410 |
+
<h3>Testing: Async (jQuery excluded)</h3>
|
411 |
+
<p>Async JavaScript will now query GTmetrix and retrieve your sites PageSpeed and YSlow scores whilst simulating the JavaScript 'async' method but excluding jQuery.</p>
|
412 |
+
<p id="aj_step2d_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
413 |
+
<table id="aj_step2d_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
414 |
+
<tr>
|
415 |
+
<td scope="row" align="center"><img src="" class="aj_step2d_screenshot aj_gtmetrix_screenshot">
|
416 |
+
<td scope="row" align="center">
|
417 |
+
<h3>PageSpeed Score</h3>
|
418 |
+
<span class="aj_step2d_pagespeed aj_gtmetrix_result"></span>
|
419 |
+
</td>
|
420 |
+
<td scope="row" align="center">
|
421 |
+
<h3>YSlow Score</h3>
|
422 |
+
<span class="aj_step2d_yslow aj_gtmetrix_result"></span>
|
423 |
+
</td>
|
424 |
+
<td scope="row" align="center">
|
425 |
+
<h3>Fully Loaded Time</h3>
|
426 |
+
<span class="aj_step2d_flt aj_gtmetrix_result"></span>
|
427 |
+
</td>
|
428 |
+
<td scope="row" align="center">
|
429 |
+
<h3>Total Page Size</h3>
|
430 |
+
<span class="aj_step2d_tps aj_gtmetrix_result"></span>
|
431 |
+
</td>
|
432 |
+
<td scope="row" align="center">
|
433 |
+
<h3>Requests</h3>
|
434 |
+
<span class="aj_step2d_requests aj_gtmetrix_result"></span>
|
435 |
+
</td>
|
436 |
+
</tr>
|
437 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_step2d_report"></span></td></tr>
|
438 |
+
<tr><td scope="row" align="left" colspan="6">Simulate <span class="aj_step2d_gtmetrix"></span>: <a href="" class="aj_step2d_url" target="_blank"></a></tr>
|
439 |
+
</table>
|
440 |
+
</td>
|
441 |
+
</tr>
|
442 |
+
<tr id="aj_step2e" class="aj_steps_hidden">
|
443 |
+
<td scope="row" align="center"></td>
|
444 |
+
<td scope="row" align="left">
|
445 |
+
<h3>Testing: Defer (jQuery excluded)</h3>
|
446 |
+
<p>Async JavaScript will now query GTmetrix and retrieve your sites PageSpeed and YSlow scores whilst simulating the JavaScript 'defer' method but excluding jQuery.</p>
|
447 |
+
<p id="aj_step2e_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
448 |
+
<table id="aj_step2e_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
449 |
+
<tr>
|
450 |
+
<td scope="row" align="center"><img src="" class="aj_step2e_screenshot aj_gtmetrix_screenshot">
|
451 |
+
<td scope="row" align="center">
|
452 |
+
<h3>PageSpeed Score</h3>
|
453 |
+
<span class="aj_step2e_pagespeed aj_gtmetrix_result"></span>
|
454 |
+
</td>
|
455 |
+
<td scope="row" align="center">
|
456 |
+
<h3>YSlow Score</h3>
|
457 |
+
<span class="aj_step2e_yslow aj_gtmetrix_result"></span>
|
458 |
+
</td>
|
459 |
+
<td scope="row" align="center">
|
460 |
+
<h3>Fully Loaded Time</h3>
|
461 |
+
<span class="aj_step2e_flt aj_gtmetrix_result"></span>
|
462 |
+
</td>
|
463 |
+
<td scope="row" align="center">
|
464 |
+
<h3>Total Page Size</h3>
|
465 |
+
<span class="aj_step2e_tps aj_gtmetrix_result"></span>
|
466 |
+
</td>
|
467 |
+
<td scope="row" align="center">
|
468 |
+
<h3>Requests</h3>
|
469 |
+
<span class="aj_step2e_requests aj_gtmetrix_result"></span>
|
470 |
+
</td>
|
471 |
+
</tr>
|
472 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_step2e_report"></span></td></tr>
|
473 |
+
<tr><td scope="row" align="left" colspan="6">Simulate <span class="aj_step2e_gtmetrix"></span>: <a href="" class="aj_step2e_url" target="_blank"></a></tr>
|
474 |
+
</table>
|
475 |
+
</td>
|
476 |
+
</tr>
|
477 |
+
<tr id="aj_step_results" class="aj_steps_hidden">
|
478 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/number_three_break_hole_150_clr_18837.gif" title="Results & Recommendations" alt="Results & Recommendations" class="aj_step_img"></td>
|
479 |
+
<td scope="row" align="left">
|
480 |
+
<h3>Step 3: Results & Recommendations</h3>
|
481 |
+
<p>Async JavaScript has finished testing your site with the most common configuration options.</p>
|
482 |
+
<p>Based on the tests Async JavaScript has determined that <span class="aj_gtmetrix_config"></span> has resulted in <span id="aj_gtmetrix_inde_pagespeed"></span> in PageSpeed from <span id="aj_gtmetrix_baseline_pagespeed"></span> to <span id="aj_gtmetrix_best_pagespeed"></span> and <span id="aj_gtmetrix_inde_yslow"></span> in YSlow from <span id="aj_gtmetrix_baseline_yslow"></span> to <span id="aj_gtmetrix_best_yslow"></span>, with a Fully Loaded time of <span id="aj_gtmetrix_best_fullyloaded"></span>.</p>
|
483 |
+
<p>Before applying these settings it is important to check your site is still functioning correctly. Click the link below to open your site in a new tab / window to simulate the Async JavaScript settings and check that everything is working, and also be sure to check the console for any JavaScript errors (see <a href="https://codex.wordpress.org/Using_Your_Browser_to_Diagnose_JavaScript_Errors" target="_blank">Using Your Browser to Diagnose JavaScript Errors</a>)</p>
|
484 |
+
<ul>
|
485 |
+
<li>Simulate <span class="aj_gtmetrix_config"></span>: <a href="" id="aj_gtmetrix_best_url" target="_blank"></a></li>
|
486 |
+
</ul>
|
487 |
+
<p>Once you have simulated <span class="aj_gtmetrix_config"></span> click on the button below to continue.</p>
|
488 |
+
<p><button data-id="aj_step4" class="aj_steps_button">Proceed to Step 4</button></p>
|
489 |
+
</td>
|
490 |
+
</tr>
|
491 |
+
<tr id="aj_step4" class="aj_steps_hidden">
|
492 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/number_four_break_hole_150_clr_18840.gif" title="Apply Settings" alt="Apply Settings" class="aj_step_img"></td>
|
493 |
+
<td scope="row" align="left">
|
494 |
+
<h3>Step 4: Apply Settings</h3>
|
495 |
+
<p>Is your site still functioning properly and are there no JavaScript errors in the console?</p>
|
496 |
+
<p><input type="radio" name="aj_step4_check" value="y"> Yes <input type="radio" name="aj_step4_check" value="n"> No</p>
|
497 |
+
<div id="aj_step4_y">
|
498 |
+
<p>Great to hear! To apply these settings click the button below.</p>
|
499 |
+
<p><button data-id="aj_apply_settings" class="aj_steps_button">Apply Settings</button></p>
|
500 |
+
</div>
|
501 |
+
<div id="aj_step4_n">
|
502 |
+
<p>Ok, so you have run the simulation on <span class="aj_gtmetrix_config"></span> and although there has been an improvement in reported performance, the simulation shows that something is not right with your site.</p>
|
503 |
+
<div id="aj_step4_jquery_excluded">
|
504 |
+
<p>In most cases the issue being experienced relates to jQuery (usually due to inline JavaScript which relies on jQuery) and the solution is to exclude jQuery. However, in this simulation jQuery has already been exculded. As a result a different configuration may work better with a marginal sacrifice in site speed improvement.</p>
|
505 |
+
<p>Below are links that can be used to run simulations on each of the basic configurations. Click on each of the links and check the functionality of your site as well as the console for errors.</p>
|
506 |
+
<ul>
|
507 |
+
<li>Simulate <span class="aj_step2b_gtmetrix"></span>: <a href="" class="aj_step2b_url" target="_blank"></a></li>
|
508 |
+
<li>Simulate <span class="aj_step2c_gtmetrix"></span>: <a href="" class="aj_step2c_url" target="_blank"></a></li>
|
509 |
+
<li>Simulate <span class="aj_step2d_gtmetrix"></span>: <a href="" class="aj_step2d_url" target="_blank"></a></li>
|
510 |
+
<li>Simulate <span class="aj_step2e_gtmetrix"></span>: <a href="" class="aj_step2e_url" target="_blank"></a></li>
|
511 |
+
</ul>
|
512 |
+
<p>Click one of the buttons below to apply these settings or click the Settings button to go to the settings page for manual configuration.</p>
|
513 |
+
<p>
|
514 |
+
<button data-id="aj_step2b_apply" class="aj_steps_button">Apply <span class="aj_step2b_gtmetrix"></button>
|
515 |
+
<button data-id="aj_step2c_apply" class="aj_steps_button">Apply <span class="aj_step2c_gtmetrix"></button>
|
516 |
+
<button data-id="aj_step2d_apply" class="aj_steps_button">Apply <span class="aj_step2d_gtmetrix"></button>
|
517 |
+
<button data-id="aj_step2e_apply" class="aj_steps_button">Apply <span class="aj_step2e_gtmetrix"></button>
|
518 |
+
</p>
|
519 |
+
<p>
|
520 |
+
<button data-id="aj_goto_settings" class="aj_steps_button">Settings</button>
|
521 |
+
</p>
|
522 |
+
</div>
|
523 |
+
<div id="aj_step4_jquery_not_excluded">
|
524 |
+
<p>In most cases the issue being experienced relates to jQuery (usually due to inline JavaScript which relies on jQuery) and the solution is to exclude jQuery.</p>
|
525 |
+
<p>Below are links that can be used to run simulations on each of the configurations with jQuery excluded. Click on each of the links and check the functionality of your site as well as the console for errors.</p>
|
526 |
+
<ul>
|
527 |
+
<li>Simulate <span class="aj_step2d_gtmetrix"></span>: <a href="" class="aj_step2d_url" target="_blank"></a></li>
|
528 |
+
<li>Simulate <span class="aj_step2e_gtmetrix"></span>: <a href="" class="aj_step2e_url" target="_blank"></a></li>
|
529 |
+
</ul>
|
530 |
+
<p>Click one of the buttons below to apply these settings or click the Settings button to go to the settings page for manual configuration.</p>
|
531 |
+
<p>
|
532 |
+
<button data-id="aj_step2d_apply" class="aj_steps_button">Apply <span class="aj_step2d_gtmetrix"></button>
|
533 |
+
<button data-id="aj_step2e_apply" class="aj_steps_button">Apply <span class="aj_step2e_gtmetrix"></button>
|
534 |
+
</p>
|
535 |
+
<p>
|
536 |
+
<button data-id="aj_goto_settings" class="aj_steps_button">Settings</button>
|
537 |
+
</p>
|
538 |
+
</div>
|
539 |
+
</div>
|
540 |
+
</td>
|
541 |
+
</tr>
|
542 |
+
<tr id="aj_step5" class="aj_steps_hidden">
|
543 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/number_five_break_hole_150_clr_18842.gif" title="Further Hints & Tips" alt="Further Hints & Tips" class="aj_step_img"></td>
|
544 |
+
<td scope="row" align="left">
|
545 |
+
<?php echo hints_tips(); ?>
|
546 |
+
<p><button data-id="aj_goto_settings" class="aj_steps_button">Settings</button></p>
|
547 |
+
</td>
|
548 |
+
</tr>
|
549 |
+
</table>
|
550 |
+
<?php
|
551 |
+
} else if ( $active_tab == 'status' ) {
|
552 |
+
$site_url = trailingslashit( get_site_url() );
|
553 |
+
$aj_gtmetrix_username = get_option( 'aj_gtmetrix_username', '' );
|
554 |
+
$aj_gtmetrix_api_key = get_option( 'aj_gtmetrix_api_key', '' );
|
555 |
+
$aj_gtmetrix_server = get_option( 'aj_gtmetrix_server', '' );
|
556 |
+
if ( $aj_gtmetrix_username != '' && $aj_gtmetrix_api_key != '' ) {
|
557 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
558 |
+
$status = $test->status();
|
559 |
+
$credits = $status['api_credits'];
|
560 |
+
} else {
|
561 |
+
$credits = 'N/A';
|
562 |
+
}
|
563 |
+
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? 'Enabled' : 'Disabled';
|
564 |
+
$aj_method = ( get_option( 'aj_method' ) == 'async' ) ? 'Async' : 'Defer';
|
565 |
+
$aj_jquery = ( get_option( 'aj_jquery' ) == 'async' ) ? 'Async' : 'Defer';
|
566 |
+
$aj_exclusions = get_option( 'aj_exclusions', '' );
|
567 |
+
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? 'Enabled' : 'Disabled';
|
568 |
+
$aj_autoptimize_method = ( get_option( 'aj_autoptimize_method' ) == 'async' ) ? 'Async' : 'Defer';
|
569 |
+
?>
|
570 |
+
<table class="form-table" width="100%" cellpadding="10">
|
571 |
+
<tr>
|
572 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/finger_point_out_punch_hole_400_clr_17860.png" title="Most Recent GTmetrix Results" alt="Most Recent GTmetrix Results" class="aj_step_img"></td>
|
573 |
+
<td scope="row" align="left">
|
574 |
+
<h3>Async JavaScript</h3>
|
575 |
+
<ul>
|
576 |
+
<li><strong>Status:</strong> <?php echo $aj_enabled; ?></li>
|
577 |
+
<?php
|
578 |
+
if ( $aj_enabled == 'Enabled' ) {
|
579 |
+
?>
|
580 |
+
<li><strong>Method:</strong> <?php echo $aj_method; ?></li>
|
581 |
+
<li><strong>jQuery:</strong> <?php echo $aj_jquery; ?></li>
|
582 |
+
<li><strong>Exclusions:</strong> <?php echo $aj_exclusions; ?></li>
|
583 |
+
<?php
|
584 |
+
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
|
585 |
+
?>
|
586 |
+
<li><strong>Autoptimize Status:</strong> <?php echo $aj_autoptimize_enabled; ?></li>
|
587 |
+
<?php
|
588 |
+
if ( $aj_autoptimize_enabled == 'Enabled' ) {
|
589 |
?>
|
590 |
+
<li><strong>Autoptimize Method:</strong> <?php echo $aj_autoptimize_method; ?></li>
|
591 |
<?php
|
592 |
}
|
593 |
+
} else {
|
594 |
+
?>
|
595 |
+
<li>Autoptimize not installed or activated.</li>
|
596 |
+
<?php
|
597 |
+
}
|
598 |
+
}
|
599 |
+
?>
|
600 |
+
</ul>
|
601 |
+
<hr />
|
602 |
+
<h3>Latest GTmetrix Results</h3>
|
603 |
+
<?php
|
604 |
+
$aj_gtmetrix_results = get_option( 'aj_gtmetrix_results', array() );
|
605 |
+
if ( isset( $aj_gtmetrix_results['latest'] ) ) {
|
606 |
+
$latest = $aj_gtmetrix_results['latest'];
|
607 |
+
$screenshot = $latest['screenshot'];
|
608 |
+
$pagespeed = $latest['results']['pagespeed_score'];
|
609 |
+
$yslow = $latest['results']['yslow_score'];
|
610 |
+
$pr = round( 255 * ( 1 - ( $pagespeed / 100 ) ), 0 );
|
611 |
+
$yr = round( 255 * ( 1 - ( $yslow / 100 ) ), 0 );
|
612 |
+
$pg = round( 255 * ( $pagespeed / 100 ), 0 );
|
613 |
+
$yg = round( 255 * ( $yslow / 100 ), 0 );
|
614 |
+
$pagespeed_style = ' style="color: rgb(' . $pr . ',' . $pg . ',0 )"';
|
615 |
+
$yslow_style = ' style="color: rgb(' . $yr . ',' . $yg . ',0 )"';
|
616 |
+
$flt = number_format( ( float )$latest['results']['fully_loaded_time'] / 1000, 2, '.', '' );
|
617 |
+
$tps = number_format( ( float )$latest['results']['page_bytes'] / 1024, 0, '.', '' );
|
618 |
+
$requests = $latest['results']['page_elements'];
|
619 |
+
$report = $latest['results']['report_url'];
|
620 |
+
$report_url = '<a href="' . $report . '" target="_blank">' . $report . '</a>';
|
621 |
+
?>
|
622 |
+
<p id="aj_latest_please_wait"><img src="<?php echo AJ_PLUGIN_URL; ?>images/loading.gif" title="Please Wait" alt="Please Wait" class="aj_step_img"></p>
|
623 |
+
<table id="aj_latest_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10">
|
624 |
+
<tr>
|
625 |
+
<td scope="row" align="center"><img src="data:image/jpeg;base64,<?php echo $screenshot; ?>" class="aj_latest_screenshot aj_gtmetrix_screenshot">
|
626 |
+
<td scope="row" align="center">
|
627 |
+
<h3>PageSpeed Score</h3>
|
628 |
+
<span class="aj_latest_pagespeed aj_gtmetrix_result"<?php echo $pagespeed_style; ?>><?php echo $pagespeed; ?>%</span>
|
629 |
+
</td>
|
630 |
+
<td scope="row" align="center">
|
631 |
+
<h3>YSlow Score</h3>
|
632 |
+
<span class="aj_latest_yslow aj_gtmetrix_result"<?php echo $yslow_style; ?>><?php echo $yslow; ?>%</span>
|
633 |
+
</td>
|
634 |
+
<td scope="row" align="center">
|
635 |
+
<h3>Fully Loaded Time</h3>
|
636 |
+
<span class="aj_latest_flt aj_gtmetrix_result"><?php echo $flt; ?>s</span>
|
637 |
+
</td>
|
638 |
+
<td scope="row" align="center">
|
639 |
+
<h3>Total Page Size</h3>
|
640 |
+
<span class="aj_latest_tps aj_gtmetrix_result"><?php echo $tps; ?>KB</span>
|
641 |
+
</td>
|
642 |
+
<td scope="row" align="center">
|
643 |
+
<h3>Requests</h3>
|
644 |
+
<span class="aj_latest_requests aj_gtmetrix_result"><?php echo $requests; ?></span>
|
645 |
+
</td>
|
646 |
+
</tr>
|
647 |
+
<tr><td scope="row" align="left" colspan="6">See full report: <span class="aj_latest_report"><?php echo $report_url; ?></span></td></tr>
|
648 |
+
</table>
|
649 |
+
<hr />
|
650 |
+
<?php
|
651 |
+
} else {
|
652 |
+
?>
|
653 |
+
<table id="aj_latest_gtmetrix_results" class="form-table aj-steps-table" width="100%" cellpadding="10" style="display: none;">
|
654 |
+
<tr>
|
655 |
+
<td scope="row" align="center"><img src="" class="aj_latest_screenshot aj_gtmetrix_screenshot">
|
656 |
+
<td scope="row" align="center">
|
657 |
+
<h3>PageSpeed Score</h3>
|
658 |
+
<span class="aj_latest_pagespeed aj_gtmetrix_result"></span>
|
659 |
+
</td>
|
660 |
+
<td scope="row" align="center">
|
661 |
+
<h3>YSlow Score</h3>
|
662 |
+
<span class="aj_latest_yslow aj_gtmetrix_result"></span>
|
663 |
+
</td>
|
664 |
+
<td scope="row" align="center">
|
665 |
+
<h3>Fully Loaded Time</h3>
|
666 |
+
<span class="aj_latest_flt aj_gtmetrix_result"></span>
|
667 |
+
</td>
|
668 |
+
<td scope="row" align="center">
|
669 |
+
<h3>Total Page Size</h3>
|
670 |
+
<span class="aj_latest_tps aj_gtmetrix_result"></span>
|
671 |
+
</td>
|
672 |
+
<td scope="row" align="center">
|
673 |
+
<h3>Requests</h3>
|
674 |
+
<span class="aj_latest_requests aj_gtmetrix_result"></span>
|
675 |
+
</td>
|
676 |
+
</tr>
|
677 |
+
<tr><td scope="row" align="center" colspan="6">See full report: <span class="aj_latest_report"></span></td></tr>
|
678 |
+
</table>
|
679 |
+
<hr />
|
680 |
+
<?php
|
681 |
+
}
|
682 |
+
?>
|
683 |
+
<p>Please click on the button below to generate a new GTmetrix Report.</p>
|
684 |
+
<p><strong>Please Note:</strong> By clicking the button below you acknowledge that you understand that one (1) GTmetrix API credit will be used.</p>
|
685 |
+
<p><button data-id="aj_gtmetrix_test" class="aj_steps_button">Run GTmetrix Test</button></p>
|
686 |
+
<h3>GTmetrix API Key</h3>
|
687 |
+
<p>If you haven't already done so, grab an API Key from GTmetrix so that Async JavaScript can obtain your PageSpeed / YSlow results. Here's how:</p>
|
688 |
+
<ol>
|
689 |
+
<li>Navigate to <a href="https://gtmetrix.com/api/" target="_blank">https://gtmetrix.com/api/</a> (link opens in a new tab)</li>
|
690 |
+
<li>If you do not already have an account with GTmetrix, go ahead and sign up (it's FREE!).</li>
|
691 |
+
<li>Log in to your GTmetrix account.</li>
|
692 |
+
<li>If you haven't yet generated your API Key, click on <strong>Generate API Key</strong></li>
|
693 |
+
<li>Copy your Username and API Key into the fields below:<br /><input type="text" id="aj_gtmetrix_username" value="<?php echo $aj_gtmetrix_username; ?>" placeholder="GTmetrix Username"><input type="text" id="aj_gtmetrix_api_key" value="<?php echo $aj_gtmetrix_api_key; ?>" placeholder="GTmetrix API Key"></li>
|
694 |
+
<li>Select the desired server.<br />
|
695 |
+
<select id="aj_gtmetrix_server">
|
696 |
+
<?php
|
697 |
+
$gtmetrix_locations = array(
|
698 |
+
'Vancouver, Canada' => 1,
|
699 |
+
'London, United Kingdom' => 2,
|
700 |
+
'Sydney, Australia' => 3,
|
701 |
+
'Dallas, United States' => 4,
|
702 |
+
'Mumbai, India' => 5
|
703 |
+
);
|
704 |
+
foreach ( $gtmetrix_locations as $location => $value ) {
|
705 |
+
$selected = ( $aj_gtmetrix_server == $value ) ? ' selected="selected"' : '';
|
706 |
+
echo '<option value="' . $value . '"' . $selected . '>' . $location . '</option>';
|
707 |
+
}
|
708 |
+
?>
|
709 |
+
</select>
|
710 |
+
</li>
|
711 |
+
<li>GTmetrix Credits Available: <span class="aj_gtmetrix_credits"><?php echo $credits; ?></span></li>
|
712 |
+
</ol>
|
713 |
+
<hr />
|
714 |
+
<?php echo hints_tips(); ?>
|
715 |
+
</td>
|
716 |
+
</tr>
|
717 |
+
</table>
|
718 |
+
<?php
|
719 |
+
} else if ( $active_tab == 'settings' ) {
|
720 |
+
$site_url = trailingslashit( get_site_url() );
|
721 |
+
$aj_gtmetrix_username = ( get_option( 'aj_gtmetrix_username' ) ) ? get_option( 'aj_gtmetrix_username' ) : '';
|
722 |
+
$aj_gtmetrix_api_key = ( get_option( 'aj_gtmetrix_api_key' ) ) ? get_option( 'aj_gtmetrix_api_key' ) : '';
|
723 |
+
$aj_gtmetrix_server = ( get_option( 'aj_gtmetrix_server' ) ) ? get_option( 'aj_gtmetrix_server' ) : '';
|
724 |
+
$aj_enabled = get_option( 'aj_enabled', 0 );
|
725 |
+
$aj_enabled_checked = ( $aj_enabled == 1 ) ? ' checked="checked"' : '';
|
726 |
+
$aj_method = get_option( 'aj_method', 'async' );
|
727 |
+
$aj_method_async = ( $aj_method == 'async' ) ? ' checked="checked"' : '';
|
728 |
+
$aj_method_defer = ( $aj_method == 'defer' ) ? ' checked="checked"' : '';
|
729 |
+
$aj_jquery = get_option( 'aj_jquery', 'async' );
|
730 |
+
$aj_jquery = ( $aj_jquery == 'same ' ) ? $aj_method : $aj_jquery;
|
731 |
+
$aj_jquery_async = ( $aj_jquery == 'async' ) ? ' checked="checked"' : '';
|
732 |
+
$aj_jquery_defer = ( $aj_jquery == 'defer' ) ? ' checked="checked"' : '';
|
733 |
+
$aj_jquery_exclude = ( $aj_jquery == 'exclude' ) ? ' checked="checked"' : '';
|
734 |
+
$aj_exclusions = get_option( 'aj_exclusions', '' );
|
735 |
+
$aj_autoptimize_enabled = get_option( 'aj_autoptimize_enabled', 0 );
|
736 |
+
$aj_autoptimize_enabled_checked = ( $aj_autoptimize_enabled == 1 ) ? ' checked="checked"' : '';
|
737 |
+
$aj_autoptimize_method = get_option( 'aj_autoptimize_method', 'async' );
|
738 |
+
$aj_autoptimize_async = ( $aj_autoptimize_method == 'async' ) ? ' checked="checked"' : '';
|
739 |
+
$aj_autoptimize_defer = ( $aj_autoptimize_method == 'defer' ) ? ' checked="checked"' : '';
|
740 |
+
?>
|
741 |
+
<table class="form-table" width="100%" cellpadding="10">
|
742 |
+
<tr id="aj_intro">
|
743 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/finger_point_out_punch_hole_400_clr_17860.png" title="Async JavaScript" alt="Async JavaScript" class="aj_step_img"></td>
|
744 |
+
<td scope="row" align="left" style="vertical-align: top !important;">
|
745 |
+
<h3>Async JavaScript</h3>
|
746 |
+
<?php echo about_aj(); ?>
|
747 |
+
</td>
|
748 |
+
</tr>
|
749 |
+
<tr id="aj_settings_enable">
|
750 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/finger_point_out_punch_hole_400_clr_17860.png" title="Enable Async JavaScript" alt="Enable Async JavaScript" class="aj_step_img"></td>
|
751 |
+
<td scope="row" align="left" style="vertical-align: top !important;">
|
752 |
+
<h3>Enable Async JavaScript</h3>
|
753 |
+
<p><label>Enable Async JavaScript? </label><input type="checkbox" id="aj_enabled" id="aj_enabled" value="1" <?php echo $aj_enabled_checked; ?> /></p>
|
754 |
+
<hr />
|
755 |
+
<h3>Async JavaScript Method</h3>
|
756 |
+
<p>Please select the method (<strong>async</strong> or <strong>defer</strong>) that you wish to enable:</p>
|
757 |
+
<p><label>Method: </label><input type="radio" name="aj_method" value="async" <?php echo $aj_method_async; ?> /> Async <input type="radio" name="aj_method" value="defer" <?php echo $aj_method_defer; ?> /> Defer</p>
|
758 |
+
<hr />
|
759 |
+
<h3>jQuery</h3>
|
760 |
+
<p>Often if jQuery is loaded with <strong>async</strong> or <strong>defer</strong> it can break some jQuery functions, specifically inline scripts which require jQuery to be loaded before the scripts are run. <strong><em>Sometimes</em></strong> choosing a different method (<strong>async</strong> or <strong>defer</strong>) will work, otherwise it may be necessary to exclude jQuery from having <strong>async</strong> or <strong>defer</strong> applied.</p>
|
761 |
+
<p><label>jQuery Method: </label><input type="radio" name="aj_jquery" value="async" <?php echo $aj_jquery_async; ?> /> Async <input type="radio" name="aj_jquery" value="defer" <?php echo $aj_jquery_defer; ?> /> Defer <input type="radio" name="aj_jquery" value="exclude" <?php echo $aj_jquery_exclude; ?> /> Exclude</p>
|
762 |
+
<hr />
|
763 |
+
<h3>Script Exclusion</h3>
|
764 |
+
<p>Please list any scripts which you would like excluded from having <strong>async</strong> or <strong>defer</strong> applied during page load. (comma seperated list eg: jquery.js,jquery-ui.js)</p>
|
765 |
+
<p><label>Exclusions: </label><textarea name="aj_exclusions" style="width:95%;"><?php echo $aj_exclusions; ?></textarea></p>
|
766 |
+
<hr />
|
767 |
+
<h3>Async JavaScript For Plugins</h3>
|
768 |
+
<p>Although not recommended, some themes / plugins can load JavaScript files without using the <strong><a href="https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts" target="_blank">wp_enqueue_script</a></strong> function. In some cases this is necessary for the functionality of the theme / plugin.</p>
|
769 |
+
<p>If these themes / plugins provide a hook that can be used to manipulate how the JavaScript file is loaded then Async JavaScript may be able to provide support for these themes / plugins.</p>
|
770 |
+
<p>If you have any active themes / plugins that Async JavaScript supports then these will be listed below.</p>
|
771 |
+
<p>If you think you have found a plugin that Async JavaScript may be able to provide support for please lodge a ticket at <a href="https://cloughit.com.au/support/?wpsc_category=8" target="_blank">https://cloughit.com.au/support/</a></p>
|
772 |
+
<?php
|
773 |
+
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
|
774 |
+
?>
|
775 |
+
<div class="aj_plugin">
|
776 |
+
<h4>Plugin: Autoptimize</h4>
|
777 |
+
<p><a href="https://wordpress.org/plugins/autoptimize/" target="_blank">https://wordpress.org/plugins/autoptimize/</a></p>
|
778 |
+
<p><label>Enable Autoptimize Support: </label><input type="checkbox" id="aj_autoptimize_enabled" value="1" <?php echo $aj_autoptimize_enabled_checked; ?> /></p>
|
779 |
+
<p><label>jQuery Method: </label><input type="radio" name="aj_autoptimize_method" value="async" <?php echo $aj_autoptimize_async; ?> /> Async <input type="radio" name="aj_autoptimize_method" value="defer" <?php echo $aj_autoptimize_defer; ?> /> Defer</p>
|
780 |
+
</div>
|
781 |
+
<?php
|
782 |
+
}
|
783 |
+
?>
|
784 |
+
<p><button data-id="aj_save_settings" class="aj_steps_button">Save Settings</button></p>
|
785 |
+
</td>
|
786 |
+
</tr>
|
787 |
+
</table>
|
788 |
+
<?php
|
789 |
+
} else if ( $active_tab == 'help' ) {
|
790 |
+
?>
|
791 |
+
<table class="form-table" width="100%" cellpadding="10">
|
792 |
+
<tr>
|
793 |
+
<td scope="row" align="center" style="vertical-align: top !important;"><img src="<?php echo AJ_PLUGIN_URL; ?>images/stick_figure_panicking_150_clr_13267.gif" title="Help & Support" alt="Help & Support" class="aj_step_img"></td>
|
794 |
+
<td scope="row" align="left" style="vertical-align: top !important;">
|
795 |
+
<h3>Help & Support</h3>
|
796 |
+
<p>Below are some answers to some frequently asked questions about Async JavaScript</p>
|
797 |
+
<hr />
|
798 |
+
<h3>Which browsers support the 'async' and 'defer' attributes?</h3>
|
799 |
+
<p>The 'async' attribute is new in HTML5. It is supported by the following browsers:</p>
|
800 |
+
<ul>
|
801 |
+
<li>Chrome</li>
|
802 |
+
<li>IE 10 and higher</li>
|
803 |
+
<li>Firefox 3.6 and higher</li>
|
804 |
+
<li>Safari</li>
|
805 |
+
<li>Opera</li>
|
806 |
+
</ul>
|
807 |
+
<hr />
|
808 |
+
<h3>Where can I get help?</h3>
|
809 |
+
<p>Async JavaScript is supported exclusively via our Support Ticketing System at <a href="https://cloughit.com.au/support/?wpsc_category=8" target="_blank">https://cloughit.com.au/support/</a></p>
|
810 |
+
<hr />
|
811 |
+
<h3>What support do you provide?</h3>
|
812 |
+
<p>We will provide support for any functionality of the Async JavaScript plugin itself, suggestions for theme / plugin support and suggestions on how Async JavaScript could be improved.</p>
|
813 |
+
<hr />
|
814 |
+
<h3>What support don't you provide?</h3>
|
815 |
+
<p>We will not provide support for questions such as 'Why is Async JavaScript not making any improvement on my site?'. If you need this level of support we offer a bundled Async JavaScript Pro plus Installation & Configuration (homepage only) AUD $155.00 (<a href="https://cloughit.com.au/product/async-javascript-pro-plus-install/" target="_blank">buy now!</a>)</p>
|
816 |
+
<hr />
|
817 |
+
<h3>Can I use the WordPress Forums to get support for Async JavaScript?</h3>
|
818 |
+
<p>No. Support is provided via our Support Ticketing System at <a href="https://cloughit.com.au/support/?wpsc_category=8" target="_blank">https://cloughit.com.au/support/</a></p>
|
819 |
+
<hr />
|
820 |
+
<h3>Can I email the author directly to get support for Async JavaScript?</h3>
|
821 |
+
<p>No. Support is provided via our Support Ticketing System at <a href="https://cloughit.com.au/support/?wpsc_category=8" target="_blank">https://cloughit.com.au/support/</a></p>
|
822 |
+
<hr />
|
823 |
+
<h3>What about CSS?</h3>
|
824 |
+
<p>As the name implies, Async JavaScript is built to enhance JavaScript loading only. Async JavaScript does not have any impact on CSS.</p>
|
825 |
+
<p>We recommend using the awesome <a href="https://wordpress.org/plugins/autoptimize/" target="_blank">Autoptimize</a> plugin alongside Async JavaScript for CSS optimization.</p>
|
826 |
+
<hr />
|
827 |
+
<h3>Do you have a pro version?</h3>
|
828 |
+
<p>Yes we do! Here are some of the benefits of Async JavaScript Pro:</p>
|
829 |
+
<ul>
|
830 |
+
<li>Selective ‘async’ – choose which JavaScripts to apply ‘async’ to</li>
|
831 |
+
<li>Selective ‘defer’ – choose which JavaScripts to apply ‘defer’ to</li>
|
832 |
+
<li>Exclude individual scripts – choose which JavaScripts to ignore</li>
|
833 |
+
<li>Exclude plugins – choose local plugin JavaScripts to ignore</li>
|
834 |
+
<li>Exclude themes – choose local theme JavaScripts to ignore</li>
|
835 |
+
</ul>
|
836 |
+
<p><a href="https://cloughit.com.au/product/async-javascript-pro/" target="_blank">Buy Now!</a></p>
|
837 |
+
<hr />
|
838 |
+
<h3>I want out, how should I remove Async JavaScript?</h3>
|
839 |
+
<ul>
|
840 |
+
<li>Disable the plugin</li>
|
841 |
+
<li>Delete the plugin</li>
|
842 |
+
</ul>
|
843 |
+
</td>
|
844 |
+
</tr>
|
845 |
+
</table>
|
846 |
+
<?php
|
847 |
+
}
|
848 |
+
?>
|
849 |
</div>
|
850 |
<?php
|
851 |
}
|
852 |
/**
|
853 |
+
* about_aj()
|
854 |
+
*
|
855 |
+
* Return common text for about Async JavaScript
|
856 |
+
*
|
857 |
+
*/
|
858 |
+
function about_aj() {
|
859 |
+
$return = '';
|
860 |
+
$return .= '<p>When a JavaScript file is loaded via the <strong><a href="https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts" target="_blank">wp_enqueue_script</a></strong> function, Async JavaScript will add an <strong>async</strong> or <strong>defer</strong> attribute.</p>';
|
861 |
+
$return .= '<p>There are several ways an external JavaScript file can be executed:</p>';
|
862 |
+
$return .= '<ul style="list-style:disc inside;">';
|
863 |
+
$return .= '<li>If <strong>async</strong> is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)</li>';
|
864 |
+
$return .= '<li>If <strong>defer</strong> is present and <strong>async</strong> is not present: The script is executed when the page has finished parsing</li>';
|
865 |
+
$return .= '<li>If neither <strong>async</strong> or <strong>defer</strong> is present: The script is fetched and executed immediately, before the browser continues parsing the page</li>';
|
866 |
+
$return .= '</ul>';
|
867 |
+
$return .= '<p>Using <strong>async</strong> or <strong>defer</strong> helps to eliminate render-blocking JavaScript in above-the-fold content. This can also help to increase your pagespeed which in turn can assist in improving your page ranking.</p>';
|
868 |
+
return $return;
|
869 |
+
}
|
870 |
+
/**
|
871 |
+
* hints_tips()
|
872 |
*
|
873 |
+
* Return common text for Hints & Tips
|
874 |
*
|
875 |
+
*/
|
876 |
+
function hints_tips() {
|
877 |
+
$return = '';
|
878 |
+
$return .= '<h3>Further Hints & Tips</h3>';
|
879 |
+
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
|
880 |
+
$return .= '<p>Async JavaScript has detected that you have Autoptimize installed and active. Async JavaScript can further enhance Autoptimize results by applying Async or Defer to the cache files used by Autoptimize.</p>';
|
881 |
+
} else {
|
882 |
+
$return .= '<p>Async JavaScript has detected that you do not have Autoptimize installed and active. Autoptimize can provide further optimization of JavaScript which can benefit the results of Async JavaScripts (and Async JavaScript can also enhance Autoptimize results!)</p>';
|
883 |
+
$return .= '<p>You can install Autoptimize from the plugin repository, or download it from here: <a href="https://wordpress.org/plugins/autoptimize/" target="_blank">https://wordpress.org/plugins/autoptimize/</a></p>';
|
884 |
+
}
|
885 |
+
$return .= '<p>Through our testing the following common Autoptimize settings work well to achieve the best results. Of course each website is different so you may need to fine tune these settings to suit.</p>';
|
886 |
+
$return .= '<ol>';
|
887 |
+
$return .= '<li>Navigate to <strong>Settings > Autoptimize</strong></li>';
|
888 |
+
$return .= '<li>Click on the <strong>Show advanced settings</strong> button</li>';
|
889 |
+
$return .= '<li>Under <strong>JavaScript Options</strong> set the following:</li>';
|
890 |
+
$return .= '<ul>';
|
891 |
+
$return .= '<li><strong>Optimize JavaScript Code?</strong>: Checked</li>';
|
892 |
+
$return .= '<li><strong>Force JavaScript in <head>?</strong>: Unchecked</li>';
|
893 |
+
$return .= '<li><strong>Also aggregate inline JS?</strong>: Checked<br />(did you need to exclude jQuery in Async JavaScript? Enabling this option <strong><em>MAY</em></strong> help resolve jQuery errors caused by inline JavaScript / jQuery code)</li>';
|
894 |
+
$return .= '<li><strong>Exclude scripts from Autoptimize:</strong>: Leave as default (or add any other scripts that you may need to exclude)</li>';
|
895 |
+
$return .= '<li><strong>Add try-catch wrapping?</strong>: Unchecked</li>';
|
896 |
+
$return .= '</ul>';
|
897 |
+
$return .= '<li>Click on the <strong>Save Changes and Empty Cache</strong> button</li>';
|
898 |
+
$return .= '<li>Navigate to <strong>Settings > Async JavaScript</strong></li>';
|
899 |
+
$return .= '<li>Click on the <strong>Settings</strong> tab</li>';
|
900 |
+
$return .= '<li>Scroll down to <strong>Async JavaScript For Plugins</strong></li>';
|
901 |
+
$return .= '<li>Under <strong>Autoptimize</strong> set the following:</li>';
|
902 |
+
$return .= '<ul>';
|
903 |
+
$return .= '<li><strong>Enable Autoptimize Support</strong>: Checked</li>';
|
904 |
+
$return .= '<li><strong>Method</strong>: Select either <strong>Async</strong> or <strong>Defer</strong> (testing has found that <strong>Defer</strong> usually works best here!)</li>';
|
905 |
+
$return .= '</ul>';
|
906 |
+
$return .= '<li>Click on <strong>Save Changes</strong></li>';
|
907 |
+
$return .= '</ol>';
|
908 |
+
return $return;
|
909 |
+
}
|
910 |
+
/**
|
911 |
+
* async_js()
|
912 |
+
*
|
913 |
+
* Add 'async' or 'defer' attribute to '<script>' tasks called via wp_enqueue_script using the 'script_loader_tag' filter
|
914 |
*
|
915 |
*/
|
916 |
add_filter( 'script_loader_tag', 'async_js', 10, 3 );
|
917 |
function async_js( $tag, $handle, $src ) {
|
918 |
+
if ( isset( $_GET['aj_simulate'] ) ) {
|
919 |
+
$aj_enabled = true;
|
920 |
+
$aj_method = $_GET['aj_simulate'];
|
921 |
+
if ( isset( $_GET['aj_simulate_jquery'] ) ) {
|
922 |
+
$aj_jquery = $_GET['aj_simulate_jquery'];
|
923 |
+
} else {
|
924 |
+
$aj_jquery = $aj_method;
|
925 |
+
}
|
926 |
+
$array_exclusions = array();
|
927 |
+
} else {
|
928 |
+
$aj_enabled = ( get_option( 'aj_enabled', 0 ) == 1 ) ? true : false;
|
929 |
+
$aj_method = ( get_option( 'aj_method' ) == 'async' ) ? 'async' : 'defer';
|
930 |
+
$aj_jquery = get_option( 'aj_jquery', 'async' );
|
931 |
+
$aj_jquery = ( $aj_jquery == 'same ' ) ? $aj_method : $aj_jquery;
|
932 |
+
$aj_exclusions = get_option( 'aj_exclusions', '' );
|
933 |
+
$array_exclusions = ( $aj_exclusions != '' ) ? explode( ',', $aj_exclusions ) : array();
|
934 |
+
}
|
935 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
936 |
if ( is_array( $array_exclusions ) && !empty( $array_exclusions ) ) {
|
937 |
foreach ( $array_exclusions as $exclusion ) {
|
955 |
return $tag;
|
956 |
}
|
957 |
return $tag;
|
958 |
+
}
|
959 |
/**
|
960 |
* my_autoptimize_defer()
|
961 |
*
|
962 |
* Adds support for Autoptimize plugin. Adds 'async' attribute to '<script>' tasks called via autoptimize_filter_js_defer filter
|
963 |
* Autoptimize: https://wordpress.org/plugins/autoptimize/
|
964 |
*
|
|
|
|
|
965 |
*/
|
966 |
add_filter( 'autoptimize_filter_js_defer', 'my_autoptimize_defer', 11 );
|
967 |
function my_autoptimize_defer( $defer ) {
|
968 |
+
$aj_enabled = ( get_option( 'aj_enabled', 0 ) == 1 ) ? true : false;
|
969 |
+
$aj_method = ( get_option( 'aj_method' ) == 'async' ) ? 'async' : 'defer';
|
970 |
+
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled', 0 ) == 1 ) ? true : false;
|
971 |
+
$aj_autoptimize_method = ( get_option( 'aj_autoptimize_method', 'async' ) == 'async' ) ? 'async' : 'defer';
|
|
|
|
|
|
|
|
|
972 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
973 |
if ( false !== $aj_autoptimize_enabled ) {
|
974 |
return " " . $aj_autoptimize_method . "='" . $aj_autoptimize_method . "' ";
|
975 |
}
|
976 |
}
|
977 |
}
|
978 |
+
/**
|
979 |
+
* async_javascript_dismiss_upgrade()
|
980 |
+
*
|
981 |
+
* Dismiss notices
|
982 |
+
*
|
983 |
+
*/
|
984 |
add_action( 'wp_ajax_async_javascript_dismiss_upgrade', 'async_javascript_dismiss_upgrade' );
|
985 |
function async_javascript_dismiss_upgrade() {
|
986 |
$notice_id = isset( $_REQUEST['notice_id'] ) && $_REQUEST['notice_id'] != '' ? $_REQUEST['notice_id'] : '';
|
987 |
update_option( 'aj_upgrade_notice', $notice_id );
|
988 |
die();
|
989 |
}
|
990 |
+
/**
|
991 |
+
* async_javascript_dismiss_upgrade()
|
992 |
+
*
|
993 |
+
* Ajax function for Async JavaScript
|
994 |
+
*
|
995 |
+
*/
|
996 |
+
function aj_steps() {
|
997 |
+
$aj_gtmetrix_results = get_option( 'aj_gtmetrix_results', array() );
|
998 |
+
if ( !isset( $_POST['sub_action'] ) ) {
|
999 |
+
$return = array(
|
1000 |
+
'status' => false,
|
1001 |
+
'error' => 'No sub action defined.'
|
1002 |
+
);
|
1003 |
+
} else {
|
1004 |
+
$sub_action = $_POST['sub_action'];
|
1005 |
+
switch ( $sub_action ) {
|
1006 |
+
case 'aj_step2':
|
1007 |
+
$aj_gtmetrix_username = $_POST['aj_gtmetrix_username'];
|
1008 |
+
$aj_gtmetrix_api_key = $_POST['aj_gtmetrix_api_key'];
|
1009 |
+
$aj_gtmetrix_server = $_POST['aj_gtmetrix_server'];
|
1010 |
+
$site_url = trailingslashit( $_POST['site_url'] );
|
1011 |
+
update_option( 'aj_gtmetrix_username', $aj_gtmetrix_username );
|
1012 |
+
update_option( 'aj_gtmetrix_api_key', $aj_gtmetrix_api_key );
|
1013 |
+
update_option( 'aj_gtmetrix_server', $aj_gtmetrix_server );
|
1014 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
1015 |
+
$args = array(
|
1016 |
+
'url' => $site_url,
|
1017 |
+
'location' => $aj_gtmetrix_server
|
1018 |
+
);
|
1019 |
+
$testid = $test->test( $args );
|
1020 |
+
if ( $testid ) {
|
1021 |
+
$test->get_results();
|
1022 |
+
if ( $test->error() ) {
|
1023 |
+
$return = array(
|
1024 |
+
'status' => false,
|
1025 |
+
'error' => $test->error()
|
1026 |
+
);
|
1027 |
+
} else {
|
1028 |
+
$testid = $test->get_test_id();
|
1029 |
+
$results = $test->results();
|
1030 |
+
$resources = $test->resources();
|
1031 |
+
$status = $test->status();
|
1032 |
+
$credits = $status['api_credits'];
|
1033 |
+
$return = array(
|
1034 |
+
'status' => true,
|
1035 |
+
'testid' => $testid,
|
1036 |
+
'results' => $results,
|
1037 |
+
'resources' => $resources,
|
1038 |
+
'id' => $sub_action,
|
1039 |
+
'name' => 'Baseline',
|
1040 |
+
'url' => $args['url'],
|
1041 |
+
'credits' => $credits
|
1042 |
+
);
|
1043 |
+
$aj_gtmetrix_results[$sub_action] = $return;
|
1044 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1045 |
+
}
|
1046 |
+
} else {
|
1047 |
+
$return = array(
|
1048 |
+
'status' => false,
|
1049 |
+
'error' => $test->error()
|
1050 |
+
);
|
1051 |
+
}
|
1052 |
+
break;
|
1053 |
+
case 'aj_step2b':
|
1054 |
+
$aj_gtmetrix_username = $_POST['aj_gtmetrix_username'];
|
1055 |
+
$aj_gtmetrix_api_key = $_POST['aj_gtmetrix_api_key'];
|
1056 |
+
$aj_gtmetrix_server = $_POST['aj_gtmetrix_server'];
|
1057 |
+
$site_url = trailingslashit( $_POST['site_url'] );
|
1058 |
+
update_option( 'aj_gtmetrix_username', $aj_gtmetrix_username );
|
1059 |
+
update_option( 'aj_gtmetrix_api_key', $aj_gtmetrix_api_key );
|
1060 |
+
update_option( 'aj_gtmetrix_server', $aj_gtmetrix_server );
|
1061 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
1062 |
+
$args = array(
|
1063 |
+
'url' => $site_url . '?aj_simulate=async',
|
1064 |
+
'location' => $aj_gtmetrix_server
|
1065 |
+
);
|
1066 |
+
$testid = $test->test( $args );
|
1067 |
+
if ( $testid ) {
|
1068 |
+
$test->get_results();
|
1069 |
+
if ( $test->error() ) {
|
1070 |
+
$return = array(
|
1071 |
+
'status' => false,
|
1072 |
+
'error' => $test->error()
|
1073 |
+
);
|
1074 |
+
} else {
|
1075 |
+
$testid = $test->get_test_id();
|
1076 |
+
$results = $test->results();
|
1077 |
+
$resources = $test->resources();
|
1078 |
+
$status = $test->status();
|
1079 |
+
$credits = $status['api_credits'];
|
1080 |
+
$return = array(
|
1081 |
+
'status' => true,
|
1082 |
+
'testid' => $testid,
|
1083 |
+
'results' => $results,
|
1084 |
+
'resources' => $resources,
|
1085 |
+
'id' => $sub_action,
|
1086 |
+
'name' => 'Async',
|
1087 |
+
'url' => $args['url'],
|
1088 |
+
'credits' => $credits
|
1089 |
+
);
|
1090 |
+
$aj_gtmetrix_results[$sub_action] = $return;
|
1091 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1092 |
+
}
|
1093 |
+
} else {
|
1094 |
+
$return = array(
|
1095 |
+
'status' => false,
|
1096 |
+
'error' => $test->error()
|
1097 |
+
);
|
1098 |
+
}
|
1099 |
+
break;
|
1100 |
+
case 'aj_step2c':
|
1101 |
+
$aj_gtmetrix_username = $_POST['aj_gtmetrix_username'];
|
1102 |
+
$aj_gtmetrix_api_key = $_POST['aj_gtmetrix_api_key'];
|
1103 |
+
$aj_gtmetrix_server = $_POST['aj_gtmetrix_server'];
|
1104 |
+
$site_url = trailingslashit( $_POST['site_url'] );
|
1105 |
+
update_option( 'aj_gtmetrix_username', $aj_gtmetrix_username );
|
1106 |
+
update_option( 'aj_gtmetrix_api_key', $aj_gtmetrix_api_key );
|
1107 |
+
update_option( 'aj_gtmetrix_server', $aj_gtmetrix_server );
|
1108 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
1109 |
+
$args = array(
|
1110 |
+
'url' => $site_url . '?aj_simulate=defer',
|
1111 |
+
'location' => $aj_gtmetrix_server
|
1112 |
+
);
|
1113 |
+
$testid = $test->test( $args );
|
1114 |
+
if ( $testid ) {
|
1115 |
+
$test->get_results();
|
1116 |
+
if ( $test->error() ) {
|
1117 |
+
$return = array(
|
1118 |
+
'status' => false,
|
1119 |
+
'error' => $test->error()
|
1120 |
+
);
|
1121 |
+
} else {
|
1122 |
+
$testid = $test->get_test_id();
|
1123 |
+
$results = $test->results();
|
1124 |
+
$resources = $test->resources();
|
1125 |
+
$status = $test->status();
|
1126 |
+
$credits = $status['api_credits'];
|
1127 |
+
$return = array(
|
1128 |
+
'status' => true,
|
1129 |
+
'testid' => $testid,
|
1130 |
+
'results' => $results,
|
1131 |
+
'resources' => $resources,
|
1132 |
+
'id' => $sub_action,
|
1133 |
+
'name' => 'Defer',
|
1134 |
+
'url' => $args['url'],
|
1135 |
+
'credits' => $credits
|
1136 |
+
);
|
1137 |
+
$aj_gtmetrix_results[$sub_action] = $return;
|
1138 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1139 |
+
}
|
1140 |
+
} else {
|
1141 |
+
$return = array(
|
1142 |
+
'status' => false,
|
1143 |
+
'error' => $test->error()
|
1144 |
+
);
|
1145 |
+
}
|
1146 |
+
break;
|
1147 |
+
case 'aj_step2d':
|
1148 |
+
$aj_gtmetrix_username = $_POST['aj_gtmetrix_username'];
|
1149 |
+
$aj_gtmetrix_api_key = $_POST['aj_gtmetrix_api_key'];
|
1150 |
+
$aj_gtmetrix_server = $_POST['aj_gtmetrix_server'];
|
1151 |
+
$site_url = trailingslashit( $_POST['site_url'] );
|
1152 |
+
update_option( 'aj_gtmetrix_username', $aj_gtmetrix_username );
|
1153 |
+
update_option( 'aj_gtmetrix_api_key', $aj_gtmetrix_api_key );
|
1154 |
+
update_option( 'aj_gtmetrix_server', $aj_gtmetrix_server );
|
1155 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
1156 |
+
$args = array(
|
1157 |
+
'url' => $site_url . '?aj_simulate=async&aj_simulate_jquery=exclude',
|
1158 |
+
'location' => $aj_gtmetrix_server
|
1159 |
+
);
|
1160 |
+
$testid = $test->test( $args );
|
1161 |
+
if ( $testid ) {
|
1162 |
+
$test->get_results();
|
1163 |
+
if ( $test->error() ) {
|
1164 |
+
$return = array(
|
1165 |
+
'status' => false,
|
1166 |
+
'error' => $test->error()
|
1167 |
+
);
|
1168 |
+
} else {
|
1169 |
+
$testid = $test->get_test_id();
|
1170 |
+
$results = $test->results();
|
1171 |
+
$resources = $test->resources();
|
1172 |
+
$status = $test->status();
|
1173 |
+
$credits = $status['api_credits'];
|
1174 |
+
$return = array(
|
1175 |
+
'status' => true,
|
1176 |
+
'testid' => $testid,
|
1177 |
+
'results' => $results,
|
1178 |
+
'resources' => $resources,
|
1179 |
+
'id' => $sub_action,
|
1180 |
+
'name' => 'Async (jQuery Excluded)',
|
1181 |
+
'url' => $args['url'],
|
1182 |
+
'credits' => $credits
|
1183 |
+
);
|
1184 |
+
$aj_gtmetrix_results[$sub_action] = $return;
|
1185 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1186 |
+
}
|
1187 |
+
} else {
|
1188 |
+
$return = array(
|
1189 |
+
'status' => false,
|
1190 |
+
'error' => $test->error()
|
1191 |
+
);
|
1192 |
+
}
|
1193 |
+
break;
|
1194 |
+
case 'aj_step2e':
|
1195 |
+
$aj_gtmetrix_username = $_POST['aj_gtmetrix_username'];
|
1196 |
+
$aj_gtmetrix_api_key = $_POST['aj_gtmetrix_api_key'];
|
1197 |
+
$aj_gtmetrix_server = $_POST['aj_gtmetrix_server'];
|
1198 |
+
$site_url = trailingslashit( $_POST['site_url'] );
|
1199 |
+
update_option( 'aj_gtmetrix_username', $aj_gtmetrix_username );
|
1200 |
+
update_option( 'aj_gtmetrix_api_key', $aj_gtmetrix_api_key );
|
1201 |
+
update_option( 'aj_gtmetrix_server', $aj_gtmetrix_server );
|
1202 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
1203 |
+
$args = array(
|
1204 |
+
'url' => $site_url . '?aj_simulate=defer&aj_simulate_jquery=exclude',
|
1205 |
+
'location' => $aj_gtmetrix_server
|
1206 |
+
);
|
1207 |
+
$testid = $test->test( $args );
|
1208 |
+
if ( $testid ) {
|
1209 |
+
$test->get_results();
|
1210 |
+
if ( $test->error() ) {
|
1211 |
+
$return = array(
|
1212 |
+
'status' => false,
|
1213 |
+
'error' => $test->error()
|
1214 |
+
);
|
1215 |
+
} else {
|
1216 |
+
$testid = $test->get_test_id();
|
1217 |
+
$results = $test->results();
|
1218 |
+
$resources = $test->resources();
|
1219 |
+
$status = $test->status();
|
1220 |
+
$credits = $status['api_credits'];
|
1221 |
+
$return = array(
|
1222 |
+
'status' => true,
|
1223 |
+
'testid' => $testid,
|
1224 |
+
'results' => $results,
|
1225 |
+
'resources' => $resources,
|
1226 |
+
'id' => $sub_action,
|
1227 |
+
'name' => 'Defer (jQuery Excluded)',
|
1228 |
+
'url' => $args['url'],
|
1229 |
+
'credits' => $credits
|
1230 |
+
);
|
1231 |
+
$aj_gtmetrix_results[$sub_action] = $return;
|
1232 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1233 |
+
}
|
1234 |
+
} else {
|
1235 |
+
$return = array(
|
1236 |
+
'status' => false,
|
1237 |
+
'error' => $test->error()
|
1238 |
+
);
|
1239 |
+
}
|
1240 |
+
break;
|
1241 |
+
case 'aj_step_results':
|
1242 |
+
$best_pagespeed = 0;
|
1243 |
+
$best_yslow = 0;
|
1244 |
+
$best_overall = 0;
|
1245 |
+
$best_result = array();
|
1246 |
+
$baseline = $aj_gtmetrix_results['aj_step2'];
|
1247 |
+
foreach ( $aj_gtmetrix_results as $aj_step => $aj_gtmetrix_result ) {
|
1248 |
+
if ( $aj_step != 'aj_step2' ) {
|
1249 |
+
$pagespeed = $aj_gtmetrix_result['results']['pagespeed_score'];
|
1250 |
+
$yslow = $aj_gtmetrix_result['results']['yslow_score'];
|
1251 |
+
$combined = $pagespeed + $yslow;
|
1252 |
+
if ( $combined > $best_overall ) {
|
1253 |
+
$best_overall = $combined;
|
1254 |
+
$best_result = $aj_gtmetrix_result;
|
1255 |
+
}
|
1256 |
+
}
|
1257 |
+
}
|
1258 |
+
if ( !empty( $best_result ) ) {
|
1259 |
+
$return = $best_result;
|
1260 |
+
$return['status'] = true;
|
1261 |
+
$return['baseline_pagespeed'] = $baseline['results']['pagespeed_score'];
|
1262 |
+
$return['baseline_yslow'] = $baseline['results']['yslow_score'];
|
1263 |
+
$aj_gtmetrix_results['best_result'] = $return;
|
1264 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1265 |
+
} else {
|
1266 |
+
$return = array(
|
1267 |
+
'status' => false,
|
1268 |
+
'error' => 'No detected increase'
|
1269 |
+
);
|
1270 |
+
}
|
1271 |
+
break;
|
1272 |
+
case 'aj_apply_settings':
|
1273 |
+
$settings = $_POST['settings'];
|
1274 |
+
if ( $settings != '' ) {
|
1275 |
+
$best_id = $settings;
|
1276 |
+
} else {
|
1277 |
+
$best_result = $aj_gtmetrix_results['best_result'];
|
1278 |
+
$best_id = $best_result['id'];
|
1279 |
+
}
|
1280 |
+
update_option( 'aj_enabled', 1 );
|
1281 |
+
if ( $best_id == 'aj_step2b' || $best_id == 'aj_step2d' ) {
|
1282 |
+
update_option( 'aj_method', 'async' );
|
1283 |
+
} else if ( $best_id == 'aj_step2c' || $best_id == 'aj_step2e' ) {
|
1284 |
+
update_option( 'aj_method', 'defer' );
|
1285 |
+
}
|
1286 |
+
if ( $best_id == 'aj_step2b' ) {
|
1287 |
+
update_option( 'aj_jquery', 'async' );
|
1288 |
+
} else if ( $best_id == 'aj_step2d' ) {
|
1289 |
+
update_option( 'aj_jquery', 'defer' );
|
1290 |
+
} else if ( $best_id == 'aj_step2c' || $best_id == 'aj_step2e' ) {
|
1291 |
+
update_option( 'aj_jquery', 'exclude' );
|
1292 |
+
}
|
1293 |
+
update_option( 'aj_exclusions', '' );
|
1294 |
+
$return['status'] = true;
|
1295 |
+
break;
|
1296 |
+
case 'aj_gtmetrix_test':
|
1297 |
+
$aj_gtmetrix_username = $_POST['aj_gtmetrix_username'];
|
1298 |
+
$aj_gtmetrix_api_key = $_POST['aj_gtmetrix_api_key'];
|
1299 |
+
$aj_gtmetrix_server = $_POST['aj_gtmetrix_server'];
|
1300 |
+
$site_url = trailingslashit( $_POST['site_url'] );
|
1301 |
+
update_option( 'aj_gtmetrix_username', $aj_gtmetrix_username );
|
1302 |
+
update_option( 'aj_gtmetrix_api_key', $aj_gtmetrix_api_key );
|
1303 |
+
update_option( 'aj_gtmetrix_server', $aj_gtmetrix_server );
|
1304 |
+
$test = new Services_WTF_Test( $aj_gtmetrix_username, $aj_gtmetrix_api_key );
|
1305 |
+
$args = array(
|
1306 |
+
'url' => $site_url,
|
1307 |
+
'location' => $aj_gtmetrix_server
|
1308 |
+
);
|
1309 |
+
$testid = $test->test( $args );
|
1310 |
+
if ( $testid ) {
|
1311 |
+
$test->get_results();
|
1312 |
+
if ( $test->error() ) {
|
1313 |
+
$return = array(
|
1314 |
+
'status' => false,
|
1315 |
+
'error' => $test->error()
|
1316 |
+
);
|
1317 |
+
} else {
|
1318 |
+
$testid = $test->get_test_id();
|
1319 |
+
$results = $test->results();
|
1320 |
+
$resources = $test->resources();
|
1321 |
+
$screenshot = base64_encode( file_get_contents( $results['report_url'] . '/screenshot.jpg' ) );
|
1322 |
+
$status = $test->status();
|
1323 |
+
$credits = $status['api_credits'];
|
1324 |
+
$return = array(
|
1325 |
+
'status' => true,
|
1326 |
+
'testid' => $testid,
|
1327 |
+
'results' => $results,
|
1328 |
+
'resources' => $resources,
|
1329 |
+
'id' => $sub_action,
|
1330 |
+
'name' => 'Latest',
|
1331 |
+
'url' => $args['url'],
|
1332 |
+
'credits' => $credits,
|
1333 |
+
'screenshot' => $screenshot
|
1334 |
+
);
|
1335 |
+
$aj_gtmetrix_results['latest'] = $return;
|
1336 |
+
update_option( 'aj_gtmetrix_results', $aj_gtmetrix_results );
|
1337 |
+
}
|
1338 |
+
} else {
|
1339 |
+
$return = array(
|
1340 |
+
'status' => false,
|
1341 |
+
'error' => $test->error()
|
1342 |
+
);
|
1343 |
+
}
|
1344 |
+
break;
|
1345 |
+
case 'aj_save_settings':
|
1346 |
+
$aj_enabled = $_POST['aj_enabled'];
|
1347 |
+
$aj_method = $_POST['aj_method'];
|
1348 |
+
$aj_jquery = $_POST['aj_jquery'];
|
1349 |
+
$aj_exclusions = $_POST['aj_exclusions'];
|
1350 |
+
$aj_autoptimize_enabled = $_POST['aj_autoptimize_enabled'];
|
1351 |
+
$aj_autoptimize_method = $_POST['aj_autoptimize_method'];
|
1352 |
+
update_option( 'aj_enabled', $aj_enabled );
|
1353 |
+
update_option( 'aj_method', $aj_method );
|
1354 |
+
update_option( 'aj_jquery', $aj_jquery );
|
1355 |
+
update_option( 'aj_exclusions', $aj_exclusions );
|
1356 |
+
update_option( 'aj_autoptimize_enabled', $aj_autoptimize_enabled );
|
1357 |
+
update_option( 'aj_autoptimize_method', $aj_autoptimize_method );
|
1358 |
+
$return['status'] = true;
|
1359 |
+
break;
|
1360 |
+
}
|
1361 |
+
}
|
1362 |
+
if( is_null( $return ) ) {
|
1363 |
+
$return = array(
|
1364 |
+
'status' => false
|
1365 |
+
);
|
1366 |
+
}
|
1367 |
+
echo json_encode( $return );
|
1368 |
+
wp_die();
|
1369 |
+
}
|
1370 |
+
add_action( 'wp_ajax_aj_steps', 'aj_steps' );
|
css/admin.css
CHANGED
@@ -1,15 +1,89 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
.aj_method {
|
14 |
display:none;
|
15 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.aj_method,
|
2 |
+
.aj_steps_hidden,
|
3 |
+
#aj_step2_gtmetrix_results,
|
4 |
+
#aj_step2b_gtmetrix_results,
|
5 |
+
#aj_step2c_gtmetrix_results,
|
6 |
+
#aj_step2d_gtmetrix_results,
|
7 |
+
#aj_step2e_gtmetrix_results,
|
8 |
+
#aj_latest_please_wait,
|
9 |
+
#aj_step4_y,
|
10 |
+
#aj_step4_n,
|
11 |
+
#aj_notification {
|
|
|
|
|
12 |
display:none;
|
13 |
+
}
|
14 |
+
#aj_step2_gtmetrix_results td,
|
15 |
+
#aj_step2b_gtmetrix_results td,
|
16 |
+
#aj_step2c_gtmetrix_results td,
|
17 |
+
#aj_step2d_gtmetrix_results td,
|
18 |
+
#aj_step2e_gtmetrix_results td {
|
19 |
+
vertical-align: top !important;
|
20 |
+
text-align: center !important;
|
21 |
+
}
|
22 |
+
.aj_gtmetrix_result {
|
23 |
+
font-size: 48px !important;
|
24 |
+
}
|
25 |
+
.aj_gtmetrix_screenshot,
|
26 |
+
#aj_notification {
|
27 |
+
-webkit-box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.75);
|
28 |
+
-moz-box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.75);
|
29 |
+
box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.75);
|
30 |
+
max-width:200px;
|
31 |
+
}
|
32 |
+
.aj_gtmetrix_screenshot_dashboard {
|
33 |
+
-webkit-box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.75);
|
34 |
+
-moz-box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.75);
|
35 |
+
box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.75);
|
36 |
+
max-width:125px;
|
37 |
+
}
|
38 |
+
|
39 |
+
.aj-steps-table h3 {
|
40 |
+
height: 2em !important;
|
41 |
+
}
|
42 |
+
.aj_step_img {
|
43 |
+
max-width:150px;
|
44 |
+
}
|
45 |
+
.aj_field_error {
|
46 |
+
border:solid 1px #00ffff !important;
|
47 |
+
}
|
48 |
+
#aj_notification {
|
49 |
+
position:fixed;
|
50 |
+
top:50%;
|
51 |
+
left:40%;
|
52 |
+
width:20%;
|
53 |
+
z-index:105;
|
54 |
+
text-align:center;
|
55 |
+
font-weight:normal;
|
56 |
+
font-size:14px;
|
57 |
+
font-weight:bold;
|
58 |
+
color:white;
|
59 |
+
background-color:#FF7800;
|
60 |
+
padding:5px;
|
61 |
+
}
|
62 |
+
#aj_notification span.aj_dismiss {
|
63 |
+
border:2px solid #FFF;
|
64 |
+
padding:0 5px;
|
65 |
+
cursor:pointer;
|
66 |
+
float:right;
|
67 |
+
margin-right:10px;
|
68 |
+
}
|
69 |
+
#aj_notification a {
|
70 |
+
color:white;
|
71 |
+
text-decoration:none;
|
72 |
+
font-weight:bold
|
73 |
+
}
|
74 |
+
.aj ol {
|
75 |
+
list-style-type: decimal !important;
|
76 |
+
}
|
77 |
+
.aj ul {
|
78 |
+
list-style-type: circle !important;
|
79 |
+
}
|
80 |
+
.aj ol,
|
81 |
+
.aj ul {
|
82 |
+
margin-left: 2em !important;
|
83 |
+
}
|
84 |
+
.aj_plugin {
|
85 |
+
border: solid 1px #cccccc;
|
86 |
+
padding: 15px;
|
87 |
+
background-color: #f5f5dc;
|
88 |
+
margin-top: 15px;
|
89 |
+
}
|
css/admin.min.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
1 |
+
#aj_latest_please_wait,#aj_notification,#aj_step2_gtmetrix_results,#aj_step2b_gtmetrix_results,#aj_step2c_gtmetrix_results,#aj_step2d_gtmetrix_results,#aj_step2e_gtmetrix_results,#aj_step4_n,#aj_step4_y,.aj_method,.aj_steps_hidden{display:none}#aj_step2_gtmetrix_results td,#aj_step2b_gtmetrix_results td,#aj_step2c_gtmetrix_results td,#aj_step2d_gtmetrix_results td,#aj_step2e_gtmetrix_results td{vertical-align:top!important;text-align:center!important}.aj_gtmetrix_result{font-size:48px!important}#aj_notification,.aj_gtmetrix_screenshot{-webkit-box-shadow:0 0 15px 5px rgba(0,0,0,.75);-moz-box-shadow:0 0 15px 5px rgba(0,0,0,.75);box-shadow:0 0 15px 5px rgba(0,0,0,.75);max-width:200px}.aj_gtmetrix_screenshot_dashboard{-webkit-box-shadow:0 0 15px 5px rgba(0,0,0,.75);-moz-box-shadow:0 0 15px 5px rgba(0,0,0,.75);box-shadow:0 0 15px 5px rgba(0,0,0,.75);max-width:125px}.aj-steps-table h3{height:2em!important}.aj_step_img{max-width:150px}.aj_field_error{border:1px solid #0ff!important}#aj_notification{position:fixed;top:50%;left:40%;width:20%;z-index:105;text-align:center;font-size:14px;font-weight:700;color:#fff;background-color:#FF7800;padding:5px}#aj_notification span.aj_dismiss{border:2px solid #FFF;padding:0 5px;cursor:pointer;float:right;margin-right:10px}#aj_notification a{color:#fff;text-decoration:none;font-weight:700}.aj ol{list-style-type:decimal!important}.aj ul{list-style-type:circle!important}.aj ol,.aj ul{margin-left:2em!important}.aj_plugin{border:1px solid #ccc;padding:15px;background-color:beige;margin-top:15px}
|
images/finger_point_out_punch_hole_400_clr_17860.png
ADDED
Binary file
|
images/loading.gif
ADDED
Binary file
|
images/not_available.jpg
ADDED
Binary file
|
images/number-block-eight.jpg
ADDED
Binary file
|
images/number-block-five.jpg
ADDED
Binary file
|
images/number-block-four.jpg
ADDED
Binary file
|
images/number-block-nine.jpg
ADDED
Binary file
|
images/number-block-one.jpg
ADDED
Binary file
|
images/number-block-seven.jpg
ADDED
Binary file
|
images/number-block-six.jpg
ADDED
Binary file
|
images/number-block-three.jpg
ADDED
Binary file
|
images/number-block-two.jpg
ADDED
Binary file
|
images/number_five_break_hole_150_clr_18842.gif
ADDED
Binary file
|
images/number_four_break_hole_150_clr_18840.gif
ADDED
Binary file
|
images/number_one_break_hole_150_clr_18741.gif
ADDED
Binary file
|
images/number_three_break_hole_150_clr_18837.gif
ADDED
Binary file
|
images/number_two_break_hole_150_clr_18753.gif
ADDED
Binary file
|
images/stick_figure_panicking_150_clr_13267.gif
ADDED
Binary file
|
js/admin.js
CHANGED
@@ -1,42 +1,165 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
} else {
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
* functions and actions to load after document ready
|
31 |
*/
|
32 |
-
jQuery(document).ready(function() {
|
33 |
-
isChecked();
|
34 |
|
35 |
-
jQuery(document).on('click','
|
36 |
-
isChecked();
|
37 |
-
});
|
38 |
-
|
39 |
-
jQuery(document).on('click','.aj-upgrade-notice .notice-dismiss',function() {
|
40 |
var notice_id = jQuery( '.aj-upgrade-notice' ).attr( 'data-id' );
|
41 |
jQuery.ajax({
|
42 |
url: aj.ajaxurl,
|
@@ -46,4 +169,128 @@ jQuery(document).ready(function() {
|
|
46 |
}
|
47 |
});
|
48 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
});
|
1 |
+
function aj_step( theStep ) {
|
2 |
+
var aj_gtmetrix_username = jQuery( '#aj_gtmetrix_username' ).val();
|
3 |
+
var aj_gtmetrix_api_key = jQuery( '#aj_gtmetrix_api_key' ).val();
|
4 |
+
var aj_gtmetrix_server = jQuery( '#aj_gtmetrix_server' ).val();
|
5 |
+
if ( theStep == 'aj_step_results' ) {
|
6 |
+
var data = {
|
7 |
+
'action': 'aj_steps',
|
8 |
+
'sub_action': theStep,
|
9 |
+
'site_url': aj_localize_admin.siteurl,
|
10 |
+
'aj_gtmetrix_username': aj_gtmetrix_username,
|
11 |
+
'aj_gtmetrix_api_key': aj_gtmetrix_api_key,
|
12 |
+
'aj_gtmetrix_server': aj_gtmetrix_server
|
13 |
+
};
|
14 |
+
jQuery.post(aj_localize_admin.ajaxurl, data, function( response ) {
|
15 |
+
try {
|
16 |
+
response = jQuery.parseJSON( response );
|
17 |
+
if ( response.status !== false ) {
|
18 |
+
var baseline_pagespeed = response.baseline_pagespeed;
|
19 |
+
var baseline_yslow = response.baseline_yslow;
|
20 |
+
var pagespeed = response.results.pagespeed_score;
|
21 |
+
var yslow = response.results.yslow_score;
|
22 |
+
var aj_gtmetrix_config = response.name;
|
23 |
+
var flt = parseFloat( response.results.fully_loaded_time / 1000 ).toFixed( 2 );
|
24 |
+
var url = response.url;
|
25 |
+
jQuery( '.aj_gtmetrix_config' ).html( aj_gtmetrix_config );
|
26 |
+
if ( pagespeed > baseline_pagespeed ) {
|
27 |
+
jQuery( '#aj_gtmetrix_inde_pagespeed' ).html( 'an increase' );
|
28 |
+
} else if ( pagespeed < baseline_pagespeed ) {
|
29 |
+
jQuery( '#aj_gtmetrix_inde_pagespeed' ).html( 'a decrease' );
|
30 |
+
} else {
|
31 |
+
jQuery( '#aj_gtmetrix_inde_pagespeed' ).html( 'no change' );
|
32 |
+
}
|
33 |
+
if ( yslow > baseline_yslow ) {
|
34 |
+
jQuery( '#aj_gtmetrix_inde_yslow' ).html( 'an increase' );
|
35 |
+
} else if ( yslow < baseline_yslow ) {
|
36 |
+
jQuery( '#aj_gtmetrix_inde_yslow' ).html( 'a decrease' );
|
37 |
+
} else {
|
38 |
+
jQuery( '#aj_gtmetrix_inde_yslow' ).html( 'no change' );
|
39 |
+
}
|
40 |
+
jQuery( '#aj_gtmetrix_baseline_pagespeed' ).html( baseline_pagespeed + '%' );
|
41 |
+
jQuery( '#aj_gtmetrix_best_pagespeed' ).html( pagespeed + '%' );
|
42 |
+
jQuery( '#aj_gtmetrix_baseline_yslow' ).html( baseline_yslow + '%' );
|
43 |
+
jQuery( '#aj_gtmetrix_best_yslow' ).html( yslow + '%' );
|
44 |
+
jQuery( '#aj_gtmetrix_best_fullyloaded' ).html( flt + 's' );
|
45 |
+
jQuery( '#aj_gtmetrix_best_url' ).attr( 'href', url ).html( url );
|
46 |
+
if ( response.id == 'aj_step2b' || response.id == 'aj_step2c' ) {
|
47 |
+
jQuery( '#aj_step4_jquery_excluded' ).hide();
|
48 |
+
jQuery( '#aj_step4_jquery_not_excluded' ).show();
|
49 |
+
} else if ( response.id == 'aj_step2d' || response.id == 'aj_step2e' ) {
|
50 |
+
jQuery( '#aj_step4_jquery_excluded' ).show();
|
51 |
+
jQuery( '#aj_step4_jquery_not_excluded' ).hide();
|
52 |
+
}
|
53 |
+
jQuery( '.aj_gtmetrix_credits' ).html( response.credits );
|
54 |
+
jQuery( '#aj_step_results' ).show();
|
55 |
+
} else {
|
56 |
+
console.log(response);
|
57 |
+
}
|
58 |
+
}
|
59 |
+
catch( err ) {
|
60 |
+
console.log( err );
|
61 |
+
}
|
62 |
+
});
|
63 |
} else {
|
64 |
+
var data = {
|
65 |
+
'action': 'aj_steps',
|
66 |
+
'sub_action': theStep,
|
67 |
+
'site_url': aj_localize_admin.siteurl,
|
68 |
+
'aj_gtmetrix_username': aj_gtmetrix_username,
|
69 |
+
'aj_gtmetrix_api_key': aj_gtmetrix_api_key,
|
70 |
+
'aj_gtmetrix_server': aj_gtmetrix_server
|
71 |
+
};
|
72 |
+
jQuery.post(aj_localize_admin.ajaxurl, data, function( response ) {
|
73 |
+
try {
|
74 |
+
response = jQuery.parseJSON( response );
|
75 |
+
if ( response.status !== false ) {
|
76 |
+
var screenshot = response.results.report_url + '/screenshot.jpg';
|
77 |
+
var pagespeed = response.results.pagespeed_score;
|
78 |
+
var yslow = response.results.yslow_score;
|
79 |
+
var flt = parseFloat( response.results.fully_loaded_time / 1000 ).toFixed( 2 );
|
80 |
+
var tps = Math.floor( response.results.page_bytes / 1024 );
|
81 |
+
var requests = response.results.page_elements;
|
82 |
+
var report = '<a href="' + response.results.report_url + '" target="_blank">' + response.results.report_url + '</a>';
|
83 |
+
var report_url = report.replace( 'https://', 'https://' + aj_gtmetrix_username + ':' + aj_gtmetrix_api_key + '@' );
|
84 |
+
var step_name = response.name;
|
85 |
+
var step_url = response.url;
|
86 |
+
var pr = 255 * ( 1 - ( pagespeed / 100 ) );
|
87 |
+
var yr = 255 * ( 1 - ( yslow / 100 ) );
|
88 |
+
var pg = 255 * ( pagespeed / 100 );
|
89 |
+
var yg = 255 * ( yslow / 100 );
|
90 |
+
var prgb = 'rgb(' + Math.floor( pr ) + ',' + Math.floor( pg ) + ',0 )';
|
91 |
+
var yrgb = 'rgb(' + Math.floor( yr ) + ',' + Math.floor( yg ) + ',0 )';
|
92 |
+
if ( theStep == 'aj_gtmetrix_test' ) {
|
93 |
+
theStep = 'aj_latest';
|
94 |
+
}
|
95 |
+
jQuery( '#' + theStep + '_please_wait' ).hide();
|
96 |
+
jQuery( '.' + theStep + '_screenshot' ).attr( 'src', screenshot );
|
97 |
+
jQuery( '.' + theStep + '_pagespeed' ).html( pagespeed + '%' ).css( { color: prgb } );
|
98 |
+
jQuery( '.' + theStep + '_yslow' ).html( yslow + '%' ).css( { color: yrgb } );
|
99 |
+
jQuery( '.' + theStep + '_flt' ).html( flt + 's' );
|
100 |
+
jQuery( '.' + theStep + '_tps' ).html( tps + 'KB' );
|
101 |
+
jQuery( '.' + theStep + '_requests' ).html( requests );
|
102 |
+
jQuery( '.' + theStep + '_report' ).html( report_url );
|
103 |
+
jQuery( '#' + theStep + '_gtmetrix_results' ).show();
|
104 |
+
jQuery( '.' + theStep + '_gtmetrix' ).html( step_name );
|
105 |
+
jQuery( '.' + theStep + '_url' ).attr( 'href', step_url ).html( step_url );
|
106 |
+
jQuery( '.aj_gtmetrix_credits' ).html( response.credits );
|
107 |
+
if ( theStep == 'aj_step2' ) {
|
108 |
+
jQuery( '#aj_notification' ).fadeIn( 'slow' ).html( 'Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>' );
|
109 |
+
jQuery( '#aj_step2b' ).show();
|
110 |
+
jQuery( 'html, body' ).animate({
|
111 |
+
scrollTop: jQuery( "#aj_step2b" ).offset().top
|
112 |
+
}, 1000 );
|
113 |
+
aj_step( 'aj_step2b' );
|
114 |
+
} else if ( theStep == 'aj_step2b' ) {
|
115 |
+
jQuery( '#aj_step2c' ).show();
|
116 |
+
jQuery( 'html, body' ).animate({
|
117 |
+
scrollTop: jQuery( "#aj_step2c" ).offset().top
|
118 |
+
}, 1000 );
|
119 |
+
aj_step( 'aj_step2c' );
|
120 |
+
} else if ( theStep == 'aj_step2c' ) {
|
121 |
+
jQuery( '#aj_step2d' ).show();
|
122 |
+
jQuery( 'html, body' ).animate({
|
123 |
+
scrollTop: jQuery( "#aj_step2d" ).offset().top
|
124 |
+
}, 1000 );
|
125 |
+
aj_step( 'aj_step2d' );
|
126 |
+
} else if ( theStep == 'aj_step2d' ) {
|
127 |
+
jQuery( '#aj_step2e' ).show();
|
128 |
+
jQuery( 'html, body' ).animate({
|
129 |
+
scrollTop: jQuery( "#aj_step2e" ).offset().top
|
130 |
+
}, 1000 );
|
131 |
+
aj_step( 'aj_step2e' );
|
132 |
+
} else if ( theStep == 'aj_step2e' ) {
|
133 |
+
jQuery( '#aj_step_results' ).show();
|
134 |
+
jQuery( 'html, body' ).animate({
|
135 |
+
scrollTop: jQuery( "#aj_step_results" ).offset().top
|
136 |
+
}, 1000 );
|
137 |
+
aj_step( 'aj_step_results' );
|
138 |
+
} else if ( theStep == 'aj_latest' ) {
|
139 |
+
jQuery( '#aj_notification' ).fadeIn( 'slow' ).html( 'Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>' );
|
140 |
+
jQuery( '#aj_latest_gtmetrix_results' ).show();
|
141 |
+
jQuery( '#aj_latest_please_wait' ).hide();
|
142 |
+
jQuery( 'html, body' ).animate({
|
143 |
+
scrollTop: jQuery( "#aj_latest_please_wait" ).offset().top
|
144 |
+
}, 1000 );
|
145 |
+
}
|
146 |
+
} else {
|
147 |
+
console.log(response);
|
148 |
+
}
|
149 |
+
}
|
150 |
+
catch( err ) {
|
151 |
+
console.log( err );
|
152 |
+
}
|
153 |
+
});
|
154 |
}
|
155 |
}
|
156 |
|
157 |
/**
|
158 |
* functions and actions to load after document ready
|
159 |
*/
|
160 |
+
jQuery( document ).ready( function() {
|
|
|
161 |
|
162 |
+
jQuery( document ).on( 'click', '.aj-upgrade-notice .notice-dismiss', function() {
|
|
|
|
|
|
|
|
|
163 |
var notice_id = jQuery( '.aj-upgrade-notice' ).attr( 'data-id' );
|
164 |
jQuery.ajax({
|
165 |
url: aj.ajaxurl,
|
169 |
}
|
170 |
});
|
171 |
});
|
172 |
+
|
173 |
+
jQuery( document ).on( 'click', '.aj_steps_button', function(e) {
|
174 |
+
e.preventDefault();
|
175 |
+
var theStep = jQuery( this ).attr( 'data-id' );
|
176 |
+
if ( theStep == 'aj_goto_settings' ) {
|
177 |
+
var newURL = aj_localize_admin.ajadminurl + '&tab=settings';
|
178 |
+
window.location.href = newURL;
|
179 |
+
} else if ( theStep == 'aj_apply_settings' || theStep == 'aj_step2b_apply' || theStep == 'aj_step2c_apply' || theStep == 'aj_step2d_apply' || theStep == 'aj_step2e_apply') {
|
180 |
+
if ( theStep != 'aj_apply_settings' ) {
|
181 |
+
var settings = theStep.replace( '_apply', '' );
|
182 |
+
} else {
|
183 |
+
var settings = '';
|
184 |
+
jQuery( '#aj_notification' ).fadeIn( 'slow' ).html( 'Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>' );
|
185 |
+
}
|
186 |
+
var data = {
|
187 |
+
'action': 'aj_steps',
|
188 |
+
'sub_action': 'aj_apply_settings',
|
189 |
+
'settings': settings,
|
190 |
+
'site_url': aj_localize_admin.siteurl
|
191 |
+
};
|
192 |
+
jQuery.post(aj_localize_admin.ajaxurl, data, function( response ) {
|
193 |
+
try {
|
194 |
+
response = jQuery.parseJSON( response );
|
195 |
+
if ( response.status !== false ) {
|
196 |
+
jQuery( '#aj_step5' ).show();
|
197 |
+
jQuery( 'html, body' ).animate({
|
198 |
+
scrollTop: jQuery( "#aj_step5" ).offset().top
|
199 |
+
}, 1000 );
|
200 |
+
if ( settings != '' ) {
|
201 |
+
jQuery( '#aj_notification' ).fadeIn( 'slow' ).html( 'Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>' );
|
202 |
+
}
|
203 |
+
} else {
|
204 |
+
console.log(response);
|
205 |
+
}
|
206 |
+
}
|
207 |
+
catch( err ) {
|
208 |
+
console.log( err );
|
209 |
+
}
|
210 |
+
});
|
211 |
+
} else if ( theStep == 'aj_save_settings' ) {
|
212 |
+
if ( jQuery( '#aj_enabled' ).is( ':checked' ) ) {
|
213 |
+
var aj_enabled = 1;
|
214 |
+
} else {
|
215 |
+
var aj_enabled = 0;
|
216 |
+
}
|
217 |
+
var aj_method = jQuery( 'input[type=radio][name=aj_method]:checked' ).val();
|
218 |
+
var aj_jquery = jQuery( 'input[type=radio][name=aj_jquery]:checked' ).val();
|
219 |
+
var aj_exclusions = jQuery( '#aj_exclusions' ).val();
|
220 |
+
if ( jQuery( '#aj_autoptimize_enabled' ).is( ':visible' ) ) {
|
221 |
+
if ( jQuery( '#aj_autoptimize_enabled' ).is( ':checked' ) ) {
|
222 |
+
var aj_autoptimize_enabled = 1;
|
223 |
+
var aj_autoptimize_method = jQuery( 'input[type=radio][name=aj_autoptimize_method]:checked' ).val();
|
224 |
+
} else {
|
225 |
+
var aj_autoptimize_enabled = 0;
|
226 |
+
var aj_autoptimize_method = jQuery( 'input[type=radio][name=aj_autoptimize_method]:checked' ).val();
|
227 |
+
}
|
228 |
+
} else {
|
229 |
+
var aj_autoptimize_enabled = 0;
|
230 |
+
var aj_autoptimize_method = 'async';
|
231 |
+
}
|
232 |
+
var data = {
|
233 |
+
'action': 'aj_steps',
|
234 |
+
'sub_action': 'aj_save_settings',
|
235 |
+
'aj_enabled': aj_enabled,
|
236 |
+
'aj_method': aj_method,
|
237 |
+
'aj_jquery': aj_jquery,
|
238 |
+
'aj_exclusions': aj_exclusions,
|
239 |
+
'aj_autoptimize_enabled': aj_autoptimize_enabled,
|
240 |
+
'aj_autoptimize_method': aj_autoptimize_method
|
241 |
+
};
|
242 |
+
jQuery.post(aj_localize_admin.ajaxurl, data, function( response ) {
|
243 |
+
try {
|
244 |
+
response = jQuery.parseJSON( response );
|
245 |
+
if ( response.status !== false ) {
|
246 |
+
jQuery( '#aj_notification' ).fadeIn( 'slow' ).html( 'Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>' );
|
247 |
+
} else {
|
248 |
+
console.log(response);
|
249 |
+
}
|
250 |
+
}
|
251 |
+
catch( err ) {
|
252 |
+
console.log( err );
|
253 |
+
}
|
254 |
+
});
|
255 |
+
} else {
|
256 |
+
var aj_gtmetrix_username = jQuery( '#aj_gtmetrix_username' ).val();
|
257 |
+
var aj_gtmetrix_api_key = jQuery( '#aj_gtmetrix_api_key' ).val();
|
258 |
+
var aj_gtmetrix_server = jQuery( '#aj_gtmetrix_server' ).val();
|
259 |
+
var isError = false;
|
260 |
+
if ( aj_gtmetrix_username == '' ) {
|
261 |
+
jQuery( '#aj_gtmetrix_username' ).addClass( 'aj_field_error' );
|
262 |
+
isError = true;
|
263 |
+
}
|
264 |
+
if ( aj_gtmetrix_api_key == '' ) {
|
265 |
+
jQuery( '#aj_gtmetrix_api_key' ).addClass( 'aj_field_error' );
|
266 |
+
isError = true;
|
267 |
+
}
|
268 |
+
if ( isError === false ) {
|
269 |
+
if ( theStep != 'aj_gtmetrix_test' ) {
|
270 |
+
jQuery( this ).hide();
|
271 |
+
jQuery( '#' + theStep ).show();
|
272 |
+
} else {
|
273 |
+
jQuery( '#aj_latest_please_wait' ).show();
|
274 |
+
}
|
275 |
+
aj_step( theStep );
|
276 |
+
} else {
|
277 |
+
return false;
|
278 |
+
}
|
279 |
+
}
|
280 |
+
});
|
281 |
+
|
282 |
+
jQuery( document ).on( 'change', 'input[type=radio][name=aj_step4_check]', function() {
|
283 |
+
var theSelection = jQuery( this ).val();
|
284 |
+
if ( theSelection == 'y' ) {
|
285 |
+
jQuery( '#aj_step4_y' ).show();
|
286 |
+
jQuery( '#aj_step4_n' ).hide();
|
287 |
+
} else {
|
288 |
+
jQuery( '#aj_step4_n' ).show();
|
289 |
+
jQuery( '#aj_step4_y' ).hide();
|
290 |
+
}
|
291 |
+
});
|
292 |
+
|
293 |
+
jQuery( document ).on( 'click', '.aj_dismiss', function() {
|
294 |
+
jQuery( '#aj_notification' ).fadeOut( 'slow' );
|
295 |
+
});
|
296 |
});
|
js/admin.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
function
|
1 |
+
function aj_step(e){var t=jQuery("#aj_gtmetrix_username").val(),a=jQuery("#aj_gtmetrix_api_key").val(),s=jQuery("#aj_gtmetrix_server").val();if("aj_step_results"==e){var r={action:"aj_steps",sub_action:e,site_url:aj_localize_admin.siteurl,aj_gtmetrix_username:t,aj_gtmetrix_api_key:a,aj_gtmetrix_server:s};jQuery.post(aj_localize_admin.ajaxurl,r,function(e){try{if(e=jQuery.parseJSON(e),e.status!==!1){var t=e.baseline_pagespeed,a=e.baseline_yslow,s=e.results.pagespeed_score,r=e.results.yslow_score,_=e.name,i=parseFloat(e.results.fully_loaded_time/1e3).toFixed(2),j=e.url;jQuery(".aj_gtmetrix_config").html(_),s>t?jQuery("#aj_gtmetrix_inde_pagespeed").html("an increase"):t>s?jQuery("#aj_gtmetrix_inde_pagespeed").html("a decrease"):jQuery("#aj_gtmetrix_inde_pagespeed").html("no change"),r>a?jQuery("#aj_gtmetrix_inde_yslow").html("an increase"):a>r?jQuery("#aj_gtmetrix_inde_yslow").html("a decrease"):jQuery("#aj_gtmetrix_inde_yslow").html("no change"),jQuery("#aj_gtmetrix_baseline_pagespeed").html(t+"%"),jQuery("#aj_gtmetrix_best_pagespeed").html(s+"%"),jQuery("#aj_gtmetrix_baseline_yslow").html(a+"%"),jQuery("#aj_gtmetrix_best_yslow").html(r+"%"),jQuery("#aj_gtmetrix_best_fullyloaded").html(i+"s"),jQuery("#aj_gtmetrix_best_url").attr("href",j).html(j),"aj_step2b"==e.id||"aj_step2c"==e.id?(jQuery("#aj_step4_jquery_excluded").hide(),jQuery("#aj_step4_jquery_not_excluded").show()):("aj_step2d"==e.id||"aj_step2e"==e.id)&&(jQuery("#aj_step4_jquery_excluded").show(),jQuery("#aj_step4_jquery_not_excluded").hide()),jQuery(".aj_gtmetrix_credits").html(e.credits),jQuery("#aj_step_results").show()}else console.log(e)}catch(l){console.log(l)}})}else{var r={action:"aj_steps",sub_action:e,site_url:aj_localize_admin.siteurl,aj_gtmetrix_username:t,aj_gtmetrix_api_key:a,aj_gtmetrix_server:s};jQuery.post(aj_localize_admin.ajaxurl,r,function(s){try{if(s=jQuery.parseJSON(s),s.status!==!1){var r=s.results.report_url+"/screenshot.jpg",_=s.results.pagespeed_score,i=s.results.yslow_score,j=parseFloat(s.results.fully_loaded_time/1e3).toFixed(2),l=Math.floor(s.results.page_bytes/1024),o=s.results.page_elements,u='<a href="'+s.results.report_url+'" target="_blank">'+s.results.report_url+"</a>",n=u.replace("https://","https://"+t+":"+a+"@"),p=s.name,y=s.url,d=255*(1-_/100),c=255*(1-i/100),m=255*(_/100),Q=255*(i/100),h="rgb("+Math.floor(d)+","+Math.floor(m)+",0 )",g="rgb("+Math.floor(c)+","+Math.floor(Q)+",0 )";"aj_gtmetrix_test"==e&&(e="aj_latest"),jQuery("#"+e+"_please_wait").hide(),jQuery("."+e+"_screenshot").attr("src",r),jQuery("."+e+"_pagespeed").html(_+"%").css({color:h}),jQuery("."+e+"_yslow").html(i+"%").css({color:g}),jQuery("."+e+"_flt").html(j+"s"),jQuery("."+e+"_tps").html(l+"KB"),jQuery("."+e+"_requests").html(o),jQuery("."+e+"_report").html(n),jQuery("#"+e+"_gtmetrix_results").show(),jQuery("."+e+"_gtmetrix").html(p),jQuery("."+e+"_url").attr("href",y).html(y),jQuery(".aj_gtmetrix_credits").html(s.credits),"aj_step2"==e?(jQuery("#aj_notification").fadeIn("slow").html('Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>'),jQuery("#aj_step2b").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2b").offset().top},1e3),aj_step("aj_step2b")):"aj_step2b"==e?(jQuery("#aj_step2c").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2c").offset().top},1e3),aj_step("aj_step2c")):"aj_step2c"==e?(jQuery("#aj_step2d").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2d").offset().top},1e3),aj_step("aj_step2d")):"aj_step2d"==e?(jQuery("#aj_step2e").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2e").offset().top},1e3),aj_step("aj_step2e")):"aj_step2e"==e?(jQuery("#aj_step_results").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step_results").offset().top},1e3),aj_step("aj_step_results")):"aj_latest"==e&&(jQuery("#aj_notification").fadeIn("slow").html('Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>'),jQuery("#aj_latest_gtmetrix_results").show(),jQuery("#aj_latest_please_wait").hide(),jQuery("html, body").animate({scrollTop:jQuery("#aj_latest_please_wait").offset().top},1e3))}else console.log(s)}catch(f){console.log(f)}})}}jQuery(document).ready(function(){jQuery(document).on("click",".aj-upgrade-notice .notice-dismiss",function(){var e=jQuery(".aj-upgrade-notice").attr("data-id");jQuery.ajax({url:aj.ajaxurl,data:{action:"async_javascript_dismiss_upgrade",notice_id:e}})}),jQuery(document).on("click",".aj_steps_button",function(e){e.preventDefault();var t=jQuery(this).attr("data-id");if("aj_goto_settings"==t){var a=aj_localize_admin.ajadminurl+"&tab=settings";window.location.href=a}else if("aj_apply_settings"==t||"aj_step2b_apply"==t||"aj_step2c_apply"==t||"aj_step2d_apply"==t||"aj_step2e_apply"==t){if("aj_apply_settings"!=t)var s=t.replace("_apply","");else{var s="";jQuery("#aj_notification").fadeIn("slow").html('Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>')}var r={action:"aj_steps",sub_action:"aj_apply_settings",settings:s,site_url:aj_localize_admin.siteurl};jQuery.post(aj_localize_admin.ajaxurl,r,function(e){try{e=jQuery.parseJSON(e),e.status!==!1?(jQuery("#aj_step5").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step5").offset().top},1e3),""!=s&&jQuery("#aj_notification").fadeIn("slow").html('Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>')):console.log(e)}catch(t){console.log(t)}})}else if("aj_save_settings"==t){if(jQuery("#aj_enabled").is(":checked"))var _=1;else var _=0;var i=jQuery("input[type=radio][name=aj_method]:checked").val(),j=jQuery("input[type=radio][name=aj_jquery]:checked").val(),l=jQuery("#aj_exclusions").val();if(jQuery("#aj_autoptimize_enabled").is(":visible"))if(jQuery("#aj_autoptimize_enabled").is(":checked"))var o=1,u=jQuery("input[type=radio][name=aj_autoptimize_method]:checked").val();else var o=0,u=jQuery("input[type=radio][name=aj_autoptimize_method]:checked").val();else var o=0,u="async";var r={action:"aj_steps",sub_action:"aj_save_settings",aj_enabled:_,aj_method:i,aj_jquery:j,aj_exclusions:l,aj_autoptimize_enabled:o,aj_autoptimize_method:u};jQuery.post(aj_localize_admin.ajaxurl,r,function(e){try{e=jQuery.parseJSON(e),e.status!==!1?jQuery("#aj_notification").fadeIn("slow").html('Settings Saved <span class="aj_dismiss"><a title="dismiss this notification">x</a></span>'):console.log(e)}catch(t){console.log(t)}})}else{var n=jQuery("#aj_gtmetrix_username").val(),p=jQuery("#aj_gtmetrix_api_key").val(),y=(jQuery("#aj_gtmetrix_server").val(),!1);if(""==n&&(jQuery("#aj_gtmetrix_username").addClass("aj_field_error"),y=!0),""==p&&(jQuery("#aj_gtmetrix_api_key").addClass("aj_field_error"),y=!0),y!==!1)return!1;"aj_gtmetrix_test"!=t?(jQuery(this).hide(),jQuery("#"+t).show()):jQuery("#aj_latest_please_wait").show(),aj_step(t)}}),jQuery(document).on("change","input[type=radio][name=aj_step4_check]",function(){var e=jQuery(this).val();"y"==e?(jQuery("#aj_step4_y").show(),jQuery("#aj_step4_n").hide()):(jQuery("#aj_step4_n").show(),jQuery("#aj_step4_y").hide())}),jQuery(document).on("click",".aj_dismiss",function(){jQuery("#aj_notification").fadeOut("slow")})});
|
lib/gtmetrix/class.Services_WTF_Test.php
ADDED
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Service_WTF_Test
|
5 |
+
*
|
6 |
+
* Version 0.4
|
7 |
+
*
|
8 |
+
* A PHP REST client for the Web Testing Framework (WTF) Testing Service API
|
9 |
+
* Currently only supports GTmetrix. See:
|
10 |
+
*
|
11 |
+
* http://gtmetrix.com/api/
|
12 |
+
*
|
13 |
+
* for more information on the API and how to contribute to the web testing
|
14 |
+
* framework!
|
15 |
+
*
|
16 |
+
* Copyright Gossamer Threads Inc. (http://gt.net/)
|
17 |
+
* License: http://opensource.org/licenses/GPL-2.0 GPL 2
|
18 |
+
*
|
19 |
+
* This software is free software distributed under the terms of the GNU
|
20 |
+
* General Public License 2.0.
|
21 |
+
*
|
22 |
+
* Changelog:
|
23 |
+
*
|
24 |
+
* 0.4
|
25 |
+
* - fixed download_resources bug
|
26 |
+
* - added $append parameter to download_resources
|
27 |
+
* - some refactoring for consistency
|
28 |
+
*
|
29 |
+
* 0.3
|
30 |
+
* - added download_resources method
|
31 |
+
*
|
32 |
+
* June 27, 2012
|
33 |
+
* - polling frequency in get_results() made less frantic
|
34 |
+
* - version changed to 0.2
|
35 |
+
*
|
36 |
+
* June 5, 2012
|
37 |
+
* - status method added
|
38 |
+
* - user_agent property updated
|
39 |
+
*
|
40 |
+
* January 23, 2012
|
41 |
+
* - Initial release
|
42 |
+
*/
|
43 |
+
|
44 |
+
class Services_WTF_Test {
|
45 |
+
const api_url = 'https://gtmetrix.com/api/0.1';
|
46 |
+
private $username = '';
|
47 |
+
private $password = '';
|
48 |
+
private $user_agent = 'Services_WTF_Test_php/0.4 (+http://gtmetrix.com/api/)';
|
49 |
+
protected $test_id = '';
|
50 |
+
protected $result = array( );
|
51 |
+
protected $error = '';
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Constructor
|
55 |
+
*
|
56 |
+
* $username string username to log in with
|
57 |
+
* $password string password/apikey to log in with
|
58 |
+
*/
|
59 |
+
public function __construct( $username = '', $password = '' ) {
|
60 |
+
$this->username = $username;
|
61 |
+
$this->password = $password;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function api_username( $username ) {
|
65 |
+
$this->username = $username;
|
66 |
+
}
|
67 |
+
|
68 |
+
public function api_password( $password ) {
|
69 |
+
$this->password = $password;
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* user_agent()
|
74 |
+
*
|
75 |
+
* $user_agent string in the form of "product name/version number" used to identify the application to the API
|
76 |
+
*
|
77 |
+
* Optional, defaults to "Services_WTF_Test_php/0.1 (+http://gtmetrix.com/api/)"
|
78 |
+
*/
|
79 |
+
public function user_agent( $user_agent ) {
|
80 |
+
$this->user_agent = $user_agent;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* query()
|
85 |
+
*
|
86 |
+
* Makes curl connection to API
|
87 |
+
*
|
88 |
+
* $command string command to send
|
89 |
+
* $req string GET|POST|DELETE request to send API
|
90 |
+
* $params array POST data if request is POST
|
91 |
+
*
|
92 |
+
* returns raw http data (JSON object in most API cases) on success, false otherwise
|
93 |
+
*/
|
94 |
+
protected function query( $command, $req = 'GET', $params = '' ) {
|
95 |
+
$ch = curl_init();
|
96 |
+
|
97 |
+
if ( substr( $command, 0, strlen( self::api_url ) - 1 ) == self::api_url ) {
|
98 |
+
$URL = $command;
|
99 |
+
} else {
|
100 |
+
$URL = self::api_url . '/' . $command;
|
101 |
+
}
|
102 |
+
|
103 |
+
curl_setopt( $ch, CURLOPT_URL, $URL );
|
104 |
+
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
105 |
+
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
|
106 |
+
curl_setopt( $ch, CURLOPT_USERAGENT, $this->user_agent );
|
107 |
+
curl_setopt( $ch, CURLOPT_USERPWD, $this->username . ":" . $this->password );
|
108 |
+
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $req );
|
109 |
+
// CURLOPT_SSL_VERIFYPEER turned off to avoid failure when cURL has no CA cert bundle: see http://curl.haxx.se/docs/sslcerts.html
|
110 |
+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
|
111 |
+
|
112 |
+
if ( $req == 'POST' )
|
113 |
+
curl_setopt( $ch, CURLOPT_POSTFIELDS, $params );
|
114 |
+
|
115 |
+
$results = curl_exec( $ch );
|
116 |
+
if ( $results === false )
|
117 |
+
$this->error = curl_error( $ch );
|
118 |
+
|
119 |
+
curl_close( $ch );
|
120 |
+
|
121 |
+
return $results;
|
122 |
+
}
|
123 |
+
|
124 |
+
protected function checkid() {
|
125 |
+
if ( empty( $this->test_id ) ) {
|
126 |
+
$this->error = 'No test_id! Please start a new test or load an existing test first.';
|
127 |
+
return false;
|
128 |
+
}
|
129 |
+
|
130 |
+
return true;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* error()
|
135 |
+
*
|
136 |
+
* Returns error message
|
137 |
+
*/
|
138 |
+
public function error() {
|
139 |
+
return $this->error;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* test()
|
144 |
+
*
|
145 |
+
* Sends new test to GTMetrix API
|
146 |
+
*
|
147 |
+
* $data array array containing parameters to send API
|
148 |
+
*
|
149 |
+
* returns the test_id on success, false otherwise;
|
150 |
+
*/
|
151 |
+
public function test( $data ) {
|
152 |
+
|
153 |
+
if ( empty( $data ) ) {
|
154 |
+
$this->error = 'Parameters need to be set to start a new test!';
|
155 |
+
return false;
|
156 |
+
}
|
157 |
+
|
158 |
+
if ( !isset( $data['url'] ) OR empty( $data['url'] ) ) {
|
159 |
+
$this->error = 'No URL given!';
|
160 |
+
return false;
|
161 |
+
}
|
162 |
+
|
163 |
+
// check URL
|
164 |
+
if ( !preg_match( '@^https?://@', $data['url'] ) ) {
|
165 |
+
$this->error = 'Bad URL.';
|
166 |
+
return false;
|
167 |
+
}
|
168 |
+
|
169 |
+
if ( !empty( $this->result ) )
|
170 |
+
$this->result = array( );
|
171 |
+
|
172 |
+
$data = http_build_query( $data );
|
173 |
+
|
174 |
+
$result = $this->query( 'test', 'POST', $data );
|
175 |
+
|
176 |
+
if ( $result != false ) {
|
177 |
+
$result = json_decode( $result, true );
|
178 |
+
if ( empty( $result['error'] ) ) {
|
179 |
+
$this->test_id = $result['test_id'];
|
180 |
+
|
181 |
+
if ( isset( $result['state'] ) AND !empty( $result['state'] ) )
|
182 |
+
$this->result = $result;
|
183 |
+
|
184 |
+
return $this->test_id;
|
185 |
+
} else {
|
186 |
+
$this->error = $result['error'];
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
return false;
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* load()
|
195 |
+
*
|
196 |
+
* Query an existing test from GTMetrix API
|
197 |
+
*
|
198 |
+
* $test_id string The existing test's test ID
|
199 |
+
*
|
200 |
+
* test_id must be valid, or else all query methods will fail
|
201 |
+
*/
|
202 |
+
public function load( $test_id ) {
|
203 |
+
$this->test_id = $test_id;
|
204 |
+
|
205 |
+
if ( !empty( $this->result ) )
|
206 |
+
$this->result = array( );
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* delete()
|
211 |
+
*
|
212 |
+
* Delete the test from the GTMetrix database
|
213 |
+
*
|
214 |
+
* Precondition: member test_id is not empty
|
215 |
+
*
|
216 |
+
* returns message on success, false otherwise
|
217 |
+
*/
|
218 |
+
public function delete() {
|
219 |
+
if ( !$this->checkid() )
|
220 |
+
return false;
|
221 |
+
|
222 |
+
$command = "test/" . $this->test_id;
|
223 |
+
|
224 |
+
$result = $this->query( $command, "DELETE" );
|
225 |
+
if ( $result != false ) {
|
226 |
+
$result = json_decode( $result, true );
|
227 |
+
return ($result['message']) ? true : false;
|
228 |
+
}
|
229 |
+
|
230 |
+
return false;
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* get_test_id()
|
235 |
+
*
|
236 |
+
* Returns the test_id, false if test_id is not set
|
237 |
+
*/
|
238 |
+
public function get_test_id() {
|
239 |
+
return ($this->test_id) ? $this->test_id : false;
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* poll_state()
|
244 |
+
*
|
245 |
+
* polls the state of the test
|
246 |
+
*
|
247 |
+
* Precondition: member test_id is not empty
|
248 |
+
*
|
249 |
+
* The class will save a copy of the state object,
|
250 |
+
* which contains information such as the test results and resource urls (or nothing if an error occured)
|
251 |
+
* so that additional queries to the API is not required.
|
252 |
+
*
|
253 |
+
* returns true on successful poll, or false on network error or no test_id
|
254 |
+
*/
|
255 |
+
public function poll_state() {
|
256 |
+
if ( !$this->checkid() )
|
257 |
+
return false;
|
258 |
+
|
259 |
+
if ( !empty( $this->result ) ) {
|
260 |
+
if ( $this->result['state'] == "completed" )
|
261 |
+
return true;
|
262 |
+
}
|
263 |
+
|
264 |
+
$command = "test/" . $this->test_id;
|
265 |
+
|
266 |
+
$result = $this->query( $command );
|
267 |
+
if ( $result != false ) {
|
268 |
+
$result = json_decode( $result, true );
|
269 |
+
|
270 |
+
if ( !empty( $result['error'] ) AND !isset( $result['state'] ) ) {
|
271 |
+
$this->error = $result['error'];
|
272 |
+
return false;
|
273 |
+
}
|
274 |
+
|
275 |
+
$this->result = $result;
|
276 |
+
if ( $result['state'] == 'error' )
|
277 |
+
$this->error = $result['error'];
|
278 |
+
|
279 |
+
return true;
|
280 |
+
}
|
281 |
+
|
282 |
+
return false;
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* state()
|
287 |
+
*
|
288 |
+
* Returns the state of the test (queued, started, completed, error)
|
289 |
+
*
|
290 |
+
* Precondition: member test_id is not empty
|
291 |
+
*
|
292 |
+
* returns the state of the test, or false on networking error
|
293 |
+
*/
|
294 |
+
public function state() {
|
295 |
+
if ( !$this->checkid() )
|
296 |
+
return false;
|
297 |
+
|
298 |
+
if ( empty( $this->result ) )
|
299 |
+
return false;
|
300 |
+
|
301 |
+
return $this->result['state'];
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* completed()
|
306 |
+
*
|
307 |
+
* returns true if the test is complete, false otherwise
|
308 |
+
*/
|
309 |
+
public function completed() {
|
310 |
+
return ($this->state() == 'completed') ? true : false;
|
311 |
+
}
|
312 |
+
|
313 |
+
/*
|
314 |
+
* get_results()
|
315 |
+
*
|
316 |
+
* locks and polls API until test results are received
|
317 |
+
* waits for 6 seconds before first check, then polls every 2 seconds
|
318 |
+
* at the 30 second mark it reduces frequency to 5 seconds
|
319 |
+
*/
|
320 |
+
|
321 |
+
public function get_results() {
|
322 |
+
sleep( 6 );
|
323 |
+
$i = 1;
|
324 |
+
while ( $this->poll_state() ) {
|
325 |
+
if ( $this->state() == 'completed' OR $this->state() == 'error' )
|
326 |
+
break;
|
327 |
+
sleep( $i++ <= 13 ? 2 : 5 );
|
328 |
+
}
|
329 |
+
}
|
330 |
+
|
331 |
+
/**
|
332 |
+
* locations()
|
333 |
+
*
|
334 |
+
* Returns a list of GTMetrix server locations accompanied by their location IDs
|
335 |
+
* that can be used in newTest() to select a different server location for testing
|
336 |
+
*
|
337 |
+
* returns the location list in array format, the error message if an error occured,
|
338 |
+
* or false if a query error occured.
|
339 |
+
*/
|
340 |
+
public function locations() {
|
341 |
+
$result = $this->query( 'locations' );
|
342 |
+
if ( $result != false ) {
|
343 |
+
$result = json_decode( $result, true );
|
344 |
+
if ( empty( $result['error'] ) ) {
|
345 |
+
return $result;
|
346 |
+
} else {
|
347 |
+
$this->error = $result['error'];
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
+
return false;
|
352 |
+
}
|
353 |
+
|
354 |
+
/**
|
355 |
+
* results()
|
356 |
+
*
|
357 |
+
* Get test results
|
358 |
+
*
|
359 |
+
* returns the test results, or false if the test hasn't completed yet
|
360 |
+
*/
|
361 |
+
public function results() {
|
362 |
+
if ( !$this->completed() )
|
363 |
+
return false;
|
364 |
+
|
365 |
+
return $this->result['results'];
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* resources()
|
370 |
+
*
|
371 |
+
* Get test resource URLs
|
372 |
+
*
|
373 |
+
* returns the test resources, or false if the test hasn't completed yet
|
374 |
+
*/
|
375 |
+
public function resources( $item = 'all' ) {
|
376 |
+
if ( !$this->completed() )
|
377 |
+
return false;
|
378 |
+
|
379 |
+
return $this->result['resources'];
|
380 |
+
}
|
381 |
+
|
382 |
+
/**
|
383 |
+
* fetch_resources()
|
384 |
+
*
|
385 |
+
* Downloads test resources to a specified location
|
386 |
+
*
|
387 |
+
* $items string/array item(s) to download (empty or null will result in all resources downloading)
|
388 |
+
* $location string location to download to
|
389 |
+
*
|
390 |
+
* returns true if successful, the error message if an error occured
|
391 |
+
*/
|
392 |
+
public function download_resources( $items = null, $location = './', $append_test_id = false ) {
|
393 |
+
|
394 |
+
if ( !$this->completed() )
|
395 |
+
return false;
|
396 |
+
|
397 |
+
$resources = $this->result['resources'];
|
398 |
+
$resource_types = array(
|
399 |
+
'report_pdf' => 'pdf',
|
400 |
+
'pagespeed' => 'txt',
|
401 |
+
'har' => 'txt',
|
402 |
+
'pagespeed_files' => 'tar',
|
403 |
+
'yslow' => 'txt',
|
404 |
+
'screenshot' => 'jpg',
|
405 |
+
);
|
406 |
+
|
407 |
+
if ( !$items or $items == '' ) {
|
408 |
+
$items = array_keys( $resource_types );
|
409 |
+
}
|
410 |
+
|
411 |
+
if ( !is_array( $items ) ) {
|
412 |
+
$items = array( $items );
|
413 |
+
}
|
414 |
+
|
415 |
+
if ( !is_writable( $location ) ) {
|
416 |
+
$this->error = 'Permission denied in ' . $location;
|
417 |
+
return false;
|
418 |
+
}
|
419 |
+
|
420 |
+
foreach ( $items as $item ) {
|
421 |
+
|
422 |
+
if ( !array_key_exists( $item, $resources ) ) {
|
423 |
+
$this->error = $item . ' does not exist';
|
424 |
+
return false;
|
425 |
+
}
|
426 |
+
|
427 |
+
$file = fopen( $location . $item . ($append_test_id ? '-' . $this->test_id : '') . '.' . $resource_types[$item], "w" );
|
428 |
+
|
429 |
+
$ch = curl_init();
|
430 |
+
curl_setopt( $ch, CURLOPT_URL, $resources[$item] );
|
431 |
+
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
432 |
+
curl_setopt( $ch, CURLOPT_FILE, $file );
|
433 |
+
curl_setopt( $ch, CURLOPT_HEADER, 0 );
|
434 |
+
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
|
435 |
+
curl_setopt( $ch, CURLOPT_USERAGENT, $this->user_agent );
|
436 |
+
curl_setopt( $ch, CURLOPT_USERPWD, $this->username . ":" . $this->password );
|
437 |
+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
|
438 |
+
|
439 |
+
$results = curl_exec( $ch );
|
440 |
+
if ( $results === false )
|
441 |
+
$this->error = curl_error( $ch );
|
442 |
+
|
443 |
+
curl_close( $ch );
|
444 |
+
}
|
445 |
+
return true;
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* status()
|
450 |
+
*
|
451 |
+
* Get account status
|
452 |
+
*
|
453 |
+
* returns credits remaining, and timestamp of next top-up
|
454 |
+
*/
|
455 |
+
public function status() {
|
456 |
+
$result = $this->query( 'status' );
|
457 |
+
if ( $result != false ) {
|
458 |
+
$result = json_decode( $result, true );
|
459 |
+
if ( empty( $result['error'] ) ) {
|
460 |
+
return $result;
|
461 |
+
} else {
|
462 |
+
$this->error = $result['error'];
|
463 |
+
}
|
464 |
+
}
|
465 |
+
return false;
|
466 |
+
}
|
467 |
+
|
468 |
+
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: (cloughit)
|
|
3 |
Donate link: http://www.cloughit.com.au/donate/ (coming soon)
|
4 |
Tags: async,javascript,google,pagespeed,js,speed,performance,boost,render,blocking,above-the-fold
|
5 |
Requires at least: 2.8
|
6 |
-
Tested up to: 4.7.
|
7 |
-
Stable tag:
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,28 +12,33 @@ Async JavaScript adds a 'async' or 'defer' attribute to JavaScripts loaded via w
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
|
21 |
<em>Want more control? </em><strong>Async JavaScript Pro</strong> allows you to:
|
22 |
|
23 |
-
* Selective
|
24 |
-
* Selective
|
25 |
-
* Exclude individual scripts
|
26 |
-
* Exclude plugins
|
|
|
27 |
|
28 |
<a href="http://cloughit.com.au/product/async-javascript-pro/" target="_blank">Read more...</a>
|
29 |
|
30 |
== Installation ==
|
31 |
|
32 |
-
Just install from your WordPress "Plugins | Add New" screen and all will be well. Manual installation is very
|
33 |
|
34 |
1. Upload the zip-file and unzip it in the /wp-content/plugins/ directory
|
35 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
36 |
-
3. Go to `Async JavaScript` menu to load setings page
|
37 |
|
38 |
== Frequently Asked Questions ==
|
39 |
|
@@ -47,19 +52,43 @@ The 'async' attribute is new in HTML5. It is supported by the following browsers
|
|
47 |
* Safari
|
48 |
* Opera
|
49 |
|
50 |
-
= Where can I
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
|
56 |
-
= What
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
= I want out, how should I remove Async JavaScript? =
|
65 |
|
@@ -72,6 +101,12 @@ Coming soon!
|
|
72 |
|
73 |
== Changelog ==
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
= 1.17.02.06 =
|
76 |
|
77 |
* FIX: Remove variable notice
|
3 |
Donate link: http://www.cloughit.com.au/donate/ (coming soon)
|
4 |
Tags: async,javascript,google,pagespeed,js,speed,performance,boost,render,blocking,above-the-fold
|
5 |
Requires at least: 2.8
|
6 |
+
Tested up to: 4.7.4
|
7 |
+
Stable tag: 2.17.04.25
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
When a JavaScript file is loaded via the wp_enqueue_script function, Async JavaScript will add an async or defer attribute.
|
16 |
|
17 |
+
There are several ways an external JavaScript file can be executed:
|
18 |
|
19 |
+
* If async is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)
|
20 |
+
* If defer is present and async is not present: The script is executed when the page has finished parsing
|
21 |
+
* If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page
|
22 |
+
|
23 |
+
Using async or defer helps to eliminate render-blocking JavaScript in above-the-fold content. This can also help to increase your pagespeed which in turn can assist in improving your page ranking.
|
24 |
|
25 |
<em>Want more control? </em><strong>Async JavaScript Pro</strong> allows you to:
|
26 |
|
27 |
+
* Selective ‘async’ – choose which JavaScripts to apply ‘async’ to
|
28 |
+
* Selective ‘defer’ – choose which JavaScripts to apply ‘defer’ to
|
29 |
+
* Exclude individual scripts – choose which JavaScripts to ignore
|
30 |
+
* Exclude plugins – choose local plugin JavaScripts to ignore
|
31 |
+
* Exclude themes – choose local theme JavaScripts to ignore
|
32 |
|
33 |
<a href="http://cloughit.com.au/product/async-javascript-pro/" target="_blank">Read more...</a>
|
34 |
|
35 |
== Installation ==
|
36 |
|
37 |
+
Just install from your WordPress "Plugins | Add New" screen and all will be well. Manual installation is very straight forward as well:
|
38 |
|
39 |
1. Upload the zip-file and unzip it in the /wp-content/plugins/ directory
|
40 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
41 |
+
3. Go to `Settings` - `Async JavaScript` menu to load setings page
|
42 |
|
43 |
== Frequently Asked Questions ==
|
44 |
|
52 |
* Safari
|
53 |
* Opera
|
54 |
|
55 |
+
= Where can I get help? =
|
56 |
+
|
57 |
+
Async JavaScript is supported exclusively via our Support Ticketing System at <a href="https://cloughit.com.au/support/?wpsc_category=8">https://cloughit.com.au/support/</a>
|
58 |
+
|
59 |
+
= What support do you provide? =
|
60 |
+
|
61 |
+
We will provide support for any functionality of the Async JavaScript plugin itself, suggestions for theme / plugin support and suggestions on how Async JavaScript could be improved.
|
62 |
+
|
63 |
+
= What support don't you provide? =
|
64 |
+
|
65 |
+
We will not provide support for questions such as 'Why is Async JavaScript not making any improvement on my site?'. If you need this level of support we offer a bundled Async JavaScript Pro plus Installation & Configuration (homepage only) AUD $155.00 (<a href="https://cloughit.com.au/product/async-javascript-pro-plus-install/">buy now!</a>)
|
66 |
+
|
67 |
+
= Can I use the WordPress Forums to get support for Async JavaScript? =
|
68 |
+
|
69 |
+
No. Support is provided via our Support Ticketing System at <a href="https://cloughit.com.au/support/?wpsc_category=8">https://cloughit.com.au/support/</a>
|
70 |
|
71 |
+
= Can I email the author directly to get support for Async JavaScript? =
|
72 |
|
73 |
+
No. Support is provided via our Support Ticketing System at <a href="https://cloughit.com.au/support/?wpsc_category=8">https://cloughit.com.au/support/</a>
|
74 |
|
75 |
+
= What about CSS? =
|
76 |
|
77 |
+
As the name implies, Async JavaScript is built to enhance JavaScript loading only. Async JavaScript does not have any impact on CSS.
|
78 |
+
|
79 |
+
We recommend using the awesome <a href="https://wordpress.org/plugins/autoptimize/">Autoptimize</a> plugin alongside Async JavaScript for CSS optimization.
|
80 |
+
|
81 |
+
= Do you have a pro version? =
|
82 |
+
|
83 |
+
Yes we do! Here are some of the benefits of Async JavaScript Pro:
|
84 |
+
|
85 |
+
* Selective ‘async’ – choose which JavaScripts to apply ‘async’ to
|
86 |
+
* Selective ‘defer’ – choose which JavaScripts to apply ‘defer’ to
|
87 |
+
* Exclude individual scripts – choose which JavaScripts to ignore
|
88 |
+
* Exclude plugins – choose local plugin JavaScripts to ignore
|
89 |
+
* Exclude themes – choose local theme JavaScripts to ignore
|
90 |
+
|
91 |
+
<a href="https://cloughit.com.au/product/async-javascript-pro/">Buy Now!</a>
|
92 |
|
93 |
= I want out, how should I remove Async JavaScript? =
|
94 |
|
101 |
|
102 |
== Changelog ==
|
103 |
|
104 |
+
= 2.17.04.25 =
|
105 |
+
|
106 |
+
* massive Massive MASSIVE rewrite of Async JavaScript!!!
|
107 |
+
* Now includes a setup Wizard, Status page, Settings page and a help page.
|
108 |
+
* Communicates directly with GTmetrix (account required)
|
109 |
+
|
110 |
= 1.17.02.06 =
|
111 |
|
112 |
* FIX: Remove variable notice
|