PluginProbe
Autoptimize / 3.0.3
Autoptimize v3.0.3
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
← All changes | classes/autoptimizeExtra.php +56 -10 2.7.73.0.3 View file →
@@ -116,8 +116,10 @@
116 116 public function filter_remove_qs( $src )
117 117 {
118 118 if ( strpos( $src, '?ver=' ) ) {
119 119 $src = remove_query_arg( 'ver', $src );
120 + } else if ( strpos( $src, '?v=' ) ) {
121 + $src = remove_query_arg( 'v', $src );
120 122 }
121 123
122 124 return $src;
123 125 }
@@ -128,9 +130,9 @@
128 130 if ( ! empty( $in ) ) {
129 131 $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' );
130 132 }
131 133
132 - $settings = $this->options['autoptimize_extra_text_field_3'];
134 + $settings = wp_strip_all_tags( $this->options['autoptimize_extra_text_field_3'] );
133 135 $async = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' );
134 136 $attr = apply_filters( 'autoptimize_filter_extra_async', 'async' );
135 137 foreach ( $async as $k => $v ) {
136 138 $async[ $k ] = $attr;
@@ -183,11 +185,16 @@
183 185 add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 );
184 186 }
185 187
186 188 // Preload!
187 - if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) ) {
189 + if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) || ! empty( autoptimizeConfig::get_post_meta_ao_settings( 'ao_post_preload' ) ) ) {
188 190 add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 );
189 191 }
192 +
193 + // Remove global styles.
194 + if ( ! empty( $options['autoptimize_extra_checkbox_field_8'] ) ) {
195 + $this->disable_global_styles();
196 + }
190 197 }
191 198
192 199 public function filter_remove_emoji_dns_prefetch( $urls, $relation_type )
193 200 {
@@ -236,9 +243,11 @@
236 243 // Get fonts name.
237 244 $font = str_replace( array( '%7C', '%7c' ), '|', $font );
238 245 if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) {
239 246 // (Somewhat) change Google Fonts APIv2 syntax back to v1.
240 - $font = str_replace( array( 'wght@', 'wght%40', ';', '%3B' ), array( '', '', ',', ',' ), $font );
247 + // todo: support for 100..900
248 + $font = rawurldecode( $font );
249 + $font = str_replace( array( 'css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family=' ), array( 'css?', '', '', '', '', 'italic', ':italic', ',', '%7C' ), $font );
241 250 }
242 251 $font = explode( 'family=', $font );
243 252 $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
244 253 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
@@ -342,9 +351,9 @@
342 351 $preconns = array();
343 352
344 353 // Get settings and store in array.
345 354 if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) {
346 - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
355 + $preconns = array_filter( array_map( 'trim', explode( ',', wp_strip_all_tags( $options['autoptimize_extra_text_field_2'] ) ) ) );
347 356 }
348 357 $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
349 358
350 359 // Walk array, extract domain and add to new array with crossorigin attribute.
@@ -397,10 +406,19 @@
397 406 // make array from comma separated list.
398 407 $options = $this->options;
399 408 $preloads = array();
400 409 if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) {
401 - $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) );
410 + $preloads = array_filter( array_map( 'trim', explode( ',', wp_strip_all_tags( $options['autoptimize_extra_text_field_7'] ) ) ) );
402 411 }
412 +
413 + if ( false === autoptimizeImages::imgopt_active() && false === autoptimizeImages::should_lazyload_wrapper() ) {
414 + // only do this here if imgopt/ lazyload are not active?
415 + $metabox_preloads = array_filter( array_map( 'trim', explode( ',', wp_strip_all_tags( autoptimizeConfig::get_post_meta_ao_settings( 'ao_post_preload' ) ) ) ) );
416 + if ( ! empty( $metabox_preloads ) ) {
417 + $preloads = array_merge( $preloads, $metabox_preloads );
418 + }
419 + }
420 +
403 421 $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads );
404 422
405 423 // immediately return if nothing to be preloaded.
406 424 if ( empty( $preloads ) ) {
@@ -409,8 +427,12 @@
409 427
410 428 // iterate through array and add preload link to tmp string.
411 429 $preload_output = '';
412 430 foreach ( $preloads as $preload ) {
431 + if ( $preload !== filter_var( $preload, FILTER_VALIDATE_URL ) ) {
432 + continue;
433 + }
434 + $preload = esc_url_raw( $preload );
413 435 $crossorigin = '';
414 436 $preload_as = '';
415 437 $mime_type = '';
416 438 $_preload = strtok( $preload, '?' );
@@ -418,9 +440,9 @@
418 440 if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) {
419 441 $preload_as = 'style';
420 442 } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) {
421 443 $preload_as = 'script';
422 - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.woff' ) || autoptimizeUtils::str_ends_in( $_preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $_preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $_preload, '.eot' ) ) {
444 + } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.woff' ) || autoptimizeUtils::str_ends_in( $_preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $_preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $_preload, '.eot' ) || autoptimizeUtils::str_ends_in( $_preload, '.otf' ) ) {
423 445 $preload_as = 'font';
424 446 $crossorigin = ' crossorigin';
425 447 $mime_type = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
426 448 if ( ' type="font/eot"' === $mime_type ) {
@@ -425,9 +447,9 @@
425 447 $mime_type = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
426 448 if ( ' type="font/eot"' === $mime_type ) {
427 449 $mime_type = 'application/vnd.ms-fontobject';
428 450 }
429 - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $_preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $_preload, '.webp' ) || autoptimizeUtils::str_ends_in( $_preload, '.png' ) || autoptimizeUtils::str_ends_in( $_preload, '.gif' ) ) {
451 + } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $_preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $_preload, '.webp' ) || autoptimizeUtils::str_ends_in( $_preload, '.png' ) || autoptimizeUtils::str_ends_in( $_preload, '.gif' ) || autoptimizeUtils::str_ends_in( $_preload, '.svg' ) ) {
430 452 $preload_as = 'image';
431 453 } else {
432 454 $preload_as = 'other';
433 455 }
@@ -435,15 +457,33 @@
435 457 $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
436 458 }
437 459 $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output );
438 460
461 + return $this->inject_preloads( $preload_output, $in );
462 + }
463 +
464 + public static function inject_preloads( $preloads, $html ) {
439 465 // add string to head (before first link node by default).
440 466 $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' );
441 - $position = autoptimizeUtils::strpos( $in, $preload_inject );
467 + $position = autoptimizeUtils::strpos( $html, $preload_inject );
442 468
443 - return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) );
469 + return autoptimizeUtils::substr_replace( $html, $preloads . $preload_inject, $position, strlen( $preload_inject ) );
444 470 }
471 +
472 + public function disable_global_styles()
473 + {
474 + remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
475 + remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
476 + remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
445 477
478 + if ( true === apply_filters( 'autoptimize_filter_extra_global_styles_and_block_css', true ) ) {
479 + add_action( 'wp_enqueue_scripts', function(){
480 + wp_dequeue_style( 'wp-block-library' );
481 + wp_dequeue_style( 'wp-block-library-theme' );
482 + });
483 + }
484 + }
485 +
446 486 public function admin_menu()
447 487 {
448 488 // no acces if multisite and not network admin and no site config allowed.
449 489 if ( autoptimizeConfig::should_show_menu_tabs() ) {
@@ -483,9 +523,9 @@
483 523 #autoptimize_extra_descr{font-size: 120%;}
484 524 </style>
485 525 <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
486 526 <div class="wrap">
487 - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
527 + <h1><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? _e( 'Autoptimize Pro Settings', 'autoptimize' ) : _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
488 528 <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
489 529 <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
490 530 <div class="notice-warning notice"><p>
491 531 <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
@@ -518,8 +558,14 @@
518 558 <tr>
519 559 <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
520 560 <td>
521 561 <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label>
562 + </td>
563 + </tr>
564 + <tr>
565 + <th scope="row"><?php _e( 'Remove WordPress block CSS', 'autoptimize' ); ?></th>
566 + <td>
567 + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_8]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_8'] ) && '1' === $options['autoptimize_extra_checkbox_field_8'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'WordPress adds block CSS and global styles to improve easy styling of block-based sites, but which can add a significant amount of CSS and SVG. If you are sure your site can do without the block CSS and "global styles", you can disable them here.', 'autoptimize' ); ?></label>
522 568 </td>
523 569 </tr>
524 570 <tr>
525 571 <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>