Version Description
- extra security measure; check the nonce when saving settings/ going through wizard.
- wizard: if something fails then communicate this onscreen instead of on the console.
- autoptimize integration: change copy to explain this might or might not be helpful.
Download this release
Release Info
Developer | futtta |
Plugin | Async JavaScript |
Version | 2.20.03.01 |
Comparing to | |
See all releases |
Code changes from version 2.20.02.27 to 2.20.03.01
- async-javascript.php +1 -1
- asyncjsAllAjax.php +2 -2
- asyncjsBackendClass.php +4 -1
- asyncjsSettingsScreens.php +3 -3
- js/admin.js +14 -5
- js/admin.min.js +1 -1
- readme.txt +7 -1
async-javascript.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Async JavaScript
|
4 |
* Plugin URI: https://autoptimize.com/
|
5 |
* Description: Async JavaScript gives you full control of which scripts to add a 'async' or 'defer' attribute to or to exclude to help increase the performance of your WordPress website
|
6 |
-
* Version: 2.20.
|
7 |
* Author: Frank Goossens (futtta)
|
8 |
* Author URI: https://autoptimize.com/
|
9 |
* Text Domain: async-javascript
|
3 |
* Plugin Name: Async JavaScript
|
4 |
* Plugin URI: https://autoptimize.com/
|
5 |
* Description: Async JavaScript gives you full control of which scripts to add a 'async' or 'defer' attribute to or to exclude to help increase the performance of your WordPress website
|
6 |
+
* Version: 2.20.03.01
|
7 |
* Author: Frank Goossens (futtta)
|
8 |
* Author URI: https://autoptimize.com/
|
9 |
* Text Domain: async-javascript
|
asyncjsAllAjax.php
CHANGED
@@ -9,10 +9,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
9 |
*/
|
10 |
|
11 |
$aj_gtmetrix_results = get_option( 'aj_gtmetrix_results', array() );
|
12 |
-
if ( ! isset( $_POST['sub_action'] ) || ! current_user_can( 'manage_options' ) ) {
|
13 |
$return = array(
|
14 |
'status' => false,
|
15 |
-
'error' => 'No sub action defined.'
|
16 |
);
|
17 |
} else {
|
18 |
$sub_action = sanitize_text_field( $_POST['sub_action'] );
|
9 |
*/
|
10 |
|
11 |
$aj_gtmetrix_results = get_option( 'aj_gtmetrix_results', array() );
|
12 |
+
if ( ! isset( $_POST['sub_action'] ) || ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'aj_nonce', 'security', false ) ) {
|
13 |
$return = array(
|
14 |
'status' => false,
|
15 |
+
'error' => 'No sub action defined or security issue.'
|
16 |
);
|
17 |
} else {
|
18 |
$sub_action = sanitize_text_field( $_POST['sub_action'] );
|
asyncjsBackendClass.php
CHANGED
@@ -17,7 +17,7 @@ class AsyncJavaScriptBackend {
|
|
17 |
define( 'AJ_ADMIN_URL', trailingslashit( admin_url() ) );
|
18 |
define( 'AJ_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
19 |
define( 'AJ_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
20 |
-
define( 'AJ_VERSION', '2.
|
21 |
define( 'AJ_UA', 'Async JavaScript/' . AJ_VERSION . ' (+https://autoptimize.com/)' );
|
22 |
add_filter( 'plugin_action_links_'.plugin_basename( 'async-javascript/async-javascript.php' ), array( $this, 'setmeta' ), 10, 2 );
|
23 |
add_action( 'plugins_loaded', array( $this, 'aj_admin_init' ) );
|
@@ -152,6 +152,9 @@ class AsyncJavaScriptBackend {
|
|
152 |
// upgrade from 2.18.06.13, enable aj for logged users & checkout/ cart to ensure non-regression
|
153 |
update_option( 'aj_enabled_logged', 1 );
|
154 |
update_option( 'aj_enabled_shop', 1 );
|
|
|
|
|
|
|
155 |
}
|
156 |
|
157 |
if ( $aj_version != AJ_VERSION ) {
|
17 |
define( 'AJ_ADMIN_URL', trailingslashit( admin_url() ) );
|
18 |
define( 'AJ_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
19 |
define( 'AJ_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
20 |
+
define( 'AJ_VERSION', '2.20.03.01' );
|
21 |
define( 'AJ_UA', 'Async JavaScript/' . AJ_VERSION . ' (+https://autoptimize.com/)' );
|
22 |
add_filter( 'plugin_action_links_'.plugin_basename( 'async-javascript/async-javascript.php' ), array( $this, 'setmeta' ), 10, 2 );
|
23 |
add_action( 'plugins_loaded', array( $this, 'aj_admin_init' ) );
|
152 |
// upgrade from 2.18.06.13, enable aj for logged users & checkout/ cart to ensure non-regression
|
153 |
update_option( 'aj_enabled_logged', 1 );
|
154 |
update_option( 'aj_enabled_shop', 1 );
|
155 |
+
} else if ( $aj_version < '2.20.03.01' ) {
|
156 |
+
// reset gtmetrix API key which *could* have been used to inject malicious JavaScript.
|
157 |
+
update_option( 'aj_gtmetrix_api_key', '');
|
158 |
}
|
159 |
|
160 |
if ( $aj_version != AJ_VERSION ) {
|
asyncjsSettingsScreens.php
CHANGED
@@ -162,14 +162,14 @@ echo $output;
|
|
162 |
?>
|
163 |
<div class="aj_plugin">
|
164 |
<h4><?php _e('Plugin: Autoptimize', 'async-javascript'); ?></h4>
|
165 |
-
<p><a href="https://wordpress.org/plugins/autoptimize/" target="_blank">https://wordpress.org/plugins/autoptimize/</a></p>
|
166 |
<p>
|
167 |
-
<label><?php _e('Enable Autoptimize Support:', 'async-javascript'); ?> </label>
|
168 |
<input type="checkbox" id="aj_autoptimize_enabled" value="1" <?php echo $aj_autoptimize_enabled_checked; ?> />
|
169 |
</p>
|
170 |
<p>
|
171 |
-
<label><?php _e('
|
172 |
<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
|
|
|
173 |
</p>
|
174 |
</div>
|
175 |
<?php
|
162 |
?>
|
163 |
<div class="aj_plugin">
|
164 |
<h4><?php _e('Plugin: Autoptimize', 'async-javascript'); ?></h4>
|
|
|
165 |
<p>
|
166 |
+
<label><?php _e('Enable Autoptimize Support to allow you to override AO\'s default "defer" flag (see below):', 'async-javascript'); ?> </label>
|
167 |
<input type="checkbox" id="aj_autoptimize_enabled" value="1" <?php echo $aj_autoptimize_enabled_checked; ?> />
|
168 |
</p>
|
169 |
<p>
|
170 |
+
<label><?php _e('Autoptimize Javascript Method:', 'async-javascript'); ?> </label>
|
171 |
<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
|
172 |
+
<div><?php _e('If Async Javascripts is set to "async" you can try changing Autoptimize\'s Javascript Method to "async" as well. This might help improving performance, but on the other hand might break things, so test to see if this is useful.', 'async-javascript'); ?></div>
|
173 |
</p>
|
174 |
</div>
|
175 |
<?php
|
js/admin.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
/* globals aj_localize_admin,jQuery */
|
2 |
/* eslint no-console: 1 */
|
3 |
// updated:
|
4 |
-
//
|
5 |
function notifySettingsSaved() {
|
6 |
jQuery("#aj_notification").
|
7 |
fadeIn("slow").
|
@@ -10,6 +10,15 @@ function notifySettingsSaved() {
|
|
10 |
fadeOut("slow");
|
11 |
}
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
function aj_step(theStep) {
|
14 |
var aj_nonce = jQuery("#aj_nonce").val();
|
15 |
var aj_gtmetrix_username = jQuery("#aj_gtmetrix_username").val();
|
@@ -69,10 +78,10 @@ function aj_step(theStep) {
|
|
69 |
jQuery(".aj_gtmetrix_credits").html(response.credits);
|
70 |
jQuery("#aj_step_results").show();
|
71 |
} else {
|
72 |
-
|
73 |
}
|
74 |
} catch (err) {
|
75 |
-
|
76 |
}
|
77 |
});
|
78 |
} else {
|
@@ -188,10 +197,10 @@ function aj_step(theStep) {
|
|
188 |
);
|
189 |
}
|
190 |
} else {
|
191 |
-
|
192 |
}
|
193 |
} catch (err) {
|
194 |
-
|
195 |
}
|
196 |
});
|
197 |
}
|
1 |
/* globals aj_localize_admin,jQuery */
|
2 |
/* eslint no-console: 1 */
|
3 |
// updated:
|
4 |
+
// 2020-02-01 12:04:00
|
5 |
function notifySettingsSaved() {
|
6 |
jQuery("#aj_notification").
|
7 |
fadeIn("slow").
|
10 |
fadeOut("slow");
|
11 |
}
|
12 |
|
13 |
+
function log_error(err) {
|
14 |
+
if ( err.error ) {
|
15 |
+
aj_error = err.error;
|
16 |
+
} else {
|
17 |
+
aj_error = JSON.stringify(err);
|
18 |
+
}
|
19 |
+
jQuery('div.aj_loader').replaceWith("<h2 style='color:red'>Error: " + aj_error + "</h2>");
|
20 |
+
}
|
21 |
+
|
22 |
function aj_step(theStep) {
|
23 |
var aj_nonce = jQuery("#aj_nonce").val();
|
24 |
var aj_gtmetrix_username = jQuery("#aj_gtmetrix_username").val();
|
78 |
jQuery(".aj_gtmetrix_credits").html(response.credits);
|
79 |
jQuery("#aj_step_results").show();
|
80 |
} else {
|
81 |
+
log_error(response);
|
82 |
}
|
83 |
} catch (err) {
|
84 |
+
log_error(err);
|
85 |
}
|
86 |
});
|
87 |
} else {
|
197 |
);
|
198 |
}
|
199 |
} else {
|
200 |
+
log_error(response);
|
201 |
}
|
202 |
} catch (err) {
|
203 |
+
log_error(err);
|
204 |
}
|
205 |
});
|
206 |
}
|
js/admin.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
function notifySettingsSaved(){jQuery("#aj_notification").fadeIn("slow").html(
|
1 |
+
function notifySettingsSaved(){jQuery("#aj_notification").fadeIn("slow").html("Settings Saved <span class=\"aj_dismiss\"><a title=\"dismiss this notification\">x</a></span>").delay(500).fadeOut("slow")}function log_error(a){aj_error=a.error?a.error:JSON.stringify(a),jQuery("div.aj_loader").replaceWith("<h2 style='color:red'>Error: "+aj_error+"</h2>")}function aj_step(a){var b=jQuery("#aj_nonce").val(),c=jQuery("#aj_gtmetrix_username").val(),d=jQuery("#aj_gtmetrix_api_key").val(),e=jQuery("#aj_gtmetrix_server").val(),f={action:"aj_steps",sub_action:a,site_url:aj_localize_admin.siteurl,aj_gtmetrix_username:c,aj_gtmetrix_api_key:d,aj_gtmetrix_server:e,security:b};"aj_step_results"==a?jQuery.post(aj_localize_admin.ajaxurl,f,function(a){try{if(a=jQuery.parseJSON(a),!1!==a.status){var b=a.baseline_pagespeed,c=a.baseline_yslow,d=a.results.pagespeed_score,e=a.results.yslow_score,f=a.name,g=parseFloat(a.results.fully_loaded_time/1e3).toFixed(2),h=a.url;jQuery(".aj_gtmetrix_config").html(f),d>b?jQuery("#aj_gtmetrix_inde_pagespeed").html("an increase"):d<b?jQuery("#aj_gtmetrix_inde_pagespeed").html("a decrease"):jQuery("#aj_gtmetrix_inde_pagespeed").html("no change"),e>c?jQuery("#aj_gtmetrix_inde_yslow").html("an increase"):e<c?jQuery("#aj_gtmetrix_inde_yslow").html("a decrease"):jQuery("#aj_gtmetrix_inde_yslow").html("no change"),jQuery("#aj_gtmetrix_baseline_pagespeed").html(b+"%"),jQuery("#aj_gtmetrix_best_pagespeed").html(d+"%"),jQuery("#aj_gtmetrix_baseline_yslow").html(c+"%"),jQuery("#aj_gtmetrix_best_yslow").html(e+"%"),jQuery("#aj_gtmetrix_best_fullyloaded").html(g+"s"),jQuery("#aj_gtmetrix_best_url").attr("href",h).html(h),"aj_step2b"==a.id||"aj_step2c"==a.id?(jQuery("#aj_step4_jquery_excluded").hide(),jQuery("#aj_step4_jquery_not_excluded").show()):("aj_step2d"==a.id||"aj_step2e"==a.id)&&(jQuery("#aj_step4_jquery_excluded").show(),jQuery("#aj_step4_jquery_not_excluded").hide()),jQuery(".aj_gtmetrix_credits").html(a.credits),jQuery("#aj_step_results").show()}else log_error(a)}catch(a){log_error(a)}}):jQuery.post(aj_localize_admin.ajaxurl,f,function(b){try{if(b=jQuery.parseJSON(b),!1!==b.status){var e=b.results.report_url+"/screenshot.jpg",f=b.results.pagespeed_score,g=b.results.yslow_score,h=parseFloat(b.results.fully_loaded_time/1e3).toFixed(2),i=Math.floor(b.results.page_bytes/1024);1024<i?i=i/1024+"MB":i+="KB";var j=b.results.page_elements,k="<a href=\""+b.results.report_url+"\" target=\"_blank\">"+b.results.report_url+"</a>",l=k.replace("https://","https://"+c+":"+d+"@"),m=b.name,n=b.url,o="rgb("+Math.floor(255*(1-f/100))+","+Math.floor(255*(f/100))+",0 )",p="rgb("+Math.floor(255*(1-g/100))+","+Math.floor(255*(g/100))+",0 )";"aj_gtmetrix_test"==a&&(a="aj_latest"),jQuery("#"+a+"_please_wait").hide(),jQuery("."+a+"_screenshot").attr("src",e),jQuery("."+a+"_pagespeed").html(f+"%").css({color:o}),jQuery("."+a+"_yslow").html(g+"%").css({color:p}),jQuery("."+a+"_flt").html(h+"s"),jQuery("."+a+"_tps").html(i),jQuery("."+a+"_requests").html(j),jQuery("."+a+"_report").html(l),jQuery("#"+a+"_gtmetrix_results").show(),jQuery("."+a+"_gtmetrix").html(m),jQuery("."+a+"_url").attr("href",n).html(n),jQuery(".aj_gtmetrix_credits").html(b.credits),"aj_step2"==a?(notifySettingsSaved(),jQuery("#aj_step2b").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2b").offset().top},1e3),aj_step("aj_step2b")):"aj_step2b"==a?(jQuery("#aj_step2c").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2c").offset().top},1e3),aj_step("aj_step2c")):"aj_step2c"==a?(jQuery("#aj_step2d").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2d").offset().top},1e3),aj_step("aj_step2d")):"aj_step2d"==a?(jQuery("#aj_step2e").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step2e").offset().top},1e3),aj_step("aj_step2e")):"aj_step2e"==a?(jQuery("#aj_step_results").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step_results").offset().top},1e3),aj_step("aj_step_results")):"aj_latest"==a&&(notifySettingsSaved(),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 log_error(b)}catch(a){log_error(a)}})}jQuery(document).ready(function(){"function"==typeof jQuery(".aj_chosen").chosen&&jQuery(".aj_chosen").chosen(),jQuery("#aj_enabled").change(function(){this.checked?jQuery(".aj_enabled_sub").show("slow"):jQuery(".aj_enabled_sub:visible").hide("slow")}),jQuery(document).on("click",".aj_steps_button",function(a){a.preventDefault();var b=jQuery("#aj_nonce").val(),c=jQuery(this).attr("data-id"),d=c.replace("_apply",""),e=1;if("aj_goto_settings"==c){var f=aj_localize_admin.ajadminurl+"&tab=settings";window.location.href=f}else if("aj_apply_settings"==c||"aj_step2b_apply"==c||"aj_step2c_apply"==c||"aj_step2d_apply"==c||"aj_step2e_apply"==c){"aj_apply_settings"==c?(d="",notifySettingsSaved()):d=c.replace("_apply","");var g={action:"aj_steps",sub_action:"aj_apply_settings",settings:d,site_url:aj_localize_admin.siteurl,security:b};jQuery.post(aj_localize_admin.ajaxurl,g,function(a){try{if(a=jQuery.parseJSON(a),!1===a.status)console.log(a);else if(jQuery("#aj_step4").length)jQuery("#aj_step5").show(),jQuery("html, body").animate({scrollTop:jQuery("#aj_step5").offset().top},1e3),""!=d&¬ifySettingsSaved();else if(""!=d){notifySettingsSaved();var b=aj_localize_admin.ajadminurl+"&tab=settings";window.location.href=b}}catch(a){console.log(a)}})}else if("aj_save_settings"==c){e=jQuery("#aj_enabled").is(":checked")?1:0,aj_enabled_logged=jQuery("#aj_enabled_logged").is(":checked")?1:0,aj_enabled_shop=jQuery("#aj_enabled_shop").is(":checked")?1:0;var h=jQuery("input[type=radio][name=aj_method]:checked").val(),i=jQuery("input[type=radio][name=aj_jquery]:checked").val(),j=jQuery("#aj_async").val(),k=jQuery("#aj_defer").val(),l=jQuery("#aj_exclusions").val(),m=jQuery("#aj_plugin_exclusions").chosen().val(),n=jQuery("#aj_theme_exclusions").chosen().val(),o=1,p=jQuery("input[type=radio][name=aj_autoptimize_method]:checked").val();"function"==typeof jQuery(".aj_chosen").chosen?(m=jQuery("#aj_plugin_exclusions").chosen().val(),n=jQuery("#aj_theme_exclusions").chosen().val()):(m=jQuery("#aj_plugin_exclusions").val(),n=jQuery("#aj_theme_exclusions").val()),jQuery("#aj_autoptimize_enabled").is(":visible")?jQuery("#aj_autoptimize_enabled").is(":checked")?(o=1,p=jQuery("input[type=radio][name=aj_autoptimize_method]:checked").val()):(o=0,p=jQuery("input[type=radio][name=aj_autoptimize_method]:checked").val()):(o=0,p="async");var q={action:"aj_steps",sub_action:"aj_save_settings",aj_enabled:e,aj_enabled_logged:aj_enabled_logged,aj_enabled_shop:aj_enabled_shop,aj_method:h,aj_jquery:i,aj_async:j,aj_defer:k,aj_exclusions:l,aj_plugin_exclusions:m,aj_theme_exclusions:n,aj_autoptimize_enabled:o,aj_autoptimize_method:p,security:b};jQuery.post(aj_localize_admin.ajaxurl,q,function(a){try{a=jQuery.parseJSON(a),!1===a.status?console.log(a):notifySettingsSaved()}catch(a){console.log(a)}})}else{var r=jQuery("#aj_gtmetrix_username").val(),s=jQuery("#aj_gtmetrix_api_key").val(),t=jQuery("#aj_gtmetrix_server").val(),u=!1;if(""==r&&(jQuery("#aj_gtmetrix_username").addClass("aj_field_error"),u=!0),""==s&&(jQuery("#aj_gtmetrix_api_key").addClass("aj_field_error"),u=!0),!1===u)"aj_gtmetrix_test"==c?jQuery("#aj_latest_please_wait").show():(jQuery(this).hide(),jQuery("#"+c).show()),aj_step(c);else return!1}}),jQuery(document).on("change","input[type=radio][name=aj_step4_check]",function(){var a=jQuery("#aj_nonce").val(),b=jQuery(this).val();"y"==b?(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_nonce").val();jQuery("#aj_notification").fadeOut("slow")})});
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
|
|
4 |
Tags: async, javascript, pagespeed, performance, render blocking
|
5 |
Requires at least: 4.6
|
6 |
Tested up to: 5.4
|
7 |
-
Stable tag: 2.20.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -57,6 +57,12 @@ We recommend using the awesome <a href="https://wordpress.org/plugins/autoptimiz
|
|
57 |
|
58 |
== Changelog ==
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
= 2.20.02.27 =
|
61 |
|
62 |
* fix for some nasty issues, thanks for the heads-up Mikey
|
4 |
Tags: async, javascript, pagespeed, performance, render blocking
|
5 |
Requires at least: 4.6
|
6 |
Tested up to: 5.4
|
7 |
+
Stable tag: 2.20.03.01
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
57 |
|
58 |
== Changelog ==
|
59 |
|
60 |
+
= 2.20.03.01 =
|
61 |
+
|
62 |
+
* extra security measure; check the nonce when saving settings/ going through wizard.
|
63 |
+
* wizard: if something fails then communicate this onscreen instead of on the console.
|
64 |
+
* autoptimize integration: change copy to explain this might or might not be helpful.
|
65 |
+
|
66 |
= 2.20.02.27 =
|
67 |
|
68 |
* fix for some nasty issues, thanks for the heads-up Mikey
|