Async JavaScript - Version 1.16.08.09

Version Description

  • MOD: Added ability to check for spaces in comma separated exclusion list
  • MOD: Added support link
Download this release

Release Info

Developer cloughit
Plugin Icon 128x128 Async JavaScript
Version 1.16.08.09
Comparing to
See all releases

Code changes from version 1.16.06.22 to 1.16.08.09

Files changed (2) hide show
  1. async-javascript.php +37 -39
  2. readme.txt +7 -2
async-javascript.php CHANGED
@@ -2,9 +2,9 @@
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
  /*
4
  Plugin Name: Async JavaScript
5
- Plugin URI: http://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: 1.16.06.22
8
  Author: Clough I.T. Solutions
9
  Author URI: http://www.cloughit.com.au/
10
  Text Domain: async-javascript
@@ -19,20 +19,20 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
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', '1.16.06.22' );
27
  wp_register_style(
28
  'aj_admin_styles',
29
- plugins_url('/css/admin.css',__FILE__)
30
  );
31
- wp_enqueue_style('aj_admin_styles');
32
  wp_enqueue_script(
33
  'aj_admin_scripts',
34
- plugins_url('/js/admin.js',__FILE__),
35
- array('jquery'),
36
  time()
37
  );
38
  wp_localize_script( 'aj_admin_scripts', 'aj', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
@@ -42,8 +42,8 @@ function aj_admin_init() {
42
  register_setting( 'aj_options', 'aj_upgrade_notice' );
43
  register_setting( 'aj_options', 'autoptimize_enabled' );
44
  register_setting( 'aj_options', 'aj_autoptimize_enabled' );
45
- $autoptimize_enabled = get_option('autoptimize_enabled');
46
- $aj_autoptimize_enabled = get_option('aj_autoptimize_enabled');
47
  if ( $autoptimize_enabled !== false && $aj_autoptimize_enabled === false ) {
48
  $aj_autoptimize_enabled = $autoptimize_enabled;
49
  update_option( 'aj_autoptimize_enabled', $aj_autoptimize_enabled );
@@ -58,9 +58,8 @@ function aj_admin_init() {
58
  * @param n/a
59
  * @return n/a
60
  */
