Completed
Push — master ( 8cd4be...fd6893 )
by frank
02:38
created
autoptimize.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,66 +17,66 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 
20
-if ( ! defined( 'ABSPATH' ) ) {
20
+if (!defined('ABSPATH')) {
21 21
     exit;
22 22
 }
23 23
 
24
-define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.8.1' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.8.1');
25 25
 
26 26
 // plugin_dir_path() returns the trailing slash!
27
-define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
28
-define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ );
27
+define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__));
28
+define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__);
29 29
 
30 30
 // Bail early if attempting to run on non-supported php versions.
31
-if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
31
+if (version_compare(PHP_VERSION, '5.6', '<')) {
32 32
     function autoptimize_incompatible_admin_notice() {
33
-        echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>';
34
-        if ( isset( $_GET['activate'] ) ) {
35
-            unset( $_GET['activate'] );
33
+        echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>';
34
+        if (isset($_GET['activate'])) {
35
+            unset($_GET['activate']);
36 36
         }
37 37
     }
38 38
     function autoptimize_deactivate_self() {
39
-        deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) );
39
+        deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE));
40 40
     }
41
-    add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' );
42
-    add_action( 'admin_init', 'autoptimize_deactivate_self' );
41
+    add_action('admin_notices', 'autoptimize_incompatible_admin_notice');
42
+    add_action('admin_init', 'autoptimize_deactivate_self');
43 43
     return;
44 44
 }
45 45
 
46
-function autoptimize_autoload( $class_name ) {
47
-    if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) {
48
-        $file     = strtolower( $class_name );
49
-        $file     = str_replace( '_', '-', $file );
50
-        $path     = dirname( __FILE__ ) . '/classes/external/php/';
51
-        $filepath = $path . $file . '.php';
52
-    } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) {
53
-        $file     = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name );
54
-        $path     = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/';
55
-        $filepath = $path . $file . '.php';
56
-    } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) {
46
+function autoptimize_autoload($class_name) {
47
+    if (in_array($class_name, array('Minify_HTML', 'JSMin'))) {
48
+        $file     = strtolower($class_name);
49
+        $file     = str_replace('_', '-', $file);
50
+        $path     = dirname(__FILE__).'/classes/external/php/';
51
+        $filepath = $path.$file.'.php';
52
+    } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) {
53
+        $file     = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name);
54
+        $path     = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/';
55
+        $filepath = $path.$file.'.php';
56
+    } elseif ('autoptimize' === substr($class_name, 0, 11)) {
57 57
         // One of our "old" classes.
58 58
         $file     = $class_name;
59
-        $path     = dirname( __FILE__ ) . '/classes/';
60
-        $filepath = $path . $file . '.php';
61
-    } elseif ( 'PAnD' === $class_name ) {
59
+        $path     = dirname(__FILE__).'/classes/';
60
+        $filepath = $path.$file.'.php';
61
+    } elseif ('PAnD' === $class_name) {
62 62
         $file     = 'persist-admin-notices-dismissal';
63
-        $path     = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/';
64
-        $filepath = $path . $file . '.php';
63
+        $path     = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/';
64
+        $filepath = $path.$file.'.php';
65 65
     }
66 66
 
67 67
     // If we didn't match one of our rules, bail!
68
-    if ( ! isset( $filepath ) ) {
68
+    if (!isset($filepath)) {
69 69
         return;
70 70
     }
71 71
 
72 72
     require $filepath;
73 73
 }
74 74
 
75
-spl_autoload_register( 'autoptimize_autoload' );
75
+spl_autoload_register('autoptimize_autoload');
76 76
 
77 77
 // Load WP CLI command(s) on demand.
78
-if ( defined( 'WP_CLI' ) && WP_CLI ) {
79
-    require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php';
78
+if (defined('WP_CLI') && WP_CLI) {
79
+    require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php';
80 80
 }
81 81
 
82 82
 /**
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 function autoptimize() {
88 88
     static $plugin = null;
89 89
 
90
-    if ( null === $plugin ) {
91
-        $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
90
+    if (null === $plugin) {
91
+        $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
92 92
     }
93 93
 
94 94
     return $plugin;
Please login to merge, or discard this patch.
classes/autoptimizeConfig.php 1 patch
Spacing   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Main configuration logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
      */
36 36
     private function __construct()
37 37
     {
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
             // Add the admin page and settings.
40
-            if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41
-                add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
40
+            if (autoptimizeOptionWrapper::is_ao_active_for_network()) {
41
+                add_action('network_admin_menu', array($this, 'addmenu'));
42 42
             }
43 43
 
44
-            add_action( 'admin_menu', array( $this, 'addmenu' ) );
45
-            add_action( 'admin_init', array( $this, 'registersettings' ) );
46
-            add_action( 'admin_init', array( 'PAnD', 'init' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46
+            add_action('admin_init', array('PAnD', 'init'));
47 47
 
48 48
             // Set meta info.
49
-            if ( function_exists( 'plugin_row_meta' ) ) {
49
+            if (function_exists('plugin_row_meta')) {
50 50
                 // 2.8 and higher.
51
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52
-            } elseif ( function_exists( 'post_class' ) ) {
51
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
52
+            } elseif (function_exists('post_class')) {
53 53
                 // 2.7 and lower.
54
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
54
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
55
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
56 56
             }
57 57
 
58 58
             // Clean cache?
59
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
59
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
60 60
                 autoptimizeCache::clearall();
61
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
61
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
62 62
             }
63 63
 
64
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
64
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
65 65
         }
66 66
 
67 67
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     static public function instance()
78 78
     {
79 79
         // Only one instance.
80
-        if ( null === self::$instance ) {
80
+        if (null === self::$instance) {
81 81
             self::$instance = new autoptimizeConfig();
82 82
         }
83 83
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     public function show_network_message() {
88 88
         ?>
89 89
         <div class="wrap">
90
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
90
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
91 91
             <?php echo $this->ao_admin_tabs(); ?>
92
-            <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
92
+            <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p>
93 93
         </div>
94 94
         <?php
95 95
     }
@@ -184,32 +184,32 @@  discard block
 block discarded – undo
184 184
 <div class="wrap">
185 185
 
186 186
 <!-- Temporary nudge to disable aoccss power-up. -->
187
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
187
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
188 188
     <div class="notice-info notice"><p>
189
-        <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
189
+        <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?>
190 190
     </p></div>
191 191
 <?php } ?>
192 192
 
193 193
 <div id="autoptimize_main">
194
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
194
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
195 195
     <?php echo $this->ao_admin_tabs(); ?>
196 196
 
197
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
198
-<?php settings_fields( 'autoptimize' ); ?>
197
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
198
+<?php settings_fields('autoptimize'); ?>
199 199
 
200 200
 <ul>
201 201
 
202 202
 <?php
203 203
 // Only show enable site configuration in network site option.
204
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
204
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
205 205
 ?>
206 206
     <li class="itemDetail multiSite">
207
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
207
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
208 208
         <table class="form-table">
209 209
             <tr valign="top">
210
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
211
-                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
212
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
210
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
211
+                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/>
212
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
213 213
             </tr>
214 214
         </table>
215 215
     </li>
@@ -218,120 +218,120 @@  discard block
 block discarded – undo
218 218
 <?php } ?>    
219 219
 
220 220
 <li class="itemDetail">
221
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
221
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
222 222
 <table class="form-table">
223 223
 <tr valign="top">
224
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
225
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
224
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
225
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
226 226
 </tr>
227 227
 <tr valign="top" class="js_sub js_aggregate_master">
228
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
229
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
230
-<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
228
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
229
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/>
230
+<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
231 231
 </tr>
232 232
 <tr valign="top" class="js_sub js_not_aggregate">
233
-<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
234
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
235
-<?php _e( 'When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
233
+<th scope="row"><?php _e('Do not aggregate but defer?', 'autoptimize'); ?></th>
234
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get('autoptimize_js_defer_not_aggregate') ? 'checked="checked" ' : ''; ?>/>
235
+<?php _e('When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize'); ?></label></td>
236 236
 </tr>
237 237
 <tr valign="top" class="js_sub js_aggregate">
238
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
239
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
240
-<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td>
238
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
239
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
240
+<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td>
241 241
 </tr>
242 242
 <tr valign="top" class="js_sub js_aggregate">
243
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
244
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
245
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
243
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
244
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
245
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
246 246
 </tr>
247
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
247
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
248 248
 <tr valign="top" class="js_sub js_aggregate">
249 249
 <th scope="row">
250 250
 <?php
251
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
252
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
251
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
252
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
253 253
 ?>
254 254
 </th>
255
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
256
-<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td>
255
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
256
+<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td>
257 257
 </tr>
258 258
 <?php } ?>
259 259
 <tr valign="top" class="js_sub">
260
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
261
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js' ) ); ?>"/><br />
260
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
261
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js')); ?>"/><br />
262 262
 <?php
263
-echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
263
+echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
264 264
 ?>
265 265
 </label></td>
266 266
 </tr>
267 267
 <tr valign="top" class="js_sub js_aggregate">
268
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
269
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
270
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
268
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
269
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
270
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
271 271
 </tr>
272 272
 </table>
273 273
 </li>
274 274
 
275 275
 <li class="itemDetail">
276
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
276
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
277 277
 <table class="form-table">
278 278
 <tr valign="top">
279
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
280
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
279
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
280
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
281 281
 </tr>
282 282
 <tr class="css_sub" valign="top">
283
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
284
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
285
-<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
283
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
284
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/>
285
+<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
286 286
 </tr>
287 287
 <tr valign="top" class="css_sub css_aggregate">
288
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
289
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
290
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
288
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
289
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/>
290
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
291 291
 </tr>
292 292
 <tr class="css_sub css_aggregate" valign="top">
293
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
294
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
295
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
293
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
294
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
295
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
296 296
 </tr>
297
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
297
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
298 298
 <tr valign="top" class="css_sub css_aggregate">
299 299
 <th scope="row">
300 300
 <?php
301
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
302
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
301
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
302
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
303 303
 ?>
304 304
 </th>
305
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
306
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
305
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
306
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
307 307
 </tr>
308 308
 <?php } ?>
309 309
 <tr valign="top" class="css_sub">
310
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
311
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
310
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
311
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/>
312 312
 <?php
313
-_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' );
313
+_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize');
314 314
 echo ' ';
315
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
315
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
316 316
 // translators: links "autoptimize critical CSS" tab.
317
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
317
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
318 318
 ?>
319 319
 </label></td>
320 320
 </tr>
321 321
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
322 322
 <th scope="row"></th>
323
-<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td>
323
+<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
324 324
 </tr>
325 325
 <tr valign="top" class="css_sub css_aggregate">
326
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
327
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
328
-<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
326
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
327
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/>
328
+<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td>
329 329
 </tr>
330 330
 <tr valign="top" class="css_sub">
331
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
332
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
331
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
332
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br />
333 333
 <?php
334
-echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
334
+echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
335 335
 ?>
336 336
 </label></td>
337 337
 </tr>
@@ -339,55 +339,55 @@  discard block
 block discarded – undo
339 339
 </li>
340 340
 
341 341
 <li class="itemDetail">
342
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
342
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
343 343
 <table class="form-table">
344 344
 <tr valign="top">
345
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
346
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
345
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
346
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
347 347
 </tr>
348 348
 <tr class="html_sub" valign="top">
349
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
350
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
351
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
349
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
350
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
351
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
352 352
 </tr>
353 353
 </table>
354 354
 </li>
355 355
 
356 356
 <li class="itemDetail">
357
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
357
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
358 358
 <table class="form-table">
359 359
 <tr valign="top">
360
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
361
-<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
362
-<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td>
360
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
361
+<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br />
362
+<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td>
363 363
 </tr>
364 364
 </table>
365 365
 </li>
366 366
 
367 367
 <li class="itemDetail">
368
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
368
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
369 369
 <table class="form-table" >
370 370
 <tr valign="top" >
371
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
372
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
371
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
372
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
373 373
 </tr>
374 374
 <tr valign="top" >
375
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
376
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
375
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
376
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
377 377
 </tr>
378 378
 <tr valign="top" >
379
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
379
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
380 380
 <td>
381 381
     <?php
382 382
     $ao_stat_arr = autoptimizeCache::stats();
383
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
384
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
383
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
384
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
385 385
         $details       = '';
386
-        if ( $ao_cache_size > 0 ) {
387
-            $details = ', ~' . $ao_cache_size . ' total';
386
+        if ($ao_cache_size > 0) {
387
+            $details = ', ~'.$ao_cache_size.' total';
388 388
         }
389 389
         // translators: Kilobytes + timestamp shown.
390
-        printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
390
+        printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2]));
391 391
     }
