Autoptimize - Version 2.4.3

Version Description

  • improved Google Fonts optimzation, praise to @nextendweb (of Smartslider3 fame)!
  • improved deferring of non-aggregated CSS when "inline & defer" is active
  • bugfix: extra ao_cachechecker scheduled jobs & improve scheduling logic
  • bugfix: some extra checks on vars to avoid PHP notices
Download this release

Release Info

Developer futtta
Plugin Icon 128x128 Autoptimize
Version 2.4.3
Comparing to
See all releases

Code changes from version 2.4.2 to 2.4.3

autoptimize.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Autoptimize
4
  Plugin URI: https://autoptimize.com/
5
  Description: Optimize your website's performance: JS, CSS, HTML, images, Google Fonts and more!
6
- Version: 2.4.2
7
  Author: Frank Goossens (futtta)
8
  Author URI: https://autoptimize.com/
9
  Text Domain: autoptimize
@@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
20
  exit;
21
  }
22
 
23
- define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.4.2' );
24
 
25
  // plugin_dir_path() returns the trailing slash!
26
  define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
3
  Plugin Name: Autoptimize
4
  Plugin URI: https://autoptimize.com/
5
  Description: Optimize your website's performance: JS, CSS, HTML, images, Google Fonts and more!
6
+ Version: 2.4.3
7
  Author: Frank Goossens (futtta)
8
  Author URI: https://autoptimize.com/
9
  Text Domain: autoptimize
20
  exit;
21
  }
22
 
23
+ define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.4.3' );
24
 
25
  // plugin_dir_path() returns the trailing slash!
26
  define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
classes/autoptimizeCacheChecker.php CHANGED
@@ -41,6 +41,9 @@ class autoptimizeCacheChecker
41
  $frequency = 'twicedaily';
42
  }
43
  if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) {
 
 
 
44
  wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK );
45
  } elseif ( $schedule && ! $do_cache_check ) {
46
  wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
@@ -84,7 +87,6 @@ class autoptimizeCacheChecker
84
 
85
  public function show_admin_notice()
86
  {
87
- // fixme: make notices dismissable.
88
  if ( (bool) get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) {
89
  echo '<div class="notice notice-warning"><p>';
90
  _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' );
41
  $frequency = 'twicedaily';
42
  }
43
  if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) {
44
+ if ( $schedule ) {
45
+ wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
46
+ }
47
  wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK );
48
  } elseif ( $schedule && ! $do_cache_check ) {
49
  wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
87
 
88
  public function show_admin_notice()
89
  {
 
90
  if ( (bool) get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) {
91
  echo '<div class="notice notice-warning"><p>';
92
  _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' );
classes/autoptimizeExtra.php CHANGED
@@ -289,12 +289,10 @@ class autoptimizeExtra
289
  $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
290
  }
291
 
292
- $fonts_markup = '<script data-cfasync="false" id="ao_optimized_gfonts" type="text/javascript">WebFontConfig={google:{families:[\'';
293
- foreach ( $fonts_array as $fnt ) {
294
- $fonts_markup .= $fnt . "','";
295
- }
296
- $fonts_markup = trim( trim( $fonts_markup, "'" ), ',' );
297
- $fonts_markup .= '] },classes:false, events:false, timeout:1500};(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
298
  }
299
 
300
  // Replace back in markup.
@@ -485,9 +483,9 @@ class autoptimizeExtra
485
  $site_host = AUTOPTIMIZE_SITE_DOMAIN;
486
  $url_parsed = parse_url( $url );
487
 
488
- if ( $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
489
  return false;
490
- } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && $url_parsed['host'] !== $site_host ) {
491
  return false;
492
  } elseif ( strpos( $url, '.php' ) !== false ) {
493
  return false;
@@ -607,7 +605,7 @@ class autoptimizeExtra
607
  $_setting = $this->options['autoptimize_extra_select_field_6'];
608
  }
609
 