61
- add_action('admin_menu','async_javascript_menu');
62
  function async_javascript_menu() {
63
- //add_menu_page('Async JavaScript Admin','Async JavaScript','manage_options','async-javascript','async_javascript_admin');
64
  add_submenu_page(
65
  'options-general.php',
66
  'Async JavaScript Admin',
@@ -80,10 +79,6 @@ function async_javascript_menu() {
80
  * @return n/a
81
  */
82
  function async_javascript_admin() {
83
- // Display settings saved message if optioned updated
84
- /*if( isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' ) {
85
- echo '<div class="updated"><p><strong>Settings saved.</strong></p></div>';
86
- }*/
87
  // load settings from database
88
  ?>
89
  <div class="wrap">
@@ -92,10 +87,10 @@ function async_javascript_admin() {
92
  <?php
93
  settings_fields( 'aj_options' );
94
  do_settings_sections( 'aj_options' );
95
- $aj_enabled = (get_option('aj_enabled') == 1) ? array(true,'checked','') : array(false,'','style="display:none;"');
96
- $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async';
97
- $aj_exclusions = get_option('aj_exclusions');
98
- $aj_autoptimize_enabled = (get_option('aj_autoptimize_enabled') == 1) ? 'checked' : '';
99
  ?>
100
  <table class="form-table" width="100%" cellpadding="10">
101
  <tbody>
@@ -129,7 +124,7 @@ function async_javascript_admin() {
129
  <tr><td scope="row" align="left" colspan="2">Please select the method (async or defer) that you wish to enable:</td></tr>
130
  <tr>
131
  <td scope="row" align="left" style="width:20%;">Method</td>
132
- <td scope="row" align="left"><input type="radio" name="aj_method" value="async" <?php if ($aj_method == 'async') { echo 'checked'; } ?> /> Async <input type="radio" name="aj_method" value="defer" <?php if ($aj_method == 'defer') { echo 'checked'; } ?> /> Defer </td>
133
  </tr>
134
  </tbody>
135
  </table>
@@ -170,7 +165,9 @@ function async_javascript_admin() {
170
  <?php submit_button(); ?>
171
  </td>
172
  <td style="width:25%;vertical-align: top;">
173
- <a href="http://cloughit.com.au/product/async-javascript-pro/" target="_blank"><img src="<?php echo AJ_PLUGIN_URL; ?>images/async-javascript-pro.jpg" style="max-width:100%;"></a>
 
 
174
  </td>
175
  </tr>
176
  </tbody>
@@ -190,18 +187,19 @@ function async_javascript_admin() {
190
  * @return string $tag Modified <script> tag
191
  *
192
  */
193
- add_filter('script_loader_tag','async_js',20,3);
194
- function async_js($tag,$handle,$src) {
195
- $aj_enabled = (get_option('aj_enabled') == 1) ? true : false;
196
- $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async';
197
- $aj_exclusions = get_option('aj_exclusions');
198
- $array_exclusions = !empty($aj_exclusions) ? explode(',',$aj_exclusions) : array();
199
- if (false !== $aj_enabled && false === is_admin()) {
200
- if (is_array($array_exclusions) && !empty($array_exclusions)) {
201
- foreach ($array_exclusions as $exclusion) {
 
202
  if ( $exclusion != '' ) {
203
- if (false !== strpos(strtolower($src),strtolower($exclusion))) {
204
- return $tag;
205
  }
206
  }
207
  }
@@ -220,13 +218,13 @@ function async_js($tag,$handle,$src) {
220
  * @param string $defer current value of $defer as passed to function
221
  * @return string 'async' attribute
222
  */
223
- add_filter('autoptimize_filter_js_defer','my_autoptimize_defer',11);
224
- function my_autoptimize_defer($defer) {
225
- $aj_enabled = (get_option('aj_enabled') == 1) ? true : false;
226
- $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async';
227
- $aj_autoptimize_enabled = (get_option('aj_autoptimize_enabled') == 1) ? true : false;
228
- if (false !== $aj_enabled && false === is_admin()) {
229
- if (false !== $aj_autoptimize_enabled) {
230
  return " " . $aj_method . "='" . $aj_method . "' ";
231
  }
232
  }
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
  /*
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: 1.16.08.09
8
  Author: Clough I.T. Solutions
9
  Author URI: http://www.cloughit.com.au/
10
  Text Domain: async-javascript
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', '1.16.06.22' );
27
  wp_register_style(
28
  'aj_admin_styles',
29
+ plugins_url( '/css/admin.css', __FILE__ )
30
  );
31
+ wp_enqueue_style( 'aj_admin_styles' );
32
  wp_enqueue_script(
33
  'aj_admin_scripts',
34
+ plugins_url( '/js/admin.js', __FILE__ ),
35
+ array( 'jquery' ),
36
  time()
37
  );
38
  wp_localize_script( 'aj_admin_scripts', 'aj', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
42
  register_setting( 'aj_options', 'aj_upgrade_notice' );
43
  register_setting( 'aj_options', 'autoptimize_enabled' );
44
  register_setting( 'aj_options', 'aj_autoptimize_enabled' );
45
+ $autoptimize_enabled = get_option( 'autoptimize_enabled' );
46
+ $aj_autoptimize_enabled = get_option( 'aj_autoptimize_enabled' );
47
  if ( $autoptimize_enabled !== false && $aj_autoptimize_enabled === false ) {
48
  $aj_autoptimize_enabled = $autoptimize_enabled;
49
  update_option( 'aj_autoptimize_enabled', $aj_autoptimize_enabled );
58
  * @param n/a
59
  * @return n/a
60
  */
61
+ add_action( 'admin_menu', 'async_javascript_menu' );
62
  function async_javascript_menu() {
 
63
  add_submenu_page(
64
  'options-general.php',
65
  'Async JavaScript Admin',
79
  * @return n/a
80
  */
81
  function async_javascript_admin() {
 
 
 
 
82
  // load settings from database
83
  ?>
84
  <div class="wrap">
87
  <?php
88
  settings_fields( 'aj_options' );
89
  do_settings_sections( 'aj_options' );
90
+ $aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? array( true, 'checked', '' ) : array( false, '', 'style="display:none;"' );
91
+ $aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
92
+ $aj_exclusions = get_option( 'aj_exclusions' );
93
+ $aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? 'checked' : '';
94
  ?>
95
  <table class="form-table" width="100%" cellpadding="10">
96
  <tbody>
124
  <tr><td scope="row" align="left" colspan="2">Please select the method (async or defer) that you wish to enable:</td></tr>
125
  <tr>
126
  <td scope="row" align="left" style="width:20%;">Method</td>
127
+ <td scope="row" align="left"><input type="radio" name="aj_method" value="async" <?php if ( $aj_method == 'async' ) { echo 'checked'; } ?> /> Async <input type="radio" name="aj_method" value="defer" <?php if ($aj_method == 'defer') { echo 'checked'; } ?> /> Defer </td>
128
  </tr>
129
  </tbody>
130
  </table>
165
  <?php submit_button(); ?>
166
  </td>
167
  <td style="width:25%;vertical-align: top;">
168
+ <a href="https://cloughit.com.au/product/async-javascript-pro/" target="_blank"><img src="https://www.cloughit.com.au/wp-content/uploads/async-javascript-pro.jpg" style="max-width:100%;"></a>
169
+ <h2>Need Some Help?</h2>
170
+ <p>Lodge a support request at <a href="https://cloughit.com.au/support/?wpsc_category=8" target="_blank">https://cloughit.com.au/support/</a></p>
171
  </td>
172
  </tr>
173
  </tbody>
187
  * @return string $tag Modified <script> tag
188
  *
189
  */
190
+ add_filter( 'script_loader_tag', 'async_js', 10, 3 );
191
+ function async_js( $tag, $handle, $src ) {
192
+ $aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
193
+ $aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
194
+ $aj_exclusions = get_option( 'aj_exclusions' );
195
+ $array_exclusions = !empty( $aj_exclusions ) ? explode( ',', $aj_exclusions ) : array();
196
+ if ( false !== $aj_enabled && false === is_admin() ) {
197
+ if ( is_array( $array_exclusions ) && !empty( $array_exclusions ) ) {
198
+ foreach ( $array_exclusions as $exclusion ) {
199
+ $exclusion = trim( $exclusion );
200
  if ( $exclusion != '' ) {
201
+ if ( false !== strpos( strtolower( $src ), strtolower( $exclusion ) ) ) {
202
+ return $src;
203
  }
204
  }
205
  }
218
  * @param string $defer current value of $defer as passed to function
219
  * @return string 'async' attribute
220
  */
221
+ add_filter( 'autoptimize_filter_js_defer', 'my_autoptimize_defer', 11 );
222
+ function my_autoptimize_defer( $defer ) {
223
+ $aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
224
+ $aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
225
+ $aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? true : false;
226
+ if ( false !== $aj_enabled && false === is_admin() ) {
227
+ if ( false !== $aj_autoptimize_enabled ) {
228
  return " " . $aj_method . "='" . $aj_method . "' ";
229
  }
230
  }
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.5.2
7
- Stable tag: 1.16.06.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -70,6 +70,11 @@ Please lodge a support request at https://wordpress.org/support/plugin/async-jav
70
 
71
  == Changelog ==
72
 
 
 
 
 
 
73
  = 1.16.06.22 =
74
 
75
  * MOD: Remove admin message marketing
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.6
7
+ Stable tag: 1.16.08.09
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
70
 
71
  == Changelog ==
72
 
73
+ = 1.16.08.09 =
74
+
75
+ * MOD: Added ability to check for spaces in comma separated exclusion list
76
+ * MOD: Added support link
77
+
78
  = 1.16.06.22 =
79
 
80
  * MOD: Remove admin message marketing