392 392
     ?>
393 393
 </td>
@@ -396,41 +396,41 @@  discard block
 block discarded – undo
396 396
 </li>
397 397
 
398 398
 <li class="itemDetail">
399
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
399
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
400 400
 <table class="form-table">
401 401
     <tr valign="top" >
402
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
403
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
404
-    <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td>
402
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
403
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
404
+    <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td>
405 405
     </tr>
406 406
     <?php
407 407
     $_min_excl_class = '';
408
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
408
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
409 409
         $_min_excl_class = 'hidden';
410 410
     }
411 411
     ?>
412 412
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
413
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
414
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
415
-        <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td>
413
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
414
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
415
+        <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td>
416 416
     </tr>
417 417
     <tr valign="top">
418
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
419
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
420
-        <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
418
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
419
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
420
+        <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td>
421 421
     </tr>
422 422
     <tr valign="top">
423
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
424
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
425
-    <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
423
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
424
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
425
+    <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td>
426 426
     </tr>
427 427
     <?php
428
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
428
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
429 429
     ?>
430 430
     <tr valign="top" >
431
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
432
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
433
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
431
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
432
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
433
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
434 434
         </td>
435 435
     </tr>
436 436
     <?php } ?>
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 </ul>
441 441
 
442 442
 <p class="submit">
443
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
444
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
443
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
444
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
445 445
 </p>
446 446
 
447 447
 </form>
@@ -450,46 +450,46 @@  discard block
 block discarded – undo
450 450
     <div class="autoptimize_banner hidden">
451 451
     <ul>
452 452
     <?php