610
- if ( ! $_setting || empty( $_setting ) || ( '1' !== $_setting && '3' !== $_setting ) ) {
611
  // default image opt. value is 2 ("glossy").
612
  $_img_q = '2';
613
  } else {
289
  $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
290
  }
291
 
292
+ $fonts_array = array_map( 'urldecode', $fonts_array );
293
+ $fonts_markup = '<script data-cfasync="false" id="ao_optimized_gfonts_config" type="text/javascript">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>';
294
+ $fonts_library_markup = '<script data-cfasync="false" id="ao_optimized_gfonts_webfontloader" type="text/javascript">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
295
+ $in = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
 
 
296
  }
297
 
298
  // Replace back in markup.
483
  $site_host = AUTOPTIMIZE_SITE_DOMAIN;
484
  $url_parsed = parse_url( $url );
485
 
486
+ if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
487
  return false;
488
+ } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
489
  return false;
490
  } elseif ( strpos( $url, '.php' ) !== false ) {
491
  return false;
605
  $_setting = $this->options['autoptimize_extra_select_field_6'];
606
  }
607
 
608
+ if ( ! isset( $_setting ) || empty( $_setting ) || ( '1' !== $_setting && '3' !== $_setting ) ) {
609
  // default image opt. value is 2 ("glossy").
610
  $_img_q = '2';
611
  } else {
classes/autoptimizeStyles.php CHANGED
@@ -176,6 +176,10 @@ class autoptimizeStyles extends autoptimizeBase
176
  $this->css[] = array( $media, $path );
177
  } else {
178
  // Link is dynamic (.php etc).
 
 
 
 
179
  $tag = '';
180
  }
181
  } else {
@@ -212,24 +216,7 @@ class autoptimizeStyles extends autoptimizeBase
212
  $new_tag = $tag;
213
  }
214
 
215
- // Defer single CSS if "inline & defer" is ON and there is inline CSS.
216
- if ( $this->defer && ! empty( $this->defer_inline ) ) {
217
- // Get/ set (via filter) the JS to be triggers onload of the preloaded CSS.
218
- $_preload_onload = apply_filters(
219
- 'autoptimize_filter_css_preload_onload',
220
- "this.onload=null;this.rel='stylesheet'",
221
- $url
222
- );
223
- // Adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback.
224
- $new_tag = '<noscript>' . $new_tag . '</noscript>' . str_replace(
225
- array(
226
- "rel='stylesheet'",
227
- 'rel="stylesheet"',
228
- ),
229
- "rel='preload' as='style' onload=\"" . $_preload_onload . "\"",
230
- $new_tag
231
- );
232
- }
233
 
234
  // And replace!
235
  $this->content = str_replace( $tag, $new_tag, $this->content );
@@ -244,6 +231,38 @@ class autoptimizeStyles extends autoptimizeBase
244
  return false;
