PluginProbe
Autoptimize / trunk
Autoptimize vtrunk
3.1.16 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 All 108 releases
← All changes | classes/autoptimizeExtra.php +157 -66 2.6.0 → trunk View file →
@@ -63,9 +63,9 @@
63 63 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
64 64 }
65 65 add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) );
66 66 } else {
67 - $this->run_on_frontend();
67 + add_action( 'wp', array( $this, 'run_on_frontend' ) );
68 68 }
69 69 }
70 70
71 71 public function set_options( array $options )
@@ -100,9 +100,9 @@
100 100 // Removes TinyMCE emojis.
101 101 add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) );
102 102
103 103 // Removes emoji dns-preftech.
104 - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 );
104 + add_filter( 'emoji_svg_url', '__return_false' );
105 105 }
106 106
107 107 public function filter_disable_emojis_tinymce( $plugins )
108 108 {
@@ -114,10 +114,14 @@
114 114 }
115 115
116 116 public function filter_remove_qs( $src )
117 117 {
118 - if ( strpos( $src, '?ver=' ) ) {
119 - $src = remove_query_arg( 'ver', $src );
118 + if ( ! empty( $src ) ) {
119 + if ( strpos( $src, '?ver=' ) ) {
120 + $src = remove_query_arg( 'ver', $src );
121 + } elseif ( strpos( $src, '?v=' ) ) {
122 + $src = remove_query_arg( 'v', $src );
123 + }
120 124 }
121 125
122 126 return $src;
123 127 }
@@ -128,9 +132,9 @@
128 132 if ( ! empty( $in ) ) {
129 133 $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' );
130 134 }
131 135
132 - $settings = $this->options['autoptimize_extra_text_field_3'];
136 + $settings = wp_strip_all_tags( $this->options['autoptimize_extra_text_field_3'] );
133 137 $async = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' );
134 138 $attr = apply_filters( 'autoptimize_filter_extra_async', 'async' );
135 139 foreach ( $async as $k => $v ) {
136 140 $async[ $k ] = $attr;
@@ -141,10 +145,18 @@
141 145
142 146 return $merged;
143 147 }
144 148
145 - protected function run_on_frontend()
149 + public function run_on_frontend()
146 150 {
151 + // only run the Extra optimizations on frontend if general conditions
152 + // for optimizations are met, this to ensure e.g. removing querystrings
153 + // is not done when optimizing for logged in users is off, breaking
154 + // some pagebuilders (Divi & Elementor).
155 + if ( false === autoptimizeMain::should_buffer() ) {
156 + return;
157 + }
158 +
147 159 $options = $this->options;
148 160
149 161 // Disable emojis if specified.
150 162 if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) {
@@ -167,8 +179,17 @@
167 179 if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) {
168 180 add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 );
169 181 add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 );
170 182 add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 );
183 +
184 + if ( '2' === $options['autoptimize_extra_radio_field_4'] ) {
185 + // remove Google Fonts, adding filters to also remove Google Fonts from 3rd party themes/ plugins.
186 + // inspired by https://wordpress.org/plugins/disable-remove-google-fonts/.
187 + remove_action( 'wp_footer', 'et_builder_print_font' ); // Divi.
188 + remove_action( 'wp_footer', array( 'RevSliderFront', 'load_google_fonts' ) ); // Revslider.
189 + add_filter( 'elementor/frontend/print_google_fonts', '__return_false' ); // Elementor.
190 + add_filter( 'fl_builder_google_fonts_pre_enqueue', '__return_empty_array' ); // Beaver Builder.
191 + }
171 192 }
172 193
173 194 // Preconnect!
174 195 if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) {
@@ -175,18 +196,16 @@
175 196 add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 );
176 197 }
177 198
178 199 // Preload!
179 - if ( ! empty( $options['autoptimize_extra_text_field_7'] ) ) {
200 + if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) || ! empty( autoptimizeConfig::get_post_meta_ao_settings( 'ao_post_preload' ) ) ) {
180 201 add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 );
181 202 }
182 - }
183 203
184 - public function filter_remove_emoji_dns_prefetch( $urls, $relation_type )
185 - {
186 - $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' );
187 -
188 - return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url );
204 + // Remove global styles.
205 + if ( ! empty( $options['autoptimize_extra_checkbox_field_8'] ) ) {
206 + $this->disable_global_styles();
207 + }
189 208 }
190 209
191 210 public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type )
192 211 {
@@ -199,9 +218,18 @@
199 218
200 219 if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) {
201 220 $cnt = 0;
202 221 foreach ( $urls as $url ) {
203 - if ( false !== strpos( $url, $url_to_remove ) ) {
222 + // $url can be an array, in which case we need to fetch the value of the href key.
223 + if ( is_array( $url ) ) {
224 + if ( isset( $url['href'] ) ) {
225 + $url = $url['href'];
226 + } else {
227 + continue;
228 + }
229 + }
230 +
231 + if ( is_string( $url ) && false !== strpos( $url, $url_to_remove ) ) {
204 232 unset( $urls[ $cnt ] );
205 233 }
206 234 $cnt++;
207 235 }
@@ -226,8 +254,14 @@
226 254 foreach ( $matches[2] as $font ) {
227 255 if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) {
228 256 // Get fonts name.
229 257 $font = str_replace( array( '%7C', '%7c' ), '|', $font );
258 + if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) {
259 + // (Somewhat) change Google Fonts APIv2 syntax back to v1.
260 + // todo: support for 100..900
261 + $font = rawurldecode( $font );
262 + $font = str_replace( array( 'css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family=' ), array( 'css?', '', '', '', '', 'italic', ':italic', ',', '%7C' ), $font );
263 + }
230 264 $font = explode( 'family=', $font );
231 265 $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
232 266 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
233 267 $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) );
@@ -276,13 +310,13 @@
276 310 }
277 311
278 312 if ( ! empty( $fonts_string ) ) {
279 313 if ( '5' === $options['autoptimize_extra_radio_field_4'] ) {
280 - $rel_string = 'rel="preload" as="style" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
314 + $rel_string = 'rel="stylesheet" media="print" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
281 315 } else {
282 316 $rel_string = 'rel="stylesheet"';
283 317 }
284 - $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />';
318 + $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '">';
285 319 }
286 320 } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) {
287 321 // Aggregate & load async (webfont.js impl.)!
288 322 $fonts_array = array();
@@ -310,9 +344,9 @@
310 344 if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
311 345 $type_js = 'type="text/javascript" ';
312 346 }
313 347
314 - $fonts_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>';
348 + $fonts_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT ) . ' },classes:false, events:false, timeout:1500};</script>';
315 349 $fonts_library_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(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>';
316 350 $in = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
317 351 }
318 352
@@ -320,13 +354,8 @@
320 354 $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
321 355 $out = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
322 356 unset( $fonts_collection );
323 357
324 - // and insert preload polyfill if "link preload" and if the polyfill isn't there yet (courtesy of inline&defer).
325 - $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill();
326 - if ( '5' === $options['autoptimize_extra_radio_field_4'] && strpos( $out, $preload_polyfill ) === false ) {
327 - $out = str_replace( '</body>', $preload_polyfill . '</body>', $out );
328 - }
329 358 return $out;
330 359 }
331 360
332 361 public function filter_preconnect( $hints, $relation_type )
@@ -335,9 +364,9 @@
335 364 $preconns = array();
336 365
337 366 // Get settings and store in array.
338 367 if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) {
339 - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
368 + $preconns = array_filter( array_map( 'trim', explode( ',', wp_strip_all_tags( $options['autoptimize_extra_text_field_2'] ) ) ) );
340 369 }
341 370 $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
342 371
343 372 // Walk array, extract domain and add to new array with crossorigin attribute.
@@ -390,10 +419,19 @@
390 419 // make array from comma separated list.
391 420 $options = $this->options;
392 421 $preloads = array();
393 422 if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) {
394 - $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) );
423 + $preloads = array_filter( array_map( 'trim', explode( ',', wp_strip_all_tags( $options['autoptimize_extra_text_field_7'] ) ) ) );
395 424 }
425 +
426 + if ( false === autoptimizeImages::imgopt_active() && false === autoptimizeImages::should_lazyload_wrapper() ) {
427 + // only do this here if imgopt/ lazyload are not active?
428 + $metabox_preloads = array_filter( array_map( 'trim', explode( ',', wp_strip_all_tags( autoptimizeConfig::get_post_meta_ao_settings( 'ao_post_preload' ) ) ) ) );
429 + if ( ! empty( $metabox_preloads ) ) {
430 + $preloads = array_merge( $preloads, $metabox_preloads );
431 + }
432 + }
433 +
396 434 $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads );
397 435
398 436 // immediately return if nothing to be preloaded.
399 437 if ( empty( $preloads ) ) {
@@ -402,46 +440,81 @@
402 440
403 441 // iterate through array and add preload link to tmp string.
404 442 $preload_output = '';
405 443 foreach ( $preloads as $preload ) {
444 + if ( filter_var( $preload, FILTER_VALIDATE_URL ) !== $preload ) {
445 + continue;
446 + }
447 + $preload = esc_url_raw( $preload );
406 448 $crossorigin = '';
407 449 $preload_as = '';
408 450 $mime_type = '';
451 + $_preload = strtok( $preload, '?' );
409 452
410 - if ( autoptimizeUtils::str_ends_in( $preload, '.css' ) ) {
453 + if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) {
411 454 $preload_as = 'style';
412 - } elseif ( autoptimizeUtils::str_ends_in( $preload, '.js' ) ) {
455 + } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) {
413 456 $preload_as = 'script';
414 - } 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' ) ) {
457 + } 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' ) ) {
415 458 $preload_as = 'font';
416 459 $crossorigin = ' crossorigin';
417 - $mime_type = ' type="font/' . pathinfo( $preload, PATHINFO_EXTENSION ) . '"';
460 + $mime_type = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
418 461 if ( ' type="font/eot"' === $mime_type ) {
419 462 $mime_type = 'application/vnd.ms-fontobject';
420 463 }
421 - } 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' ) ) {
464 + } 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' ) ) {
422 465 $preload_as = 'image';
423 466 } else {
424 467 $preload_as = 'other';
425 468 }
426 469
427 - $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
470 + $preload_output .= '<link rel="preload" fetchpriority="high" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
428 471 }
429 472 $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output );
430 473
474 + return $this->inject_preloads( $preload_output, $in );
475 + }
476 +
477 + public static function inject_preloads( $preloads, $html ) {
431 478 // add string to head (before first link node by default).
432 479 $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' );
433 - $position = autoptimizeUtils::strpos( $in, $preload_inject );
480 + $position = autoptimizeUtils::strpos( $html, $preload_inject );
434 481
435 - return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) );
482 + return autoptimizeUtils::substr_replace( $html, $preloads . $preload_inject, $position, strlen( $preload_inject ) );
436 483 }
437 484
485 + public function disable_global_styles()
486 + {
487 + remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
488 + remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
489 + remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
490 +
491 + if ( true === apply_filters( 'autoptimize_filter_extra_global_styles_and_block_css', true ) ) {
492 + add_action(
493 + 'wp_enqueue_scripts',
494 + function() {
495 + wp_dequeue_style( 'wp-block-library' );
496 + wp_dequeue_style( 'wp-block-library-theme' );
497 + }
498 + );
499 + }
500 +
501 + if ( true === apply_filters( 'autoptimize_filter_extra_remove_woocommerce_block_css', true ) ) {
502 + add_action(
503 + 'wp_enqueue_scripts',
504 + function() {
505 + wp_dequeue_style( 'wc-blocks-style' );
506 + }
507 + );
508 + }
509 + }
510 +
438 511 public function admin_menu()
439 512 {
440 513 // no acces if multisite and not network admin and no site config allowed.
441 514 if ( autoptimizeConfig::should_show_menu_tabs() ) {
442 515 add_submenu_page(
443 - null,
516 + '',
444 517 'autoptimize_extra',
445 518 'autoptimize_extra',
446 519 'manage_options',
447 520 'autoptimize_extra',
@@ -446,16 +519,16 @@
446 519 'manage_options',
447 520 'autoptimize_extra',
448 521 array( $this, 'options_page' )
449 522 );
450 - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
451 523 }
524 + register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
452 525 }
453 526
454 527 public function add_extra_tab( $in )
455 528 {
456 529 if ( autoptimizeConfig::should_show_menu_tabs() ) {
457 - $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) );
530 + $in = array_merge( $in, array( 'autoptimize_extra' => esc_html__( 'Extra', 'autoptimize' ) ) );
458 531 }
459 532
460 533 return $in;
461 534 }
@@ -461,8 +534,10 @@
461 534 }
462 535
463 536 public function options_page()
464 537 {
538 + // phpcs:disable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace
539 +
465 540 // Working with actual option values from the database here.
466 541 // That way any saves are still processed as expected, but we can still
467 542 // override behavior by using `new autoptimizeExtra($custom_options)` and not have that custom
468 543 // behavior being persisted in the DB even if save is done here.
@@ -473,99 +548,115 @@
473 548 #ao_settings_form {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;}
474 549 #ao_settings_form .form-table th {font-weight: normal;}
475 550 #autoptimize_extra_descr{font-size: 120%;}
476 551 </style>
477 - <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
552 + <script>document.title = "Autoptimize: <?php esc_html_e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
478 553 <div class="wrap">
479 - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
554 + <h1><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? esc_html_e( 'Autoptimize Pro Settings', 'autoptimize' ) : esc_html_e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
480 555 <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
481 556 <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
482 557 <div class="notice-warning notice"><p>
483 - <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
558 + <?php esc_html_e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
484 559 </p></div>
485 560 <?php } ?>
486 561
487 562 <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
488 563 <?php settings_fields( 'autoptimize_extra_settings' ); ?>
489 - <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
490 - <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
564 + <h2><?php esc_html_e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
565 + <span id='autoptimize_extra_descr'><?php esc_html_e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
491 566 <table class="form-table">
492 567 <tr>
493 - <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th>
568 + <th scope="row"><?php esc_html_e( 'Google Fonts', 'autoptimize' ); ?></th>
494 569 <td>
495 - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/>
496 - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/>
570 + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php esc_html_e( 'Leave as is', 'autoptimize' ); ?><br/>
571 + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php esc_html_e( 'Remove Google Fonts', 'autoptimize' ); ?><br/>
497 572 <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
498 - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo __( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
573 + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo esc_html__( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( esc_html__( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
499 574 <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
500 - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
501 - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php _e( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ); ?><br/>
575 + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo esc_html__( 'Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( esc_html__( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?>
576 + <span <?php if ( '4' !== $gfonts ){ echo "style='display:none;' "; } ?> ><br/><input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php echo sprintf( esc_html__( 'Combine and load fonts asynchronously with %1$swebfont.js%2$s', 'autoptimize' ), '<a href="https://github.com/typekit/webfontloader#readme" target="_blank">', '</a>' ) . ' ' . esc_html__( '(deprecated)', 'autoptimize' ); ?></span><br/>
502 577 </td>
503 578 </tr>
504 579 <tr>
505 - <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th>
580 + <th scope="row"><?php esc_html_e( 'Remove emojis', 'autoptimize' ); ?></th>
506 581 <td>
507 - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label>
582 + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php esc_html_e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label>
508 583 </td>
509 584 </tr>
510 585 <tr>
511 - <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
586 + <th scope="row"><?php esc_html_e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
512 587 <td>
513 - <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>
588 + <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'>
589 + <?php
590 + // translators: just a code tag around "ver" which is the parameter added to CSS/ JS URL's by wordpress.
591 + printf( esc_html__( 'Removing query strings (or more specifically the %1$sver%2$s parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ), '<code>', '</code>' );
592 + ?>
593 + </label>
514 594 </td>
515 595 </tr>
516 596 <tr>
517 - <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>
597 + <th scope="row"><?php esc_html_e( 'Remove WordPress block CSS', 'autoptimize' ); ?></th>
518 598 <td>
519 - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label>
599 + <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 esc_html_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>
520 600 </td>
521 601 </tr>
522 602 <tr>
523 - <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th>
603 + <th scope="row"><?php esc_html_e( 'Preconnect to 3rd party domains (advanced users)', 'autoptimize' ); ?></th>
524 604 <td>
525 - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php _e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label>
605 + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br />
606 + <?php
607 + // Translators; link to a page on keycdn blog about preconnecting.
608 + printf( esc_html__( 'Add 3rd party domains you want the browser to %1$spreconnect%2$s to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ), '<a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">', '</a>' );
609 + ?>
610 + </label>
526 611 </td>
527 612 </tr>
528 613 <tr>
529 - <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th>
614 + <th scope="row"><?php esc_html_e( 'Preload specific requests (advanced users)', 'autoptimize' ); ?></th>
530 615 <td>
616 + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php esc_html_e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label>
617 + </td>
618 + </tr>
619 + <tr>
620 + <th scope="row"><?php esc_html_e( 'Async Javascript-files (advanced users)', 'autoptimize' ); ?></th>
621 + <td>
531 622 <?php
532 623 if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) {
533 624 // translators: link points Async Javascript settings page.
534 - printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' );
625 + printf( esc_html__( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' );
535 626 } else {
536 - ?>
627 + ?>
537 628 <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'>
538 629 <br />
539 630 <?php
540 - _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' );
631 + printf( esc_html__( 'Comma-separated list of local or 3rd party JS-files that should loaded with the %1$sasync%2$s flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' ), '<code>', '</code>' );
541 632 // translators: %s will be replaced by a link to the "async javascript" plugin.
542 - echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' );
633 + echo sprintf( esc_html__( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' );
543 634 $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term';
544 - echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
635 + echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', esc_html__( 'Click here to install and activate it.', 'autoptimize' ) );
545 636 }
546 637 ?>
547 638 </td>
548 639 </tr>
549 640 <tr>
550 - <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
641 + <th scope="row"><?php esc_html_e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
551 642 <td>
552 643 <?php
553 644 if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) {
554 - _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
645 + esc_html_e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
555 646 $lyte_config_url = 'options-general.php?page=lyte_settings_page';
556 - echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) );
647 + echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', esc_html__( 'Click here to configure it.', 'autoptimize' ) );
557 648 } else {
558 649 // translators: %s will be replaced by a link to "wp youtube lyte" plugin.
559 - echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' );
650 + echo sprintf( esc_html__( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' );
560 651 $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term';
561 - echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
652 + echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', esc_html__( 'Click here to install and activate it.', 'autoptimize' ) );
562 653 }
563 654 ?>
564 655 </td>
565 656 </tr>
566 657 </table>
567 - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
658 + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e( 'Save Changes', 'autoptimize' ); ?>" /></p>
568 659 </form>
569 660 <?php
570 661 }
571 662 }