453
-    if ( $this->settings_screen_do_remote_http ) {
454
-        $ao_banner = get_transient( 'autoptimize_banner' );
455
-        if ( empty( $ao_banner ) ) {
456
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
457
-            if ( ! is_wp_error( $banner_resp ) ) {
458
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
459
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
460
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
453
+    if ($this->settings_screen_do_remote_http) {
454
+        $ao_banner = get_transient('autoptimize_banner');
455
+        if (empty($ao_banner)) {
456
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
457
+            if (!is_wp_error($banner_resp)) {
458
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
459
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
460
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
461 461
                 }
462 462
             }
463 463
         }
464 464
         echo $ao_banner;
465 465
     }
466 466
     ?>
467
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
468
-        <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
467
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
468
+        <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li>
469 469
     </ul>
470 470
     </div>
471 471
     <div style="margin-left:10px;margin-top:-5px;">
472 472
         <h2>
473
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
473
+            <?php _e('futtta about', 'autoptimize'); ?>
474 474
             <select id="feed_dropdown" >
475
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
476
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
477
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
475
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
476
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
477
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
478 478
             </select>
479 479
         </h2>
480 480
         <div id="futtta_feed">
481 481
             <div id="autoptimizefeed">
482
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
482
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
483 483
             </div>
484 484
             <div id="wordpressfeed">
485
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
485
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
486 486
             </div>
487 487
             <div id="webtechfeed">
488
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
488
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
489 489
             </div>
490 490
         </div>
491 491
     </div>
492
-    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
492
+    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div>
493 493
 </div>
494 494
 
495 495
 <script type="text/javascript">
@@ -655,82 +655,82 @@  discard block
 block discarded – undo
655 655
 
656 656
     public function addmenu()
657 657
     {
658
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
658
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
659 659
             // multisite, network admin, ao network activated: add normal settings page at network level.
660
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
661
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
660
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
661
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
662 662
             // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options.
663
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
663
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
664 664
         } else {
665 665
             // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on.
666
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
666
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
667 667
         }
668 668
 
669
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
670
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
669
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
670
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
671 671
     }
672 672
 
673 673
     public function autoptimize_admin_scripts()
674 674
     {
675
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
676
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
675
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
676
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
677 677
     }
678 678
 
679 679
     public function autoptimize_admin_styles()
680 680
     {
681
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
682
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
681
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
682
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
683 683
     }
684 684
 
685 685
     public function registersettings() {
686
-        register_setting( 'autoptimize', 'autoptimize_html' );
687
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
688
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
689
-        register_setting( 'autoptimize', 'autoptimize_js' );
690
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
691
-        register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
692
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
693
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
694
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
695
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
696
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
697
-        register_setting( 'autoptimize', 'autoptimize_css' );
698
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
699
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
700
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
701
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
702
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
703
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
704
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
705
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
706
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
707
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
708
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
709
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
710
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
711
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
712
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
686
+        register_setting('autoptimize', 'autoptimize_html');
687
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
688
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
689
+        register_setting('autoptimize', 'autoptimize_js');
690
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
691
+        register_setting('autoptimize', 'autoptimize_js_defer_not_aggregate');
692
+        register_setting('autoptimize', 'autoptimize_js_exclude');
693
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
694
+        register_setting('autoptimize', 'autoptimize_js_justhead');
695
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
696
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
697
+        register_setting('autoptimize', 'autoptimize_css');
698
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
699
+        register_setting('autoptimize', 'autoptimize_css_exclude');
700
+        register_setting('autoptimize', 'autoptimize_css_justhead');
701
+        register_setting('autoptimize', 'autoptimize_css_datauris');
702
+        register_setting('autoptimize', 'autoptimize_css_defer');
703
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
704
+        register_setting('autoptimize', 'autoptimize_css_inline');
705
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
706
+        register_setting('autoptimize', 'autoptimize_cdn_url');
707
+        register_setting('autoptimize', 'autoptimize_cache_clean');
708
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
709
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
710
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
711
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
712
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
713 713
     }
714 714
 
715
-    public function setmeta( $links, $file = null )
715
+    public function setmeta($links, $file = null)
716 716
     {
717 717
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
718 718
         // Do it only once - saves time.
719 719
         static $plugin;
720
-        if ( empty( $plugin ) ) {
721
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
720
+        if (empty($plugin)) {
721
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
722 722
         }
723 723
 
724
-        if ( null === $file ) {
724
+        if (null === $file) {
725 725
             // 2.7 and lower.
726
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
727
-            array_unshift( $links, $settings_link );
726
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
727
+            array_unshift($links, $settings_link);
728 728
         } else {
729 729
             // 2.8 and higher.
730 730
             // If it's us, add the link.
731
-            if ( $file === $plugin ) {
732
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
733
-                $links   = array_merge( $links, $newlink );
731
+            if ($file === $plugin) {
732
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
733
+                $links   = array_merge($links, $newlink);
734 734
             }
735 735
         }
736 736
 
@@ -807,8 +807,8 @@  discard block
 block discarded – undo
807 807
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
808 808
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
809 809
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
810
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
811
-            'autoptimize_imgopt_text_field_6'     => '',  // optimization exclusions empty.
810
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
811
+            'autoptimize_imgopt_text_field_6'     => '', // optimization exclusions empty.
812 812
             'autoptimize_imgopt_number_field_7'   => '0', // lazy load from nth image (0 = lazyload all).
813 813
         );
814 814
         return $defaults;
@@ -821,58 +821,58 @@  discard block
 block discarded – undo
821 821
      *
822 822
      * @return string
823 823
      */
824
-    public static function get_ao_css_preload_onload( $media = 'all' )
824
+    public static function get_ao_css_preload_onload($media = 'all')
825 825
     {
826
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
826
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
827 827
         return $preload_onload;
828 828
     }
829 829
 
830
-    public function get( $key )
830
+    public function get($key)
831 831
     {
832
-        if ( ! is_array( $this->config ) ) {
832
+        if (!is_array($this->config)) {
833 833
             // Default config.
834 834
             $config = self::get_defaults();
835 835
 
836 836
             // Override with user settings.
837
-            foreach ( array_keys( $config ) as $name ) {
838
-                $conf = autoptimizeOptionWrapper::get_option( $name );
839
-                if ( false !== $conf ) {
837
+            foreach (array_keys($config) as $name) {
838
+                $conf = autoptimizeOptionWrapper::get_option($name);
839
+                if (false !== $conf) {
840 840
                     // It was set before!
841
-                    $config[ $name ] = $conf;
841
+                    $config[$name] = $conf;
842 842
                 }
843 843
             }
844 844
 
845 845
             // Save for next call.
846
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
846
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
847 847
         }
848 848
 
849
-        if ( isset( $this->config[ $key ] ) ) {
850
-            return $this->config[ $key ];
849
+        if (isset($this->config[$key])) {
850
+            return $this->config[$key];
851 851
         }
852 852
 
853 853
         return false;
854 854
     }
855 855
 
856
-    private function get_futtta_feeds( $url ) {
857
-        if ( $this->settings_screen_do_remote_http ) {
858
-            $rss      = fetch_feed( $url );
856
+    private function get_futtta_feeds($url) {
857
+        if ($this->settings_screen_do_remote_http) {
858
+            $rss      = fetch_feed($url);
859 859
             $maxitems = 0;
860 860
 
861
-            if ( ! is_wp_error( $rss ) ) {
862
-                $maxitems  = $rss->get_item_quantity( 7 );
863
-                $rss_items = $rss->get_items( 0, $maxitems );
861
+            if (!is_wp_error($rss)) {
862
+                $maxitems  = $rss->get_item_quantity(7);
863
+                $rss_items = $rss->get_items(0, $maxitems);
864 864
             }
865 865
             ?>
866 866
             <ul>
867
-                <?php if ( 0 == $maxitems ) : ?>
868
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
867
+                <?php if (0 == $maxitems) : ?>
868
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
869 869
                 <?php else : ?>
870
-                    <?php foreach ( $rss_items as $item ) : ?>
870
+                    <?php foreach ($rss_items as $item) : ?>
871 871
                         <li>
872
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
872
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
873 873
                                 <?php // translators: the variable contains a date. ?>
874
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
875
-                                <?php echo esc_html( $item->get_title() ); ?>
874
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
875
+                                <?php echo esc_html($item->get_title()); ?>
876 876
                             </a>
877 877
                         </li>
878 878
                     <?php endforeach; ?>
@@ -885,23 +885,23 @@  discard block
 block discarded – undo
885 885
     static function ao_admin_tabs()
886 886
     {
887 887
         // based on http://wordpress.stackexchange.com/a/58826 .
888
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
888
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
889 889
         $tab_content = '';
890
-        $tabs_count  = count( $tabs );
891
-        if ( $tabs_count > 1 ) {
892
-            if ( isset( $_GET['page'] ) ) {
890
+        $tabs_count  = count($tabs);
891
+        if ($tabs_count > 1) {
892
+            if (isset($_GET['page'])) {
893 893
                 $current_id = $_GET['page'];
894 894
             } else {
895 895
                 $current_id = 'autoptimize';
896 896
             }
897 897
             $tab_content .= '<h2 class="nav-tab-wrapper">';
898
-            foreach ( $tabs as $tab_id => $tab_name ) {
899
-                if ( $current_id == $tab_id ) {
898
+            foreach ($tabs as $tab_id => $tab_name) {
899
+                if ($current_id == $tab_id) {
900 900
                     $class = ' nav-tab-active';
901 901
                 } else {
902 902
                     $class = '';
903 903
                 }
904
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
904
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
905 905
             }
906 906
             $tab_content .= '</h2>';
907 907
         } else {
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
      */
919 919
     public static function is_admin_and_not_ajax()
920 920
     {
921
-        return ( is_admin() && ! self::doing_ajax() );
921
+        return (is_admin() && !self::doing_ajax());
922 922
     }
923 923
 
924 924
     /**
@@ -928,10 +928,10 @@  discard block
 block discarded – undo
928 928
      */
929 929
     protected static function doing_ajax()
930 930
     {
931
-        if ( function_exists( 'wp_doing_ajax' ) ) {
931
+        if (function_exists('wp_doing_ajax')) {
932 932
             return wp_doing_ajax();
933 933
         }
934
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
934
+        return (defined('DOING_AJAX') && DOING_AJAX);
935 935
     }
936 936
 
937 937
     /**
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
      * @return bool
941 941
      */
942 942
     public static function should_show_menu_tabs() {
943
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
943
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
944 944
             return true;
945 945
         } else {
946 946
             return false;
Please login to merge, or discard this patch.
classes/autoptimizeImages.php 1 patch
Spacing   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles optimizing images.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -23,18 +23,18 @@  discard block
 block discarded – undo
23 23
      */
24 24
     protected static $instance = null;
25 25
 
26
-    public function __construct( array $options = array() )
26
+    public function __construct(array $options = array())
27 27
     {
28 28
         // If options are not provided, fetch them.
29
-        if ( empty( $options ) ) {
29
+        if (empty($options)) {
30 30
             $options = $this->fetch_options();
31 31
         }
32 32
 
33
-        $this->set_options( $options );
33
+        $this->set_options($options);
34 34
         $this->lazyload_counter = 0;
35 35
     }
36 36
 
37
-    public function set_options( array $options )
37
+    public function set_options(array $options)
38 38
     {
39 39
         $this->options = $options;
40 40
 
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
 
44 44
     public static function fetch_options()
45 45
     {
46
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
47
-        if ( empty( $value ) ) {
46
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
47
+        if (empty($value)) {
48 48
             // Fallback to returning defaults when no stored option exists yet.
49 49
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
50 50
         }
51 51
 
52 52
         // get service availability and add it to the options-array.
53
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
53
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
54 54
 
55
-        if ( empty( $value['availabilities'] ) ) {
56
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
55
+        if (empty($value['availabilities'])) {
56
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
57 57
         }
58 58
 
59 59
         return $value;
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
         // and does not use/ request the availablity data (which could slow things down).
67 67
         static $imgopt_active = null;
68 68
 
69
-        if ( null === $imgopt_active ) {
70
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
71
-            if ( ! empty( $opts ) && is_array( $opts ) && array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $opts ) && ! empty( $opts['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $opts['autoptimize_imgopt_checkbox_field_1'] ) {
69
+        if (null === $imgopt_active) {
70
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
71
+            if (!empty($opts) && is_array($opts) && array_key_exists('autoptimize_imgopt_checkbox_field_1', $opts) && !empty($opts['autoptimize_imgopt_checkbox_field_1']) && '1' === $opts['autoptimize_imgopt_checkbox_field_1']) {
72 72
                 $imgopt_active = true;
73 73
             } else {
74 74
                 $imgopt_active = false;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public static function instance()
90 90
     {
91
-        if ( null === self::$instance ) {
91
+        if (null === self::$instance) {
92 92
             self::$instance = new self();
93 93
         }
94 94
 
@@ -97,34 +97,34 @@  discard block
 block discarded – undo
97 97
 
98 98
     public function run()
99 99
     {
100
-        if ( is_admin() ) {
101
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
102
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
100
+        if (is_admin()) {
101
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
102
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
103 103
             } else {
104
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
104
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
105 105
             }
106
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
106
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
107 107
         } else {
108
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
108
+            add_action('wp', array($this, 'run_on_frontend'));
109 109
         }
110 110
     }
111 111
 
112 112
     public function run_on_frontend() {
113
-        if ( ! $this->should_run() ) {
114
-            if ( $this->should_lazyload() ) {
113
+        if (!$this->should_run()) {
114
+            if ($this->should_lazyload()) {
115 115
                 add_filter(
116 116
                     'wp_lazy_loading_enabled',
117 117
                     '__return_false'
118 118
                 );
119 119
                 add_filter(
120 120
                     'autoptimize_html_after_minify',
121
-                    array( $this, 'filter_lazyload_images' ),
121
+                    array($this, 'filter_lazyload_images'),
122 122
                     10,
123 123
                     1
124 124
                 );
125 125
                 add_action(
126 126
                     'wp_footer',
127
-                    array( $this, 'add_lazyload_js_footer' ),
127
+                    array($this, 'add_lazyload_js_footer'),
128 128
                     10,
129 129
                     0
130 130
                 );
@@ -134,43 +134,43 @@  discard block
 block discarded – undo
134 134
 
135 135
         $active = false;
136 136
 
137
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
137
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
138 138
             add_filter(
139 139
                 'autoptimize_html_after_minify',
140
-                array( $this, 'filter_optimize_images' ),
140
+                array($this, 'filter_optimize_images'),
141 141
                 10,
142 142
                 1
143 143
             );
144 144
             $active = true;
145 145
         }
146 146
 
147
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
147
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
148 148
             add_filter(
149 149
                 'autoptimize_filter_base_replace_cdn',
150
-                array( $this, 'filter_optimize_css_images' ),
150
+                array($this, 'filter_optimize_css_images'),
151 151
                 10,
152 152
                 1
153 153
             );
154 154
             $active = true;
155 155
         }
156 156
 
157
-        if ( $active ) {
157
+        if ($active) {
158 158
             add_filter(
159 159
                 'autoptimize_extra_filter_tobepreconn',
160
-                array( $this, 'filter_preconnect_imgopt_url' ),
160
+                array($this, 'filter_preconnect_imgopt_url'),
161 161
                 10,
162 162
                 1
163 163
             );
164 164
         }
165 165
 
166
-        if ( $this->should_lazyload() ) {
166
+        if ($this->should_lazyload()) {
167 167
             add_filter(
168 168
                 'wp_lazy_loading_enabled',
169 169
                 '__return_false'
170 170
             );
171 171
             add_action(
172 172
                 'wp_footer',
173
-                array( $this, 'add_lazyload_js_footer' ),
173
+                array($this, 'add_lazyload_js_footer'),
174 174
                 10,
175 175
                 0
176 176
             );
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
     protected function should_run()
186 186
     {
187 187
         $opts              = $this->options;
188
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
189
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
188
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
189
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
190 190
 
191 191
         $do_cdn      = true;
192 192
         $_userstatus = $this->get_imgopt_provider_userstatus();
193
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
193
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
194 194
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
195 195
             $do_cdn = false;
196 196
         }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             $this->imgopt_active()
200 200
             && $do_cdn
201 201
             && $service_not_down
202
-            && ( $not_launch_status || $this->launch_ok() )
202
+            && ($not_launch_status || $this->launch_ok())
203 203
         ) {
204 204
             return true;
205 205
         }
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
     {
211 211
         static $imgopt_host = null;
212 212
 
213
-        if ( null === $imgopt_host ) {
213
+        if (null === $imgopt_host) {
214 214
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
215 215
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
216
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
217
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
216
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
217
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
218 218
             }
219
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
219
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
220 220
         }
221 221
 
222 222
         return $imgopt_host;
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
     public static function get_service_url_suffix()
233 233
     {
234
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
234
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
235 235
 
236 236
         return $suffix;
237 237
     }
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
     {
241 241
         static $quality = null;
242 242
 
243
-        if ( null === $quality ) {
243
+        if (null === $quality) {
244 244
             $q_array = $this->get_img_quality_array();
245 245
             $setting = $this->get_img_quality_setting();
246 246
             $quality = apply_filters(
247 247
                 'autoptimize_filter_imgopt_quality',
248
-                'q_' . $q_array[ $setting ]
248
+                'q_'.$q_array[$setting]
249 249
             );
250 250
         }
251 251
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         static $map = null;
258 258
 
259
-        if ( null === $map ) {
259
+        if (null === $map) {
260 260
             $map = array(
261 261
                 '1' => 'lossy',
262 262
                 '2' => 'glossy',
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
     {
276 276
         static $q = null;
277 277
 
278
-        if ( null === $q ) {
279
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
278
+        if (null === $q) {
279
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
280 280
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
281 281
             }
282 282
 
283
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
283
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
284 284
                 // default image opt. value is 2 ("glossy").
285 285
                 $q = '2';
286 286
             } else {
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
         return $q;
292 292
     }
293 293
 
294
-    public function filter_preconnect_imgopt_url( array $in )
294
+    public function filter_preconnect_imgopt_url(array $in)
295 295
     {
296
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
297
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
296
+        $url_parts = parse_url($this->get_imgopt_base_url());
297
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
298 298
 
299 299
         return $in;
300 300
     }
@@ -307,20 +307,20 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return string
309 309
      */
310
-    private function normalize_img_url( $in )
310
+    private function normalize_img_url($in)
311 311
     {
312 312
         // Only parse the site url once.
313 313
         static $parsed_site_url = null;
314
-        if ( null === $parsed_site_url ) {
315
-            $parsed_site_url = parse_url( site_url() );
314
+        if (null === $parsed_site_url) {
315
+            $parsed_site_url = parse_url(site_url());
316 316
         }
317 317
 
318 318
         // get CDN domain once.
319 319
         static $cdn_domain = null;
320
-        if ( is_null( $cdn_domain ) ) {
320
+        if (is_null($cdn_domain)) {
321 321
             $cdn_url = $this->get_cdn_url();
322
-            if ( ! empty( $cdn_url ) ) {
323
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
322
+            if (!empty($cdn_url)) {
323
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
324 324
             } else {
325 325
                 $cdn_domain = '';
326 326
             }
@@ -336,49 +336,49 @@  discard block
 block discarded – undo
336 336
          * identical string operations).
337 337
          */
338 338
         static $cache = null;
339
-        if ( null === $cache ) {
339
+        if (null === $cache) {
340 340
             $cache = array();
341 341
         }
342 342
 
343 343
         // Do the work on cache miss only.
344
-        if ( ! isset( $cache[ $in ] ) ) {
344
+        if (!isset($cache[$in])) {
345 345
             // Default to (the trimmed version of) what was given to us.
346
-            $result = trim( $in );
346
+            $result = trim($in);
347 347
 
348 348
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
349
-            if ( strpos( $result, '&quot;' ) !== false ) {
350
-                $result = str_replace( '&quot;', '', $result );
349
+            if (strpos($result, '&quot;') !== false) {
350
+                $result = str_replace('&quot;', '', $result);
351 351
             }
352 352
 
353
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
354
-                $result = $parsed_site_url['scheme'] . ':' . $result;
355
-            } elseif ( 0 === strpos( $result, '/' ) ) {
353
+            if (autoptimizeUtils::is_protocol_relative($result)) {
354
+                $result = $parsed_site_url['scheme'].':'.$result;
355
+            } elseif (0 === strpos($result, '/')) {
356 356
                 // Root-relative...
357
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
358
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
359
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
357
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
358
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
359
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
360 360
             }
361 361
 
362 362
             // filter (default off) to remove QS from image URL's to avoid eating away optimization credits.
363
-            if ( apply_filters( 'autoptimize_filter_imgopt_no_querystring', false ) && strpos( $result, '?' ) !== false ) {
364
-                $result = strtok( $result, '?' );
363
+            if (apply_filters('autoptimize_filter_imgopt_no_querystring', false) && strpos($result, '?') !== false) {
364
+                $result = strtok($result, '?');
365 365
             }
366 366
 
367
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
367
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
368 368
 
369 369
             // Store in cache.
370
-            $cache[ $in ] = $result;
370
+            $cache[$in] = $result;
371 371
         }
372 372
 
373
-        return $cache[ $in ];
373
+        return $cache[$in];
374 374
     }
375 375
 
376
-    public function filter_optimize_css_images( $in )
376
+    public function filter_optimize_css_images($in)
377 377
     {
378
-        $in = $this->normalize_img_url( $in );
378
+        $in = $this->normalize_img_url($in);
379 379
 
380
-        if ( $this->can_optimize_image( $in ) ) {
381
-            return $this->build_imgopt_url( $in, '', '' );
380
+        if ($this->can_optimize_image($in)) {
381
+            return $this->build_imgopt_url($in, '', '');
382 382
         } else {
383 383
             return $in;
384 384
         }
@@ -388,53 +388,53 @@  discard block
 block discarded – undo
388 388
     {
389 389
         static $imgopt_base_url = null;
390 390
 
391
-        if ( null === $imgopt_base_url ) {
391
+        if (null === $imgopt_base_url) {
392 392
             $imgopt_host     = $this->get_imgopt_host();
393 393
             $quality         = $this->get_img_quality_string();
394
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
395
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
396
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
394
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
395
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
396
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
397 397
         }
398 398
 
399 399
         return $imgopt_base_url;
400 400
     }
401 401
 
402
-    private function can_optimize_image( $url, $tag = '', $testing = false )
402
+    private function can_optimize_image($url, $tag = '', $testing = false)
403 403
     {
404 404
         static $cdn_url      = null;
405 405
         static $nopti_images = null;
406 406
 
407
-        if ( null === $cdn_url ) {
407
+        if (null === $cdn_url) {
408 408
             $cdn_url = apply_filters(
409 409
                 'autoptimize_filter_base_cdnurl',
410
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
410
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
411 411
             );
412 412
         }
413 413
 
414
-        if ( null === $nopti_images || $testing ) {
415
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_text_field_6', $this->options ) ) {
414
+        if (null === $nopti_images || $testing) {
415
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_text_field_6', $this->options)) {
416 416
                 $nopti_images = $this->options['autoptimize_imgopt_text_field_6'];
417 417
             }
418
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', $nopti_images );
418
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', $nopti_images);
419 419
         }
420 420
 
421 421
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
422
-        $url        = $this->normalize_img_url( $url );
423
-        $url_parsed = parse_url( $url );
422
+        $url        = $this->normalize_img_url($url);
423
+        $url_parsed = parse_url($url);
424 424
 
425
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
425
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
426 426
             return false;
427
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
427
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
428 428
             return false;
429
-        } elseif ( strpos( $url, '.php' ) !== false ) {
429
+        } elseif (strpos($url, '.php') !== false) {
430 430
             return false;
431
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
431
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif'), '', $url_parsed['path']) === $url_parsed['path']) {
432 432
             // fixme: better check against end of string.
433 433
             return false;
434
-        } elseif ( ! empty( $nopti_images ) ) {
435
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
436
-            foreach ( $nopti_images_array as $nopti_image ) {
437
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
434
+        } elseif (!empty($nopti_images)) {
435
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
436
+            foreach ($nopti_images_array as $nopti_image) {
437
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
438 438
                     return false;
439 439
                 }
440 440
             }
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
         return true;
443 443
     }
444 444
 
445
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
445
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
446 446
     {
447 447
         // sanitize width and height.
448
-        if ( strpos( $width, '%' ) !== false ) {
448
+        if (strpos($width, '%') !== false) {
449 449
             $width = 0;
450 450
         }
451
-        if ( strpos( $height, '%' ) !== false ) {
451
+        if (strpos($height, '%') !== false) {
452 452
             $height = 0;
453 453
         }
454 454
         $width  = (int) $width;
@@ -462,46 +462,46 @@  discard block
 block discarded – undo
462 462
         );
463 463
 
464 464
         // If filter modified the url, return that.
465
-        if ( $filtered_url !== $orig_url ) {
465
+        if ($filtered_url !== $orig_url) {
466 466
             return $filtered_url;
467 467
         }
468 468
 
469
-        $orig_url        = $this->normalize_img_url( $orig_url );
469
+        $orig_url        = $this->normalize_img_url($orig_url);
470 470
         $imgopt_base_url = $this->get_imgopt_base_url();
471 471
         $imgopt_size     = '';
472 472
 
473
-        if ( $width && 0 !== $width ) {
474
-            $imgopt_size = ',w_' . $width;
473
+        if ($width && 0 !== $width) {
474
+            $imgopt_size = ',w_'.$width;
475 475
         }
476 476
 
477
-        if ( $height && 0 !== $height ) {
478
-            $imgopt_size .= ',h_' . $height;
477
+        if ($height && 0 !== $height) {
478
+            $imgopt_size .= ',h_'.$height;
479 479
         }
480 480
 
481
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
481
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
482 482
 
483 483
         return $url;
484 484
     }
485 485
 
486
-    public function replace_data_thumbs( $matches )
486
+    public function replace_data_thumbs($matches)
487 487
     {
488
-        return $this->replace_img_callback( $matches, 150, 150 );
488
+        return $this->replace_img_callback($matches, 150, 150);
489 489
     }
490 490
 
491
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
491
+    public function replace_img_callback($matches, $width = 0, $height = 0)
492 492
     {
493
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
494
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
495
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
493
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
494
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
495
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
496 496
         } else {
497 497
             return $matches[0];
498 498
         }
499 499
     }
500 500
 
501
-    public function replace_icon_callback( $matches )
501
+    public function replace_icon_callback($matches)
502 502
     {
503
-        if ( array_key_exists( '2', $matches ) ) {
504
-            $sizes  = explode( 'x', $matches[2] );
503
+        if (array_key_exists('2', $matches)) {
504
+            $sizes  = explode('x', $matches[2]);
505 505
             $width  = $sizes[0];
506 506
             $height = $sizes[1];
507 507
         } else {
@@ -510,14 +510,14 @@  discard block
 block discarded – undo
510 510
         }
511 511
 
512 512
         // make sure we're not trying to optimize a *.ico file
513
-        if ( strpos( $matches[1], '.ico' ) === false ) {
514
-            return $this->replace_img_callback( $matches, $width, $height );
513
+        if (strpos($matches[1], '.ico') === false) {
514
+            return $this->replace_img_callback($matches, $width, $height);
515 515
         } else {
516 516
             return $matches[0];
517 517
         }
518 518
     }
519 519
 
520
-    public function filter_optimize_images( $in, $testing = false )
520
+    public function filter_optimize_images($in, $testing = false)
521 521
     {
522 522
         /*
523 523
          * potential future functional improvements:
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
         $to_replace = array();
528 528
 
529 529
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
530
-        if ( $this->should_lazyload() ) {
530
+        if ($this->should_lazyload()) {
531 531
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
532 532
                 'SCRIPT',
533 533
                 '<script',
@@ -537,161 +537,161 @@  discard block
 block discarded – undo
537 537
         }
538 538
 
539 539
         // extract img tags.
540
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
541
-            foreach ( $matches[0] as $tag ) {
540
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
541
+            foreach ($matches[0] as $tag) {
542 542
                 $orig_tag = $tag;
543 543
                 $imgopt_w = '';
544 544
                 $imgopt_h = '';
545 545
 
546 546
                 // first do (data-)srcsets.
547
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
548
-                    foreach ( $allsrcsets as $srcset ) {
547
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
548
+                    foreach ($allsrcsets as $srcset) {
549 549
                         $srcset      = $srcset[2];
550 550
                         $orig_srcset = $srcset;
551
-                        $srcsets     = explode( ',', $srcset );
552
-                        foreach ( $srcsets as $indiv_srcset ) {
553
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
554
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
555
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
551
+                        $srcsets     = explode(',', $srcset);
552
+                        foreach ($srcsets as $indiv_srcset) {
553
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
554
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
555
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
556 556
                             }
557
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag, $testing ) ) {
558
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
559
-                                $srcset     = str_replace( $indiv_srcset_parts[0], $imgopt_url, $srcset );
557
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag, $testing)) {
558
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
559
+                                $srcset     = str_replace($indiv_srcset_parts[0], $imgopt_url, $srcset);
560 560
                             }
561 561
                         }
562
-                        $tag = str_replace( $orig_srcset, $srcset, $tag );
562
+                        $tag = str_replace($orig_srcset, $srcset, $tag);
563 563
                     }
564 564
                 }
565 565
 
566 566
                 // proceed with img src.
567 567
                 // get width and height and add to $imgopt_size.
568
-                $_get_size = $this->get_size_from_tag( $tag );
568
+                $_get_size = $this->get_size_from_tag($tag);
569 569
                 $imgopt_w  = $_get_size['width'];
570 570
                 $imgopt_h  = $_get_size['height'];
571 571
 
572 572
                 // then start replacing images src.
573
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
574
-                    foreach ( $urls as $url ) {
573
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
574
+                    foreach ($urls as $url) {
575 575
                         $full_src_orig = $url[0];
576 576
                         $url           = $url[1];
577
-                        if ( $this->can_optimize_image( $url, $full_src_orig, $testing ) ) {
578
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
579
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
580
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
577
+                        if ($this->can_optimize_image($url, $full_src_orig, $testing)) {
578
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
579
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
580
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
581 581
                         }
582 582
                     }
583 583
                 }
584 584
 
585 585
                 // do lazyload stuff.
586
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
586
+                if ($this->should_lazyload($in) && !empty($url)) {
587 587
                     // first do lpiq placeholder logic.
588
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
588
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
589 589
                         // if all img src have been replaced during srcset, we have to extract the
590 590
                         // origin url from the imgopt one to be able to set a lqip placeholder.
591
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
591
+                        $_url = substr($url, strpos($url, '/http') + 1);
592 592
                     } else {
593 593
                         $_url = $url;
594 594
                     }
595 595
 
596
-                    $_url = $this->normalize_img_url( $_url );
596
+                    $_url = $this->normalize_img_url($_url);
597 597
 
598 598
                     $placeholder = '';
599
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true, $_url ) ) {
599
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true, $_url)) {
600 600
                         $lqip_w = '';
601 601
                         $lqip_h = '';
602
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
603
-                            $lqip_w = ',w_' . $imgopt_w;
602
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
603
+                            $lqip_w = ',w_'.$imgopt_w;
604 604
                         }
605
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
606
-                            $lqip_h = ',h_' . $imgopt_h;
605
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
606
+                            $lqip_h = ',h_'.$imgopt_h;
607 607
                         }
608
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
608
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
609 609
                     }
610 610
                     // then call add_lazyload-function with lpiq placeholder if set.
611
-                    $tag = $this->add_lazyload( $tag, $placeholder );
611
+                    $tag = $this->add_lazyload($tag, $placeholder);
612 612
                 }
613 613
 
614 614
                 // and add tag to array for later replacement.
615
-                if ( $tag !== $orig_tag ) {
616
-                    $to_replace[ $orig_tag ] = $tag;
615
+                if ($tag !== $orig_tag) {
616
+                    $to_replace[$orig_tag] = $tag;
617 617
                 }
618 618
             }
619 619
         }
620 620
 
621 621
         // and replace all.
622
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
622
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
623 623
 
624 624
         // img thumbnails in e.g. woocommerce.
625
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
625
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
626 626
             $out = preg_replace_callback(
627 627
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
628
-                array( $this, 'replace_data_thumbs' ),
628
+                array($this, 'replace_data_thumbs'),
629 629
                 $out
630 630
             );
631 631
         }
632 632
 
633 633
         // background-image in inline style.
634
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
634
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
635 635
             $out = preg_replace_callback(
636 636
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
637
-                array( $this, 'replace_img_callback' ),
637
+                array($this, 'replace_img_callback'),
638 638
                 $out
639 639
             );
640 640
         }
641 641
 
642 642
         // act on icon links.
643
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
643
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
644 644
             $out = preg_replace_callback(
645 645
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
646
-                array( $this, 'replace_icon_callback' ),
646
+                array($this, 'replace_icon_callback'),
647 647
                 $out
648 648
             );
649 649
         }
650 650
 
651 651
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
652
-        if ( $this->should_lazyload() ) {
652
+        if ($this->should_lazyload()) {
653 653
             $out = autoptimizeBase::restore_marked_content(
654 654
                 'SCRIPT',
655 655
                 $out
656 656
             );
657 657
 
658
-            $out = $this->process_picture_tag( $out, true, true );
659
-            $out = $this->process_bgimage( $out );
658
+            $out = $this->process_picture_tag($out, true, true);
659
+            $out = $this->process_bgimage($out);
660 660
         } else {
661
-            $out = $this->process_picture_tag( $out, true, false );
661
+            $out = $this->process_picture_tag($out, true, false);
662 662
         }
663 663
 
664 664
         return $out;
665 665
     }
666 666
 
667
-    public function get_size_from_tag( $tag ) {
667
+    public function get_size_from_tag($tag) {
668 668
         // reusable function to extract widht and height from an image tag
669 669
         // enforcing a filterable maximum width and height (default 4999X4999).
670 670
         $width  = '';
671 671
         $height = '';
672 672
 
673
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
674
-            if ( strpos( $_width[2], '%' ) === false ) {
673
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
674
+            if (strpos($_width[2], '%') === false) {
675 675
                 $width = (int) $_width[2];
676 676
             }
677 677
         }
678
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
679
-            if ( strpos( $_height[2], '%' ) === false ) {
678
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
679
+            if (strpos($_height[2], '%') === false) {
680 680
                 $height = (int) $_height[2];
681 681
             }
682 682
         }
683 683
 
684 684
         // check for and enforce (filterable) max sizes.
685
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
686
-        if ( $width > $_max_width ) {
685
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
686
+        if ($width > $_max_width) {
687 687
             $_width = $_max_width;
688
-            $height = $_width / $width * $height;
688
+            $height = $_width/$width*$height;
689 689
             $width  = $_width;
690 690
         }
691
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
692
-        if ( $height > $_max_height ) {
691
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
692
+        if ($height > $_max_height) {
693 693
             $_height = $_max_height;
694
-            $width   = $_height / $height * $width;
694
+            $width   = $_height/$height*$width;
695 695
             $height  = $_height;
696 696
         }
697 697
 
@@ -710,26 +710,26 @@  discard block
 block discarded – undo
710 710
         return $self->should_lazyload();
711 711
     }
712 712
 
713
-    public function should_lazyload( $context = '' ) {
714
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
713
+    public function should_lazyload($context = '') {
714
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
715 715
             $lazyload_return = true;
716 716
         } else {
717 717
             $lazyload_return = false;
718 718
         }
719
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
719
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
720 720
 
721 721
         return $lazyload_return;
722 722
     }
723 723
 
724 724
     public function check_nolazy() {
725
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
725
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
726 726
             return true;
727 727
         } else {
728 728
             return false;
729 729
         }
730 730
     }
731 731
 
732
-    public function filter_lazyload_images( $in )
732
+    public function filter_lazyload_images($in)
733 733
     {
734 734
         // only used is image optimization is NOT active but lazyload is.
735 735
         $to_replace = array();
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
         );
744 744
 
745 745
         // extract img tags and add lazyload attribs.
746
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
747
-            foreach ( $matches[0] as $tag ) {
748
-                if ( $this->should_lazyload( $out ) ) {
749
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
746
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
747
+            foreach ($matches[0] as $tag) {
748
+                if ($this->should_lazyload($out)) {
749
+                    $to_replace[$tag] = $this->add_lazyload($tag);
750 750
                 }
751 751
             }
752
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
752
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
753 753
         }
754 754
 
755 755
         // and also lazyload picture tag.
756
-        $out = $this->process_picture_tag( $out, false, true );
756
+        $out = $this->process_picture_tag($out, false, true);
757 757
 
758 758
         // and inline style blocks with background-image.
759
-        $out = $this->process_bgimage( $out );
759
+        $out = $this->process_bgimage($out);
760 760
 
761 761
         // restore noscript tags.
762 762
         $out = autoptimizeBase::restore_marked_content(
@@ -767,86 +767,86 @@  discard block
 block discarded – undo
767 767
         return $out;
768 768
     }
769 769
 
770
-    public function add_lazyload( $tag, $placeholder = '' ) {
770
+    public function add_lazyload($tag, $placeholder = '') {
771 771
         // adds actual lazyload-attributes to an image node.
772 772
         $this->lazyload_counter++;
773
-        $_lazyload_from_nth = apply_filters( 'autoptimize_filter_imgopt_lazyload_from_nth', $this->options['autoptimize_imgopt_number_field_7'] );
774
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag && $this->lazyload_counter >= $_lazyload_from_nth ) {
775
-            $tag = $this->maybe_fix_missing_quotes( $tag );
773
+        $_lazyload_from_nth = apply_filters('autoptimize_filter_imgopt_lazyload_from_nth', $this->options['autoptimize_imgopt_number_field_7']);
774
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag && $this->lazyload_counter >= $_lazyload_from_nth) {
775
+            $tag = $this->maybe_fix_missing_quotes($tag);
776 776
 
777 777
             // store original tag for use in noscript version.
778
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
778
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
779 779
 
780
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
780
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
781 781
 
782 782
             // insert lazyload class.
783
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
783
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
784 784
 
785
-            if ( ! $placeholder || empty( $placeholder ) ) {
785
+            if (!$placeholder || empty($placeholder)) {
786 786
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
787
-                $_get_size = $this->get_size_from_tag( $tag );
787
+                $_get_size = $this->get_size_from_tag($tag);
788 788
                 $width     = $_get_size['width'];
789 789
                 $height    = $_get_size['height'];
790
-                if ( false === $width || empty( $width ) ) {
790
+                if (false === $width || empty($width)) {
791 791
                     $width = 210; // default width for SVG placeholder.
792 792
                 }
793
-                if ( false === $height || empty( $height ) ) {
794
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
793
+                if (false === $height || empty($height)) {
794
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
795 795
                 }
796 796
 
797 797
                 // insert the actual lazyload stuff.
798 798
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
799
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
799
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
800 800
             }
801 801
 
802
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
803
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
802
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
803
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
804 804
 
805 805
             // move sizes to data-sizes unless filter says no.
806
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
807
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
806
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
807
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
808 808
             }
809 809
 
810 810
             // add the noscript-tag from earlier.
811
-            $tag = $noscript_tag . $tag;
812
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
811
+            $tag = $noscript_tag.$tag;
812
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
813 813
         }
814 814
 
815 815
         return $tag;
816 816
     }
817 817
 
818 818
     public function add_lazyload_js_footer() {
819
-        if ( false === autoptimizeMain::should_buffer() ) {
819
+        if (false === autoptimizeMain::should_buffer()) {
820 820
             return;
821 821
         }
822 822
 
823 823
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
824 824
         $noptimize_flag = '';
825
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
825
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
826 826
             $noptimize_flag = ' data-noptimize="1"';
827 827
         }
828 828
 
829
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
829
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
830 830
         $cdn_url      = $this->get_cdn_url();
831
-        if ( ! empty( $cdn_url ) ) {
832
-            $cdn_url      = rtrim( $cdn_url, '/' );
833
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
831
+        if (!empty($cdn_url)) {
832
+            $cdn_url      = rtrim($cdn_url, '/');
833
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
834 834
         }
835 835
 
836 836
         $type_js = '';
837
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
837
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
838 838
             $type_js = ' type="text/javascript"';
839 839
         }
840 840
 
841 841
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
842
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
843
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
844
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
842
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
843
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
844
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
845 845
 
846 846
         // And add webp detection and loading JS.
847
-        if ( $this->should_ngimg() ) {
847
+        if ($this->should_ngimg()) {
848 848
             // Add AVIF code, can be disabled for now to only do webp.
849
-            if ( apply_filters( 'autoptimize_filter_imgopt_do_avif', true ) ) {
849
+            if (apply_filters('autoptimize_filter_imgopt_do_avif', true)) {
850 850
                 $_ngimg_detect = 'function c_img(a,b){src="avif"==b?"data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABoAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACJtZGF0EgAKCBgADsgQEAwgMgwf8AAAWAAAAACvJ+o=":"data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==";var c=new Image;c.onload=function(){var d=0<c.width&&0<c.height;a(d,b)},c.onerror=function(){a(!1,b)},c.src=src}function s_img(a,b){w=window,"avif"==b?!1==a?c_img(s_img,"webp"):w.ngImg="avif":!1==a?w.ngImg=!1:w.ngImg="webp"}c_img(s_img,"avif");';
851 851
                 $_ngimg_load   = 'document.addEventListener("lazybeforeunveil",function({target:a}){window.ngImg&&["data-src","data-srcset"].forEach(function(b){attr=a.getAttribute(b),null!==attr&&-1==attr.indexOf("/client/to_")&&a.setAttribute(b,attr.replace(/\/client\//,"/client/to_"+window.ngImg+","))})});';
852 852
             } else {
@@ -854,8 +854,8 @@  discard block
 block discarded – undo
854 854
                 $_ngimg_load   = "document.addEventListener('lazybeforeunveil',function({target:b}){window.supportsWebP&&['data-src','data-srcset'].forEach(function(c){attr=b.getAttribute(c),null!==attr&&-1==attr.indexOf('/client/to_webp')&&b.setAttribute(c,attr.replace(/\/client\//,'/client/to_webp,'))})});";
855 855
             }
856 856
             // Keeping autoptimize_filter_imgopt_webp_js filter for now, but it is deprecated as not only for webp any more.
857
-            $_ngimg_output = apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_ngimg_detect . $_ngimg_load . '</script>' );
858
-            echo apply_filters( 'autoptimize_filter_imgopt_ngimg_js', $_ngimg_output );
857
+            $_ngimg_output = apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_ngimg_detect.$_ngimg_load.'</script>');
858
+            echo apply_filters('autoptimize_filter_imgopt_ngimg_js', $_ngimg_output);
859 859
         }
860 860
     }
861 861
 
@@ -863,10 +863,10 @@  discard block
 block discarded – undo
863 863
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
864 864
         static $cdn_url = null;
865 865
 
866
-        if ( null === $cdn_url ) {
867
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
868
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
869
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
866
+        if (null === $cdn_url) {
867
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
868
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
869
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
870 870
         }
871 871
 
872 872
         return $cdn_url;
@@ -876,47 +876,47 @@  discard block
 block discarded – undo
876 876
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
877 877
         static $exclude_lazyload_array = null;
878 878
 
879
-        if ( null === $exclude_lazyload_array ) {
879
+        if (null === $exclude_lazyload_array) {
880 880
             $options = $this->options;
881 881
 
882 882
             // set default exclusions.
883
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
883
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
884 884
 
885 885
             // add from setting.
886
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
886
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
887 887
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
888
-                if ( ! empty( $exclude_lazyload_option ) ) {
889
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
888
+                if (!empty($exclude_lazyload_option)) {
889
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
890 890
                 }
891 891
             }
892 892
 
893 893
             // and filter for developer-initiated changes.
894
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
894
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
895 895
         }
896 896
 
897 897
         return $exclude_lazyload_array;
898 898
     }
899 899
 
900
-    public function inject_classes_in_tag( $tag, $target_class ) {
901
-        if ( strpos( $tag, 'class=' ) !== false ) {
902
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
900
+    public function inject_classes_in_tag($tag, $target_class) {
901
+        if (strpos($tag, 'class=') !== false) {
902
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
903 903
         } else {
904
-            $tag = preg_replace( '/(<[a-zA-Z]*)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
904
+            $tag = preg_replace('/(<[a-zA-Z]*)\s/', '$1 class="'.trim($target_class).'" ', $tag);
905 905
         }
906 906
 
907 907
         return $tag;
908 908
     }
909 909
 
910
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
911
-        return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20' . $imgopt_w . '%20' . $imgopt_h . '%22%3E%3C/svg%3E';
910
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
911
+        return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20'.$imgopt_w.'%20'.$imgopt_h.'%22%3E%3C/svg%3E';
912 912
     }
913 913
 
914 914
     public function should_ngimg() {
915 915
         static $ngimg_return = null;
916 916
 
917
-        if ( is_null( $ngimg_return ) ) {
917
+        if (is_null($ngimg_return)) {
918 918
             // webp only works if imgopt and lazyload are also active.
919
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
919
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
920 920
                 $ngimg_return = true;
921 921
             } else {
922 922
                 $ngimg_return = false;
@@ -926,9 +926,9 @@  discard block
 block discarded – undo
926 926
         return $ngimg_return;
927 927
     }
928 928
 
929
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
929
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
930 930
         // check if "<picture" is present and if filter allows us to process <picture>.
931
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
931
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
932 932
             return $in;
933 933
         }
934 934
 
@@ -936,37 +936,37 @@  discard block
 block discarded – undo
936 936
         $to_replace_pict = array();
937 937
 
938 938
         // extract and process each picture-node.
939
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
940
-        foreach ( $_pictures as $_picture ) {
941
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
942
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
943
-                foreach ( $_sources as $_source ) {
939
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
940
+        foreach ($_pictures as $_picture) {
941
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
942
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
943
+                foreach ($_sources as $_source) {
944 944
                     $_picture_replacement = $_source[0];
945 945
 
946 946
                     // should we optimize the image?
947
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
948
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
947
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
948
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
949 949
                     }
950 950
                     // should we lazy-load?
951
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
952
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
951
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
952
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
953 953
                     }
954
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
954
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
955 955
                 }
956 956
             }
957 957
         }
958 958
 
959 959
         // and return the fully procesed $in.
960
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
960
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
961 961
 
962 962
         return $out;
963 963
     }
964 964
 
965
-    public function process_bgimage( $in ) {
966
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
965
+    public function process_bgimage($in) {
966
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
967 967
             $out = preg_replace_callback(
968 968
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
969
-                array( $this, 'lazyload_bgimg_callback' ),
969
+                array($this, 'lazyload_bgimg_callback'),
970 970
                 $in
971 971
             );
972 972
             return $out;
@@ -974,27 +974,27 @@  discard block
 block discarded – undo
974 974
         return $in;
975 975
     }
976 976
 
977
-    public function lazyload_bgimg_callback( $matches ) {
978
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
977
+    public function lazyload_bgimg_callback($matches) {
978
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
979 979
             // get placeholder & lazyload class strings.
980
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
981
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
980
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
981
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
982 982
             // replace background-image URL with SVG placeholder.
983
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
983
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
984 984
             // add data-bg attribute with real background-image URL for lazyload to pick up.
985
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
985
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
986 986
             // add lazyload class to tag.
987
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
987
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
988 988
             return $out;
989 989
         }
990 990
         return $matches[0];
991 991
     }
992 992
 
993
-    public function maybe_fix_missing_quotes( $tag_in ) {
993
+    public function maybe_fix_missing_quotes($tag_in) {
994 994
         // W3TC's Minify_HTML class removes quotes around attribute value, this re-adds them for the class and width/height attributes so we can lazyload properly.
995
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
996
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
997
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
995
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
996
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
997
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
998 998
             return $tag_out;
999 999
         } else {
1000 1000
             return $tag_in;
@@ -1007,23 +1007,23 @@  discard block
 block discarded – undo
1007 1007
     public function imgopt_admin_menu()
1008 1008
     {
1009 1009
         // no acces if multisite and not network admin and no site config allowed.
1010
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1010
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1011 1011
             add_submenu_page(
1012 1012
                 null,
1013 1013
                 'autoptimize_imgopt',
1014 1014
                 'autoptimize_imgopt',
1015 1015
                 'manage_options',
1016 1016
                 'autoptimize_imgopt',
1017
-                array( $this, 'imgopt_options_page' )
1017
+                array($this, 'imgopt_options_page')
1018 1018
             );
1019 1019
         }
1020
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
1020
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
1021 1021
     }
1022 1022
 
1023
-    public function add_imgopt_tab( $in )
1023
+    public function add_imgopt_tab($in)
1024 1024
     {
1025
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1026
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
1025
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1026
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1027 1027
         }
1028 1028
 
1029 1029
         return $in;
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
     public function imgopt_options_page()
1033 1033
     {
1034 1034
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1035
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1035
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1036 1036
             $this->query_img_provider_stats();
1037 1037
         }
1038 1038
 
@@ -1044,47 +1044,47 @@  discard block
 block discarded – undo
1044 1044
         #ao_settings_form .form-table th {font-weight: normal;}
1045 1045
         #autoptimize_imgopt_descr{font-size: 120%;}
1046 1046
     </style>
1047
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1047
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1048 1048
     <div class="wrap">
1049
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1049
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1050 1050
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1051
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1051
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1052 1052
             <div class="notice-warning notice"><p>
1053 1053
             <?php
1054 1054
             // translators: "Autoptimize support forum" will appear in a "a href".
1055
-            echo sprintf( __( 'The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize' ), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>' );
1055
+            echo sprintf(__('The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize'), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>');
1056 1056
             ?>
1057 1057
             </p></div>
1058 1058
         <?php } ?>
1059 1059
 
1060
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1060
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1061 1061
             <div class="notice-warning notice"><p>
1062
-            <?php _e( 'The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize' ); ?>
1062
+            <?php _e('The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize'); ?>
1063 1063
             </p></div>
1064 1064
         <?php } ?>
1065 1065
 
1066
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1066
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1067 1067
             <div class="notice-warning notice"><p>
1068 1068
             <?php
1069 1069
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1070
-            echo sprintf( __( 'Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize' ), '<a href="admin.php?page=jetpack#/settings">', '</a>' );
1070
+            echo sprintf(__('Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize'), '<a href="admin.php?page=jetpack#/settings">', '</a>');
1071 1071
             ?>
1072 1072
             </p></div>
1073 1073
         <?php } ?>
1074
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1075
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1076
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1077
-        <span id='autoptimize_imgopt_descr'><?php _e( 'Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP and AVIF support included!', 'autoptimize' ); ?></span>
1074
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1075
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1076
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1077
+        <span id='autoptimize_imgopt_descr'><?php _e('Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP and AVIF support included!', 'autoptimize'); ?></span>
1078 1078
         <table class="form-table">
1079 1079
             <tr>
1080
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1080
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1081 1081
                 <td>
1082
-                    <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize' ); ?></label>
1082
+                    <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_1']) && '1' === $options['autoptimize_imgopt_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize'); ?></label>
1083 1083
                     <?php
1084 1084
                     // show shortpixel status.
1085 1085
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1086
-                    if ( $_notice ) {
1087
-                        switch ( $_notice['status'] ) {
1086
+                    if ($_notice) {
1087
+                        switch ($_notice['status']) {
1088 1088
                             case 2:
1089 1089
                                 $_notice_color = 'green';
1090 1090
                                 break;
@@ -1099,35 +1099,35 @@  discard block
 block discarded – undo
1099 1099
                             default:
1100 1100
                                 $_notice_color = 'green';
1101 1101
                         }
1102
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1102
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1103 1103
                     } else {
1104 1104
                         // translators: link points to shortpixel.
1105
-                        $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP and AVIF image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1106
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1107
-                            $upsell_msg_2 = __( 'For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize' );
1105
+                        $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP and AVIF image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1106
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1107
+                            $upsell_msg_2 = __('For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize');
1108 1108
                         } else {
1109 1109
                             // translators: link points to shortpixel.
1110
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1110
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1111 1111
                         }
1112
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1112
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1113 1113
                     }
1114 1114
                     // translators: link points to shortpixel FAQ.
1115
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>' );
1116
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1115
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>');
1116
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1117 1117
                     // translators: links points to shortpixel TOS & Privacy Policy.
1118
-                    $toscopy = sprintf( __( 'Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize' ), '<a href="https://shortpixel.com/tos' . $sp_url_suffix . '" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp' . $sp_url_suffix . '" target="_blank">', '</a>' );
1119
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1118
+                    $toscopy = sprintf(__('Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize'), '<a href="https://shortpixel.com/tos'.$sp_url_suffix.'" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp'.$sp_url_suffix.'" target="_blank">', '</a>');
1119
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1120 1120
                     ?>
1121 1121
                 </td>
1122 1122
             </tr>
1123
-            <tr id='autoptimize_imgopt_optimization_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1124
-                <th scope="row"><?php _e( 'Optimization exclusions', 'autoptimize' ); ?></th>
1123
+            <tr id='autoptimize_imgopt_optimization_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1124
+                <th scope="row"><?php _e('Optimization exclusions', 'autoptimize'); ?></th>
1125 1125
                 <td>
1126
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_optimization_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_6]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_6'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_6'] ); } ?>'><br /><?php _e( 'Comma-separated list of image classes or filenames that should not be optimized.', 'autoptimize' ); ?></label>
1126
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_optimization_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_6]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_6'])) { echo esc_attr($options['autoptimize_imgopt_text_field_6']); } ?>'><br /><?php _e('Comma-separated list of image classes or filenames that should not be optimized.', 'autoptimize'); ?></label>
1127 1127
                 </td>
1128 1128
             </tr>
1129
-            <tr id='autoptimize_imgopt_quality' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1130
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1129
+            <tr id='autoptimize_imgopt_quality' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1130
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1131 1131
                 <td>
1132 1132
                     <label>
1133 1133
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1135,12 +1135,12 @@  discard block
 block discarded – undo
1135 1135
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1136 1136
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1137 1137
 
1138
-                        foreach ( $_imgopt_array as $key => $value ) {
1139
-                            echo '<option value="' . $key . '"';
1140
-                            if ( $_imgopt_val == $key ) {
1138
+                        foreach ($_imgopt_array as $key => $value) {
1139
+                            echo '<option value="'.$key.'"';
1140
+                            if ($_imgopt_val == $key) {
1141 1141
                                 echo ' selected';
1142 1142
                             }
1143
-                            echo '>' . ucfirst( $value ) . '</option>';
1143
+                            echo '>'.ucfirst($value).'</option>';
1144 1144
                         }
1145 1145
                         echo "\n";
1146 1146
                         ?>
@@ -1149,37 +1149,37 @@  discard block
 block discarded – undo
1149 1149
                     <p>
1150 1150
                         <?php
1151 1151
                             // translators: link points to shortpixel image test page.
1152
-                            echo apply_filters( 'autoptimize_imgopt_imgopt_quality_copy', sprintf( __( 'You can %1$stest compression levels here%2$s.', 'autoptimize' ), '<a href="https://shortpixel.com/oic' . $sp_url_suffix . '" target="_blank">', '</a>' ) );
1152
+                            echo apply_filters('autoptimize_imgopt_imgopt_quality_copy', sprintf(__('You can %1$stest compression levels here%2$s.', 'autoptimize'), '<a href="https://shortpixel.com/oic'.$sp_url_suffix.'" target="_blank">', '</a>'));
1153 1153
                         ?>
1154 1154
                     </p>
1155 1155
                 </td>
1156 1156
             </tr>
1157
-            <tr id='autoptimize_imgopt_ngimg' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1158
-                <th scope="row"><?php _e( 'Load WebP or AVIF in supported browsers?', 'autoptimize' ); ?></th>
1157
+            <tr id='autoptimize_imgopt_ngimg' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1158
+                <th scope="row"><?php _e('Load WebP or AVIF in supported browsers?', 'autoptimize'); ?></th>
1159 1159
                 <td>
1160
-                    <label><input type='checkbox' id='autoptimize_imgopt_ngimg_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_4'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Automatically serve "next-gen" WebP or AVIF image formats to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label>
1160
+                    <label><input type='checkbox' id='autoptimize_imgopt_ngimg_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_4']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Automatically serve "next-gen" WebP or AVIF image formats to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label>
1161 1161
                 </td>
1162 1162
             </tr>
1163 1163
             <tr>
1164
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1164
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1165 1165
                 <td>
1166
-                    <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize' ); ?></label>
1166
+                    <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_3']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize'); ?></label>
1167 1167
                 </td>
1168 1168
             </tr>
1169
-            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1170
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1169
+            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1170
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1171 1171
                 <td>
1172
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions_text' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label>
1172
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions_text' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label>
1173 1173
                 </td>
1174 1174
             </tr>
1175
-            <tr id='autoptimize_imgopt_lazyload_from_nth_image' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1176
-                <th scope="row"><?php _e( 'Lazy-load from nth image', 'autoptimize' ); ?></th>
1175
+            <tr id='autoptimize_imgopt_lazyload_from_nth_image' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1176
+                <th scope="row"><?php _e('Lazy-load from nth image', 'autoptimize'); ?></th>
1177 1177
                 <td>
1178
-                    <label><input type='number' min='0' max='50' style='width:80%' id='autoptimize_imgopt_lazyload_from_nth_image_number' name='autoptimize_imgopt_settings[autoptimize_imgopt_number_field_7]' value='<?php if ( ! empty( $options['autoptimize_imgopt_number_field_7'] ) ) { echo esc_attr( $options['autoptimize_imgopt_number_field_7'] ); } else { echo '0'; } ?>'><br /><?php _e( 'Don\'t lazyload the first X images, \'0\' lazyloads all.', 'autoptimize' ); ?></label>
1178
+                    <label><input type='number' min='0' max='50' style='width:80%' id='autoptimize_imgopt_lazyload_from_nth_image_number' name='autoptimize_imgopt_settings[autoptimize_imgopt_number_field_7]' value='<?php if (!empty($options['autoptimize_imgopt_number_field_7'])) { echo esc_attr($options['autoptimize_imgopt_number_field_7']); } else { echo '0'; } ?>'><br /><?php _e('Don\'t lazyload the first X images, \'0\' lazyloads all.', 'autoptimize'); ?></label>
1179 1179
                 </td>
1180 1180
             </tr>
1181 1181
         </table>
1182
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1182
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1183 1183
     </form>
1184 1184
     <script>
1185 1185
         jQuery(document).ready(function() {
@@ -1217,50 +1217,50 @@  discard block
 block discarded – undo
1217 1217
      * Ïmg opt status as used on dashboard.
1218 1218
      */
1219 1219
     public function get_imgopt_status_notice() {
1220
-        if ( $this->imgopt_active() ) {
1220
+        if ($this->imgopt_active()) {
1221 1221
             $_imgopt_notice  = '';
1222
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1222
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1223 1223
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1224
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1224
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1225 1225
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1226 1226
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1227 1227
 
1228
-            if ( is_array( $_stat ) ) {
1229
-                if ( 1 == $_stat['Status'] ) {
1228
+            if (is_array($_stat)) {
1229
+                if (1 == $_stat['Status']) {
1230 1230
                     // translators: "add more credits" will appear in a "a href".
1231
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1231
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1232 1232
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1233 1233
                     // translators: "add more credits" will appear in a "a href".
1234
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1234
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1235 1235
                     // translators: "associate your domain" will appear in a "a href".
1236
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you have enough credits/ CDN quota remaining, then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '<a rel="noopener noreferrer" href="' . $_imgopt_assoc . '" target="_blank">', '</a>' );
1236
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you have enough credits/ CDN quota remaining, then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize'), '<a rel="noopener noreferrer" href="'.$_imgopt_assoc.'" target="_blank">', '</a>');
1237 1237
                 } elseif ( -3 == $_stat['Status'] ) {
1238 1238
                     // translators: "check the documentation here" will appear in a "a href".
1239
-                    $_imgopt_notice = sprintf( __( 'It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize' ), '<a href="' . $_imgopt_unreach . '" target="_blank">', '</a>' );
1239
+                    $_imgopt_notice = sprintf(__('It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize'), '<a href="'.$_imgopt_unreach.'" target="_blank">', '</a>');
1240 1240
                 } else {
1241 1241
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1242 1242
                     // translators: "log in to check your account" will appear in a "a href".
1243
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1243
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1244 1244
                 }
1245 1245
 
1246 1246
                 // add info on freshness + refresh link if status is not 2 (good shape).
1247
-                if ( 2 != $_stat['Status'] ) {
1248
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1247
+                if (2 != $_stat['Status']) {
1248
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1249 1249
                         'page'                => 'autoptimize_imgopt',
1250 1250
                         'refreshImgProvStats' => '1',
1251
-                    ), admin_url( 'options-general.php' ) );
1252
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1253
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1251
+                    ), admin_url('options-general.php'));
1252
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1253
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1254 1254
                     } else {
1255
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1255
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1256 1256
                     }
1257
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1257
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1258 1258
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1259
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1259
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1260 1260
                 }
1261 1261
 
1262 1262
                 // and make the full notice filterable.
1263
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1263
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1264 1264
 
1265 1265
                 return array(
1266 1266
                     'status' => $_stat['Status'],
@@ -1281,14 +1281,14 @@  discard block
 block discarded – undo
1281 1281
      * Get img provider stats (used to display notice).
1282 1282
      */
1283 1283
     public function query_img_provider_stats() {
1284
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1284
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1285 1285
             $url      = '';
1286
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1286
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1287 1287
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1288 1288
 
1289 1289
             // make sure parse_url result makes sense, keeping $url empty if not.
1290
-            if ( $domain && ! empty( $domain ) ) {
1291
-                $url = $endpoint . $domain;
1290
+            if ($domain && !empty($domain)) {
1291
+                $url = $endpoint.$domain;
1292 1292
             }
1293 1293
 
1294 1294
             $url = apply_filters(
@@ -1298,12 +1298,12 @@  discard block
 block discarded – undo
1298 1298
 
1299 1299
             // only do the remote call if $url is not empty to make sure no parse_url
1300 1300
             // weirdness results in useless calls.
1301
-            if ( ! empty( $url ) ) {
1302
-                $response = wp_remote_get( $url );
1303
-                if ( ! is_wp_error( $response ) ) {
1304
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1305
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1306
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1301
+            if (!empty($url)) {
1302
+                $response = wp_remote_get($url);
1303
+                if (!is_wp_error($response)) {
1304
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1305
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1306
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1307 1307
                     }
1308 1308
                 }
1309 1309
             }
@@ -1326,15 +1326,15 @@  discard block
 block discarded – undo
1326 1326
     {
1327 1327
         static $launch_status = null;
1328 1328
 
1329
-        if ( null === $launch_status ) {
1329
+        if (null === $launch_status) {
1330 1330
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1331
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1332
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1331
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1332
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1333 1333
             $launch_status = false;
1334
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1334
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1335 1335
                 $launch_status = true;
1336
-                if ( ! $has_launched ) {
1337
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1336
+                if (!$has_launched) {
1337
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1338 1338
                 }
1339 1339
             }
1340 1340
         }
@@ -1351,16 +1351,16 @@  discard block
 block discarded – undo
1351 1351
     public function get_imgopt_provider_userstatus() {
1352 1352
         static $_provider_userstatus = null;
1353 1353
 
1354
-        if ( is_null( $_provider_userstatus ) ) {
1355
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1356
-            if ( is_array( $_stat ) ) {
1357
-                if ( array_key_exists( 'Status', $_stat ) ) {
1354
+        if (is_null($_provider_userstatus)) {
1355
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1356
+            if (is_array($_stat)) {
1357
+                if (array_key_exists('Status', $_stat)) {
1358 1358
                     $_provider_userstatus['Status'] = $_stat['Status'];
1359 1359
                 } else {
1360 1360
                     // if no stats then we assume all is well.
1361 1361
                     $_provider_userstatus['Status'] = 2;
1362 1362
                 }
1363
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1363
+                if (array_key_exists('timestamp', $_stat)) {
1364 1364
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1365 1365
                 } else {
1366 1366
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,66 +52,66 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rtimelimit' );
62
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' );
63
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' );
64
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' );
65
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' );
66
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' );
67
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' );
68
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' );
69
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' );
70
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rtimelimit');
62
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize');
63
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug');
64
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_key');
65
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst');
66
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin');
67
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath');
68
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery');
69
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain');
70
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss');
71 71
 
72 72
         // And add submenu-page.
73
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
73
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
74 74
     }
75 75
 
76
-    public function admin_assets( $hook ) {
76
+    public function admin_assets($hook) {
77 77
         // Return if plugin is not hooked.
78
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
78
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
79 79
             return;
80 80
         }
81 81
 
82 82
         // Stylesheets to add.
83
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
84
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
85
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
83
+        wp_enqueue_style('wp-jquery-ui-dialog');
84
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
85
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
86 86
 
87 87
         // Scripts to add.
88
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
89
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
90
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
91
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
88
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
89
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
90
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
91
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
92 92
     }
93 93
 
94 94
     public function ao_criticalcsssettings_page()
95 95
     {
96 96
         // these are not OO yet, simply require for now.
97
-        require_once( 'critcss-inc/admin_settings_rules.php' );
98
-        require_once( 'critcss-inc/admin_settings_queue.php' );
99
-        require_once( 'critcss-inc/admin_settings_key.php' );
100
-        require_once( 'critcss-inc/admin_settings_adv.php' );
101
-        require_once( 'critcss-inc/admin_settings_explain.php' );
97
+        require_once('critcss-inc/admin_settings_rules.php');
98
+        require_once('critcss-inc/admin_settings_queue.php');
99
+        require_once('critcss-inc/admin_settings_key.php');
100
+        require_once('critcss-inc/admin_settings_adv.php');
101
+        require_once('critcss-inc/admin_settings_explain.php');
102 102
 
103 103
         // fetch all options at once and populate them individually explicitely as globals.
104 104
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
105
-        foreach ( $all_options as $_option => $_value ) {
105
+        foreach ($all_options as $_option => $_value) {
106 106
             global ${$_option};
107 107
             ${$_option} = $_value;
108 108
         }
109 109
         ?>
110
-        <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
110
+        <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
111 111
         <div class="wrap">
112 112
             <div id="autoptimize_main">
113 113
                 <div id="ao_title_and_button">
114
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
114
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
115 115
                 </div>
116 116
 
117 117
                 <?php
@@ -119,39 +119,39 @@  discard block
 block discarded – undo
119 119
                 echo autoptimizeConfig::ao_admin_tabs();
120 120
 
121 121
                 // Make sure dir to write ao_ccss exists and is writable.
122
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
123
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
122
+                if (!is_dir(AO_CCSS_DIR)) {
123
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
124 124
                 } else {
125 125
                     $mkdirresp = true;
126 126
                 }
127 127
 
128 128
                 // Make sure our index.html is there.
129
-                if ( ! is_file( AO_CCSS_DIR . 'index.html' ) ) {
130
-                    $fileresp = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' );
129
+                if (!is_file(AO_CCSS_DIR.'index.html')) {
130
+                    $fileresp = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>');
131 131
                 } else {
132 132
                     $fileresp = true;
133 133
                 }
134 134
 
135 135
                 // Warn if we could not create those files.
136
-                if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
136
+                if ((!$mkdirresp) || (!$fileresp)) {
137 137
                     ?>
138 138
                     <div class="notice-error notice"><p>
139 139
                     <?php
140
-                    _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
140
+                    _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
141 141
                     ?>
142 142
                     </p></div>
143 143
                     <?php
144 144
                 }
145 145
 
146 146
                 // Check for "inline & defer CSS" being active in Autoptimize.
147
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
148
-                    if ( empty( $ao_ccss_keyst ) ) {
147
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
148
+                    if (empty($ao_ccss_keyst)) {
149 149
                         // no keystate so likely in activation-process of CCSS, let's enable "inline & defer CSS" immediately to make things easier!
150
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_css_defer', 'on' );
150
+                        autoptimizeOptionWrapper::update_option('autoptimize_css_defer', 'on');
151 151
                         ?>
152 152
                         <div class="notice-info notice"><p>
153 153
                         <?php
154
-                        _e( "The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize' );
154
+                        _e("The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize');
155 155
                         ?>
156 156
                         </p></div>
157 157
                         <?php
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                         ?>
161 161
                         <div class="notice-warning notice"><p>
162 162
                         <?php
163
-                        _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to ensure critical CSS is used on the front-end.", 'autoptimize' );
163
+                        _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to ensure critical CSS is used on the front-end.", 'autoptimize');
164 164
                         ?>
165 165
                         </p></div>
166 166
                         <?php
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
                 }
169 169
 
170 170
                 // check if WordPress cron is disabled and warn if so.
171
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
171
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
172 172
                     ?>
173 173
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
174 174
                     <?php
175
-                    _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
175
+                    _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
176 176
                     ?>
177 177
                     </p></div>
178 178
                     <?php
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 
181 181
                 // warn if it looks as though the queue processing job looks isn't running
182 182
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
183
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
184
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
183
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
184
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
185 185
                     $_jobs_all_new         = true;
186
-                    $_oldest_job_timestamp = microtime( true ); // now.
186
+                    $_oldest_job_timestamp = microtime(true); // now.
187 187
                     $_jobs_too_old         = true;
188 188
 
189 189
                     // go over queue array.
190
-                    if ( empty( $ao_ccss_queue ) ) {
190
+                    if (empty($ao_ccss_queue)) {
191 191
                         // no jobs, then no warning.
192 192
                         $_jobs_all_new = false;
193 193
                     } else {
194
-                        foreach ( $ao_ccss_queue as $job ) {
195
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
194
+                        foreach ($ao_ccss_queue as $job) {
195
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
196 196
                                 // we need to catch the oldest job's timestamp.
197 197
                                 $_oldest_job_timestamp = $job['jctime'];
198 198
                             }
199 199
 
200
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
200
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
201 201
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
202 202
                                 $_jobs_all_new = false;
203 203
                                 break;
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
                     }
207 207
 
208 208
                     // is the oldest job too old (4h)?
209
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
209
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
210 210
                         $_jobs_too_old = false;
211 211
                     }
212 212
 
213
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
213
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
214 214
                         $_warn_cron            = 'on';
215 215
                         $_transient_multiplier = 1; // store for 1 hour.
216 216
                     } else {
@@ -218,35 +218,35 @@  discard block
 block discarded – undo
218 218
                         $_transient_multiplier = 4; // store for 4 hours.
219 219
                     }
220 220
                     // and set transient.
221
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
221
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
222 222
                 }
223 223
 
224
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
224
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
225 225
                     ?>
226 226
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
227 227
                     <?php
228
-                    _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
228
+                    _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
229 229
                     ?>
230 230
                     </p></div>
231 231
                     <?php
232
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
232
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
233 233
                     ?>
234 234
                     <div class="notice-success notice"><p>
235 235
                     <?php
236
-                    _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' );
236
+                    _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize');
237 237
                     echo ' ';
238
-                    _e( 'In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize' );
238
+                    _e('In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize');
239 239
                     ?>
240 240
                     </p></div>
241 241
                     <?php
242 242
                 }
243 243
 
244 244
                 // warn if service is down.
245
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
245
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
246 246
                     ?>
247 247
                     <div class="notice-warning notice"><p>
248 248
                     <?php
249
-                    _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' );
249
+                    _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize');
250 250
                     ?>
251 251
                     </p></div>
252 252
                     <?php
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
 
255 255
                 // warn if too many rules (based on length of ao_ccss_rules option) as that might cause issues at e.g. wpengine
256 256
                 // see https://wpengine.com/support/database-optimization-best-practices/#Autoloaded_Data
257
-                $_raw_rules_length = strlen( get_option( 'autoptimize_ccss_rules', '') );
258
-                if ( $_raw_rules_length > apply_filters( 'autoptimize_ccss_rules_length_warning', 500000 ) ) {
257
+                $_raw_rules_length = strlen(get_option('autoptimize_ccss_rules', ''));
258
+                if ($_raw_rules_length > apply_filters('autoptimize_ccss_rules_length_warning', 500000)) {
259 259
                     ?>
260 260
                     <div class="notice-warning notice"><p>
261 261
                     <?php
262
-                    _e( 'It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize' );
262
+                    _e('It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize');
263 263
                     ?>
264 264
                     </p></div>
265 265
                     <?php
@@ -269,24 +269,24 @@  discard block
 block discarded – undo
269 269
                 ?>
270 270
                 <form id="settings" method="post" action="options.php">
271 271
                     <?php
272
-                    settings_fields( 'ao_ccss_options_group' );
272
+                    settings_fields('ao_ccss_options_group');
273 273
 
274 274
                     // Get API key status.
275
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
275
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
276 276
 
277
-                    if ( $this->is_multisite_network_admin() ) {
277
+                    if ($this->is_multisite_network_admin()) {
278 278
                         ?>
279 279
                         <ul id="key-panel">
280 280
                             <li class="itemDetail">
281 281
                             <?php
282 282
                                 // translators: the placesholder is for a line of code in wp-config.php.
283
-                                echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' );
283
+                                echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>');
284 284
                             ?>
285 285
                             </li>
286 286
                         </ul>
287 287
                         <?php
288 288
                     } else {
289
-                        if ( 'valid' == $key['status'] ) {
289
+                        if ('valid' == $key['status']) {
290 290
                             // If key status is valid, render other panels.
291 291
                             // Render rules section.
292 292
                             ao_ccss_render_rules();
@@ -303,23 +303,23 @@  discard block
 block discarded – undo
303 303
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
304 304
 
305 305
                             // Add hidden fields.
306
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
307
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
308
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
309
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
310
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
311
-                            echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="' . $ao_ccss_rtimelimit . '">';
312
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
313
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
314
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
315
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
316
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
306
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
307
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
308
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
309
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
310
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
311
+                            echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="'.$ao_ccss_rtimelimit.'">';
312
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
313
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
314
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
315
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
316
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
317 317
                         }
318 318
                         // Render key panel unconditionally.
319
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
319
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
320 320
                         ?>
321 321
                         <p class="submit left">
322
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
322
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
323 323
                         </p>
324 324
                         <?php
325 325
                     }
@@ -337,31 +337,31 @@  discard block
 block discarded – undo
337 337
                     });
338 338
                 }
339 339
                 </script>
340
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
341
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
342
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
340
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
341
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
342
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
343 343
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
344 344
                 </form>
345 345
                 <div id="importdialog"></div>
346 346
             </div><!-- /#autoptimize_main -->
347 347
         </div><!-- /#wrap -->
348 348
         <?php
349
-        if ( ! $this->is_multisite_network_admin() ) {
349
+        if (!$this->is_multisite_network_admin()) {
350 350
             // Include debug panel if debug mode is enable.
351
-            if ( $ao_ccss_debug ) {
351
+            if ($ao_ccss_debug) {
352 352
             ?>
353 353
                 <div id="debug">
354 354
                     <?php
355 355
                     // Include debug panel.
356
-                    include( 'critcss-inc/admin_settings_debug.php' );
356
+                    include('critcss-inc/admin_settings_debug.php');
357 357
                     ?>
358 358
                 </div><!-- /#debug -->
359 359
             <?php
360 360
             }
361 361
             echo '<script>';
362
-            include( 'critcss-inc/admin_settings_rules.js.php' );
363
-            include( 'critcss-inc/admin_settings_queue.js.php' );
364
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
362
+            include('critcss-inc/admin_settings_rules.js.php');
363
+            include('critcss-inc/admin_settings_queue.js.php');
364
+            include('critcss-inc/admin_settings_impexp.js.php');
365 365
             echo '</script>';
366 366
         }
367 367
     }
@@ -369,19 +369,19 @@  discard block
 block discarded – undo
369 369
     public static function ao_ccss_has_autorules() {
370 370
         static $_has_auto_rules = null;
371 371
 
372
-        if ( null === $_has_auto_rules ) {
372
+        if (null === $_has_auto_rules) {
373 373
             global $ao_ccss_rules;
374 374
             $_has_auto_rules = false;
375
-            if ( ! empty( $ao_ccss_rules ) ) {
376
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
377
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
378
-                        if ( ! empty( $rule['hash'] ) ) {
375
+            if (!empty($ao_ccss_rules)) {
376
+                foreach (array('types', 'paths') as $_typat) {
377
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
378
+                        if (!empty($rule['hash'])) {
379 379
                             // we have at least one AUTO job, so all is fine.
380 380
                             $_has_auto_rules = true;
381 381
                             break;
382 382
                         }
383 383
                     }
384
-                    if ( $_has_auto_rules ) {
384
+                    if ($_has_auto_rules) {
385 385
                         break;
386 386
                     }
387 387
                 }
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
     public function is_multisite_network_admin() {
395 395
         static $_multisite_network_admin = null;
396 396
 
397
-        if ( null === $_multisite_network_admin ) {
398
-            if ( is_multisite() && is_network_admin() ) {
397
+        if (null === $_multisite_network_admin) {
398
+            if (is_multisite() && is_network_admin()) {
399 399
                 $_multisite_network_admin = true;
400 400
             } else {
401 401
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.