245
  }
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  /**
248
  * Checks if the local file referenced by $path is a valid
249
  * candidate for being inlined into a data: URI
176
  $this->css[] = array( $media, $path );
177
  } else {
178
  // Link is dynamic (.php etc).
179
+ $new_tag = $this->optionally_defer_excluded( $tag, 'none' );
180
+ if ( $new_tag !== $tag ) {
181
+ $this->content = str_replace( $tag, $new_tag, $this->content );
182
+ }
183
  $tag = '';
184
  }
185
  } else {
216
  $new_tag = $tag;
217
  }
218
 
219
+ $new_tag = $this->optionally_defer_excluded( $new_tag, $url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  // And replace!
222
  $this->content = str_replace( $tag, $new_tag, $this->content );
231
  return false;
232
  }
233
 
234
+ /**
235
+ * Checks if non-optimized CSS is to be preloaded and if so return
236
+ * the tag with preload code.
237
+ *
238
+ * @param string $new_tag (required).
239
+ * @param string $url (optional).
240
+ *
241
+ * @return string $new_tag
242
+ */
243
+ private function optionally_defer_excluded( $new_tag, $url = '' )
244
+ {
245
+ // Defer single CSS if "inline & defer" is ON and there is inline CSS.
246
+ if ( $this->defer && ! empty( $this->defer_inline ) ) {
247
+ // Get/ set (via filter) the JS to be triggers onload of the preloaded CSS.
248
+ $_preload_onload = apply_filters(
249
+ 'autoptimize_filter_css_preload_onload',
250
+ "this.onload=null;this.rel='stylesheet'",
251
+ $url
252
+ );
253
+ // Adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback.
254
+ $new_tag = '<noscript>' . $new_tag . '</noscript>' . str_replace(
255
+ array(
256
+ "rel='stylesheet'",
257
+ 'rel="stylesheet"',
258
+ ),
259
+ "rel='preload' as='style' onload=\"" . $_preload_onload . "\"",
260
+ $new_tag
261
+ );
262
+ }
263
+ return $new_tag;
264
+ }
265
+
266
  /**
267
  * Checks if the local file referenced by $path is a valid
268
  * candidate for being inlined into a data: URI
classes/autoptimizeVersionUpdatesHandler.php CHANGED
@@ -46,6 +46,12 @@ class autoptimizeVersionUpdatesHandler
46
  $this->upgrade_from_2_2();
47
  $major_update = true;
48
  // No break, intentionally, so all upgrades are ran during a single request...
 
 
 
 
 
 
49
  }
50
 
51
  if ( true === $major_update ) {
@@ -203,4 +209,11 @@ class autoptimizeVersionUpdatesHandler
203
  }
204
  delete_option( 'autoptimize_css_nogooglefont' );
205
  }
 
 
 
 
 
 
 
206
  }
46
  $this->upgrade_from_2_2();
47
  $major_update = true;
48
  // No break, intentionally, so all upgrades are ran during a single request...
49
+ case '2.4':
50
+ if ( get_option( 'autoptimize_version', 'none' ) == '2.4.2' ) {
51
+ $this->upgrade_from_2_4_2();
52
+ }
53
+ $major_update = false;
54
+ // No break, intentionally, so all upgrades are ran during a single request...
55
  }
56
 
57
  if ( true === $major_update ) {
209
  }
210
  delete_option( 'autoptimize_css_nogooglefont' );
211
  }
212
+
213
+ /**
214
+ * 2.4.2 introduced too many cronned ao_cachecheckers, make this right
215
+ */
216
+ private function upgrade_from_2_4_2() {
217
+ wp_clear_scheduled_hook( 'ao_cachechecker' );
218
+ }
219
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 5.0
7
  Requires PHP: 5.3
8
- Stable tag: 2.4.2
9
 
10
  Autoptimize speeds up your website by optimizing JS, CSS, HTML, Google Fonts and images, async-ing JS, removing emoji cruft and more.
11
 
@@ -283,6 +283,12 @@ Just [fork Autoptimize on Github](https://github.com/futtta/autoptimize) and cod
283
 
284
  == Changelog ==
285
 
 
 
 
 
 
 
286
  = 2.4.2 =
287
  * misc. improvements to image optimization logic
288
  * update PAnD framework to latest version to fix issues with notices not staying dismissed
5
  Requires at least: 4.0
6
  Tested up to: 5.0
7
  Requires PHP: 5.3
8
+ Stable tag: 2.4.3
9
 
10
  Autoptimize speeds up your website by optimizing JS, CSS, HTML, Google Fonts and images, async-ing JS, removing emoji cruft and more.
11
 
283
 
284
  == Changelog ==
285
 
286
+ = 2.4.3 =
287
+ * improved Google Fonts optimzation, praise to @nextendweb (of Smartslider3 fame)!
288
+ * improved deferring of non-aggregated CSS when "inline & defer" is active
289
+ * bugfix: extra ao_cachechecker scheduled jobs & improve scheduling logic
290
+ * bugfix: some extra checks on vars to avoid PHP notices
291
+
292
  = 2.4.2 =
293
  * misc. improvements to image optimization logic
294
  * update PAnD framework to latest version to fix issues with notices not staying dismissed