Completed
Push — master ( 5da188...964b0c )
by frank
01:47
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.7.7' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.7.7');
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/autoptimizeImages.php 1 patch
Spacing   +345 added lines, -345 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,17 +23,17 @@  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
     }
35 35
 
36
-    public function set_options( array $options )
36
+    public function set_options(array $options)
37 37
     {
38 38
         $this->options = $options;
39 39
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 
43 43
     public static function fetch_options()
44 44
     {
45
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
46
-        if ( empty( $value ) ) {
45
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
46
+        if (empty($value)) {
47 47
             // Fallback to returning defaults when no stored option exists yet.
48 48
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
49 49
         }
50 50
 
51 51
         // get service availability and add it to the options-array.
52
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
52
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
53 53
 
54
-        if ( empty( $value['availabilities'] ) ) {
55
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
54
+        if (empty($value['availabilities'])) {
55
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
56 56
         }
57 57
 
58 58
         return $value;
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         // and does not use/ request the availablity data (which could slow things down).
66 66
         static $imgopt_active = null;
67 67
 
68
-        if ( null === $imgopt_active ) {
69
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
70
-            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'] ) {
68
+        if (null === $imgopt_active) {
69
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
70
+            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']) {
71 71
                 $imgopt_active = true;
72 72
             } else {
73 73
                 $imgopt_active = false;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public static function instance()
89 89
     {
90
-        if ( null === self::$instance ) {
90
+        if (null === self::$instance) {
91 91
             self::$instance = new self();
92 92
         }
93 93
 
@@ -96,34 +96,34 @@  discard block
 block discarded – undo
96 96
 
97 97
     public function run()
98 98
     {
99
-        if ( is_admin() ) {
100
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
101
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
99
+        if (is_admin()) {
100
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
101
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
102 102
             } else {
103
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
103
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
104 104
             }
105
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
105
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
106 106
         } else {
107
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
107
+            add_action('wp', array($this, 'run_on_frontend'));
108 108
         }
109 109
     }
110 110
 
111 111
     public function run_on_frontend() {
112
-        if ( ! $this->should_run() ) {
113
-            if ( $this->should_lazyload() ) {
112
+        if (!$this->should_run()) {
113
+            if ($this->should_lazyload()) {
114 114
                 add_filter(
115 115
                     'wp_lazy_loading_enabled',
116 116
                     '__return_false'
117 117
                 );
118 118
                 add_filter(
119 119
                     'autoptimize_html_after_minify',
120
-                    array( $this, 'filter_lazyload_images' ),
120
+                    array($this, 'filter_lazyload_images'),
121 121
                     10,
122 122
                     1
123 123
                 );
124 124
                 add_action(
125 125
                     'wp_footer',
126
-                    array( $this, 'add_lazyload_js_footer' ),
126
+                    array($this, 'add_lazyload_js_footer'),
127 127
                     10,
128 128
                     0
129 129
                 );
@@ -133,43 +133,43 @@  discard block
 block discarded – undo
133 133
 
134 134
         $active = false;
135 135
 
136
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
136
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
137 137
             add_filter(
138 138
                 'autoptimize_html_after_minify',
139
-                array( $this, 'filter_optimize_images' ),
139
+                array($this, 'filter_optimize_images'),
140 140
                 10,
141 141
                 1
142 142
             );
143 143
             $active = true;
144 144
         }
145 145
 
146
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
146
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
147 147
             add_filter(
148 148
                 'autoptimize_filter_base_replace_cdn',
149
-                array( $this, 'filter_optimize_css_images' ),
149
+                array($this, 'filter_optimize_css_images'),
150 150
                 10,
151 151
                 1
152 152
             );
153 153
             $active = true;
154 154
         }
155 155
 
156
-        if ( $active ) {
156
+        if ($active) {
157 157
             add_filter(
158 158
                 'autoptimize_extra_filter_tobepreconn',
159
-                array( $this, 'filter_preconnect_imgopt_url' ),
159
+                array($this, 'filter_preconnect_imgopt_url'),
160 160
                 10,
161 161
                 1
162 162
             );
163 163
         }
164 164
 
165
-        if ( $this->should_lazyload() ) {
165
+        if ($this->should_lazyload()) {
166 166
             add_filter(
167 167
                 'wp_lazy_loading_enabled',
168 168
                 '__return_false'
169 169
             );
170 170
             add_action(
171 171
                 'wp_footer',
172
-                array( $this, 'add_lazyload_js_footer' ),
172
+                array($this, 'add_lazyload_js_footer'),
173 173
                 10,
174 174
                 0
175 175
             );
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
     protected function should_run()
185 185
     {
186 186
         $opts              = $this->options;
187
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
188
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
187
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
188
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
189 189
 
190 190
         $do_cdn      = true;
191 191
         $_userstatus = $this->get_imgopt_provider_userstatus();
192
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
192
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
193 193
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
194 194
             $do_cdn = false;
195 195
         }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $this->imgopt_active()
199 199
             && $do_cdn
200 200
             && $service_not_down
201
-            && ( $not_launch_status || $this->launch_ok() )
201
+            && ($not_launch_status || $this->launch_ok())
202 202
         ) {
203 203
             return true;
204 204
         }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     {
210 210
         static $imgopt_host = null;
211 211
 
212
-        if ( null === $imgopt_host ) {
212
+        if (null === $imgopt_host) {
213 213
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
214 214
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
215
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
216
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
215
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
216
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
217 217
             }
218
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
218
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
219 219
         }
220 220
 
221 221
         return $imgopt_host;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
     public static function get_service_url_suffix()
232 232
     {
233
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
233
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
234 234
 
235 235
         return $suffix;
236 236
     }
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
     {
240 240
         static $quality = null;
241 241
 
242
-        if ( null === $quality ) {
242
+        if (null === $quality) {
243 243
             $q_array = $this->get_img_quality_array();
244 244
             $setting = $this->get_img_quality_setting();
245 245
             $quality = apply_filters(
246 246
                 'autoptimize_filter_imgopt_quality',
247
-                'q_' . $q_array[ $setting ]
247
+                'q_'.$q_array[$setting]
248 248
             );
249 249
         }
250 250
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     {
256 256
         static $map = null;
257 257
 
258
-        if ( null === $map ) {
258
+        if (null === $map) {
259 259
             $map = array(
260 260
                 '1' => 'lossy',
261 261
                 '2' => 'glossy',
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
     {
275 275
         static $q = null;
276 276
 
277
-        if ( null === $q ) {
278
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
277
+        if (null === $q) {
278
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
279 279
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
280 280
             }
281 281
 
282
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
282
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
283 283
                 // default image opt. value is 2 ("glossy").
284 284
                 $q = '2';
285 285
             } else {
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
         return $q;
291 291
     }
292 292
 
293
-    public function filter_preconnect_imgopt_url( array $in )
293
+    public function filter_preconnect_imgopt_url(array $in)
294 294
     {
295
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
296
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
295
+        $url_parts = parse_url($this->get_imgopt_base_url());
296
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
297 297
 
298 298
         return $in;
299 299
     }
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
      *
307 307
      * @return string
308 308
      */
309
-    private function normalize_img_url( $in )
309
+    private function normalize_img_url($in)
310 310
     {
311 311
         // Only parse the site url once.
312 312
         static $parsed_site_url = null;
313
-        if ( null === $parsed_site_url ) {
314
-            $parsed_site_url = parse_url( site_url() );
313
+        if (null === $parsed_site_url) {
314
+            $parsed_site_url = parse_url(site_url());
315 315
         }
316 316
 
317 317
         // get CDN domain once.
318 318
         static $cdn_domain = null;
319
-        if ( is_null( $cdn_domain ) ) {
319
+        if (is_null($cdn_domain)) {
320 320
             $cdn_url = $this->get_cdn_url();
321
-            if ( ! empty( $cdn_url ) ) {
322
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
321
+            if (!empty($cdn_url)) {
322
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
323 323
             } else {
324 324
                 $cdn_domain = '';
325 325
             }
@@ -335,44 +335,44 @@  discard block
 block discarded – undo
335 335
          * identical string operations).
336 336
          */
337 337
         static $cache = null;
338
-        if ( null === $cache ) {
338
+        if (null === $cache) {
339 339
             $cache = array();
340 340
         }
341 341
 
342 342
         // Do the work on cache miss only.
343
-        if ( ! isset( $cache[ $in ] ) ) {
343
+        if (!isset($cache[$in])) {
344 344
             // Default to (the trimmed version of) what was given to us.
345
-            $result = trim( $in );
345
+            $result = trim($in);
346 346
 
347 347
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
348
-            if ( strpos( $result, '&quot;' ) !== false ) {
349
-                $result = str_replace( '&quot;', '', $result );
348
+            if (strpos($result, '&quot;') !== false) {
349
+                $result = str_replace('&quot;', '', $result);
350 350
             }
351 351
 
352
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
353
-                $result = $parsed_site_url['scheme'] . ':' . $result;
354
-            } elseif ( 0 === strpos( $result, '/' ) ) {
352
+            if (autoptimizeUtils::is_protocol_relative($result)) {
353
+                $result = $parsed_site_url['scheme'].':'.$result;
354
+            } elseif (0 === strpos($result, '/')) {
355 355
                 // Root-relative...
356
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
357
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
358
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
356
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
357
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
358
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
359 359
             }
360 360
 
361
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
361
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
362 362
 
363 363
             // Store in cache.
364
-            $cache[ $in ] = $result;
364
+            $cache[$in] = $result;
365 365
         }
366 366
 
367
-        return $cache[ $in ];
367
+        return $cache[$in];
368 368
     }
369 369
 
370
-    public function filter_optimize_css_images( $in )
370
+    public function filter_optimize_css_images($in)
371 371
     {
372
-        $in = $this->normalize_img_url( $in );
372
+        $in = $this->normalize_img_url($in);
373 373
 
374
-        if ( $this->can_optimize_image( $in ) ) {
375
-            return $this->build_imgopt_url( $in, '', '' );
374
+        if ($this->can_optimize_image($in)) {
375
+            return $this->build_imgopt_url($in, '', '');
376 376
         } else {
377 377
             return $in;
378 378
         }
@@ -382,50 +382,50 @@  discard block
 block discarded – undo
382 382
     {
383 383
         static $imgopt_base_url = null;
384 384
 
385
-        if ( null === $imgopt_base_url ) {
385
+        if (null === $imgopt_base_url) {
386 386
             $imgopt_host     = $this->get_imgopt_host();
387 387
             $quality         = $this->get_img_quality_string();
388
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
389
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
390
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
388
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
389
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
390
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
391 391
         }
392 392
 
393 393
         return $imgopt_base_url;
394 394
     }
395 395
 
396
-    private function can_optimize_image( $url, $tag = '' )
396
+    private function can_optimize_image($url, $tag = '')
397 397
     {
398 398
         static $cdn_url      = null;
399 399
         static $nopti_images = null;
400 400
 
401
-        if ( null === $cdn_url ) {
401
+        if (null === $cdn_url) {
402 402
             $cdn_url = apply_filters(
403 403
                 'autoptimize_filter_base_cdnurl',
404
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
404
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
405 405
             );
406 406
         }
407 407
 
408
-        if ( null === $nopti_images ) {
409
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' );
408
+        if (null === $nopti_images) {
409
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', '');
410 410
         }
411 411
 
412 412
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
413
-        $url        = $this->normalize_img_url( $url );
414
-        $url_parsed = parse_url( $url );
413
+        $url        = $this->normalize_img_url($url);
414
+        $url_parsed = parse_url($url);
415 415
 
416
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
416
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
417 417
             return false;
418
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
418
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
419 419
             return false;
420
-        } elseif ( strpos( $url, '.php' ) !== false ) {
420
+        } elseif (strpos($url, '.php') !== false) {
421 421
             return false;
422
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
422
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp'), '', $url_parsed['path']) === $url_parsed['path']) {
423 423
             // fixme: better check against end of string.
424 424
             return false;
425
-        } elseif ( ! empty( $nopti_images ) ) {
426
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
427
-            foreach ( $nopti_images_array as $nopti_image ) {
428
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
425
+        } elseif (!empty($nopti_images)) {
426
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
427
+            foreach ($nopti_images_array as $nopti_image) {
428
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
429 429
                     return false;
430 430
                 }
431 431
             }
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
         return true;
434 434
     }
435 435
 
436
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
436
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
437 437
     {
438 438
         // sanitize width and height.
439
-        if ( strpos( $width, '%' ) !== false ) {
439
+        if (strpos($width, '%') !== false) {
440 440
             $width = 0;
441 441
         }
442
-        if ( strpos( $height, '%' ) !== false ) {
442
+        if (strpos($height, '%') !== false) {
443 443
             $height = 0;
444 444
         }
445 445
         $width  = (int) $width;
@@ -453,56 +453,56 @@  discard block
 block discarded – undo
453 453
         );
454 454
 
455 455
         // If filter modified the url, return that.
456
-        if ( $filtered_url !== $orig_url ) {
456
+        if ($filtered_url !== $orig_url) {
457 457
             return $filtered_url;
458 458
         }
459 459
 
460
-        $orig_url        = $this->normalize_img_url( $orig_url );
460
+        $orig_url        = $this->normalize_img_url($orig_url);
461 461
         $imgopt_base_url = $this->get_imgopt_base_url();
462 462
         $imgopt_size     = '';
463 463
 
464
-        if ( $width && 0 !== $width ) {
465
-            $imgopt_size = ',w_' . $width;
464
+        if ($width && 0 !== $width) {
465
+            $imgopt_size = ',w_'.$width;
466 466
         }
467 467
 
468
-        if ( $height && 0 !== $height ) {
469
-            $imgopt_size .= ',h_' . $height;
468
+        if ($height && 0 !== $height) {
469
+            $imgopt_size .= ',h_'.$height;
470 470
         }
471 471
 
472
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
472
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
473 473
 
474 474
         return $url;
475 475
     }
476 476
 
477
-    public function replace_data_thumbs( $matches )
477
+    public function replace_data_thumbs($matches)
478 478
     {
479
-        return $this->replace_img_callback( $matches, 150, 150 );
479
+        return $this->replace_img_callback($matches, 150, 150);
480 480
     }
481 481
 
482
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
482
+    public function replace_img_callback($matches, $width = 0, $height = 0)
483 483
     {
484
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
485
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
486
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
484
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
485
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
486
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
487 487
         } else {
488 488
             return $matches[0];
489 489
         }
490 490
     }
491 491
 
492
-    public function replace_icon_callback( $matches )
492
+    public function replace_icon_callback($matches)
493 493
     {
494
-        if ( array_key_exists( '2', $matches ) ) {
495
-            $sizes  = explode( 'x', $matches[2] );
494
+        if (array_key_exists('2', $matches)) {
495
+            $sizes  = explode('x', $matches[2]);
496 496
             $width  = $sizes[0];
497 497
             $height = $sizes[1];
498 498
         } else {
499 499
             $width  = 180;
500 500
             $height = 180;
501 501
         }
502
-        return $this->replace_img_callback( $matches, $width, $height );
502
+        return $this->replace_img_callback($matches, $width, $height);
503 503
     }
504 504
 
505
-    public function filter_optimize_images( $in )
505
+    public function filter_optimize_images($in)
506 506
     {
507 507
         /*
508 508
          * potential future functional improvements:
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         $to_replace = array();
513 513
 
514 514
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
515
-        if ( $this->should_lazyload() ) {
515
+        if ($this->should_lazyload()) {
516 516
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
517 517
                 'SCRIPT',
518 518
                 '<script',
@@ -522,25 +522,25 @@  discard block
 block discarded – undo
522 522
         }
523 523
 
524 524
         // extract img tags.
525
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
526
-            foreach ( $matches[0] as $tag ) {
525
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
526
+            foreach ($matches[0] as $tag) {
527 527
                 $orig_tag = $tag;
528 528
                 $imgopt_w = '';
529 529
                 $imgopt_h = '';
530 530
 
531 531
                 // first do (data-)srcsets.
532
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
533
-                    foreach ( $allsrcsets as $srcset ) {
532
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
533
+                    foreach ($allsrcsets as $srcset) {
534 534
                         $srcset  = $srcset[2];
535
-                        $srcsets = explode( ',', $srcset );
536
-                        foreach ( $srcsets as $indiv_srcset ) {
537
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
538
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
539
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
535
+                        $srcsets = explode(',', $srcset);
536
+                        foreach ($srcsets as $indiv_srcset) {
537
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
538
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
539
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
540 540
                             }
541
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag ) ) {
542
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
543
-                                $tag        = str_replace( $indiv_srcset_parts[0], $imgopt_url, $tag );
541
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag)) {
542
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
543
+                                $tag        = str_replace($indiv_srcset_parts[0], $imgopt_url, $tag);
544 544
                             }
545 545
                         }
546 546
                     }
@@ -548,133 +548,133 @@  discard block
 block discarded – undo
548 548
 
549 549
                 // proceed with img src.
550 550
                 // get width and height and add to $imgopt_size.
551
-                $_get_size = $this->get_size_from_tag( $tag );
551
+                $_get_size = $this->get_size_from_tag($tag);
552 552
                 $imgopt_w  = $_get_size['width'];
553 553
                 $imgopt_h  = $_get_size['height'];
554 554
 
555 555
                 // then start replacing images src.
556
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
557
-                    foreach ( $urls as $url ) {
556
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
557
+                    foreach ($urls as $url) {
558 558
                         $full_src_orig = $url[0];
559 559
                         $url           = $url[1];
560
-                        if ( $this->can_optimize_image( $url, $full_src_orig ) ) {
561
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
562
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
563
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
560
+                        if ($this->can_optimize_image($url, $full_src_orig)) {
561
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
562
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
563
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
564 564
                         }
565 565
                     }
566 566
                 }
567 567
 
568 568
                 // do lazyload stuff.
569
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
569
+                if ($this->should_lazyload($in) && !empty($url)) {
570 570
                     // first do lpiq placeholder logic.
571
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
571
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
572 572
                         // if all img src have been replaced during srcset, we have to extract the
573 573
                         // origin url from the imgopt one to be able to set a lqip placeholder.
574
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
574
+                        $_url = substr($url, strpos($url, '/http') + 1);
575 575
                     } else {
576 576
                         $_url = $url;
577 577
                     }
578 578
 
579
-                    $_url = $this->normalize_img_url( $_url );
579
+                    $_url = $this->normalize_img_url($_url);
580 580
 
581 581
                     $placeholder = '';
582
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
582
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
583 583
                         $lqip_w = '';
584 584
                         $lqip_h = '';
585
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
586
-                            $lqip_w = ',w_' . $imgopt_w;
585
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
586
+                            $lqip_w = ',w_'.$imgopt_w;
587 587
                         }
588
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
589
-                            $lqip_h = ',h_' . $imgopt_h;
588
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
589
+                            $lqip_h = ',h_'.$imgopt_h;
590 590
                         }
591
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
591
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
592 592
                     }
593 593
                     // then call add_lazyload-function with lpiq placeholder if set.
594
-                    $tag = $this->add_lazyload( $tag, $placeholder );
594
+                    $tag = $this->add_lazyload($tag, $placeholder);
595 595
                 }
596 596
 
597 597
                 // and add tag to array for later replacement.
598
-                if ( $tag !== $orig_tag ) {
599
-                    $to_replace[ $orig_tag ] = $tag;
598
+                if ($tag !== $orig_tag) {
599
+                    $to_replace[$orig_tag] = $tag;
600 600
                 }
601 601
             }
602 602
         }
603 603
 
604 604
         // and replace all.
605
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
605
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
606 606
 
607 607
         // img thumbnails in e.g. woocommerce.
608
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
608
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
609 609
             $out = preg_replace_callback(
610 610
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
611
-                array( $this, 'replace_data_thumbs' ),
611
+                array($this, 'replace_data_thumbs'),
612 612
                 $out
613 613
             );
614 614
         }
615 615
 
616 616
         // background-image in inline style.
617
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
617
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
618 618
             $out = preg_replace_callback(
619 619
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
620
-                array( $this, 'replace_img_callback' ),
620
+                array($this, 'replace_img_callback'),
621 621
                 $out
622 622
             );
623 623
         }
624 624
 
625 625
         // act on icon links.
626
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
626
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
627 627
             $out = preg_replace_callback(
628 628
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
629
-                array( $this, 'replace_icon_callback' ),
629
+                array($this, 'replace_icon_callback'),
630 630
                 $out
631 631
             );
632 632
         }
633 633
 
634 634
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
635
-        if ( $this->should_lazyload() ) {
635
+        if ($this->should_lazyload()) {
636 636
             $out = autoptimizeBase::restore_marked_content(
637 637
                 'SCRIPT',
638 638
                 $out
639 639
             );
640 640
 
641
-            $out = $this->process_picture_tag( $out, true, true );
642
-            $out = $this->process_bgimage( $out );
641
+            $out = $this->process_picture_tag($out, true, true);
642
+            $out = $this->process_bgimage($out);
643 643
         } else {
644
-            $out = $this->process_picture_tag( $out, true, false );
644
+            $out = $this->process_picture_tag($out, true, false);
645 645
         }
646 646
 
647 647
         return $out;
648 648
     }
649 649
 
650
-    public function get_size_from_tag( $tag ) {
650
+    public function get_size_from_tag($tag) {
651 651
         // reusable function to extract widht and height from an image tag
652 652
         // enforcing a filterable maximum width and height (default 4999X4999).
653 653
         $width  = '';
654 654
         $height = '';
655 655
 
656
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
657
-            if ( strpos( $_width[2], '%' ) === false ) {
656
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
657
+            if (strpos($_width[2], '%') === false) {
658 658
                 $width = (int) $_width[2];
659 659
             }
660 660
         }
661
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
662
-            if ( strpos( $_height[2], '%' ) === false ) {
661
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
662
+            if (strpos($_height[2], '%') === false) {
663 663
                 $height = (int) $_height[2];
664 664
             }
665 665
         }
666 666
 
667 667
         // check for and enforce (filterable) max sizes.
668
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
669
-        if ( $width > $_max_width ) {
668
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
669
+        if ($width > $_max_width) {
670 670
             $_width = $_max_width;
671
-            $height = $_width / $width * $height;
671
+            $height = $_width/$width*$height;
672 672
             $width  = $_width;
673 673
         }
674
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
675
-        if ( $height > $_max_height ) {
674
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
675
+        if ($height > $_max_height) {
676 676
             $_height = $_max_height;
677
-            $width   = $_height / $height * $width;
677
+            $width   = $_height/$height*$width;
678 678
             $height  = $_height;
679 679
         }
680 680
 
@@ -693,26 +693,26 @@  discard block
 block discarded – undo
693 693
         return $self->should_lazyload();
694 694
     }
695 695
 
696
-    public function should_lazyload( $context = '' ) {
697
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
696
+    public function should_lazyload($context = '') {
697
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
698 698
             $lazyload_return = true;
699 699
         } else {
700 700
             $lazyload_return = false;
701 701
         }
702
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
702
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
703 703
 
704 704
         return $lazyload_return;
705 705
     }
706 706
 
707 707
     public function check_nolazy() {
708
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
708
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
709 709
             return true;
710 710
         } else {
711 711
             return false;
712 712
         }
713 713
     }
714 714
 
715
-    public function filter_lazyload_images( $in )
715
+    public function filter_lazyload_images($in)
716 716
     {
717 717
         // only used is image optimization is NOT active but lazyload is.
718 718
         $to_replace = array();
@@ -726,20 +726,20 @@  discard block
 block discarded – undo
726 726
         );
727 727
 
728 728
         // extract img tags and add lazyload attribs.
729
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
730
-            foreach ( $matches[0] as $tag ) {
731
-                if ( $this->should_lazyload( $out ) ) {
732
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
729
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
730
+            foreach ($matches[0] as $tag) {
731
+                if ($this->should_lazyload($out)) {
732
+                    $to_replace[$tag] = $this->add_lazyload($tag);
733 733
                 }
734 734
             }
735
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
735
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
736 736
         }
737 737
 
738 738
         // and also lazyload picture tag.
739
-        $out = $this->process_picture_tag( $out, false, true );
739
+        $out = $this->process_picture_tag($out, false, true);
740 740
 
741 741
         // and inline style blocks with background-image.
742
-        $out = $this->process_bgimage( $out );
742
+        $out = $this->process_bgimage($out);
743 743
 
744 744
         // restore noscript tags.
745 745
         $out = autoptimizeBase::restore_marked_content(
@@ -750,85 +750,85 @@  discard block
 block discarded – undo
750 750
         return $out;
751 751
     }
752 752
 
753
-    public function add_lazyload( $tag, $placeholder = '' ) {
753
+    public function add_lazyload($tag, $placeholder = '') {
754 754
         // adds actual lazyload-attributes to an image node.
755
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
756
-            $tag = $this->maybe_fix_missing_quotes( $tag );
755
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) {
756
+            $tag = $this->maybe_fix_missing_quotes($tag);
757 757
 
758 758
             // store original tag for use in noscript version.
759
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
759
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
760 760
 
761
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
761
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
762 762
 
763 763
             // insert lazyload class.
764
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
764
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
765 765
 
766
-            if ( ! $placeholder || empty( $placeholder ) ) {
766
+            if (!$placeholder || empty($placeholder)) {
767 767
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
768
-                $_get_size = $this->get_size_from_tag( $tag );
768
+                $_get_size = $this->get_size_from_tag($tag);
769 769
                 $width     = $_get_size['width'];
770 770
                 $height    = $_get_size['height'];
771
-                if ( false === $width || empty( $width ) ) {
771
+                if (false === $width || empty($width)) {
772 772
                     $width = 210; // default width for SVG placeholder.
773 773
                 }
774
-                if ( false === $height || empty( $height ) ) {
775
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
774
+                if (false === $height || empty($height)) {
775
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
776 776
                 }
777 777
 
778 778
                 // insert the actual lazyload stuff.
779 779
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
780
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
780
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
781 781
             }
782 782
 
783
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
784
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
783
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
784
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
785 785
 
786 786
             // move sizes to data-sizes unless filter says no.
787
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
788
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
787
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
788
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
789 789
             }
790 790
 
791 791
             // add the noscript-tag from earlier.
792
-            $tag = $noscript_tag . $tag;
793
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
792
+            $tag = $noscript_tag.$tag;
793
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
794 794
         }
795 795
 
796 796
         return $tag;
797 797
     }
798 798
 
799 799
     public function add_lazyload_js_footer() {
800
-        if ( false === autoptimizeMain::should_buffer() ) {
800
+        if (false === autoptimizeMain::should_buffer()) {
801 801
             return;
802 802
         }
803 803
 
804 804
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
805 805
         $noptimize_flag = '';
806
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
806
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
807 807
             $noptimize_flag = ' data-noptimize="1"';
808 808
         }
809 809
 
810
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
810
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
811 811
         $cdn_url      = $this->get_cdn_url();
812
-        if ( ! empty( $cdn_url ) ) {
813
-            $cdn_url      = rtrim( $cdn_url, '/' );
814
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
812
+        if (!empty($cdn_url)) {
813
+            $cdn_url      = rtrim($cdn_url, '/');
814
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
815 815
         }
816 816
 
817 817
         $type_js = '';
818
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
818
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
819 819
             $type_js = ' type="text/javascript"';
820 820
         }
821 821
 
822 822
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
823
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
824
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
825
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
823
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
824
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
825
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
826 826
 
827 827
         // And add webp detection and loading JS.
828
-        if ( $this->should_webp() ) {
828
+        if ($this->should_webp()) {
829 829
             $_webp_detect = "function c_webp(A){var n=new Image;n.onload=function(){var e=0<n.width&&0<n.height;A(e)},n.onerror=function(){A(!1)},n.src='data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA=='}function s_webp(e){window.supportsWebP=e}c_webp(s_webp);";
830 830
             $_webp_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,'))})});";
831
-            echo apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_webp_detect . $_webp_load . '</script>' );
831
+            echo apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_webp_detect.$_webp_load.'</script>');
832 832
         }
833 833
     }
834 834
 
@@ -836,10 +836,10 @@  discard block
 block discarded – undo
836 836
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
837 837
         static $cdn_url = null;
838 838
 
839
-        if ( null === $cdn_url ) {
840
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
841
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
842
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
839
+        if (null === $cdn_url) {
840
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
841
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
842
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
843 843
         }
844 844
 
845 845
         return $cdn_url;
@@ -849,47 +849,47 @@  discard block
 block discarded – undo
849 849
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
850 850
         static $exclude_lazyload_array = null;
851 851
 
852
-        if ( null === $exclude_lazyload_array ) {
852
+        if (null === $exclude_lazyload_array) {
853 853
             $options = $this->options;
854 854
 
855 855
             // set default exclusions.
856
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
856
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
857 857
 
858 858
             // add from setting.
859
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
859
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
860 860
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
861
-                if ( ! empty( $exclude_lazyload_option ) ) {
862
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
861
+                if (!empty($exclude_lazyload_option)) {
862
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
863 863
                 }
864 864
             }
865 865
 
866 866
             // and filter for developer-initiated changes.
867
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
867
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
868 868
         }
869 869
 
870 870
         return $exclude_lazyload_array;
871 871
     }
872 872
 
873
-    public function inject_classes_in_tag( $tag, $target_class ) {
874
-        if ( strpos( $tag, 'class=' ) !== false ) {
875
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
873
+    public function inject_classes_in_tag($tag, $target_class) {
874
+        if (strpos($tag, 'class=') !== false) {
875
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
876 876
         } else {
877
-            $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
877
+            $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag);
878 878
         }
879 879
 
880 880
         return $tag;
881 881
     }
882 882
 
883
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
884
-        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';
883
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
884
+        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';
885 885
     }
886 886
 
887 887
     public function should_webp() {
888 888
         static $webp_return = null;
889 889
 
890
-        if ( is_null( $webp_return ) ) {
890
+        if (is_null($webp_return)) {
891 891
             // webp only works if imgopt and lazyload are also active.
892
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
892
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
893 893
                 $webp_return = true;
894 894
             } else {
895 895
                 $webp_return = false;
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
         return $webp_return;
900 900
     }
901 901
 
902
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
902
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
903 903
         // check if "<picture" is present and if filter allows us to process <picture>.
904
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
904
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
905 905
             return $in;
906 906
         }
907 907
 
@@ -909,37 +909,37 @@  discard block
 block discarded – undo
909 909
         $to_replace_pict = array();
910 910
 
911 911
         // extract and process each picture-node.
912
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
913
-        foreach ( $_pictures as $_picture ) {
914
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
915
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
916
-                foreach ( $_sources as $_source ) {
912
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
913
+        foreach ($_pictures as $_picture) {
914
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
915
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
916
+                foreach ($_sources as $_source) {
917 917
                     $_picture_replacement = $_source[0];
918 918
 
919 919
                     // should we optimize the image?
920
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
921
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
920
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
921
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
922 922
                     }
923 923
                     // should we lazy-load?
924
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
925
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
924
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
925
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
926 926
                     }
927
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
927
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
928 928
                 }
929 929
             }
930 930
         }
931 931
 
932 932
         // and return the fully procesed $in.
933
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
933
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
934 934
 
935 935
         return $out;
936 936
     }
937 937
 
938
-    public function process_bgimage( $in ) {
939
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
938
+    public function process_bgimage($in) {
939
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
940 940
             $out = preg_replace_callback(
941 941
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
942
-                array( $this, 'lazyload_bgimg_callback' ),
942
+                array($this, 'lazyload_bgimg_callback'),
943 943
                 $in
944 944
             );
945 945
             return $out;
@@ -947,27 +947,27 @@  discard block
 block discarded – undo
947 947
         return $in;
948 948
     }
949 949
 
950
-    public function lazyload_bgimg_callback( $matches ) {
951
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
950
+    public function lazyload_bgimg_callback($matches) {
951
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
952 952
             // get placeholder & lazyload class strings.
953
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
954
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
953
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
954
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
955 955
             // replace background-image URL with SVG placeholder.
956
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
956
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
957 957
             // add data-bg attribute with real background-image URL for lazyload to pick up.
958
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
958
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
959 959
             // add lazyload class to tag.
960
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
960
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
961 961
             return $out;
962 962
         }
963 963
         return $matches[0];
964 964
     }
965 965
 
966
-    public function maybe_fix_missing_quotes( $tag_in ) {
966
+    public function maybe_fix_missing_quotes($tag_in) {
967 967
         // 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.
968
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
969
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
970
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
968
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
969
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
970
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
971 971
             return $tag_out;
972 972
         } else {
973 973
             return $tag_in;
@@ -980,23 +980,23 @@  discard block
 block discarded – undo
980 980
     public function imgopt_admin_menu()
981 981
     {
982 982
         // no acces if multisite and not network admin and no site config allowed.
983
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
983
+        if (autoptimizeConfig::should_show_menu_tabs()) {
984 984
             add_submenu_page(
985 985
                 null,
986 986
                 'autoptimize_imgopt',
987 987
                 'autoptimize_imgopt',
988 988
                 'manage_options',
989 989
                 'autoptimize_imgopt',
990
-                array( $this, 'imgopt_options_page' )
990
+                array($this, 'imgopt_options_page')
991 991
             );
992 992
         }
993
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
993
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
994 994
     }
995 995
 
996
-    public function add_imgopt_tab( $in )
996
+    public function add_imgopt_tab($in)
997 997
     {
998
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
999
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
998
+        if (autoptimizeConfig::should_show_menu_tabs()) {
999
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1000 1000
         }
1001 1001
 
1002 1002
         return $in;
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     public function imgopt_options_page()
1006 1006
     {
1007 1007
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1008
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1008
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1009 1009
             $this->query_img_provider_stats();
1010 1010
         }
1011 1011
 
@@ -1017,47 +1017,47 @@  discard block
 block discarded – undo
1017 1017
         #ao_settings_form .form-table th {font-weight: normal;}
1018 1018
         #autoptimize_imgopt_descr{font-size: 120%;}
1019 1019
     </style>
1020
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1020
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1021 1021
     <div class="wrap">
1022
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1022
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1023 1023
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1024
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1024
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1025 1025
             <div class="notice-warning notice"><p>
1026 1026
             <?php
1027 1027
             // translators: "Autoptimize support forum" will appear in a "a href".
1028
-            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>' );
1028
+            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>');
1029 1029
             ?>
1030 1030
             </p></div>
1031 1031
         <?php } ?>
1032 1032
 
1033
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1033
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1034 1034
             <div class="notice-warning notice"><p>
1035
-            <?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' ); ?>
1035
+            <?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'); ?>
1036 1036
             </p></div>
1037 1037
         <?php } ?>
1038 1038
 
1039
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1039
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1040 1040
             <div class="notice-warning notice"><p>
1041 1041
             <?php
1042 1042
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1043
-            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>' );
1043
+            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>');
1044 1044
             ?>
1045 1045
             </p></div>
1046 1046
         <?php } ?>
1047
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1048
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1049
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1050
-        <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 support included!', 'autoptimize' ); ?></span>
1047
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1048
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1049
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1050
+        <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 support included!', 'autoptimize'); ?></span>
1051 1051
         <table class="form-table">
1052 1052
             <tr>
1053
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1053
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1054 1054
                 <td>
1055
-                    <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>
1055
+                    <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>
1056 1056
                     <?php
1057 1057
                     // show shortpixel status.
1058 1058
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1059
-                    if ( $_notice ) {
1060
-                        switch ( $_notice['status'] ) {
1059
+                    if ($_notice) {
1060
+                        switch ($_notice['status']) {
1061 1061
                             case 2:
1062 1062
                                 $_notice_color = 'green';
1063 1063
                                 break;
@@ -1072,29 +1072,29 @@  discard block
 block discarded – undo
1072 1072
                             default:
1073 1073
                                 $_notice_color = 'green';
1074 1074
                         }
1075
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1075
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1076 1076
                     } else {
1077 1077
                         // translators: link points to shortpixel.
1078
-                        $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 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>' );
1079
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1080
-                            $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' );
1078
+                        $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 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>');
1079
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1080
+                            $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');
1081 1081
                         } else {
1082 1082
                             // translators: link points to shortpixel.
1083
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive a 1 000 bonus + 50&#37; more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1083
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive a 1 000 bonus + 50&#37; more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1084 1084
                         }
1085
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1085
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1086 1086
                     }
1087 1087
                     // translators: link points to shortpixel FAQ.
1088
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>' );
1089
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1088
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>');
1089
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1090 1090
                     // translators: links points to shortpixel TOS & Privacy Policy.
1091
-                    $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>' );
1092
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1091
+                    $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>');
1092
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1093 1093
                     ?>
1094 1094
                 </td>
1095 1095
             </tr>
1096
-            <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"'; } ?>>
1097
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1096
+            <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"'; } ?>>
1097
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1098 1098
                 <td>
1099 1099
                     <label>
1100 1100
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1102,12 +1102,12 @@  discard block
 block discarded – undo
1102 1102
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1103 1103
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1104 1104
 
1105
-                        foreach ( $_imgopt_array as $key => $value ) {
1106
-                            echo '<option value="' . $key . '"';
1107
-                            if ( $_imgopt_val == $key ) {
1105
+                        foreach ($_imgopt_array as $key => $value) {
1106
+                            echo '<option value="'.$key.'"';
1107
+                            if ($_imgopt_val == $key) {
1108 1108
                                 echo ' selected';
1109 1109
                             }
1110
-                            echo '>' . ucfirst( $value ) . '</option>';
1110
+                            echo '>'.ucfirst($value).'</option>';
1111 1111
                         }
1112 1112
                         echo "\n";
1113 1113
                         ?>
@@ -1116,31 +1116,31 @@  discard block
 block discarded – undo
1116 1116
                     <p>
1117 1117
                         <?php
1118 1118
                             // translators: link points to shortpixel image test page.
1119
-                            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>' ) );
1119
+                            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>'));
1120 1120
                         ?>
1121 1121
                     </p>
1122 1122
                 </td>
1123 1123
             </tr>
1124
-            <tr id='autoptimize_imgopt_webp' <?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"'; } ?>>
1125
-                <th scope="row"><?php _e( 'Load WebP in supported browsers?', 'autoptimize' ); ?></th>
1124
+            <tr id='autoptimize_imgopt_webp' <?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"'; } ?>>
1125
+                <th scope="row"><?php _e('Load WebP in supported browsers?', 'autoptimize'); ?></th>
1126 1126
                 <td>
1127
-                    <label><input type='checkbox' id='autoptimize_imgopt_webp_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 image format to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label>
1127
+                    <label><input type='checkbox' id='autoptimize_imgopt_webp_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 image format to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label>
1128 1128
                 </td>
1129 1129
             </tr>
1130 1130
             <tr>
1131
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1131
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1132 1132
                 <td>
1133
-                    <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>
1133
+                    <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>
1134 1134
                 </td>
1135 1135
             </tr>
1136
-            <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="hidden"'; } ?>>
1137
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1136
+            <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="hidden"'; } ?>>
1137
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1138 1138
                 <td>
1139
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' 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>
1139
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' 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>
1140 1140
                 </td>
1141 1141
             </tr>
1142 1142
         </table>
1143
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1143
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1144 1144
     </form>
1145 1145
     <script>
1146 1146
         jQuery(document).ready(function() {
@@ -1176,50 +1176,50 @@  discard block
 block discarded – undo
1176 1176
      * Ïmg opt status as used on dashboard.
1177 1177
      */
1178 1178
     public function get_imgopt_status_notice() {
1179
-        if ( $this->imgopt_active() ) {
1179
+        if ($this->imgopt_active()) {
1180 1180
             $_imgopt_notice  = '';
1181
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1181
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1182 1182
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1183
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1183
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1184 1184
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1185 1185
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1186 1186
 
1187
-            if ( is_array( $_stat ) ) {
1188
-                if ( 1 == $_stat['Status'] ) {
1187
+            if (is_array($_stat)) {
1188
+                if (1 == $_stat['Status']) {
1189 1189
                     // translators: "add more credits" will appear in a "a href".
1190
-                    $_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>' );
1190
+                    $_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>');
1191 1191
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1192 1192
                     // translators: "add more credits" will appear in a "a href".
1193
-                    $_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>' );
1193
+                    $_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>');
1194 1194
                     // translators: "associate your domain" will appear in a "a href".
1195
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you already have enough credits 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>' );
1195
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you already have enough credits 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>');
1196 1196
                 } elseif ( -3 == $_stat['Status'] ) {
1197 1197
                     // translators: "check the documentation here" will appear in a "a href".
1198
-                    $_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>' );
1198
+                    $_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>');
1199 1199
                 } else {
1200 1200
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1201 1201
                     // translators: "log in to check your account" will appear in a "a href".
1202
-                    $_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>' );
1202
+                    $_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>');
1203 1203
                 }
1204 1204
 
1205 1205
                 // add info on freshness + refresh link if status is not 2 (good shape).
1206
-                if ( 2 != $_stat['Status'] ) {
1207
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1206
+                if (2 != $_stat['Status']) {
1207
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1208 1208
                         'page'                => 'autoptimize_imgopt',
1209 1209
                         'refreshImgProvStats' => '1',
1210
-                    ), admin_url( 'options-general.php' ) );
1211
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1212
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1210
+                    ), admin_url('options-general.php'));
1211
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1212
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1213 1213
                     } else {
1214
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1214
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1215 1215
                     }
1216
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1216
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1217 1217
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1218
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1218
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1219 1219
                 }
1220 1220
 
1221 1221
                 // and make the full notice filterable.
1222
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1222
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1223 1223
 
1224 1224
                 return array(
1225 1225
                     'status' => $_stat['Status'],
@@ -1240,14 +1240,14 @@  discard block
 block discarded – undo
1240 1240
      * Get img provider stats (used to display notice).
1241 1241
      */
1242 1242
     public function query_img_provider_stats() {
1243
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1243
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1244 1244
             $url      = '';
1245
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1245
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1246 1246
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1247 1247
 
1248 1248
             // make sure parse_url result makes sense, keeping $url empty if not.
1249
-            if ( $domain && ! empty( $domain ) ) {
1250
-                $url = $endpoint . $domain;
1249
+            if ($domain && !empty($domain)) {
1250
+                $url = $endpoint.$domain;
1251 1251
             }
1252 1252
 
1253 1253
             $url = apply_filters(
@@ -1257,12 +1257,12 @@  discard block
 block discarded – undo
1257 1257
 
1258 1258
             // only do the remote call if $url is not empty to make sure no parse_url
1259 1259
             // weirdness results in useless calls.
1260
-            if ( ! empty( $url ) ) {
1261
-                $response = wp_remote_get( $url );
1262
-                if ( ! is_wp_error( $response ) ) {
1263
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1264
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1265
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1260
+            if (!empty($url)) {
1261
+                $response = wp_remote_get($url);
1262
+                if (!is_wp_error($response)) {
1263
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1264
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1265
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1266 1266
                     }
1267 1267
                 }
1268 1268
             }
@@ -1285,15 +1285,15 @@  discard block
 block discarded – undo
1285 1285
     {
1286 1286
         static $launch_status = null;
1287 1287
 
1288
-        if ( null === $launch_status ) {
1288
+        if (null === $launch_status) {
1289 1289
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1290
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1291
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1290
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1291
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1292 1292
             $launch_status = false;
1293
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1293
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1294 1294
                 $launch_status = true;
1295
-                if ( ! $has_launched ) {
1296
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1295
+                if (!$has_launched) {
1296
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1297 1297
                 }
1298 1298
             }
1299 1299
         }
@@ -1310,16 +1310,16 @@  discard block
 block discarded – undo
1310 1310
     public function get_imgopt_provider_userstatus() {
1311 1311
         static $_provider_userstatus = null;
1312 1312
 
1313
-        if ( is_null( $_provider_userstatus ) ) {
1314
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1315
-            if ( is_array( $_stat ) ) {
1316
-                if ( array_key_exists( 'Status', $_stat ) ) {
1313
+        if (is_null($_provider_userstatus)) {
1314
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1315
+            if (is_array($_stat)) {
1316
+                if (array_key_exists('Status', $_stat)) {
1317 1317
                     $_provider_userstatus['Status'] = $_stat['Status'];
1318 1318
                 } else {
1319 1319
                     // if no stats then we assume all is well.
1320 1320
                     $_provider_userstatus['Status'] = 2;
1321 1321
                 }
1322
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1322
+                if (array_key_exists('timestamp', $_stat)) {
1323 1323
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1324 1324
                 } else {
1325 1325
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/external/php/minify-html.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     {
74 74
         $this->_html = str_replace("\r\n", "\n", trim($html));
75 75
         if (isset($options['xhtml'])) {
76
-            $this->_isXhtml = (bool)$options['xhtml'];
76
+            $this->_isXhtml = (bool) $options['xhtml'];
77 77
         }
78 78
         if (isset($options['cssMinifier'])) {
79 79
             $this->_cssMinifier = $options['cssMinifier'];
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
99 99
         }
100 100
 
101
-        $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
101
+        $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']);
102 102
         $this->_placeholders = array();
103 103
 
104 104
         // replace SCRIPTs (and minify) with placeholders
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             ,$this->_html);
115 115
 
116 116
         // remove HTML comments (not containing IE conditional comments).
117
-        if  ($this->_keepComments == false) {
117
+        if ($this->_keepComments == false) {
118 118
             $this->_html = preg_replace_callback(
119 119
                 '/<!--([\\s\\S]*?)-->/'
120 120
                 ,array($this, '_commentCB')
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
160 160
 
161 161
         // reverse order while preserving keys to ensure the last replacement is done first, etc ...
162
-        $this->_placeholders = array_reverse( $this->_placeholders, true );
162
+        $this->_placeholders = array_reverse($this->_placeholders, true);
163 163
 
164 164
         // fill placeholders
165 165
         $this->_html = str_replace(
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
     protected function _reservePlace($content)
181 181
     {
182
-        $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
182
+        $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%';
183 183
         $this->_placeholders[$placeholder] = $content;
184 184
         return $placeholder;
185 185
     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 
194 194
     protected function _outsideTagCB($m)
195 195
     {
196
-        return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
196
+        return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<';
197 197
     }
198 198
 
199 199
     protected function _removePreCB($m)
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     protected function _removeCdata($str)
266 266
     {
267 267
         return (false !== strpos($str, '<![CDATA['))
268
-            ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
268
+            ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str)
269 269
             : $str;
270 270
     }
271 271
 
Please login to merge, or discard this patch.
classes/autoptimizeMain.php 1 patch
Spacing   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @param string $version Version.
34 34
      * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks.
35 35
      */
36
-    public function __construct( $version, $filepath )
36
+    public function __construct($version, $filepath)
37 37
     {
38 38
         $this->version  = $version;
39 39
         $this->filepath = $filepath;
@@ -50,102 +50,102 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected function add_hooks()
52 52
     {
53
-        if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) {
54
-            define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' );
53
+        if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) {
54
+            define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded');
55 55
         }
56 56
 
57
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) );
58
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) );
57
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup'));
58
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge'));
59 59
 
60
-        add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) );
61
-        add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) );
62
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ), 15 );
63
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ), 20 );
64
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss' ), 11 );
65
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_notfound_fallback' ), 10 );
60
+        add_action('autoptimize_setup_done', array($this, 'version_upgrades_check'));
61
+        add_action('autoptimize_setup_done', array($this, 'check_cache_and_run'));
62
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'), 15);
63
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'), 20);
64
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_criticalcss'), 11);
65
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_notfound_fallback'), 10);
66 66
 
67
-        add_action( 'init', array( $this, 'load_textdomain' ) );
68
-        add_action( 'admin_init', array( 'PAnD', 'init' ) );
67
+        add_action('init', array($this, 'load_textdomain'));
68
+        add_action('admin_init', array('PAnD', 'init'));
69 69
 
70
-        if ( is_multisite() && is_admin() ) {
70
+        if (is_multisite() && is_admin()) {
71 71
             // Only if multisite and if in admin we want to check if we need to save options on network level.
72
-            add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' );
72
+            add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options');
73 73
         }
74 74
 
75 75
         // register uninstall & deactivation hooks.
76
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
77
-        register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' );
76
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
77
+        register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation');
78 78
     }
79 79
 
80 80
     public function load_textdomain()
81 81
     {
82
-        load_plugin_textdomain( 'autoptimize' );
82
+        load_plugin_textdomain('autoptimize');
83 83
     }
84 84
 
85 85
     public function setup()
86 86
     {
87 87
         // Do we gzip in php when caching or is the webserver doing it?
88
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) );
88
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip'));
89 89
 
90 90
         // These can be overridden by specifying them in wp-config.php or such.
91
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
92
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
91
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
92
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
93 93
         }
94
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
95
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
94
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
95
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
96 96
         }
97
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
98
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
97
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
98
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
99 99
         }
100 100
         // Note: trailing slash is not optional!
101
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
102
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
101
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
102
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
103 103
         }
104 104
 
105
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
105
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
106 106
 
107
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
108
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
109
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
107
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
108
+            if (function_exists('domain_mapping_siteurl')) {
109
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
110 110
             } else {
111
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
111
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
112 112
             }
113 113
         }
114
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
115
-            if ( function_exists( 'get_original_url' ) ) {
116
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
114
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
115
+            if (function_exists('get_original_url')) {
116
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
117 117
             } else {
118
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
118
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
119 119
             }
120 120
         }
121
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
122
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
121
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
122
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
123 123
                 $blog_id = get_current_blog_id();
124
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
124
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
125 125
             } else {
126
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
126
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
127 127
             }
128 128
         }
129
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
130
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
129
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
130
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
131 131
         }
132
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
133
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
132
+        if (!defined('AUTOPTIMIZE_HASH')) {
133
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
134 134
         }
135
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
136
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
135
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
136
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
137 137
         }
138 138
 
139 139
         // Multibyte-capable string replacements are available with a filter.
140 140
         // Also requires 'mbstring' extension.
141
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
142
-        if ( $with_mbstring ) {
143
-            autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) );
141
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
142
+        if ($with_mbstring) {
143
+            autoptimizeUtils::mbstring_available(\extension_loaded('mbstring'));
144 144
         } else {
145
-            autoptimizeUtils::mbstring_available( false );
145
+            autoptimizeUtils::mbstring_available(false);
146 146
         }
147 147
 
148
-        do_action( 'autoptimize_setup_done' );
148
+        do_action('autoptimize_setup_done');
149 149
     }
150 150
 
151 151
     /**
@@ -155,61 +155,61 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function version_upgrades_check()
157 157
     {
158
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
158
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
159 159
     }
160 160
 
161 161
     public function check_cache_and_run()
162 162
     {
163
-        if ( autoptimizeCache::cacheavail() ) {
163
+        if (autoptimizeCache::cacheavail()) {
164 164
             $conf = autoptimizeConfig::instance();
165
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) {
166
-                if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) {
165
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) {
166
+                if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) {
167 167
                     // Hook into WordPress frontend.
168
-                    if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
168
+                    if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
169 169
                         add_action(
170 170
                             'init',
171
-                            array( $this, 'start_buffering' ),
171
+                            array($this, 'start_buffering'),
172 172
                             self::INIT_EARLIER_PRIORITY
173 173
                         );
174 174
                     } else {
175
-                        if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
176
-                            define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
175
+                        if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
176
+                            define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
177 177
                         }
178 178
                         add_action(
179
-                            constant( 'AUTOPTIMIZE_HOOK_INTO' ),
180
-                            array( $this, 'start_buffering' ),
179
+                            constant('AUTOPTIMIZE_HOOK_INTO'),
180
+                            array($this, 'start_buffering'),
181 181
                             self::DEFAULT_HOOK_PRIORITY
182 182
                         );
183 183
                     }
184 184
                 }
185 185
 
186 186
                 // And disable Jetpack's site accelerator if JS or CSS opt. are active.
187
-                if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) {
188
-                    add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
187
+                if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) {
188
+                    add_filter('jetpack_force_disable_site_accelerator', '__return_true');
189 189
                 }
190 190
             }
191 191
         } else {
192
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
192
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
193 193
         }
194 194
     }
195 195
 
196 196
     public function maybe_run_ao_extra()
197 197
     {
198
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
198
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
199 199
             $ao_imgopt = new autoptimizeImages();
200 200
             $ao_imgopt->run();
201 201
             $ao_extra = new autoptimizeExtra();
202 202
             $ao_extra->run();
203 203
 
204 204
             // And show the imgopt notice.
205
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
205
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
206 206
         }
207 207
     }
208 208
 
209 209
     public function maybe_run_partners_tab()
210 210
     {
211 211
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
212
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
212
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
213 213
             new autoptimizePartners();
214 214
         }
215 215
     }
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
     public function maybe_run_criticalcss()
218 218
     {
219 219
         // Loads criticalcss if the power-up is not active and if the filter returns true.
220
-        if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
220
+        if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) {
221 221
             new autoptimizeCriticalCSSBase();
222 222
         }
223 223
     }
224 224
 
225 225
     public function maybe_run_notfound_fallback()
226 226
     {
227
-        if ( autoptimizeCache::do_fallback() ) {
228
-            add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) );
227
+        if (autoptimizeCache::do_fallback()) {
228
+            add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback'));
229 229
         }
230 230
     }
231 231
 
232 232
     public function hook_page_cache_purge()
233 233
     {
234 234
         // hook into a collection of page cache purge actions if filter allows.
235
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
235
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
236 236
             $page_cache_purge_actions = array(
237 237
                 'after_rocket_clean_domain', // exists.
238 238
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
                 'wpo_cache_flush', // wp-optimize.
248 248
                 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper.
249 249
             );
250
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
251
-            foreach ( $page_cache_purge_actions as $purge_action ) {
252
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
250
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
251
+            foreach ($page_cache_purge_actions as $purge_action) {
252
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
253 253
             }
254 254
         }
255 255
     }
@@ -261,38 +261,38 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function start_buffering()
263 263
     {
264
-        if ( $this->should_buffer() ) {
264
+        if ($this->should_buffer()) {
265 265
 
266 266
             // Load speedupper conditionally (true by default).
267
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
267
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
268 268
                 $ao_speedupper = new autoptimizeSpeedupper();
269 269
             }
270 270
 
271 271
             $conf = autoptimizeConfig::instance();
272 272
 
273
-            if ( $conf->get( 'autoptimize_js' ) ) {
274
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
275
-                    define( 'CONCATENATE_SCRIPTS', false );
273
+            if ($conf->get('autoptimize_js')) {
274
+                if (!defined('CONCATENATE_SCRIPTS')) {
275
+                    define('CONCATENATE_SCRIPTS', false);
276 276
                 }
277
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
278
-                    define( 'COMPRESS_SCRIPTS', false );
277
+                if (!defined('COMPRESS_SCRIPTS')) {
278
+                    define('COMPRESS_SCRIPTS', false);
279 279
                 }
280 280
             }
281 281
 
282
-            if ( $conf->get( 'autoptimize_css' ) ) {
283
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
284
-                    define( 'COMPRESS_CSS', false );
282
+            if ($conf->get('autoptimize_css')) {
283
+                if (!defined('COMPRESS_CSS')) {
284
+                    define('COMPRESS_CSS', false);
285 285
                 }
286 286
             }
287 287
 
288
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
289
-                while ( ob_get_level() > 0 ) {
288
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
289
+                while (ob_get_level() > 0) {
290 290
                     ob_end_clean();
291 291
                 }
292 292
             }
293 293
 
294 294
             // Now, start the real thing!
295
-            ob_start( array( $this, 'end_buffering' ) );
295
+            ob_start(array($this, 'end_buffering'));
296 296
         }
297 297
     }
298 298
 
@@ -303,31 +303,31 @@  discard block
 block discarded – undo
303 303
      *                          deciding once per request (for use in tests).
304 304
      * @return bool
305 305
      */
306
-    public static function should_buffer( $doing_tests = false )
306
+    public static function should_buffer($doing_tests = false)
307 307
     {
308 308
         static $do_buffering = null;
309 309
 
310 310
         // Only check once in case we're called multiple times by others but
311 311
         // still allows multiple calls when doing tests.
312
-        if ( null === $do_buffering || $doing_tests ) {
312
+        if (null === $do_buffering || $doing_tests) {
313 313
 
314 314
             $ao_noptimize = false;
315 315
 
316 316
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
317
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
317
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
318 318
                 $ao_noptimize = true;
319 319
             }
320 320
 
321 321
             // Skip checking query strings if they're disabled.
322
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
322
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
323 323
                 // Check for `ao_noptimize` (and other) keys in the query string
324 324
                 // to get non-optimized page for debugging.
325 325
                 $keys = array(
326 326
                     'ao_noptimize',
327 327
                     'ao_noptirocket',
328 328
                 );
329
-                foreach ( $keys as $key ) {
330
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
329
+                foreach ($keys as $key) {
330
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
331 331
                         $ao_noptimize = true;
332 332
                         break;
333 333
                     }
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
             }
336 336
 
337 337
             // If setting says not to optimize logged in user and user is logged in...
338
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
338
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
339 339
                 $ao_noptimize = true;
340 340
             }
341 341
 
342 342
             // If setting says not to optimize cart/checkout.
343
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) {
343
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) {
344 344
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
345
-                foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
346
-                    if ( function_exists( $func ) && $func() ) {
345
+                foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
346
+                    if (function_exists($func) && $func()) {
347 347
                         $ao_noptimize = true;
348 348
                         break;
349 349
                     }
@@ -351,10 +351,10 @@  discard block
 block discarded – undo
351 351
             }
352 352
 
353 353
             // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
354
-            if ( false === $ao_noptimize ) {
355
-                $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
356
-                foreach ( $_qs_pagebuilders as $_pagebuilder ) {
357
-                    if ( array_key_exists( $_pagebuilder, $_GET ) ) {
354
+            if (false === $ao_noptimize) {
355
+                $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor');
356
+                foreach ($_qs_pagebuilders as $_pagebuilder) {
357
+                    if (array_key_exists($_pagebuilder, $_GET)) {
358 358
                         $ao_noptimize = true;
359 359
                         break;
360 360
                     }
@@ -363,16 +363,16 @@  discard block
 block discarded – undo
363 363
 
364 364
             // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
365 365
             // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
366
-            if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
366
+            if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
367 367
                 $ao_noptimize = true;
368 368
             }
369 369
 
370 370
             // And finally allows blocking of autoptimization on your own terms regardless of above decisions.
371
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
371
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
372 372
 
373 373
             // Check for site being previewed in the Customizer (available since WP 4.0).
374 374
             $is_customize_preview = false;
375
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
375
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
376 376
                 $is_customize_preview = is_customize_preview();
377 377
             }
378 378
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
              * while the main query hasn't been ran yet. Thats why we use
384 384
              * AUTOPTIMIZE_INIT_EARLIER in tests.
385 385
              */
386
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview );
386
+            $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview);
387 387
         }
388 388
 
389 389
         return $do_buffering;
@@ -396,25 +396,25 @@  discard block
 block discarded – undo
396 396
      *
397 397
      * @return bool
398 398
      */
399
-    public function is_valid_buffer( $content )
399
+    public function is_valid_buffer($content)
400 400
     {
401 401
         // Defaults to true.
402 402
         $valid = true;
403 403
 
404
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
405
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) );
406
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 );
407
-        $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) );
404
+        $has_no_html_tag    = (false === stripos($content, '<html'));
405
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet'));
406
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0);
407
+        $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->'));
408 408
 
409
-        if ( $has_no_html_tag ) {
409
+        if ($has_no_html_tag) {
410 410
             // Can't be valid amp markup without an html tag preceding it.
411 411
             $is_amp_markup = false;
412 412
         } else {
413
-            $is_amp_markup = self::is_amp_markup( $content );
413
+            $is_amp_markup = self::is_amp_markup($content);
414 414
         }
415 415
 
416 416
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
417
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) {
417
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) {
418 418
             $valid = false;
419 419
         }
420 420
 
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
      *
430 430
      * @return bool
431 431
      */
432
-    public static function is_amp_markup( $content )
432
+    public static function is_amp_markup($content)
433 433
     {
434 434
         // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page.
435
-        if ( function_exists( 'is_amp_endpoint' ) ) {
435
+        if (function_exists('is_amp_endpoint')) {
436 436
             return is_amp_endpoint();
437 437
         }
438 438
 
439
-        $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content );
439
+        $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content);
440 440
 
441 441
         return (bool) $is_amp_markup;
442 442
     }
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
      *
450 450
      * @return string
451 451
      */
452
-    public function end_buffering( $content )
452
+    public function end_buffering($content)
453 453
     {
454 454
         // Bail early without modifying anything if we can't handle the content.
455
-        if ( ! $this->is_valid_buffer( $content ) ) {
455
+        if (!$this->is_valid_buffer($content)) {
456 456
             return $content;
457 457
         }
458 458
 
@@ -460,73 +460,73 @@  discard block
 block discarded – undo
460 460
 
461 461
         // Determine what needs to be ran.
462 462
         $classes = array();
463
-        if ( $conf->get( 'autoptimize_js' ) ) {
463
+        if ($conf->get('autoptimize_js')) {
464 464
             $classes[] = 'autoptimizeScripts';
465 465
         }
466
-        if ( $conf->get( 'autoptimize_css' ) ) {
466
+        if ($conf->get('autoptimize_css')) {
467 467
             $classes[] = 'autoptimizeStyles';
468 468
         }
469
-        if ( $conf->get( 'autoptimize_html' ) ) {
469
+        if ($conf->get('autoptimize_html')) {
470 470
             $classes[] = 'autoptimizeHTML';
471 471
         }
472 472
 
473 473
         $classoptions = array(
474 474
             'autoptimizeScripts' => array(
475
-                'aggregate'       => $conf->get( 'autoptimize_js_aggregate' ),
476
-                'justhead'        => $conf->get( 'autoptimize_js_justhead' ),
477
-                'forcehead'       => $conf->get( 'autoptimize_js_forcehead' ),
478
-                'trycatch'        => $conf->get( 'autoptimize_js_trycatch' ),
479
-                'js_exclude'      => $conf->get( 'autoptimize_js_exclude' ),
480
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
481
-                'include_inline'  => $conf->get( 'autoptimize_js_include_inline' ),
482
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
475
+                'aggregate'       => $conf->get('autoptimize_js_aggregate'),
476
+                'justhead'        => $conf->get('autoptimize_js_justhead'),
477
+                'forcehead'       => $conf->get('autoptimize_js_forcehead'),
478
+                'trycatch'        => $conf->get('autoptimize_js_trycatch'),
479
+                'js_exclude'      => $conf->get('autoptimize_js_exclude'),
480
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
481
+                'include_inline'  => $conf->get('autoptimize_js_include_inline'),
482
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
483 483
             ),
484 484
             'autoptimizeStyles'  => array(
485
-                'aggregate'       => $conf->get( 'autoptimize_css_aggregate' ),
486
-                'justhead'        => $conf->get( 'autoptimize_css_justhead' ),
487
-                'datauris'        => $conf->get( 'autoptimize_css_datauris' ),
488
-                'defer'           => $conf->get( 'autoptimize_css_defer' ),
489
-                'defer_inline'    => $conf->get( 'autoptimize_css_defer_inline' ),
490
-                'inline'          => $conf->get( 'autoptimize_css_inline' ),
491
-                'css_exclude'     => $conf->get( 'autoptimize_css_exclude' ),
492
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
493
-                'include_inline'  => $conf->get( 'autoptimize_css_include_inline' ),
494
-                'nogooglefont'    => $conf->get( 'autoptimize_css_nogooglefont' ),
495
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
485
+                'aggregate'       => $conf->get('autoptimize_css_aggregate'),
486
+                'justhead'        => $conf->get('autoptimize_css_justhead'),
487
+                'datauris'        => $conf->get('autoptimize_css_datauris'),
488
+                'defer'           => $conf->get('autoptimize_css_defer'),
489
+                'defer_inline'    => $conf->get('autoptimize_css_defer_inline'),
490
+                'inline'          => $conf->get('autoptimize_css_inline'),
491
+                'css_exclude'     => $conf->get('autoptimize_css_exclude'),
492
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
493
+                'include_inline'  => $conf->get('autoptimize_css_include_inline'),
494
+                'nogooglefont'    => $conf->get('autoptimize_css_nogooglefont'),
495
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
496 496
             ),
497 497
             'autoptimizeHTML'    => array(
498
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
498
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
499 499
             ),
500 500
         );
501 501
 
502
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
502
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
503 503
 
504 504
         // Run the classes!
505
-        foreach ( $classes as $name ) {
506
-            $instance = new $name( $content );
507
-            if ( $instance->read( $classoptions[ $name ] ) ) {
505
+        foreach ($classes as $name) {
506
+            $instance = new $name($content);
507
+            if ($instance->read($classoptions[$name])) {
508 508
                 $instance->minify();
509 509
                 $instance->cache();
510 510
                 $content = $instance->getcontent();
511 511
             }
512
-            unset( $instance );
512
+            unset($instance);
513 513
         }
514 514
 
515
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
515
+        $content = apply_filters('autoptimize_html_after_minify', $content);
516 516
 
517 517
         return $content;
518 518
     }
519 519
 
520
-    public static function autoptimize_nobuffer_optimize( $html_in ) {
520
+    public static function autoptimize_nobuffer_optimize($html_in) {
521 521
         $html_out = $html_in;
522 522
 
523
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
523
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
524 524
             $ao_speedupper = new autoptimizeSpeedupper();
525 525
         }
526 526
 
527
-        $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
528
-        if ( $self->should_buffer() ) {
529
-            $html_out = $self->end_buffering( $html_in );
527
+        $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
528
+        if ($self->should_buffer()) {
529
+            $html_out = $self->end_buffering($html_in);
530 530
         }
531 531
         return $html_out;
532 532
     }
@@ -588,45 +588,45 @@  discard block
 block discarded – undo
588 588
             'autoptimize_ccss_unloadccss',
589 589
         );
590 590
 
591
-        if ( ! is_multisite() ) {
592
-            foreach ( $delete_options as $del_opt ) {
593
-                delete_option( $del_opt );
591
+        if (!is_multisite()) {
592
+            foreach ($delete_options as $del_opt) {
593
+                delete_option($del_opt);
594 594
             }
595 595
             autoptimizeMain::remove_cronjobs();
596 596
         } else {
597 597
             global $wpdb;
598
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
598
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
599 599
             $original_blog_id = get_current_blog_id();
600
-            foreach ( $blog_ids as $blog_id ) {
601
-                switch_to_blog( $blog_id );
602
-                foreach ( $delete_options as $del_opt ) {
603
-                    delete_option( $del_opt );
600
+            foreach ($blog_ids as $blog_id) {
601
+                switch_to_blog($blog_id);
602
+                foreach ($delete_options as $del_opt) {
603
+                    delete_option($del_opt);
604 604
                 }
605 605
                 autoptimizeMain::remove_cronjobs();
606 606
             }
607
-            switch_to_blog( $original_blog_id );
607
+            switch_to_blog($original_blog_id);
608 608
         }
609 609
 
610 610
         // Remove AO CCSS cached files and directory.
611
-        $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/';
612
-        if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) {
611
+        $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/';
612
+        if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) {
613 613
             // fixme: should check for subdirs when in multisite and remove contents of those as well.
614
-            array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) );
615
-            rmdir( $ao_ccss_dir );
614
+            array_map('unlink', glob($ao_ccss_dir.'*.{css,html,json,log,zip,lock}', GLOB_BRACE));
615
+            rmdir($ao_ccss_dir);
616 616
         }
617 617
     }
618 618
 
619 619
     public static function on_deactivation()
620 620
     {
621
-        if ( is_multisite() && is_network_admin() ) {
621
+        if (is_multisite() && is_network_admin()) {
622 622
             global $wpdb;
623
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
623
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
624 624
             $original_blog_id = get_current_blog_id();
625
-            foreach ( $blog_ids as $blog_id ) {
626
-                switch_to_blog( $blog_id );
625
+            foreach ($blog_ids as $blog_id) {
626
+                switch_to_blog($blog_id);
627 627
                 autoptimizeMain::remove_cronjobs();
628 628
             }
629
-            switch_to_blog( $original_blog_id );
629
+            switch_to_blog($original_blog_id);
630 630
         } else {
631 631
             autoptimizeMain::remove_cronjobs();
632 632
         }
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
 
636 636
     public static function remove_cronjobs() {
637 637
         // Remove scheduled events.
638
-        foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) {
639
-            if ( wp_get_schedule( $_event ) ) {
640
-                wp_clear_scheduled_hook( $_event );
638
+        foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) {
639
+            if (wp_get_schedule($_event)) {
640
+                wp_clear_scheduled_hook($_event);
641 641
             }
642 642
         }
643 643
     }
@@ -646,35 +646,35 @@  discard block
 block discarded – undo
646 646
     {
647 647
         echo '<div class="error"><p>';
648 648
         // Translators: %s is the cache directory location.
649
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
649
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
650 650
         echo '</p></div>';
651 651
     }
652 652
 
653 653
     public static function notice_installed()
654 654
     {
655 655
         echo '<div class="updated"><p>';
656
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
656
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
657 657
         echo '</p></div>';
658 658
     }
659 659
 
660 660
     public static function notice_updated()
661 661
     {
662 662
         echo '<div class="updated"><p>';
663
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
663
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
664 664
         echo '</p></div>';
665 665
     }
666 666
 
667 667
     public static function notice_plug_imgopt()
668 668
     {
669 669
         // Translators: the URL added points to the Autopmize Extra settings.
670
-        $_ao_imgopt_plug_notice      = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' );
671
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
670
+        $_ao_imgopt_plug_notice      = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>');
671
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
672 672
         $_ao_imgopt_launch_ok        = autoptimizeImages::launch_ok_wrapper();
673 673
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
674 674
         $_ao_imgopt_active           = autoptimizeImages::imgopt_active();
675 675
 
676
-        if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) {
677
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
676
+        if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) {
677
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
678 678
             echo $_ao_imgopt_plug_notice;
679 679
             echo '</p></div>';
680 680
         }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSEnqueue.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS job enqueue logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
19 19
     }
20 20
 
21
-    public static function ao_ccss_enqueue( $hash ) {
21
+    public static function ao_ccss_enqueue($hash) {
22 22
         $self = new self();
23 23
         // Get key status.
24
-        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( false );
24
+        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(false);
25 25
 
26 26
         // Queue is available to anyone...
27 27
         $enqueue = true;
28 28
 
29 29
         // ... which are not the ones below.
30
-        if ( is_user_logged_in() || is_feed() || is_404() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters( 'autoptimize_filter_ccss_enqueue_should_enqueue', true ) ) {
30
+        if (is_user_logged_in() || is_feed() || is_404() || (defined('DOING_AJAX') && DOING_AJAX) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters('autoptimize_filter_ccss_enqueue_should_enqueue', true)) {
31 31
             $enqueue = false;
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( "Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log("Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3);
33 33
         }
34 34
 
35
-        if ( $enqueue ) {
35
+        if ($enqueue) {
36 36
             // Continue if queue is available
37 37
             // Attach required arrays/ vars.
38 38
             global $ao_ccss_rules;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             global $ao_ccss_forcepath;
42 42
 
43 43
             // Get request path and page type, and initialize the queue update flag.
44
-            $req_path        = strtok( $_SERVER['REQUEST_URI'], '?' );
44
+            $req_path        = strtok($_SERVER['REQUEST_URI'], '?');
45 45
             $req_type        = $self->ao_ccss_get_type();
46 46
             $job_qualify     = false;
47 47
             $target_rule     = false;
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             $queue_update    = false;
50 50
 
51 51
             // Match for paths in rules.
52
-            foreach ( $ao_ccss_rules['paths'] as $path => $props ) {
52
+            foreach ($ao_ccss_rules['paths'] as $path => $props) {
53 53
 
54 54
                 // Prepare rule target and log.
55
-                $target_rule = 'paths|' . $path;
56
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
55
+                $target_rule = 'paths|'.$path;
56
+                autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
57 57
 
58 58
                 // Path match
59 59
                 // -> exact match needed for AUTO rules
60 60
                 // -> partial match OK for MANUAL rules (which have empty hash and a file with CCSS).
61
-                if ( $path === $req_path || ( false == $props['hash'] && false != $props['file'] && preg_match( '|' . $path . '|', $req_path ) ) ) {
61
+                if ($path === $req_path || (false == $props['hash'] && false != $props['file'] && preg_match('|'.$path.'|', $req_path))) {
62 62
 
63 63
                     // There's a path match in the rule, so job QUALIFIES with a path rule match.
64 64
                     $job_qualify     = true;
65 65
                     $rule_properties = $props;
66
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
66
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
67 67
 
68 68
                     // Stop processing other path rules.
69 69
                     break;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
             }
72 72
 
73 73
             // Match for types in rules if no path rule matches and if we're not enforcing paths.
74
-            if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) {
75
-                foreach ( $ao_ccss_rules['types'] as $type => $props ) {
74
+            if (!$job_qualify && (!$ao_ccss_forcepath || !in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page'))) || !apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false))) {
75
+                foreach ($ao_ccss_rules['types'] as $type => $props) {
76 76
 
77 77
                     // Prepare rule target and log.
78
-                    $target_rule = 'types|' . $type;
79
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying page type <' . $req_type . '> on path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
78
+                    $target_rule = 'types|'.$type;
79
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying page type <'.$req_type.'> on path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
80 80
 
81
-                    if ( $req_type == $type ) {
81
+                    if ($req_type == $type) {
82 82
                         // Type match.
83 83
                         // There's a type match in the rule, so job QUALIFIES with a type rule match.
84 84
                         $job_qualify     = true;
85 85
                         $rule_properties = $props;
86
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Page type <' . $req_type . '> on path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
86
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Page type <'.$req_type.'> on path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
87 87
 
88 88
                         // Stop processing other type rules.
89 89
                         break;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 }
92 92
             }
93 93
 
94
-            if ( $job_qualify && ( ( false == $rule_properties['hash'] && false != $rule_properties['file'] ) || strpos( $req_type, 'template_' ) !== false ) ) {
94
+            if ($job_qualify && ((false == $rule_properties['hash'] && false != $rule_properties['file']) || strpos($req_type, 'template_') !== false)) {
95 95
                 // If job qualifies but rule hash is false and file isn't false (MANUAL rule) or if template, job does not qualify despite what previous evaluations says.
96 96
                 $job_qualify = false;
97
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission DISQUALIFIED by MANUAL rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
98
-            } elseif ( ! $job_qualify && empty( $rule_properties ) ) {
97
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission DISQUALIFIED by MANUAL rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
98
+            } elseif (!$job_qualify && empty($rule_properties)) {
99 99
                 // But if job does not qualify and rule properties are set, job qualifies as there is no matching rule for it yet
100 100
                 // Fill-in the new target rule.
101 101
                 $job_qualify = true;
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
                 // Should we switch to path-base AUTO-rules? Conditions:
104 104
                 // 1. forcepath option has to be enabled (off by default)
105 105
                 // 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category).
106
-                if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) {
107
-                    if ( '/' !== $req_path ) {
108
-                        $target_rule = 'paths|' . $req_path;
106
+                if (($ao_ccss_forcepath && in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page')))) || apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false)) {
107
+                    if ('/' !== $req_path) {
108
+                        $target_rule = 'paths|'.$req_path;
109 109
                     } else {
110 110
                         // Exception; we don't want a path-based rule for "/" as that messes things up, hard-switch this to a type-based is_front_page rule.
111
-                        $target_rule = 'types|' . 'is_front_page';
111
+                        $target_rule = 'types|'.'is_front_page';
112 112
                     }
113 113
                 } else {
114
-                    $target_rule = 'types|' . $req_type;
114
+                    $target_rule = 'types|'.$req_type;
115 115
                 }
116
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by MISSING rule for page type <' . $req_type . '> on path <' . $req_path . '>, new rule target is <' . $target_rule . '>', 3 );
116
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by MISSING rule for page type <'.$req_type.'> on path <'.$req_path.'>, new rule target is <'.$target_rule.'>', 3);
117 117
             } else {
118 118
                 // Or just log a job qualified by a matching rule.
119
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by AUTO rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
119
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by AUTO rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
120 120
             }
121 121
 
122 122
             // Submit job.
123
-            if ( $job_qualify ) {
124
-                if ( ! array_key_exists( $req_path, $ao_ccss_queue ) ) {
123
+            if ($job_qualify) {
124
+                if (!array_key_exists($req_path, $ao_ccss_queue)) {
125 125
                     // This is a NEW job
126 126
                     // Merge job into the queue.
127
-                    $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
127
+                    $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
128 128
                         $req_path,
129 129
                         $target_rule,
130 130
                         $req_type,
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
                 } else {
141 141
                     // This is an existing job
142 142
                     // The job is still NEW, most likely this is extra CSS file for the same page that needs a hash.
143
-                    if ( 'NEW' == $ao_ccss_queue[ $req_path ]['jqstat'] ) {
143
+                    if ('NEW' == $ao_ccss_queue[$req_path]['jqstat']) {
144 144
                         // Add hash if it's not already in the job.
145
-                        if ( ! in_array( $hash, $ao_ccss_queue[ $req_path ]['hashes'] ) ) {
145
+                        if (!in_array($hash, $ao_ccss_queue[$req_path]['hashes'])) {
146 146
                             // Push new hash to its array and update flag.
147
-                            $queue_update = array_push( $ao_ccss_queue[ $req_path ]['hashes'], $hash );
147
+                            $queue_update = array_push($ao_ccss_queue[$req_path]['hashes'], $hash);
148 148
 
149 149
                             // Log job update.
150
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Hashes UPDATED on local job id <' . $ao_ccss_queue[ $req_path ]['ljid'] . '>, job status NEW, target rule <' . $ao_ccss_queue[ $req_path ]['rtarget'] . '>, hash added: ' . $hash, 3 );
150
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Hashes UPDATED on local job id <'.$ao_ccss_queue[$req_path]['ljid'].'>, job status NEW, target rule <'.$ao_ccss_queue[$req_path]['rtarget'].'>, hash added: '.$hash, 3);
151 151
 
152 152
                             // Return from here as the hash array is already updated.
153 153
                             return true;
154 154
                         }
155
-                    } elseif ( 'NEW' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[ $req_path ]['jqstat'] ) {
155
+                    } elseif ('NEW' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[$req_path]['jqstat']) {
156 156
                         // Allow requeuing jobs that are not NEW, JOB_QUEUED or JOB_ONGOING
157 157
                         // Merge new job keeping some previous job values.
158
-                        $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
158
+                        $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
159 159
                             $req_path,
160 160
                             $target_rule,
161 161
                             $req_type,
162 162
                             $hash,
163
-                            $ao_ccss_queue[ $req_path ]['file'],
164
-                            $ao_ccss_queue[ $req_path ]['jid'],
165
-                            $ao_ccss_queue[ $req_path ]['jrstat'],
166
-                            $ao_ccss_queue[ $req_path ]['jvstat'],
163
+                            $ao_ccss_queue[$req_path]['file'],
164
+                            $ao_ccss_queue[$req_path]['jid'],
165
+                            $ao_ccss_queue[$req_path]['jrstat'],
166
+                            $ao_ccss_queue[$req_path]['jvstat'],
167 167
                             false
168 168
                         );
169 169
                         // Set update flag.
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
                     }
172 172
                 }
173 173
 
174
-                if ( $queue_update ) {
174
+                if ($queue_update) {
175 175
                     // Persist the job to the queue and return.
176
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
177
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
176
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
177
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
178 178
                     return true;
179 179
                 } else {
180 180
                     // Or just return false if no job was added.
181
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A job for path <' . $req_path . '> already exist with NEW or PENDING status, skipping job creation', 3 );
181
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A job for path <'.$req_path.'> already exist with NEW or PENDING status, skipping job creation', 3);
182 182
                     return false;
183 183
                 }
184 184
             }
@@ -195,29 +195,29 @@  discard block
 block discarded – undo
195 195
         $page_type = false;
196 196
 
197 197
         // Iterates over the array to match a type.
198
-        foreach ( $ao_ccss_types as $type ) {
199
-            if ( is_404() ) {
198
+        foreach ($ao_ccss_types as $type) {
199
+            if (is_404()) {
200 200
                 $page_type = 'is_404';
201 201
                 break;
202
-            } elseif ( strpos( $type, 'custom_post_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
202
+            } elseif (strpos($type, 'custom_post_') !== false && (!$ao_ccss_forcepath || !is_page())) {
203 203
                 // Match custom post types and not page or page not forced to path-based.
204
-                if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
204
+                if (get_post_type(get_the_ID()) === substr($type, 12)) {
205 205
                     $page_type = $type;
206 206
                     break;
207 207
                 }
208
-            } elseif ( strpos( $type, 'template_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
208
+            } elseif (strpos($type, 'template_') !== false && (!$ao_ccss_forcepath || !is_page())) {
209 209
                 // Match templates if not page or if page is not forced to path-based.
210
-                if ( is_page_template( substr( $type, 9 ) ) ) {
210
+                if (is_page_template(substr($type, 9))) {
211 211
                     $page_type = $type;
212 212
                     break;
213 213
                 }
214 214
             } else {
215 215
                 // Match all other existing types
216 216
                 // but remove prefix to be able to check if the function exists & returns true.
217
-                $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
218
-                if ( function_exists( $_type ) && call_user_func( $_type ) ) {
217
+                $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
218
+                if (function_exists($_type) && call_user_func($_type)) {
219 219
                     // Make sure we only return is_front_page (and is_home) for one page, not for the "paged frontpage" (/page/2 ..).
220
-                    if ( ( 'is_front_page' !== $_type && 'is_home' !== $_type ) || ! is_paged() ) {
220
+                    if (('is_front_page' !== $_type && 'is_home' !== $_type) || !is_paged()) {
221 221
                         $page_type = $type;
222 222
                         break;
223 223
                     }
@@ -229,44 +229,44 @@  discard block
 block discarded – undo
229 229
         return $page_type;
230 230
     }
231 231
 
232
-    public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
232
+    public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) {
233 233
         // Define a job entry to be created or updated
234 234
         // Define commom job properties.
235 235
         $path            = array();
236 236
         $path['ljid']    = $this->ao_ccss_job_id();
237 237
         $path['rtarget'] = $target;
238 238
         $path['ptype']   = $type;
239
-        $path['hashes']  = array( $hash );
239
+        $path['hashes']  = array($hash);
240 240
         $path['hash']    = $hash;
241 241
         $path['file']    = $file;
242 242
         $path['jid']     = $jid;
243 243
         $path['jqstat']  = 'NEW';
244 244
         $path['jrstat']  = $jrstat;
245 245
         $path['jvstat']  = $jvstat;
246
-        $path['jctime']  = microtime( true );
246
+        $path['jctime']  = microtime(true);
247 247
         $path['jftime']  = null;
248 248
 
249 249
         // Set operation requested.
250
-        if ( $create ) {
250
+        if ($create) {
251 251
             $operation = 'CREATED';
252 252
         } else {
253 253
             $operation = 'UPDATED';
254 254
         }
255 255
 
256 256
         // Log job creation.
257
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 );
257
+        autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3);
258 258
 
259 259
         return $path;
260 260
     }
261 261
 
262
-    public function ao_ccss_job_id( $length = 6 ) {
262
+    public function ao_ccss_job_id($length = 6) {
263 263
         // Generate random strings for the local job ID
264 264
         // Based on https://stackoverflow.com/a/4356295 .
265 265
         $characters        = '0123456789abcdefghijklmnopqrstuvwxyz';
266
-        $characters_length = strlen( $characters );
266
+        $characters_length = strlen($characters);
267 267
         $random_string     = 'j-';
268
-        for ( $i = 0; $i < $length; $i++ ) {
269
-            $random_string .= $characters[ rand( 0, $characters_length - 1 ) ];
268
+        for ($i = 0; $i < $length; $i++) {
269
+            $random_string .= $characters[rand(0, $characters_length - 1)];
270 270
         }
271 271
         return $random_string;
272 272
     }
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
     public function ao_ccss_ua() {
275 275
         // Check for criticalcss.com user agent.
276 276
         $agent = '';
277
-        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
277
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
278 278
             $agent = $_SERVER['HTTP_USER_AGENT'];
279 279
         }
280 280
 
281 281
         // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not.
282
-        $rtn = strpos( $agent, AO_CCSS_URL );
283
-        if ( 0 === $rtn ) {
282
+        $rtn = strpos($agent, AO_CCSS_URL);
283
+        if (0 === $rtn) {
284 284
             $rtn = true;
285 285
         } else {
286 286
             $rtn = false;
287 287
         }
288
-        return ( $rtn );
288
+        return ($rtn);
289 289
     }
290 290
 }
Please login to merge, or discard this patch.
classes/autoptimizeConfig.php 1 patch
Spacing   +219 added lines, -219 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,32 +35,32 @@  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' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46 46
 
47 47
             // Set meta info.
48
-            if ( function_exists( 'plugin_row_meta' ) ) {
48
+            if (function_exists('plugin_row_meta')) {
49 49
                 // 2.8 and higher.
50
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
51
-            } elseif ( function_exists( 'post_class' ) ) {
50
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
51
+            } elseif (function_exists('post_class')) {
52 52
                 // 2.7 and lower.
53
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
54
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
53
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
54
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
55 55
             }
56 56
 
57 57
             // Clean cache?
58
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
58
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
59 59
                 autoptimizeCache::clearall();
60
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
60
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
61 61
             }
62 62
 
63
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
63
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
64 64
         }
65 65
 
66 66
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     static public function instance()
77 77
     {
78 78
         // Only one instance.
79
-        if ( null === self::$instance ) {
79
+        if (null === self::$instance) {
80 80
             self::$instance = new autoptimizeConfig();
81 81
         }
82 82
 
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
     public function show_network_message() {
87 87
         ?>
88 88
         <div class="wrap">
89
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
89
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
90 90
             <?php echo $this->ao_admin_tabs(); ?>
91
-            <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>
91
+            <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 92
         </div>
93 93
         <?php
94 94
     }
@@ -181,32 +181,32 @@  discard block
 block discarded – undo
181 181
 <div class="wrap">
182 182
 
183 183
 <!-- Temporary nudge to disable aoccss power-up. -->
184
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
184
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
185 185
     <div class="notice-info notice"><p>
186
-        <?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' ); ?>
186
+        <?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'); ?>
187 187
     </p></div>
188 188
 <?php } ?>
189 189
 
190 190
 <div id="autoptimize_main">
191
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
191
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
192 192
     <?php echo $this->ao_admin_tabs(); ?>
193 193
 
194
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
195
-<?php settings_fields( 'autoptimize' ); ?>
194
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
195
+<?php settings_fields('autoptimize'); ?>
196 196
 
197 197
 <ul>
198 198
 
199 199
 <?php
200 200
 // Only show enable site configuration in network site option.
201
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
201
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
202 202
 ?>
203 203
     <li class="itemDetail multiSite">
204
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
204
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
205 205
         <table class="form-table">
206 206
             <tr valign="top">
207
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
208
-                <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" ' : ''; ?>/>
209
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
207
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
208
+                <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" ' : ''; ?>/>
209
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
210 210
             </tr>
211 211
         </table>
212 212
     </li>
@@ -215,115 +215,115 @@  discard block
 block discarded – undo
215 215
 <?php } ?>    
216 216
 
217 217
 <li class="itemDetail">
218
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
218
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
219 219
 <table class="form-table">
220 220
 <tr valign="top">
221
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
222
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
221
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
222
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
223 223
 </tr>
224 224
 <tr valign="top" class="js_sub">
225
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
226
-<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" ' : ''; ?>/>
227
-<?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>
225
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
226
+<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" ' : ''; ?>/>
227
+<?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 228
 </tr>
229 229
 <tr valign="top" class="js_sub js_aggregate">
230
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
231
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
232
-<?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>
230
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
231
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
232
+<?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>
233 233
 </tr>
234 234
 <tr valign="top" class="js_sub js_aggregate">
235
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
236
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
237
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
235
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
236
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
237
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
238 238
 </tr>
239
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
239
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
240 240
 <tr valign="top" class="js_sub js_aggregate">
241 241
 <th scope="row">
242 242
 <?php
243
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
244
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
243
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
244
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
245 245
 ?>
246 246
 </th>
247
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
248
-<?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>
247
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
248
+<?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>
249 249
 </tr>
250 250
 <?php } ?>
251 251
 <tr valign="top" class="js_sub">
252
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
253
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_html( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ) ); ?>"/><br />
252
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
253
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_html(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js')); ?>"/><br />
254 254
 <?php
255
-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' );
255
+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');
256 256
 ?>
257 257
 </label></td>
258 258
 </tr>
259 259
 <tr valign="top" class="js_sub js_aggregate">
260
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
261
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
262
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
260
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
261
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
262
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
263 263
 </tr>
264 264
 </table>
265 265
 </li>
266 266
 
267 267
 <li class="itemDetail">
268
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
268
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
269 269
 <table class="form-table">
270 270
 <tr valign="top">
271
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
272
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
271
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
272
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
273 273
 </tr>
274 274
 <tr class="css_sub" valign="top">
275
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
276
-<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" ' : ''; ?>/>
277
-<?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>
275
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
276
+<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" ' : ''; ?>/>
277
+<?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>
278 278
 </tr>
279 279
 <tr valign="top" class="css_sub css_aggregate">
280
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
281
-<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" ' : ''; ?>/>
282
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
280
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
281
+<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" ' : ''; ?>/>
282
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
283 283
 </tr>
284 284
 <tr class="css_sub css_aggregate" valign="top">
285
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
286
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
287
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
285
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
286
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
287
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
288 288
 </tr>
289
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
289
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
290 290
 <tr valign="top" class="css_sub css_aggregate">
291 291
 <th scope="row">
292 292
 <?php
293
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
294
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
293
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
294
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
295 295
 ?>
296 296
 </th>
297
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
298
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
297
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
298
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
299 299
 </tr>
300 300
 <?php } ?>
301 301
 <tr valign="top" class="css_sub">
302
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
303
-<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" ' : ''; ?>/>
302
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
303
+<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" ' : ''; ?>/>
304 304
 <?php
305
-_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' );
305
+_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');
306 306
 echo ' ';
307
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
307
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
308 308
 // translators: links "autoptimize critical CSS" tab.
309
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
309
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
310 310
 ?>
311 311
 </label></td>
312 312
 </tr>
313 313
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
314 314
 <th scope="row"></th>
315
-<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>
315
+<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>
316 316
 </tr>
317 317
 <tr valign="top" class="css_sub css_aggregate">
318
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
319
-<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" ' : ''; ?>/>
320
-<?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>
318
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
319
+<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" ' : ''; ?>/>
320
+<?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>
321 321
 </tr>
322 322
 <tr valign="top" class="css_sub">
323
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
324
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_html( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
323
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
324
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_html(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br />
325 325
 <?php
326
-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' );
326
+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');
327 327
 ?>
328 328
 </label></td>
329 329
 </tr>
@@ -331,55 +331,55 @@  discard block
 block discarded – undo
331 331
 </li>
332 332
 
333 333
 <li class="itemDetail">
334
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
334
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
335 335
 <table class="form-table">
336 336
 <tr valign="top">
337
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
338
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
337
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
338
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
339 339
 </tr>
340 340
 <tr class="html_sub" valign="top">
341
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
342
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
343
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
341
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
342
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
343
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
344 344
 </tr>
345 345
 </table>
346 346
 </li>
347 347
 
348 348
 <li class="itemDetail">
349
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
349
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
350 350
 <table class="form-table">
351 351
 <tr valign="top">
352
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
353
-<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 />
354
-<?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>
352
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
353
+<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 />
354
+<?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>
355 355
 </tr>
356 356
 </table>
357 357
 </li>
358 358
 
359 359
 <li class="itemDetail">
360
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
360
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
361 361
 <table class="form-table" >
362 362
 <tr valign="top" >
363
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
364
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
363
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
364
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
365 365
 </tr>
366 366
 <tr valign="top" >
367
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
368
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
367
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
368
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
369 369
 </tr>
370 370
 <tr valign="top" >
371
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
371
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
372 372
 <td>
373 373
     <?php
374 374
     $ao_stat_arr = autoptimizeCache::stats();
375
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
376
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
375
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
376
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
377 377
         $details       = '';
378
-        if ( $ao_cache_size > 0 ) {
379
-            $details = ', ~' . $ao_cache_size . ' total';
378
+        if ($ao_cache_size > 0) {
379
+            $details = ', ~'.$ao_cache_size.' total';
380 380
         }
381 381
         // translators: Kilobytes + timestamp shown.
382
-        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] ) );
382
+        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]));
383 383
     }
384 384
     ?>
385 385
 </td>
@@ -388,41 +388,41 @@  discard block
 block discarded – undo
388 388
 </li>
389 389
 
390 390
 <li class="itemDetail">
391
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
391
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
392 392
 <table class="form-table">
393 393
     <tr valign="top" >
394
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
395
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
396
-    <?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>
394
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
395
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
396
+    <?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>
397 397
     </tr>
398 398
     <?php
399 399
     $_min_excl_class = '';
400
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
400
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
401 401
         $_min_excl_class = 'hidden';
402 402
     }
403 403
     ?>
404 404
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
405
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
406
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
407
-        <?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>
405
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
406
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
407
+        <?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>
408 408
     </tr>
409 409
     <tr valign="top">
410
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
411
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
412
-        <?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>
410
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
411
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
412
+        <?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>
413 413
     </tr>
414 414
     <tr valign="top">
415
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
416
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
417
-    <?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>
415
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
416
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
417
+    <?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>
418 418
     </tr>
419 419
     <?php
420
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
420
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
421 421
     ?>
422 422
     <tr valign="top" >
423
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
424
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
425
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
423
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
424
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
425
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
426 426
         </td>
427 427
     </tr>
428 428
     <?php } ?>
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 </ul>
433 433
 
434 434
 <p class="submit">
435
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
436
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
435
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
436
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
437 437
 </p>
438 438
 
439 439
 </form>
@@ -442,46 +442,46 @@  discard block
 block discarded – undo
442 442
     <div class="autoptimize_banner hidden">
443 443
     <ul>
444 444
     <?php
445
-    if ( $this->settings_screen_do_remote_http ) {
446
-        $ao_banner = get_transient( 'autoptimize_banner' );
447
-        if ( empty( $ao_banner ) ) {
448
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
449
-            if ( ! is_wp_error( $banner_resp ) ) {
450
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
451
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
452
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
445
+    if ($this->settings_screen_do_remote_http) {
446
+        $ao_banner = get_transient('autoptimize_banner');
447
+        if (empty($ao_banner)) {
448
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
449
+            if (!is_wp_error($banner_resp)) {
450
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
451
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
452
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
453 453
                 }
454 454
             }
455 455
         }
456 456
         echo $ao_banner;
457 457
     }
458 458
     ?>
459
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
460
-        <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>
459
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
460
+        <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>
461 461
     </ul>
462 462
     </div>
463 463
     <div style="margin-left:10px;margin-top:-5px;">
464 464
         <h2>
465
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
465
+            <?php _e('futtta about', 'autoptimize'); ?>
466 466
             <select id="feed_dropdown" >
467
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
468
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
469
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
467
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
468
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
469
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
470 470
             </select>
471 471
         </h2>
472 472
         <div id="futtta_feed">
473 473
             <div id="autoptimizefeed">
474
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
474
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
475 475
             </div>
476 476
             <div id="wordpressfeed">
477
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
477
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
478 478
             </div>
479 479
             <div id="webtechfeed">
480
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
480
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
481 481
             </div>
482 482
         </div>
483 483
     </div>
484
-    <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>
484
+    <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>
485 485
 </div>
486 486
 
487 487
 <script type="text/javascript">
@@ -630,81 +630,81 @@  discard block
 block discarded – undo
630 630
 
631 631
     public function addmenu()
632 632
     {
633
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
633
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
634 634
             // multisite, network admin, ao network activated: add normal settings page at network level.
635
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
636
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
635
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
636
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
637 637
             // 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.
638
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
638
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
639 639
         } else {
640 640
             // 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.
641
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
641
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
642 642
         }
643 643
 
644
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
645
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
644
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
645
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
646 646
     }
647 647
 
648 648
     public function autoptimize_admin_scripts()
649 649
     {
650
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
651
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
650
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
651
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
652 652
     }
653 653
 
654 654
     public function autoptimize_admin_styles()
655 655
     {
656
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
657
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
656
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
657
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
658 658
     }
659 659
 
660 660
     public function registersettings() {
661
-        register_setting( 'autoptimize', 'autoptimize_html' );
662
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
663
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
664
-        register_setting( 'autoptimize', 'autoptimize_js' );
665
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
666
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
667
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
668
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
669
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
670
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
671
-        register_setting( 'autoptimize', 'autoptimize_css' );
672
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
673
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
674
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
675
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
676
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
677
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
678
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
679
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
680
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
681
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
682
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
683
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
684
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
685
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
686
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
661
+        register_setting('autoptimize', 'autoptimize_html');
662
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
663
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
664
+        register_setting('autoptimize', 'autoptimize_js');
665
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
666
+        register_setting('autoptimize', 'autoptimize_js_exclude');
667
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
668
+        register_setting('autoptimize', 'autoptimize_js_justhead');
669
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
670
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
671
+        register_setting('autoptimize', 'autoptimize_css');
672
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
673
+        register_setting('autoptimize', 'autoptimize_css_exclude');
674
+        register_setting('autoptimize', 'autoptimize_css_justhead');
675
+        register_setting('autoptimize', 'autoptimize_css_datauris');
676
+        register_setting('autoptimize', 'autoptimize_css_defer');
677
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
678
+        register_setting('autoptimize', 'autoptimize_css_inline');
679
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
680
+        register_setting('autoptimize', 'autoptimize_cdn_url');
681
+        register_setting('autoptimize', 'autoptimize_cache_clean');
682
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
683
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
684
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
685
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
686
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
687 687
     }
688 688
 
689
-    public function setmeta( $links, $file = null )
689
+    public function setmeta($links, $file = null)
690 690
     {
691 691
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
692 692
         // Do it only once - saves time.
693 693
         static $plugin;
694
-        if ( empty( $plugin ) ) {
695
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
694
+        if (empty($plugin)) {
695
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
696 696
         }
697 697
 
698
-        if ( null === $file ) {
698
+        if (null === $file) {
699 699
             // 2.7 and lower.
700
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
701
-            array_unshift( $links, $settings_link );
700
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
701
+            array_unshift($links, $settings_link);
702 702
         } else {
703 703
             // 2.8 and higher.
704 704
             // If it's us, add the link.
705
-            if ( $file === $plugin ) {
706
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
707
-                $links   = array_merge( $links, $newlink );
705
+            if ($file === $plugin) {
706
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
707
+                $links   = array_merge($links, $newlink);
708 708
             }
709 709
         }
710 710
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
781 781
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
782 782
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
783
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
783
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
784 784
         );
785 785
         return $defaults;
786 786
     }
@@ -792,58 +792,58 @@  discard block
 block discarded – undo
792 792
      *
793 793
      * @return string
794 794
      */
795
-    public static function get_ao_css_preload_onload( $media = 'all' )
795
+    public static function get_ao_css_preload_onload($media = 'all')
796 796
     {
797
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
797
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
798 798
         return $preload_onload;
799 799
     }
800 800
 
801
-    public function get( $key )
801
+    public function get($key)
802 802
     {
803
-        if ( ! is_array( $this->config ) ) {
803
+        if (!is_array($this->config)) {
804 804
             // Default config.
805 805
             $config = self::get_defaults();
806 806
 
807 807
             // Override with user settings.
808
-            foreach ( array_keys( $config ) as $name ) {
809
-                $conf = autoptimizeOptionWrapper::get_option( $name );
810
-                if ( false !== $conf ) {
808
+            foreach (array_keys($config) as $name) {
809
+                $conf = autoptimizeOptionWrapper::get_option($name);
810
+                if (false !== $conf) {
811 811
                     // It was set before!
812
-                    $config[ $name ] = $conf;
812
+                    $config[$name] = $conf;
813 813
                 }
814 814
             }
815 815
 
816 816
             // Save for next call.
817
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
817
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
818 818
         }
819 819
 
820
-        if ( isset( $this->config[ $key ] ) ) {
821
-            return $this->config[ $key ];
820
+        if (isset($this->config[$key])) {
821
+            return $this->config[$key];
822 822
         }
823 823
 
824 824
         return false;
825 825
     }
826 826
 
827
-    private function get_futtta_feeds( $url ) {
828
-        if ( $this->settings_screen_do_remote_http ) {
829
-            $rss      = fetch_feed( $url );
827
+    private function get_futtta_feeds($url) {
828
+        if ($this->settings_screen_do_remote_http) {
829
+            $rss      = fetch_feed($url);
830 830
             $maxitems = 0;
831 831
 
832
-            if ( ! is_wp_error( $rss ) ) {
833
-                $maxitems  = $rss->get_item_quantity( 7 );
834
-                $rss_items = $rss->get_items( 0, $maxitems );
832
+            if (!is_wp_error($rss)) {
833
+                $maxitems  = $rss->get_item_quantity(7);
834
+                $rss_items = $rss->get_items(0, $maxitems);
835 835
             }
836 836
             ?>
837 837
             <ul>
838
-                <?php if ( 0 == $maxitems ) : ?>
839
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
838
+                <?php if (0 == $maxitems) : ?>
839
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
840 840
                 <?php else : ?>
841
-                    <?php foreach ( $rss_items as $item ) : ?>
841
+                    <?php foreach ($rss_items as $item) : ?>
842 842
                         <li>
843
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
843
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
844 844
                                 <?php // translators: the variable contains a date. ?>
845
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
846
-                                <?php echo esc_html( $item->get_title() ); ?>
845
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
846
+                                <?php echo esc_html($item->get_title()); ?>
847 847
                             </a>
848 848
                         </li>
849 849
                     <?php endforeach; ?>
@@ -856,23 +856,23 @@  discard block
 block discarded – undo
856 856
     static function ao_admin_tabs()
857 857
     {
858 858
         // based on http://wordpress.stackexchange.com/a/58826 .
859
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
859
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
860 860
         $tab_content = '';
861
-        $tabs_count  = count( $tabs );
862
-        if ( $tabs_count > 1 ) {
863
-            if ( isset( $_GET['page'] ) ) {
861
+        $tabs_count  = count($tabs);
862
+        if ($tabs_count > 1) {
863
+            if (isset($_GET['page'])) {
864 864
                 $current_id = $_GET['page'];
865 865
             } else {
866 866
                 $current_id = 'autoptimize';
867 867
             }
868 868
             $tab_content .= '<h2 class="nav-tab-wrapper">';
869
-            foreach ( $tabs as $tab_id => $tab_name ) {
870
-                if ( $current_id == $tab_id ) {
869
+            foreach ($tabs as $tab_id => $tab_name) {
870
+                if ($current_id == $tab_id) {
871 871
                     $class = ' nav-tab-active';
872 872
                 } else {
873 873
                     $class = '';
874 874
                 }
875
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
875
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
876 876
             }
877 877
             $tab_content .= '</h2>';
878 878
         } else {
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
      */
890 890
     public static function is_admin_and_not_ajax()
891 891
     {
892
-        return ( is_admin() && ! self::doing_ajax() );
892
+        return (is_admin() && !self::doing_ajax());
893 893
     }
894 894
 
895 895
     /**
@@ -899,10 +899,10 @@  discard block
 block discarded – undo
899 899
      */
900 900
     protected static function doing_ajax()
901 901
     {
902
-        if ( function_exists( 'wp_doing_ajax' ) ) {
902
+        if (function_exists('wp_doing_ajax')) {
903 903
             return wp_doing_ajax();
904 904
         }
905
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
905
+        return (defined('DOING_AJAX') && DOING_AJAX);
906 906
     }
907 907
 
908 908
     /**
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
      * @return bool
912 912
      */
913 913
     public static function should_show_menu_tabs() {
914
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
914
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
915 915
             return true;
916 916
         } else {
917 917
             return false;
Please login to merge, or discard this patch.
classes/autoptimizeCache.php 1 patch
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles disk-cache-related operations.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
      * @param string $md5 Hash.
39 39
      * @param string $ext Extension.
40 40
      */
41
-    public function __construct( $md5, $ext = 'php' )
41
+    public function __construct($md5, $ext = 'php')
42 42
     {
43 43
         $_min_ext = '';
44
-        if ( apply_filters( 'autoptimize_filter_cache_url_add_min_ext', false ) ) {
44
+        if (apply_filters('autoptimize_filter_cache_url_add_min_ext', false)) {
45 45
             $_min_ext = '.min';
46 46
         }
47 47
 
48 48
         $this->cachedir = AUTOPTIMIZE_CACHE_DIR;
49 49
         $this->nogzip   = AUTOPTIMIZE_CACHE_NOGZIP;
50
-        if ( ! $this->nogzip ) {
51
-            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.php';
50
+        if (!$this->nogzip) {
51
+            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.php';
52 52
         } else {
53
-            if ( in_array( $ext, array( 'js', 'css' ) ) ) {
54
-                $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
53
+            if (in_array($ext, array('js', 'css'))) {
54
+                $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
55 55
             } else {
56
-                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
56
+                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
57 57
             }
58 58
         }
59 59
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function check()
67 67
     {
68
-        return file_exists( $this->cachedir . $this->filename );
68
+        return file_exists($this->cachedir.$this->filename);
69 69
     }
70 70
 
71 71
     /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function retrieve()
77 77
     {
78
-        if ( $this->check() ) {
79
-            if ( false == $this->nogzip ) {
80
-                return file_get_contents( $this->cachedir . $this->filename . '.none' );
78
+        if ($this->check()) {
79
+            if (false == $this->nogzip) {
80
+                return file_get_contents($this->cachedir.$this->filename.'.none');
81 81
             } else {
82
-                return file_get_contents( $this->cachedir . $this->filename );
82
+                return file_get_contents($this->cachedir.$this->filename);
83 83
             }
84 84
         }
85 85
         return false;
@@ -93,50 +93,50 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return void
95 95
      */
96
-    public function cache( $data, $mime )
96
+    public function cache($data, $mime)
97 97
     {
98 98
         // off by default; check if cachedirs exist every time before caching
99 99
         //
100 100
         // to be activated for users that experience these ugly errors;
101 101
         // PHP Warning: file_put_contents failed to open stream: No such file or directory.
102
-        if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) {
102
+        if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) {
103 103
             $this->check_and_create_dirs();
104 104
         }
105 105
 
106
-        if ( false === $this->nogzip ) {
106
+        if (false === $this->nogzip) {
107 107
             // We handle gzipping ourselves.
108 108
             $file    = 'default.php';
109
-            $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file );
110
-            $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode );
109
+            $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file);
110
+            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode);
111 111
 
112
-            file_put_contents( $this->cachedir . $this->filename, $phpcode );
113
-            file_put_contents( $this->cachedir . $this->filename . '.none', $data );
112
+            file_put_contents($this->cachedir.$this->filename, $phpcode);
113
+            file_put_contents($this->cachedir.$this->filename.'.none', $data);
114 114
         } else {
115 115
             // Write code to cache without doing anything else.
116
-            file_put_contents( $this->cachedir . $this->filename, $data );
116
+            file_put_contents($this->cachedir.$this->filename, $data);
117 117
 
118 118
             // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single.
119
-            if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) {
120
-                $_extension     = pathinfo( $this->filename, PATHINFO_EXTENSION );
121
-                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension;
122
-                if ( ( 'css' === $_extension || 'js' === $_extension ) && ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) {
123
-                    file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data );
119
+            if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) {
120
+                $_extension     = pathinfo($this->filename, PATHINFO_EXTENSION);
121
+                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension;
122
+                if (('css' === $_extension || 'js' === $_extension) && !file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) {
123
+                    file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data);
124 124
                 }
125 125
             }
126 126
 
127
-            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) {
127
+            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) {
128 128
                 // Create an additional cached gzip file.
129
-                file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) );
129
+                file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP));
130 130
                 // If PHP Brotli extension is installed, create an additional cached Brotli file.
131
-                if ( function_exists( 'brotli_compress' ) ) {
132
-                    file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) );
131
+                if (function_exists('brotli_compress')) {
132
+                    file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC));
133 133
                 }
134 134
             }
135 135
         }
136 136
 
137 137
         // Provide 3rd party action hook for every cache file that is created.
138 138
         // This hook can for example be used to inject a copy of the created cache file to a other domain.
139
-        do_action( 'autoptimize_action_cache_file_created', $this->cachedir . $this->filename );
139
+        do_action('autoptimize_action_cache_file_created', $this->cachedir.$this->filename);
140 140
     }
141 141
 
142 142
     /**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         // The original idea here was to provide 3rd party code a hook so that
152 152
         // it can "listen" to all the complete autoptimized-urls that the page
153 153
         // will emit... Or something to that effect I think?
154
-        apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename );
154
+        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename);
155 155
 
156 156
         return $this->filename;
157 157
     }
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
      * @param string $file Filename.
165 165
      * @return bool
166 166
      */
167
-    protected static function is_valid_cache_file( $dir, $file )
167
+    protected static function is_valid_cache_file($dir, $file)
168 168
     {
169
-        if ( '.' !== $file && '..' !== $file &&
170
-            false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) &&
171
-            is_file( $dir . $file ) ) {
169
+        if ('.' !== $file && '..' !== $file &&
170
+            false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) &&
171
+            is_file($dir.$file)) {
172 172
 
173 173
             // It's a valid file!
174 174
             return true;
@@ -186,16 +186,16 @@  discard block
 block discarded – undo
186 186
     protected static function clear_cache_classic()
187 187
     {
188 188
         $contents = self::get_cache_contents();
189
-        foreach ( $contents as $name => $files ) {
190
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
191
-            foreach ( $files as $file ) {
192
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
193
-                    @unlink( $dir . $file ); // @codingStandardsIgnoreLine
189
+        foreach ($contents as $name => $files) {
190
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
191
+            foreach ($files as $file) {
192
+                if (self::is_valid_cache_file($dir, $file)) {
193
+                    @unlink($dir.$file); // @codingStandardsIgnoreLine
194 194
                 }
195 195
             }
196 196
         }
197 197
 
198
-        @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine
198
+        @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine
199 199
     }
200 200
 
201 201
     /**
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
      *
207 207
      * @return bool
208 208
      */
209
-    protected static function rmdir( $pathname )
209
+    protected static function rmdir($pathname)
210 210
     {
211
-        $files = self::get_dir_contents( $pathname );
212
-        foreach ( $files as $file ) {
213
-            $path = $pathname . '/' . $file;
214
-            if ( is_dir( $path ) ) {
215
-                self::rmdir( $path );
211
+        $files = self::get_dir_contents($pathname);
212
+        foreach ($files as $file) {
213
+            $path = $pathname.'/'.$file;
214
+            if (is_dir($path)) {
215
+                self::rmdir($path);
216 216
             } else {
217
-                unlink( $path );
217
+                unlink($path);
218 218
             }
219 219
         }
220 220
 
221
-        return rmdir( $pathname );
221
+        return rmdir($pathname);
222 222
     }
223 223
 
224 224
     /**
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
         $new_name = self::get_unique_name();
240 240
 
241 241
         // Makes sure the new pathname is on the same level...
242
-        $new_pathname = dirname( $dir ) . '/' . $new_name;
243
-        $renamed      = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine
242
+        $new_pathname = dirname($dir).'/'.$new_name;
243
+        $renamed      = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine
244 244
 
245 245
         // When renamed, re-create the default cache directory back so it's
246 246
         // available again...
247
-        if ( $renamed ) {
247
+        if ($renamed) {
248 248
             $ok = self::cacheavail();
249 249
         }
250 250
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public static function advanced_cache_clear_enabled()
260 260
     {
261
-        return apply_filters( 'autoptimize_filter_cache_clear_advanced', false );
261
+        return apply_filters('autoptimize_filter_cache_clear_advanced', false);
262 262
     }
263 263
 
264 264
     /**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     protected static function get_unique_name()
270 270
     {
271 271
         $prefix   = self::get_advanced_cache_clear_prefix();
272
-        $new_name = uniqid( $prefix, true );
272
+        $new_name = uniqid($prefix, true);
273 273
 
274 274
         return $new_name;
275 275
     }
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
     protected static function get_advanced_cache_clear_prefix()
283 283
     {
284 284
         $pathname = self::get_pathname_base();
285
-        $basename = basename( $pathname );
286
-        $prefix   = $basename . '-artifact-';
285
+        $basename = basename($pathname);
286
+        $prefix   = $basename.'-artifact-';
287 287
 
288 288
         return $prefix;
289 289
     }
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return array
298 298
      */
299
-    protected static function get_dir_contents( $pathname )
299
+    protected static function get_dir_contents($pathname)
300 300
     {
301
-        return array_slice( scandir( $pathname ), 2 );
301
+        return array_slice(scandir($pathname), 2);
302 302
     }
303 303
 
304 304
     /**
@@ -311,24 +311,24 @@  discard block
 block discarded – undo
311 311
     public static function delete_advanced_cache_clear_artifacts()
312 312
     {
313 313
         // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active.
314
-        if ( ! self::advanced_cache_clear_enabled() ) {
314
+        if (!self::advanced_cache_clear_enabled()) {
315 315
             return false;
316 316
         }
317 317
 
318 318
         $dir    = self::get_pathname_base();
319 319
         $prefix = self::get_advanced_cache_clear_prefix();
320
-        $parent = dirname( $dir );
320
+        $parent = dirname($dir);
321 321
         $ok     = false;
322 322
 
323 323
         // Returns the list of files without '.' and '..' elements.
324
-        $files = self::get_dir_contents( $parent );
325
-        if ( is_array( $files ) && ! empty( $files ) ) {
326
-            foreach ( $files as $file ) {
327
-                $path     = $parent . '/' . $file;
328
-                $prefixed = ( false !== strpos( $path, $prefix ) );
324
+        $files = self::get_dir_contents($parent);
325
+        if (is_array($files) && !empty($files)) {
326
+            foreach ($files as $file) {
327
+                $path     = $parent.'/'.$file;
328
+                $prefixed = (false !== strpos($path, $prefix));
329 329
                 // Removing only our own (prefixed) directories...
330
-                if ( is_dir( $path ) && $prefixed ) {
331
-                    $ok = self::rmdir( $path );
330
+                if (is_dir($path) && $prefixed) {
331
+                    $ok = self::rmdir($path);
332 332
                 }
333 333
             }
334 334
         }
@@ -348,9 +348,9 @@  discard block
 block discarded – undo
348 348
     {
349 349
         $pathname = self::get_pathname_base();
350 350
 
351
-        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
351
+        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
352 352
             $blog_id   = get_current_blog_id();
353
-            $pathname .= $blog_id . '/';
353
+            $pathname .= $blog_id.'/';
354 354
         }
355 355
 
356 356
         return $pathname;
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      */
364 364
     protected static function get_pathname_base()
365 365
     {
366
-        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
366
+        $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR;
367 367
 
368 368
         return $pathname;
369 369
     }
@@ -375,46 +375,46 @@  discard block
 block discarded – undo
375 375
      *
376 376
      * @return bool
377 377
      */
378
-    public static function clearall( $propagate = true )
378
+    public static function clearall($propagate = true)
379 379
     {
380
-        if ( ! self::cacheavail() ) {
380
+        if (!self::cacheavail()) {
381 381
             return false;
382 382
         }
383 383
 
384 384
         // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
385
-        if ( self::advanced_cache_clear_enabled() ) {
385
+        if (self::advanced_cache_clear_enabled()) {
386 386
             self::clear_cache_via_rename();
387 387
         } else {
388 388
             self::clear_cache_classic();
389 389
         }
390 390
 
391 391
         // Remove 404 handler if required.
392
-        if ( self::do_fallback() ) {
393
-            $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php';
394
-            @unlink( $_fallback_php ); // @codingStandardsIgnoreLine
392
+        if (self::do_fallback()) {
393
+            $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php';
394
+            @unlink($_fallback_php); // @codingStandardsIgnoreLine
395 395
         }
396 396
 
397 397
         // Remove the transient so it gets regenerated...
398
-        delete_transient( 'autoptimize_stats' );
398
+        delete_transient('autoptimize_stats');
399 399
 
400 400
         // Cache was just purged, clear page cache and allow others to hook into our purging...
401
-        if ( true === $propagate ) {
402
-            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) {
401
+        if (true === $propagate) {
402
+            if (!function_exists('autoptimize_do_cachepurged_action')) {
403 403
                 function autoptimize_do_cachepurged_action() {
404
-                    do_action( 'autoptimize_action_cachepurged' );
404
+                    do_action('autoptimize_action_cachepurged');
405 405
                 }
406 406
             }
407
-            add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 );
408
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 );
407
+            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11);
408
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0);
409 409
         }
410 410
 
411 411
         // Warm cache (part of speedupper)!
412
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) {
413
-            set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 );
414
-            $url   = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 );
415
-            $url   = apply_filters( 'autoptimize_filter_cache_warmer_url', $url );
416
-            $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine
417
-            unset( $cache );
412
+        if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) {
413
+            set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10);
414
+            $url   = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000);
415
+            $url   = apply_filters('autoptimize_filter_cache_warmer_url', $url);
416
+            $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine
417
+            unset($cache);
418 418
         }
419 419
 
420 420
         return true;
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
      */
430 430
     public static function clearall_actionless()
431 431
     {
432
-        return self::clearall( false );
432
+        return self::clearall(false);
433 433
     }
434 434
 
435 435
     /**
@@ -441,8 +441,8 @@  discard block
 block discarded – undo
441 441
     {
442 442
         $contents = array();
443 443
 
444
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
445
-            $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir );
444
+        foreach (array('', 'js', 'css') as $dir) {
445
+            $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir);
446 446
         }
447 447
 
448 448
         return $contents;
@@ -455,21 +455,21 @@  discard block
 block discarded – undo
455 455
      */
456 456
     public static function stats()
457 457
     {
458
-        $stats = get_transient( 'autoptimize_stats' );
458
+        $stats = get_transient('autoptimize_stats');
459 459
 
460 460
         // If no transient, do the actual scan!
461
-        if ( ! is_array( $stats ) ) {
462
-            if ( ! self::cacheavail() ) {
461
+        if (!is_array($stats)) {
462
+            if (!self::cacheavail()) {
463 463
                 return 0;
464 464
             }
465 465
             $stats = self::stats_scan();
466 466
             $count = $stats[0];
467
-            if ( $count > 100 ) {
467
+            if ($count > 100) {
468 468
                 // Store results in transient.
469 469
                 set_transient(
470 470
                     'autoptimize_stats',
471 471
                     $stats,
472
-                    apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS )
472
+                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS)
473 473
                 );
474 474
             }
475 475
         }
@@ -492,30 +492,30 @@  discard block
 block discarded – undo
492 492
         $size  = 0;
493 493
 
494 494
         // Scan everything in our cache directories.
495
-        foreach ( self::get_cache_contents() as $name => $files ) {
496
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
497
-            foreach ( $files as $file ) {
498
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
499
-                    if ( AUTOPTIMIZE_CACHE_NOGZIP &&
495
+        foreach (self::get_cache_contents() as $name => $files) {
496
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
497
+            foreach ($files as $file) {
498
+                if (self::is_valid_cache_file($dir, $file)) {
499
+                    if (AUTOPTIMIZE_CACHE_NOGZIP &&
500 500
                         (
501
-                            false !== strpos( $file, '.js' ) ||
502
-                            false !== strpos( $file, '.css' ) ||
503
-                            false !== strpos( $file, '.img' ) ||
504
-                            false !== strpos( $file, '.txt' )
501
+                            false !== strpos($file, '.js') ||
502
+                            false !== strpos($file, '.css') ||
503
+                            false !== strpos($file, '.img') ||
504
+                            false !== strpos($file, '.txt')
505 505
                         )
506 506
                     ) {
507 507
                         // Web server is gzipping, we count .js|.css|.img|.txt files.
508 508
                         $count++;
509
-                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) {
509
+                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) {
510 510
                         // We are gzipping ourselves via php, counting only .none files.
511 511
                         $count++;
512 512
                     }
513
-                    $size += filesize( $dir . $file );
513
+                    $size += filesize($dir.$file);
514 514
                 }
515 515
             }
516 516
         }
517 517
 
518
-        $stats = array( $count, $size, time() );
518
+        $stats = array($count, $size, time());
519 519
 
520 520
         return $stats;
521 521
     }
@@ -529,22 +529,22 @@  discard block
 block discarded – undo
529 529
      */
530 530
     public static function cacheavail()
531 531
     {
532
-        if ( false === autoptimizeCache::check_and_create_dirs() ) {
532
+        if (false === autoptimizeCache::check_and_create_dirs()) {
533 533
             return false;
534 534
         }
535 535
 
536 536
         // Using .htaccess inside our cache folder to overrule wp-super-cache.
537
-        $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
538
-        if ( ! is_file( $htaccess ) ) {
537
+        $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess';
538
+        if (!is_file($htaccess)) {
539 539
             /**
540 540
              * Create `wp-content/AO_htaccess_tmpl` file with
541 541
              * whatever htaccess rules you might need
542 542
              * if you want to override default AO htaccess
543 543
              */
544
-            $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl';
545
-            if ( is_file( $htaccess_tmpl ) ) {
546
-                $content = file_get_contents( $htaccess_tmpl );
547
-            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) {
544
+            $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl';
545
+            if (is_file($htaccess_tmpl)) {
546
+                $content = file_get_contents($htaccess_tmpl);
547
+            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) {
548 548
                 $content = '<IfModule mod_expires.c>
549 549
         ExpiresActive On
550 550
         ExpiresByType text/css A30672000
@@ -598,13 +598,13 @@  discard block
 block discarded – undo
598 598
 </IfModule>';
599 599
             }
600 600
 
601
-            if ( self::do_fallback() === true ) {
602
-                $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
601
+            if (self::do_fallback() === true) {
602
+                $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php';
603 603
             }
604
-            @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
604
+            @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine
605 605
         }
606 606
 
607
-        if ( self::do_fallback() ) {
607
+        if (self::do_fallback()) {
608 608
             self::check_fallback_php();
609 609
         }
610 610
 
@@ -619,17 +619,17 @@  discard block
 block discarded – undo
619 619
      */
620 620
     public static function check_fallback_php() {
621 621
         $_fallback_filename = 'autoptimize_404_handler.php';
622
-        $_fallback_php      = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename;
622
+        $_fallback_php      = trailingslashit(WP_CONTENT_DIR).$_fallback_filename;
623 623
         $_fallback_status   = true;
624 624
 
625
-        if ( ! file_exists( $_fallback_php ) ) {
626
-            $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
627
-            $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
628
-            $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
629
-            if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
630
-                $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
625
+        if (!file_exists($_fallback_php)) {
626
+            $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename);
627
+            $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents);
628
+            $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents);
629
+            if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) {
630
+                $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents);
631 631
             }
632
-            $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
632
+            $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents);
633 633
         }
634 634
 
635 635
         return $_fallback_status;
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
     public static function do_fallback() {
647 647
         static $_do_fallback = null;
648 648
 
649
-        if ( null === $_do_fallback ) {
650
-            $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) );
649
+        if (null === $_do_fallback) {
650
+            $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', ''));
651 651
         }
652 652
 
653 653
         return $_do_fallback;
@@ -659,31 +659,31 @@  discard block
 block discarded – undo
659 659
      * and 410'ing ("Gone") if fallback not available.
660 660
      */
661 661
     public static function wordpress_notfound_fallback() {
662
-        $original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
663
-        if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) {
662
+        $original_request = strtok($_SERVER['REQUEST_URI'], '?');
663
+        if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) {
664 664
             // make sure this is not considered a 404.
665 665
             global $wp_query;
666 666
             $wp_query->is_404 = false;
667 667
 
668 668
             // set fallback path.
669
-            $js_or_css     = pathinfo( $original_request, PATHINFO_EXTENSION );
670
-            $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
669
+            $js_or_css     = pathinfo($original_request, PATHINFO_EXTENSION);
670
+            $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
671 671
 
672 672
             // prepare for Shakeeb's Unused CSS files to be 404-handled as well.
673
-            if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
674
-                $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
673
+            if (strpos($original_request, 'uucss/uucss-') !== false) {
674
+                $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
675 675
             }
676 676
 
677 677
             // set fallback URL.
678
-            $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
678
+            $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
679 679
 
680 680
             // redirect to fallback if possible.
681
-            if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
681
+            if ($original_request !== $fallback_target && file_exists($fallback_path)) {
682 682
                 // redirect to fallback.
683
-                wp_redirect( $fallback_target, 302 );
683
+                wp_redirect($fallback_target, 302);
684 684
             } else {
685 685
                 // return HTTP 410 (gone) reponse.
686
-                status_header( 410 );
686
+                status_header(410);
687 687
             }
688 688
         }
689 689
     }
@@ -695,13 +695,13 @@  discard block
 block discarded – undo
695 695
      * @return bool
696 696
      */
697 697
     public static function check_and_create_dirs() {
698
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
698
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
699 699
             // We didn't set a cache.
700 700
             return false;
701 701
         }
702 702
 
703
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
704
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
703
+        foreach (array('', 'js', 'css') as $dir) {
704
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
705 705
                 return false;
706 706
             }
707 707
         }
@@ -716,25 +716,25 @@  discard block
 block discarded – undo
716 716
      *
717 717
      * @return bool
718 718
      */
719
-    protected static function check_cache_dir( $dir )
719
+    protected static function check_cache_dir($dir)
720 720
     {
721 721
         // Try creating the dir if it doesn't exist.
722
-        if ( ! file_exists( $dir ) ) {
723
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
724
-            if ( ! file_exists( $dir ) ) {
722
+        if (!file_exists($dir)) {
723
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
724
+            if (!file_exists($dir)) {
725 725
                 return false;
726 726
             }
727 727
         }
728 728
 
729 729
         // If we still cannot write, bail.
730
-        if ( ! is_writable( $dir ) ) {
730
+        if (!is_writable($dir)) {
731 731
             return false;
732 732
         }
733 733
 
734 734
         // Create an index.html in there to avoid prying eyes!
735
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
736
-        if ( ! is_file( $idx_file ) ) {
737
-            @file_put_contents( $idx_file, '<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>' ); // @codingStandardsIgnoreLine
735
+        $idx_file = rtrim($dir, '/\\').'/index.html';
736
+        if (!is_file($idx_file)) {
737
+            @file_put_contents($idx_file, '<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>'); // @codingStandardsIgnoreLine
738 738
         }
739 739
 
740 740
         return true;
@@ -748,52 +748,52 @@  discard block
 block discarded – undo
748 748
     // @codingStandardsIgnoreStart
749 749
     public static function flushPageCache()
750 750
     {
751
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
752
-            if ( is_multisite() ) {
751
+        if (function_exists('wp_cache_clear_cache')) {
752
+            if (is_multisite()) {
753 753
                 $blog_id = get_current_blog_id();
754
-                wp_cache_clear_cache( $blog_id );
754
+                wp_cache_clear_cache($blog_id);
755 755
             } else {
756 756
                 wp_cache_clear_cache();
757 757
             }
758
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
759
-            do_action( 'cachify_flush_cache' );
760
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
758
+        } elseif (has_action('cachify_flush_cache')) {
759
+            do_action('cachify_flush_cache');
760
+        } elseif (function_exists('w3tc_pgcache_flush')) {
761 761
             w3tc_pgcache_flush();
762
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
762
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
763 763
             wp_fast_cache_bulk_delete_all();
764
-        } elseif ( class_exists( 'Swift_Performance_Cache' ) ) {
764
+        } elseif (class_exists('Swift_Performance_Cache')) {
765 765
             Swift_Performance_Cache::clear_all_cache();
766
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
766
+        } elseif (class_exists('WpFastestCache')) {
767 767
             $wpfc = new WpFastestCache();
768 768
             $wpfc->deleteCache();
769
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
769
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
770 770
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
771
-        } elseif ( class_exists( 'zencache' ) ) {
771
+        } elseif (class_exists('zencache')) {
772 772
             zencache::clear();
773
-        } elseif ( class_exists( 'comet_cache' ) ) {
773
+        } elseif (class_exists('comet_cache')) {
774 774
             comet_cache::clear();
775
-        } elseif ( class_exists( 'WpeCommon' ) ) {
775
+        } elseif (class_exists('WpeCommon')) {
776 776
             // WPEngine cache purge/flush methods to call by default
777 777
             $wpe_methods = array(
778 778
                 'purge_varnish_cache',
779 779
             );
780 780
 
781 781
             // More agressive clear/flush/purge behind a filter
782
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
783
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
782
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
783
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
784 784
             }
785 785
 
786 786
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
787
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
787
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
788 788
 
789
-            foreach ( $wpe_methods as $wpe_method ) {
790
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
789
+            foreach ($wpe_methods as $wpe_method) {
790
+                if (method_exists('WpeCommon', $wpe_method)) {
791 791
                     WpeCommon::$wpe_method();
792 792
                 }
793 793
             }
794
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
794
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
795 795
             sg_cachepress_purge_cache();
796
-        } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
796
+        } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) {
797 797
             $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
798 798
             $_kinsta_response        = wp_remote_get(
799 799
                 $_kinsta_clear_cache_url,
@@ -802,18 +802,18 @@  discard block
 block discarded – undo
802 802
                     'timeout' => 5,
803 803
                     )
804 804
             );
805
-        } elseif ( defined('NGINX_HELPER_BASENAME') ) {
806
-            do_action( 'rt_nginx_helper_purge_all' );
807
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
805
+        } elseif (defined('NGINX_HELPER_BASENAME')) {
806
+            do_action('rt_nginx_helper_purge_all');
807
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
808 808
             // fallback for WP-Super-Cache
809 809
             global $cache_path;
810
-            if ( is_multisite() ) {
810
+            if (is_multisite()) {
811 811
                 $blog_id = get_current_blog_id();
812
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
813
-                prune_super_cache( $cache_path . 'blogs/', true );
812
+                prune_super_cache(get_supercache_dir($blog_id), true);
813
+                prune_super_cache($cache_path.'blogs/', true);
814 814
             } else {
815
-                prune_super_cache( $cache_path . 'supercache/', true );
816
-                prune_super_cache( $cache_path, true );
815
+                prune_super_cache($cache_path.'supercache/', true);
816
+                prune_super_cache($cache_path, true);
817 817
             }
818 818
         }
819 819
     }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSCore.php 1 patch
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * gets called by AO core, checks the rules and if a matching rule is found returns the associated CCSS.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     {
14 14
         // fetch all options at once and populate them individually explicitely as globals.
15 15
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
16
-        foreach ( $all_options as $_option => $_value ) {
16
+        foreach ($all_options as $_option => $_value) {
17 17
             global ${$_option};
18 18
             ${$_option} = $_value;
19 19
         }
@@ -28,28 +28,28 @@  discard block
 block discarded – undo
28 28
         global $ao_ccss_unloadccss;
29 29
 
30 30
         // add all filters to do CCSS if key present.
31
-        if ( $ao_css_defer && isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) ) {
31
+        if ($ao_css_defer && isset($ao_ccss_key) && !empty($ao_ccss_key)) {
32 32
             // Set AO behavior: disable minification to avoid double minifying and caching.
33
-            add_filter( 'autoptimize_filter_css_critcss_minify', '__return_false' );
34
-            add_filter( 'autoptimize_filter_css_defer_inline', array( $this, 'ao_ccss_frontend' ), 10, 1 );
33
+            add_filter('autoptimize_filter_css_critcss_minify', '__return_false');
34
+            add_filter('autoptimize_filter_css_defer_inline', array($this, 'ao_ccss_frontend'), 10, 1);
35 35
 
36 36
             // Add the action to enqueue jobs for CriticalCSS cron.
37
-            add_action( 'autoptimize_action_css_hash', array( 'autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue' ), 10, 1 );
37
+            add_action('autoptimize_action_css_hash', array('autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue'), 10, 1);
38 38
 
39 39
             // conditionally add the filter to defer jquery and others.
40
-            if ( $ao_ccss_deferjquery ) {
41
-                add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_defer_jquery' ), 11, 1 );
40
+            if ($ao_ccss_deferjquery) {
41
+                add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_defer_jquery'), 11, 1);
42 42
             }
43 43
 
44 44
             // conditionally add filter to unload the CCSS.
45
-            if ( $ao_ccss_unloadccss ) {
46
-                add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_unloadccss' ), 12, 1 );
45
+            if ($ao_ccss_unloadccss) {
46
+                add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_unloadccss'), 12, 1);
47 47
             }
48 48
 
49 49
             // Order paths by length, as longest ones have greater priority in the rules.
50
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
51
-                $keys = array_map( 'strlen', array_keys( $ao_ccss_rules['paths'] ) );
52
-                array_multisort( $keys, SORT_DESC, $ao_ccss_rules['paths'] );
50
+            if (!empty($ao_ccss_rules['paths'])) {
51
+                $keys = array_map('strlen', array_keys($ao_ccss_rules['paths']));
52
+                array_multisort($keys, SORT_DESC, $ao_ccss_rules['paths']);
53 53
             }
54 54
 
55 55
             // Add an array with default WordPress's conditional tags
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
             $ao_ccss_types = $this->get_ao_ccss_core_types();
59 59
 
60 60
             // Extend conditional tags on plugin initalization.
61
-            add_action( apply_filters( 'autoptimize_filter_ccss_extend_types_hook', 'init' ), array( $this, 'ao_ccss_extend_types' ) );
61
+            add_action(apply_filters('autoptimize_filter_ccss_extend_types_hook', 'init'), array($this, 'ao_ccss_extend_types'));
62 62
 
63 63
             // When autoptimize cache is cleared, also clear transient cache for page templates.
64
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCriticalCSSCore', 'ao_ccss_clear_page_tpl_cache' ), 10, 0 );
64
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCriticalCSSCore', 'ao_ccss_clear_page_tpl_cache'), 10, 0);
65 65
         }
66 66
     }
67 67
 
68
-    public function ao_ccss_frontend( $inlined ) {
68
+    public function ao_ccss_frontend($inlined) {
69 69
         // Apply CriticalCSS to frontend pages
70 70
         // Attach types and settings arrays.
71 71
         global $ao_ccss_types;
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
         $no_ccss = '';
78 78
 
79 79
         // Only if keystatus is OK and option to add CCSS for logged on users is on or user is not logged in.
80
-        if ( ( $ao_ccss_keyst && 2 == $ao_ccss_keyst ) && ( $ao_ccss_loggedin || ! is_user_logged_in() ) ) {
80
+        if (($ao_ccss_keyst && 2 == $ao_ccss_keyst) && ($ao_ccss_loggedin || !is_user_logged_in())) {
81 81
             // Check for a valid CriticalCSS based on path to return its contents.
82
-            $req_path = strtok( $_SERVER['REQUEST_URI'], '?' );
83
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
84
-                foreach ( $ao_ccss_rules['paths'] as $path => $rule ) {
82
+            $req_path = strtok($_SERVER['REQUEST_URI'], '?');
83
+            if (!empty($ao_ccss_rules['paths'])) {
84
+                foreach ($ao_ccss_rules['paths'] as $path => $rule) {
85 85
                     // explicit match OR partial match if MANUAL rule.
86
-                    if ( $req_path == $path || urldecode( $req_path ) == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) {
87
-                        if ( file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
88
-                            $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
89
-                            if ( 'none' != $_ccss_contents ) {
90
-                                if ( $ao_ccss_debug ) {
91
-                                    $_ccss_contents = '/* PATH: ' . $path . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
86
+                    if ($req_path == $path || urldecode($req_path) == $path || (false == $rule['hash'] && false != $rule['file'] && strpos($req_path, str_replace(site_url(), '', $path)) !== false)) {
87
+                        if (file_exists(AO_CCSS_DIR.$rule['file'])) {
88
+                            $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
89
+                            if ('none' != $_ccss_contents) {
90
+                                if ($ao_ccss_debug) {
91
+                                    $_ccss_contents = '/* PATH: '.$path.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
92 92
                                 }
93
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
93
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
94 94
                             } else {
95 95
                                 $no_ccss = 'none';
96 96
                             }
@@ -100,55 +100,55 @@  discard block
 block discarded – undo
100 100
             }
101 101
 
102 102
             // Check for a valid CriticalCSS based on conditional tags to return its contents.
103
-            if ( ! empty( $ao_ccss_rules['types'] ) && 'none' !== $no_ccss ) {
103
+            if (!empty($ao_ccss_rules['types']) && 'none' !== $no_ccss) {
104 104
                 // order types-rules by the order of the original $ao_ccss_types array so as not to depend on the order in which rules were added.
105
-                $ao_ccss_rules['types'] = array_replace( array_intersect_key( array_flip( $ao_ccss_types ), $ao_ccss_rules['types'] ), $ao_ccss_rules['types'] );
105
+                $ao_ccss_rules['types'] = array_replace(array_intersect_key(array_flip($ao_ccss_types), $ao_ccss_rules['types']), $ao_ccss_rules['types']);
106 106
                 $is_front_page          = is_front_page();
107 107
 
108
-                foreach ( $ao_ccss_rules['types'] as $type => $rule ) {
109
-                    if ( in_array( $type, $ao_ccss_types ) && file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
110
-                        $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
111
-                        if ( $is_front_page && 'is_front_page' == $type ) {
112
-                            if ( 'none' != $_ccss_contents ) {
113
-                                if ( $ao_ccss_debug ) {
114
-                                    $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
108
+                foreach ($ao_ccss_rules['types'] as $type => $rule) {
109
+                    if (in_array($type, $ao_ccss_types) && file_exists(AO_CCSS_DIR.$rule['file'])) {
110
+                        $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
111
+                        if ($is_front_page && 'is_front_page' == $type) {
112
+                            if ('none' != $_ccss_contents) {
113
+                                if ($ao_ccss_debug) {
114
+                                    $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
115 115
                                 }
116
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
116
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
117 117
                             } else {
118 118
                                 $no_ccss = 'none';
119 119
                             }
120
-                        } elseif ( strpos( $type, 'custom_post_' ) === 0 && ! $is_front_page ) {
121
-                            if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
122
-                                if ( 'none' != $_ccss_contents ) {
123
-                                    if ( $ao_ccss_debug ) {
124
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
120
+                        } elseif (strpos($type, 'custom_post_') === 0 && !$is_front_page) {
121
+                            if (get_post_type(get_the_ID()) === substr($type, 12)) {
122
+                                if ('none' != $_ccss_contents) {
123
+                                    if ($ao_ccss_debug) {
124
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
125 125
                                     }
126
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
126
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
127 127
                                 } else {
128 128
                                     $no_ccss = 'none';
129 129
                                 }
130 130
                             }
131
-                        } elseif ( 0 === strpos( $type, 'template_' ) && ! $is_front_page ) {
132
-                            if ( is_page_template( substr( $type, 9 ) ) ) {
133
-                                if ( 'none' != $_ccss_contents ) {
134
-                                    if ( $ao_ccss_debug ) {
135
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
131
+                        } elseif (0 === strpos($type, 'template_') && !$is_front_page) {
132
+                            if (is_page_template(substr($type, 9))) {
133
+                                if ('none' != $_ccss_contents) {
134
+                                    if ($ao_ccss_debug) {
135
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
136 136
                                     }
137
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
137
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
138 138
                                 } else {
139 139
                                     $no_ccss = 'none';
140 140
                                 }
141 141
                             }
142
-                        } elseif ( ! $is_front_page ) {
142
+                        } elseif (!$is_front_page) {
143 143
                             // all "normal" conditional tags, core + woo + buddypress + edd + bbpress
144 144
                             // but we have to remove the prefix for the non-core ones for them to function.
145
-                            $type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
146
-                            if ( function_exists( $type ) && call_user_func( $type ) ) {
147
-                                if ( 'none' != $_ccss_contents ) {
148
-                                    if ( $ao_ccss_debug ) {
149
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
145
+                            $type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
146
+                            if (function_exists($type) && call_user_func($type)) {
147
+                                if ('none' != $_ccss_contents) {
148
+                                    if ($ao_ccss_debug) {
149
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
150 150
                                     }
151
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
151
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
152 152
                                 } else {
153 153
                                     $no_ccss = 'none';
154 154
                                 }
@@ -161,45 +161,45 @@  discard block
 block discarded – undo
161 161
 
162 162
         // Finally, inline the default CriticalCSS if any or else the entire CSS for the page
163 163
         // This also applies to logged in users if the option to add CCSS for logged in users has been disabled.
164
-        if ( ! empty( $inlined ) && 'none' !== $no_ccss ) {
165
-            return apply_filters( 'autoptimize_filter_ccss_core_ccss', $inlined . $ao_ccss_additional );
164
+        if (!empty($inlined) && 'none' !== $no_ccss) {
165
+            return apply_filters('autoptimize_filter_ccss_core_ccss', $inlined.$ao_ccss_additional);
166 166
         } else {
167
-            add_filter( 'autoptimize_filter_css_inline', '__return_true' );
167
+            add_filter('autoptimize_filter_css_inline', '__return_true');
168 168
             return;
169 169
         }
170 170
     }
171 171
 
172
-    public function ao_ccss_defer_jquery( $in ) {
172
+    public function ao_ccss_defer_jquery($in) {
173 173
         global $ao_ccss_loggedin;
174 174
         // defer all linked and inline JS.
175
-        if ( ( ! is_user_logged_in() || $ao_ccss_loggedin ) && preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) {
176
-            foreach ( $matches as $match ) {
177
-                if ( str_replace( apply_filters( 'autoptimize_filter_ccss_core_defer_exclude', array( 'data-noptimize="1"', 'data-cfasync="false"', 'data-pagespeed-no-defer' ) ), '', $match[0] ) !== $match[0] ) {
175
+        if ((!is_user_logged_in() || $ao_ccss_loggedin) && preg_match_all('#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER)) {
176
+            foreach ($matches as $match) {
177
+                if (str_replace(apply_filters('autoptimize_filter_ccss_core_defer_exclude', array('data-noptimize="1"', 'data-cfasync="false"', 'data-pagespeed-no-defer')), '', $match[0]) !== $match[0]) {
178 178
                     // do not touch JS with noptimize/ cfasync/ pagespeed-no-defer flags.
179 179
                     continue;
180
-                } elseif ( '' !== $match[1] && ( ! preg_match( '/<script.* type\s?=.*>/', $match[0] ) || preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0] ) ) ) {
180
+                } elseif ('' !== $match[1] && (!preg_match('/<script.* type\s?=.*>/', $match[0]) || preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0]))) {
181 181
                     // base64-encode and defer all inline JS.
182
-                    $base64_js = '<script defer src="data:text/javascript;base64,' . base64_encode( $match[1] ) . '"></script>';
183
-                    $in        = str_replace( $match[0], $base64_js, $in );
184
-                } elseif ( str_replace( array( ' defer', ' async' ), '', $match[0] ) === $match[0] ) {
182
+                    $base64_js = '<script defer src="data:text/javascript;base64,'.base64_encode($match[1]).'"></script>';
183
+                    $in        = str_replace($match[0], $base64_js, $in);
184
+                } elseif (str_replace(array(' defer', ' async'), '', $match[0]) === $match[0]) {
185 185
                     // and defer linked JS unless already deferred or asynced.
186
-                    $new_match = str_replace( '<script ', '<script defer ', $match[0] );
187
-                    $in        = str_replace( $match[0], $new_match, $in );
186
+                    $new_match = str_replace('<script ', '<script defer ', $match[0]);
187
+                    $in        = str_replace($match[0], $new_match, $in);
188 188
                 }
189 189
             }
190 190
         }
191 191
         return $in;
192 192
     }
193 193
 
194
-    public function ao_ccss_unloadccss( $html_in ) {
194
+    public function ao_ccss_unloadccss($html_in) {
195 195
         // set media attrib of inline CCSS to none at onLoad to avoid it impacting full CSS (rarely needed).
196
-        $_unloadccss_js = apply_filters( 'autoptimize_filter_ccss_core_unloadccss_js', '<script>window.addEventListener("load", function(event) {document.getElementById("aoatfcss").media="none";})</script>' );
196
+        $_unloadccss_js = apply_filters('autoptimize_filter_ccss_core_unloadccss_js', '<script>window.addEventListener("load", function(event) {document.getElementById("aoatfcss").media="none";})</script>');
197 197
 
198
-        if ( false !== strpos( $html_in, $_unloadccss_js . '</body>' ) ) {
198
+        if (false !== strpos($html_in, $_unloadccss_js.'</body>')) {
199 199
             return $html_in;
200 200
         }
201 201
 
202
-        return str_replace( '</body>', $_unloadccss_js . '</body>', $html_in );
202
+        return str_replace('</body>', $_unloadccss_js.'</body>', $html_in);
203 203
     }
204 204
 
205 205
     public function ao_ccss_extend_types() {
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
         global $ao_ccss_types;
209 209
 
210 210
         // in some cases $ao_ccss_types is empty and/or not an array, this should work around that problem.
211
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
211
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
212 212
             $ao_ccss_types = get_ao_ccss_core_types();
213
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Empty types array in extend, refetching array with core conditionals.', 3 );
213
+            autoptimizeCriticalCSSCore::ao_ccss_log('Empty types array in extend, refetching array with core conditionals.', 3);
214 214
         }
215 215
 
216 216
         // Custom Post Types.
@@ -222,23 +222,23 @@  discard block
 block discarded – undo
222 222
             'names',
223 223
             'and'
224 224
         );
225
-        foreach ( $cpts as $cpt ) {
226
-            array_unshift( $ao_ccss_types, 'custom_post_' . $cpt );
225
+        foreach ($cpts as $cpt) {
226
+            array_unshift($ao_ccss_types, 'custom_post_'.$cpt);
227 227
         }
228 228
 
229 229
         // Templates.
230 230
         // Transient cache to avoid frequent disk reads.
231
-        $templates = get_transient( 'autoptimize_ccss_page_templates' );
232
-        if ( ! $templates ) {
231
+        $templates = get_transient('autoptimize_ccss_page_templates');
232
+        if (!$templates) {
233 233
             $templates = wp_get_theme()->get_page_templates();
234
-            set_transient( 'autoptimize_ccss_page_templates', $templates, HOUR_IN_SECONDS );
234
+            set_transient('autoptimize_ccss_page_templates', $templates, HOUR_IN_SECONDS);
235 235
         }
236
-        foreach ( $templates as $tplfile => $tplname ) {
237
-            array_unshift( $ao_ccss_types, 'template_' . $tplfile );
236
+        foreach ($templates as $tplfile => $tplname) {
237
+            array_unshift($ao_ccss_types, 'template_'.$tplfile);
238 238
         }
239 239
 
240 240
         // bbPress tags.
241
-        if ( function_exists( 'is_bbpress' ) ) {
241
+        if (function_exists('is_bbpress')) {
242 242
             $ao_ccss_types = array_merge(
243 243
                 array(
244 244
                     'bbp_is_bbpress',
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         }
271 271
 
272 272
         // BuddyPress tags.
273
-        if ( function_exists( 'is_buddypress' ) ) {
273
+        if (function_exists('is_buddypress')) {
274 274
             $ao_ccss_types = array_merge(
275 275
                 array(
276 276
                     'bp_is_activation_page',
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
         }
313 313
 
314 314
         // Easy Digital Downloads (EDD) tags.
315
-        if ( function_exists( 'edd_is_checkout' ) ) {
315
+        if (function_exists('edd_is_checkout')) {
316 316
             $ao_ccss_types = array_merge(
317 317
                 array(
318 318
                     'edd_is_checkout',
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         }
325 325
 
326 326
         // WooCommerce tags.
327
-        if ( class_exists( 'WooCommerce' ) ) {
327
+        if (class_exists('WooCommerce')) {
328 328
             $ao_ccss_types = array_merge(
329 329
                 array(
330 330
                     'woo_is_account_page',
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
     public function get_ao_ccss_core_types() {
345 345
         global $ao_ccss_types;
346
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
346
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
347 347
             return array(
348 348
                 'is_404',
349 349
                 'is_archive',
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         }
365 365
     }
366 366
 
367
-    public static function ao_ccss_key_status( $render ) {
367
+    public static function ao_ccss_key_status($render) {
368 368
         // Provide key status
369 369
         // Get key and key status.
370 370
         global $ao_ccss_key;
@@ -377,55 +377,55 @@  discard block
 block discarded – undo
377 377
         $key_return = array();
378 378
         $status     = false;
379 379
 
380
-        if ( $key && 2 == $key_status ) {
380
+        if ($key && 2 == $key_status) {
381 381
             // Key exists and its status is valid.
382 382
             // Set valid key status.
383 383
             $status     = 'valid';
384
-            $status_msg = __( 'Valid' );
384
+            $status_msg = __('Valid');
385 385
             $color      = '#46b450'; // Green.
386 386
             $message    = null;
387
-        } elseif ( $key && 1 == $key_status ) {
387
+        } elseif ($key && 1 == $key_status) {
388 388
             // Key exists but its validation has failed.
389 389
             // Set invalid key status.
390 390
             $status     = 'invalid';
391
-            $status_msg = __( 'Invalid' );
391
+            $status_msg = __('Invalid');
392 392
             $color      = '#dc3232'; // Red.
393
-            $message    = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
394
-        } elseif ( $key && ! $key_status ) {
393
+            $message    = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
394
+        } elseif ($key && !$key_status) {
395 395
             // Key exists but it has no valid status yet
396 396
             // Perform key validation.
397
-            $key_check = $self->ao_ccss_key_validation( $key );
397
+            $key_check = $self->ao_ccss_key_validation($key);
398 398
 
399 399
             // Key is valid, set valid status.
400
-            if ( $key_check ) {
400
+            if ($key_check) {
401 401
                 $status     = 'valid';
402
-                $status_msg = __( 'Valid' );
402
+                $status_msg = __('Valid');
403 403
                 $color      = '#46b450'; // Green.
404 404
                 $message    = null;
405 405
             } else {
406 406
                 // Key is invalid, set invalid status.
407 407
                 $status     = 'invalid';
408
-                $status_msg = __( 'Invalid' );
408
+                $status_msg = __('Invalid');
409 409
                 $color      = '#dc3232'; // Red.
410
-                if ( get_option( 'autoptimize_ccss_keyst' ) == 1 ) {
411
-                    $message = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
410
+                if (get_option('autoptimize_ccss_keyst') == 1) {
411
+                    $message = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
412 412
                 } else {
413
-                    $message = __( 'Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize' );
413
+                    $message = __('Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize');
414 414
                 }
415 415
             }
416 416
         } else {
417 417
             // No key nor status
418 418
             // Set no key status.
419 419
             $status     = 'nokey';
420
-            $status_msg = __( 'None' );
420
+            $status_msg = __('None');
421 421
             $color      = '#ffb900'; // Yellow.
422
-            $message    = __( 'Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize' );
422
+            $message    = __('Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize');
423 423
         }
424 424
 
425 425
         // Fill returned values.
426 426
         $key_return['status'] = $status;
427 427
         // Provide rendering information if required.
428
-        if ( $render ) {
428
+        if ($render) {
429 429
             $key_return['stmsg'] = $status_msg;
430 430
             $key_return['color'] = $color;
431 431
             $key_return['msg']   = $message;
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         return $key_return;
436 436
     }
437 437
 
438
-    public function ao_ccss_key_validation( $key ) {
438
+    public function ao_ccss_key_validation($key) {
439 439
         global $ao_ccss_noptimize;
440 440
 
441 441
         // POST a dummy job to criticalcss.com to check for key validation
@@ -443,26 +443,26 @@  discard block
 block discarded – undo
443 443
         $src_url = get_home_url();
444 444
 
445 445
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
446
-        if ( ! empty( $ao_ccss_noptimize ) ) {
446
+        if (!empty($ao_ccss_noptimize)) {
447 447
             $src_url .= '?ao_noptirocket=1';
448
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
448
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
449 449
             $src_url .= '?ao_nolazy=1';
450 450
         }
451 451
 
452
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
452
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
453 453
 
454 454
         // Prepare the request.
455
-        $url  = esc_url_raw( AO_CCSS_API . 'generate' );
455
+        $url  = esc_url_raw(AO_CCSS_API.'generate');
456 456
         $args = array(
457 457
             'headers' => array(
458
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
458
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
459 459
                 'Content-type'  => 'application/json; charset=utf-8',
460
-                'Authorization' => 'JWT ' . $key,
460
+                'Authorization' => 'JWT '.$key,
461 461
                 'Connection'    => 'close',
462 462
             ),
463 463
             // Body must be JSON.
464 464
             'body'    => json_encode(
465
-                apply_filters( 'autoptimize_ccss_cron_api_generate_body',
465
+                apply_filters('autoptimize_ccss_cron_api_generate_body',
466 466
                     array(
467 467
                         'url'    => $src_url,
468 468
                         'aff'    => 1,
@@ -473,23 +473,23 @@  discard block
 block discarded – undo
473 473
         );
474 474
 
475 475
         // Dispatch the request and store its response code.
476
-        $req  = wp_safe_remote_post( $url, $args );
477
-        $code = wp_remote_retrieve_response_code( $req );
478
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
476
+        $req  = wp_safe_remote_post($url, $args);
477
+        $code = wp_remote_retrieve_response_code($req);
478
+        $body = json_decode(wp_remote_retrieve_body($req), true);
479 479
 
480
-        if ( 200 == $code ) {
480
+        if (200 == $code) {
481 481
             // Response is OK.
482 482
             // Set key status as valid and log key check.
483
-            update_option( 'autoptimize_ccss_keyst', 2 );
484
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
483
+            update_option('autoptimize_ccss_keyst', 2);
484
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
485 485
 
486 486
             // extract job-id from $body and put it in the queue as a P job
487 487
             // but only if no jobs and no rules!
488 488
             global $ao_ccss_queue;
489 489
             global $ao_ccss_rules;
490 490
 
491
-            if ( 0 == count( $ao_ccss_queue ) && 0 == count( $ao_ccss_rules['types'] ) && 0 == count( $ao_ccss_rules['paths'] ) ) {
492
-                if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] ) {
491
+            if (0 == count($ao_ccss_queue) && 0 == count($ao_ccss_rules['types']) && 0 == count($ao_ccss_rules['paths'])) {
492
+                if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status']) {
493 493
                     $jprops['ljid']     = 'firstrun';
494 494
                     $jprops['rtarget']  = 'types|is_front_page';
495 495
                     $jprops['ptype']    = 'is_front_page';
@@ -500,30 +500,30 @@  discard block
 block discarded – undo
500 500
                     $jprops['jqstat']   = $body['job']['status'];
501 501
                     $jprops['jrstat']   = null;
502 502
                     $jprops['jvstat']   = null;
503
-                    $jprops['jctime']   = microtime( true );
503
+                    $jprops['jctime']   = microtime(true);
504 504
                     $jprops['jftime']   = null;
505 505
                     $ao_ccss_queue['/'] = $jprops;
506
-                    $ao_ccss_queue_raw  = json_encode( $ao_ccss_queue );
507
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
508
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Created P job for is_front_page based on API key check response.', 3 );
506
+                    $ao_ccss_queue_raw  = json_encode($ao_ccss_queue);
507
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
508
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Created P job for is_front_page based on API key check response.', 3);
509 509
                 }
510 510
             }
511 511
             return true;
512
-        } elseif ( 401 == $code ) {
512
+        } elseif (401 == $code) {
513 513
             // Response is unauthorized
514 514
             // Set key status as invalid and log key check.
515
-            update_option( 'autoptimize_ccss_keyst', 1 );
516
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
515
+            update_option('autoptimize_ccss_keyst', 1);
516
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
517 517
             return false;
518 518
         } else {
519 519
             // Response unkown
520 520
             // Log key check attempt.
521
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2 );
522
-            if ( ! empty( $body ) ) {
523
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
521
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2);
522
+            if (!empty($body)) {
523
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
524 524
             }
525
-            if ( is_wp_error( $req ) ) {
526
-                autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
525
+            if (is_wp_error($req)) {
526
+                autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
527 527
             }
528 528
             return false;
529 529
         }
@@ -538,14 +538,14 @@  discard block
 block discarded – undo
538 538
         $viewport = array();
539 539
 
540 540
         // Viewport Width.
541
-        if ( ! empty( $ao_ccss_viewport['w'] ) ) {
541
+        if (!empty($ao_ccss_viewport['w'])) {
542 542
             $viewport['w'] = $ao_ccss_viewport['w'];
543 543
         } else {
544 544
             $viewport['w'] = '';
545 545
         }
546 546
 
547 547
         // Viewport Height.
548
-        if ( ! empty( $ao_ccss_viewport['h'] ) ) {
548
+        if (!empty($ao_ccss_viewport['h'])) {
549 549
             $viewport['h'] = $ao_ccss_viewport['h'];
550 550
         } else {
551 551
             $viewport['h'] = '';
@@ -554,23 +554,23 @@  discard block
 block discarded – undo
554 554
         return $viewport;
555 555
     }
556 556
 
557
-    public static function ao_ccss_check_contents( $ccss ) {
557
+    public static function ao_ccss_check_contents($ccss) {
558 558
         // Perform basic exploit avoidance and CSS validation.
559
-        if ( ! empty( $ccss ) ) {
559
+        if (!empty($ccss)) {
560 560
             // Try to avoid code injection.
561
-            $blocklist = array( '#!/', 'function(', '<script', '<?php' );
562
-            foreach ( $blocklist as $blocklisted ) {
563
-                if ( strpos( $ccss, $blocklisted ) !== false ) {
564
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received contained blocklisted content.', 2 );
561
+            $blocklist = array('#!/', 'function(', '<script', '<?php');
562
+            foreach ($blocklist as $blocklisted) {
563
+                if (strpos($ccss, $blocklisted) !== false) {
564
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received contained blocklisted content.', 2);
565 565
                     return false;
566 566
                 }
567 567
             }
568 568
 
569 569
             // Check for most basics CSS structures.
570
-            $needlist = array( '{', '}', ':' );
571
-            foreach ( $needlist as $needed ) {
572
-                if ( false === strpos( $ccss, $needed ) && 'none' !== $ccss ) {
573
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not seem to contain real CSS.', 2 );
570
+            $needlist = array('{', '}', ':');
571
+            foreach ($needlist as $needed) {
572
+                if (false === strpos($ccss, $needed) && 'none' !== $ccss) {
573
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not seem to contain real CSS.', 2);
574 574
                     return false;
575 575
                 }
576 576
             }
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
         return true;
581 581
     }
582 582
 
583
-    public static function ao_ccss_log( $msg, $lvl ) {
583
+    public static function ao_ccss_log($msg, $lvl) {
584 584
         // Commom logging facility
585 585
         // Attach debug option.
586 586
         global $ao_ccss_debug;
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
         // 3: DD (for debug)
592 592
         // Default: UU (for unkown).
593 593
         $level = false;
594
-        switch ( $lvl ) {
594
+        switch ($lvl) {
595 595
             case 1:
596 596
                 $level = 'II';
597 597
                 break;
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
                 break;
601 601
             case 3:
602 602
                 // Output debug messages only if debug mode is enabled.
603
-                if ( $ao_ccss_debug ) {
603
+                if ($ao_ccss_debug) {
604 604
                     $level = 'DD';
605 605
                 }
606 606
                 break;
@@ -609,19 +609,19 @@  discard block
 block discarded – undo
609 609
         }
610 610
 
611 611
         // Prepare and write a log message if there's a valid level.
612
-        if ( $level ) {
612
+        if ($level) {
613 613
 
614 614
             // Prepare message.
615
-            $message = date( 'c' ) . ' - [' . $level . '] ' . htmlentities( $msg ) . '<br>';
615
+            $message = date('c').' - ['.$level.'] '.htmlentities($msg).'<br>';
616 616
 
617 617
             // Write message to log file.
618
-            error_log( $message, 3, AO_CCSS_LOG );
618
+            error_log($message, 3, AO_CCSS_LOG);
619 619
         }
620 620
     }
621 621
 
622 622
     public static function ao_ccss_clear_page_tpl_cache() {
623 623
         // Clears transient cache for page templates.
624
-        delete_transient( 'autoptimize_ccss_page_templates' );
624
+        delete_transient('autoptimize_ccss_page_templates');
625 625
     }
626 626
 
627 627
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettingsAjax.php 1 patch
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS settings AJAX logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
@@ -21,47 +21,47 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function run() {
23 23
         // add filters.
24
-        add_action( 'wp_ajax_fetch_critcss', array( $this, 'critcss_fetch_callback' ) );
25
-        add_action( 'wp_ajax_save_critcss', array( $this, 'critcss_save_callback' ) );
26
-        add_action( 'wp_ajax_rm_critcss', array( $this, 'critcss_rm_callback' ) );
27
-        add_action( 'wp_ajax_rm_critcss_all', array( $this, 'critcss_rm_all_callback' ) );
28
-        add_action( 'wp_ajax_ao_ccss_export', array( $this, 'ao_ccss_export_callback' ) );
29
-        add_action( 'wp_ajax_ao_ccss_import', array( $this, 'ao_ccss_import_callback' ) );
24
+        add_action('wp_ajax_fetch_critcss', array($this, 'critcss_fetch_callback'));
25
+        add_action('wp_ajax_save_critcss', array($this, 'critcss_save_callback'));
26
+        add_action('wp_ajax_rm_critcss', array($this, 'critcss_rm_callback'));
27
+        add_action('wp_ajax_rm_critcss_all', array($this, 'critcss_rm_all_callback'));
28
+        add_action('wp_ajax_ao_ccss_export', array($this, 'ao_ccss_export_callback'));
29
+        add_action('wp_ajax_ao_ccss_import', array($this, 'ao_ccss_import_callback'));
30 30
     }
31 31
 
32 32
     public function critcss_fetch_callback() {
33 33
         // Ajax handler to obtain a critical CSS file from the filesystem.
34 34
         // Check referer.
35
-        check_ajax_referer( 'fetch_critcss_nonce', 'critcss_fetch_nonce' );
35
+        check_ajax_referer('fetch_critcss_nonce', 'critcss_fetch_nonce');
36 36
 
37 37
         // Initialize error flag.
38 38
         $error = true;
39 39
 
40 40
         // Allow no content for MANUAL rules (as they may not exist just yet).
41
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
41
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
42 42
             $content = '';
43 43
             $error   = false;
44
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
44
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
45 45
             // Or check user permissios and filename.
46 46
             // Set file path and obtain its content.
47
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
48
-            if ( file_exists( $critcssfile ) ) {
49
-                $content = file_get_contents( $critcssfile );
47
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
48
+            if (file_exists($critcssfile)) {
49
+                $content = file_get_contents($critcssfile);
50 50
                 $error   = false;
51 51
             }
52 52
         }
53 53
 
54 54
         // Prepare response.
55
-        if ( $error ) {
55
+        if ($error) {
56 56
             $response['code']   = '500';
57
-            $response['string'] = 'Error reading file ' . $critcssfile . '.';
57
+            $response['string'] = 'Error reading file '.$critcssfile.'.';
58 58
         } else {
59 59
             $response['code']   = '200';
60 60
             $response['string'] = $content;
61 61
         }
62 62
 
63 63
         // Dispatch respose.
64
-        echo json_encode( $response );
64
+        echo json_encode($response);
65 65
 
66 66
         // Close ajax request.
67 67
         wp_die();
@@ -74,22 +74,22 @@  discard block
 block discarded – undo
74 74
 
75 75
         // Ajax handler to write a critical CSS to the filesystem
76 76
         // Check referer.
77
-        check_ajax_referer( 'save_critcss_nonce', 'critcss_save_nonce' );
77
+        check_ajax_referer('save_critcss_nonce', 'critcss_save_nonce');
78 78
 
79 79
         // Allow empty contents for MANUAL rules (as they are fetched later).
80
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
80
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
81 81
             $critcssfile = false;
82 82
             $status      = true;
83
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
83
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
84 84
             // Or check user permissios and filename
85 85
             // Set critical CSS content.
86
-            $critcsscontents = stripslashes( $_POST['critcsscontents'] );
86
+            $critcsscontents = stripslashes($_POST['critcsscontents']);
87 87
 
88 88
             // If there is content and it's valid, write the file.
89
-            if ( $critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents( $critcsscontents ) ) {
89
+            if ($critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents($critcsscontents)) {
90 90
                 // Set file path and status.
91
-                $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
92
-                $status      = file_put_contents( $critcssfile, $critcsscontents, LOCK_EX );
91
+                $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
92
+                $status      = file_put_contents($critcssfile, $critcsscontents, LOCK_EX);
93 93
                 // Or set as error.
94 94
             } else {
95 95
                 $error = true;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
         }
101 101
 
102 102
         // Prepare response.
103
-        if ( ! $status || $error ) {
103
+        if (!$status || $error) {
104 104
             $response['code']   = '500';
105
-            $response['string'] = 'Error saving file ' . $critcssfile . '.';
105
+            $response['string'] = 'Error saving file '.$critcssfile.'.';
106 106
         } else {
107 107
             $response['code'] = '200';
108
-            if ( $critcssfile ) {
109
-                $response['string'] = 'File ' . $critcssfile . ' saved.';
108
+            if ($critcssfile) {
109
+                $response['string'] = 'File '.$critcssfile.' saved.';
110 110
             } else {
111 111
                 $response['string'] = 'Empty content do not need to be saved.';
112 112
             }
113 113
         }
114 114
 
115 115
         // Dispatch respose.
116
-        echo json_encode( $response );
116
+        echo json_encode($response);
117 117
 
118 118
         // Close ajax request.
119 119
         wp_die();
@@ -123,40 +123,40 @@  discard block
 block discarded – undo
123 123
     public function critcss_rm_callback() {
124 124
         // Ajax handler to delete a critical CSS from the filesystem
125 125
         // Check referer.
126
-        check_ajax_referer( 'rm_critcss_nonce', 'critcss_rm_nonce' );
126
+        check_ajax_referer('rm_critcss_nonce', 'critcss_rm_nonce');
127 127
 
128 128
         // Initialize error and status flags.
129 129
         $error  = true;
130 130
         $status = false;
131 131
 
132 132
         // Allow no file for MANUAL rules (as they may not exist just yet).
133
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
133
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
134 134
             $error = false;
135
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
135
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
136 136
             // Or check user permissios and filename
137 137
             // Set file path and delete it.
138
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
139
-            if ( file_exists( $critcssfile ) ) {
140
-                $status = unlink( $critcssfile );
138
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
139
+            if (file_exists($critcssfile)) {
140
+                $status = unlink($critcssfile);
141 141
                 $error  = false;
142 142
             }
143 143
         }
144 144
 
145 145
         // Prepare response.
146
-        if ( $error ) {
146
+        if ($error) {
147 147
             $response['code']   = '500';
148
-            $response['string'] = 'Error removing file ' . $critcssfile . '.';
148
+            $response['string'] = 'Error removing file '.$critcssfile.'.';
149 149
         } else {
150 150
             $response['code'] = '200';
151
-            if ( $status ) {
152
-                $response['string'] = 'File ' . $critcssfile . ' removed.';
151
+            if ($status) {
152
+                $response['string'] = 'File '.$critcssfile.' removed.';
153 153
             } else {
154 154
                 $response['string'] = 'No file to be removed.';
155 155
             }
156 156
         }
157 157
 
158 158
         // Dispatch respose.
159
-        echo json_encode( $response );
159
+        echo json_encode($response);
160 160
 
161 161
         // Close ajax request.
162 162
         wp_die();
@@ -165,28 +165,28 @@  discard block
 block discarded – undo
165 165
     public function critcss_rm_all_callback() {
166 166
         // Ajax handler to delete a critical CSS from the filesystem
167 167
         // Check referer.
168
-        check_ajax_referer( 'rm_critcss_all_nonce', 'critcss_rm_all_nonce' );
168
+        check_ajax_referer('rm_critcss_all_nonce', 'critcss_rm_all_nonce');
169 169
 
170 170
         // Initialize error and status flags.
171 171
         $error  = true;
172 172
         $status = false;
173 173
 
174 174
         // Remove all ccss files on filesystem.
175
-        if ( current_user_can( 'manage_options' ) ) {
176
-            if ( file_exists( AO_CCSS_DIR ) && is_dir( AO_CCSS_DIR ) ) {
177
-                array_map( 'unlink', glob( AO_CCSS_DIR . 'ccss_*.css', GLOB_BRACE ) );
175
+        if (current_user_can('manage_options')) {
176
+            if (file_exists(AO_CCSS_DIR) && is_dir(AO_CCSS_DIR)) {
177
+                array_map('unlink', glob(AO_CCSS_DIR.'ccss_*.css', GLOB_BRACE));
178 178
                 $error  = false;
179 179
                 $status = true;
180 180
             }
181 181
         }
182 182
 
183 183
         // Prepare response.
184
-        if ( $error ) {
184
+        if ($error) {
185 185
             $response['code']   = '500';
186 186
             $response['string'] = 'Error removing all critical CSS files.';
187 187
         } else {
188 188
             $response['code'] = '200';
189
-            if ( $status ) {
189
+            if ($status) {
190 190
                 $response['string'] = 'Critical CSS Files removed.';
191 191
             } else {
192 192
                 $response['string'] = 'No file removed.';
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Dispatch respose.
197
-        echo json_encode( $response );
197
+        echo json_encode($response);
198 198
 
199 199
         // Close ajax request.
200 200
         wp_die();
@@ -203,70 +203,70 @@  discard block
 block discarded – undo
203 203
     public function ao_ccss_export_callback() {
204 204
         // Ajax handler export settings
205 205
         // Check referer.
206
-        check_ajax_referer( 'ao_ccss_export_nonce', 'ao_ccss_export_nonce' );
206
+        check_ajax_referer('ao_ccss_export_nonce', 'ao_ccss_export_nonce');
207 207
 
208
-        if ( ! class_exists( 'ZipArchive' ) ) {
208
+        if (!class_exists('ZipArchive')) {
209 209
             $response['code'] = '500';
210 210
             $response['msg']  = 'PHP ZipArchive not present, cannot create zipfile';
211
-            echo json_encode( $response );
211
+            echo json_encode($response);
212 212
             wp_die();
213 213
         }
214 214
 
215 215
         // Init array, get options and prepare the raw object.
216 216
         $settings               = array();
217
-        $settings['rules']      = get_option( 'autoptimize_ccss_rules' );
218
-        $settings['additional'] = get_option( 'autoptimize_ccss_additional' );
219
-        $settings['viewport']   = get_option( 'autoptimize_ccss_viewport' );
220
-        $settings['finclude']   = get_option( 'autoptimize_ccss_finclude' );
221
-        $settings['rlimit']     = get_option( 'autoptimize_ccss_rlimit' );
222
-        $settings['noptimize']  = get_option( 'autoptimize_ccss_noptimize' );
223
-        $settings['debug']      = get_option( 'autoptimize_ccss_debug' );
224
-        $settings['key']        = get_option( 'autoptimize_ccss_key' );
217
+        $settings['rules']      = get_option('autoptimize_ccss_rules');
218
+        $settings['additional'] = get_option('autoptimize_ccss_additional');
219
+        $settings['viewport']   = get_option('autoptimize_ccss_viewport');
220
+        $settings['finclude']   = get_option('autoptimize_ccss_finclude');
221
+        $settings['rlimit']     = get_option('autoptimize_ccss_rlimit');
222
+        $settings['noptimize']  = get_option('autoptimize_ccss_noptimize');
223
+        $settings['debug']      = get_option('autoptimize_ccss_debug');
224
+        $settings['key']        = get_option('autoptimize_ccss_key');
225 225
 
226 226
         // Initialize error flag.
227 227
         $error = true;
228 228
 
229 229
         // Check user permissions.
230
-        if ( current_user_can( 'manage_options' ) ) {
230
+        if (current_user_can('manage_options')) {
231 231
             // Prepare settings file path and content.
232
-            $exportfile = AO_CCSS_DIR . 'settings.json';
233
-            $contents   = json_encode( $settings );
234
-            $status     = file_put_contents( $exportfile, $contents, LOCK_EX );
232
+            $exportfile = AO_CCSS_DIR.'settings.json';
233
+            $contents   = json_encode($settings);
234
+            $status     = file_put_contents($exportfile, $contents, LOCK_EX);
235 235
             $error      = false;
236 236
         }
237 237
 
238 238
         // Prepare archive.
239
-        $zipfile = AO_CCSS_DIR . date( 'Ymd-H\hi' ) . '_ao_ccss_settings.zip';
240
-        $file    = pathinfo( $zipfile, PATHINFO_BASENAME );
239
+        $zipfile = AO_CCSS_DIR.date('Ymd-H\hi').'_ao_ccss_settings.zip';
240
+        $file    = pathinfo($zipfile, PATHINFO_BASENAME);
241 241
         $zip     = new ZipArchive();
242
-        $ret     = $zip->open( $zipfile, ZipArchive::CREATE );
243
-        if ( true !== $ret ) {
242
+        $ret     = $zip->open($zipfile, ZipArchive::CREATE);
243
+        if (true !== $ret) {
244 244
             $error = true;
245 245
         } else {
246
-            $zip->addFile( AO_CCSS_DIR . 'settings.json', 'settings.json' );
247
-            if ( file_exists( AO_CCSS_DIR . 'queue.json' ) ) {
248
-                $zip->addFile( AO_CCSS_DIR . 'queue.json', 'queue.json' );
246
+            $zip->addFile(AO_CCSS_DIR.'settings.json', 'settings.json');
247
+            if (file_exists(AO_CCSS_DIR.'queue.json')) {
248
+                $zip->addFile(AO_CCSS_DIR.'queue.json', 'queue.json');
249 249
             }
250 250
             $options = array(
251 251
                 'add_path'        => './',
252 252
                 'remove_all_path' => true,
253 253
             );
254
-            $zip->addGlob( AO_CCSS_DIR . '*.css', 0, $options );
254
+            $zip->addGlob(AO_CCSS_DIR.'*.css', 0, $options);
255 255
             $zip->close();
256 256
         }
257 257
 
258 258
         // Prepare response.
259
-        if ( ! $status || $error ) {
259
+        if (!$status || $error) {
260 260
             $response['code'] = '500';
261
-            $response['msg']  = 'Error saving file ' . $file . ', code: ' . $ret;
261
+            $response['msg']  = 'Error saving file '.$file.', code: '.$ret;
262 262
         } else {
263 263
             $response['code'] = '200';
264
-            $response['msg']  = 'File ' . $file . ' saved.';
264
+            $response['msg']  = 'File '.$file.' saved.';
265 265
             $response['file'] = $file;
266 266
         }
267 267
 
268 268
         // Dispatch respose.
269
-        echo json_encode( $response );
269
+        echo json_encode($response);
270 270
 
271 271
         // Close ajax request.
272 272
         wp_die();
@@ -275,54 +275,54 @@  discard block
 block discarded – undo
275 275
     public function ao_ccss_import_callback() {
276 276
         // Ajax handler import settings
277 277
         // Check referer.
278
-        check_ajax_referer( 'ao_ccss_import_nonce', 'ao_ccss_import_nonce' );
278
+        check_ajax_referer('ao_ccss_import_nonce', 'ao_ccss_import_nonce');
279 279
 
280 280
         // Initialize error flag.
281 281
         $error = false;
282 282
 
283 283
         // Process an uploaded file with no errors.
284
-        if ( current_user_can( 'manage_options' ) && ! $_FILES['file']['error'] && strpos( $_FILES['file']['name'], '.zip' ) === strlen( $_FILES['file']['name'] ) - 4 ) {
284
+        if (current_user_can('manage_options') && !$_FILES['file']['error'] && strpos($_FILES['file']['name'], '.zip') === strlen($_FILES['file']['name']) - 4) {
285 285
             // Save file to the cache directory.
286
-            $zipfile = AO_CCSS_DIR . $_FILES['file']['name'];
287
-            move_uploaded_file( $_FILES['file']['tmp_name'], $zipfile );
286
+            $zipfile = AO_CCSS_DIR.$_FILES['file']['name'];
287
+            move_uploaded_file($_FILES['file']['tmp_name'], $zipfile);
288 288
 
289 289
             // Extract archive.
290 290
             $zip = new ZipArchive;
291
-            if ( $zip->open( $zipfile ) === true ) {
292
-                $zip->extractTo( AO_CCSS_DIR );
291
+            if ($zip->open($zipfile) === true) {
292
+                $zip->extractTo(AO_CCSS_DIR);
293 293
                 $zip->close();
294 294
             } else {
295 295
                 $error = 'could not extract';
296 296
             }
297 297
 
298
-            if ( ! $error ) {
298
+            if (!$error) {
299 299
                 // only known files allowed, all others are deleted.
300
-                $_dir_contents_ccss = glob( AO_CCSS_DIR . 'ccss_*.css' );
301
-                $_dir_known_ok      = array( AO_CCSS_DIR . 'queue.lock', AO_CCSS_DIR . 'queuelog.html', AO_CCSS_DIR . 'index.html', AO_CCSS_DIR . 'settings.json' );
302
-                $_dir_contents_ok   = array_merge( $_dir_contents_ccss, $_dir_known_ok );
303
-                $_dir_contents_all  = glob( AO_CCSS_DIR . '*' );
304
-                $_dir_to_be_deleted = array_diff( $_dir_contents_all, $_dir_contents_ok );
305
-                foreach ( $_dir_to_be_deleted as $_file_to_be_deleted ) {
306
-                    unlink( $_file_to_be_deleted );
300
+                $_dir_contents_ccss = glob(AO_CCSS_DIR.'ccss_*.css');
301
+                $_dir_known_ok      = array(AO_CCSS_DIR.'queue.lock', AO_CCSS_DIR.'queuelog.html', AO_CCSS_DIR.'index.html', AO_CCSS_DIR.'settings.json');
302
+                $_dir_contents_ok   = array_merge($_dir_contents_ccss, $_dir_known_ok);
303
+                $_dir_contents_all  = glob(AO_CCSS_DIR.'*');
304
+                $_dir_to_be_deleted = array_diff($_dir_contents_all, $_dir_contents_ok);
305
+                foreach ($_dir_to_be_deleted as $_file_to_be_deleted) {
306
+                    unlink($_file_to_be_deleted);
307 307
                 }
308 308
 
309 309
                 // Archive extraction ok, continue settings importing
310 310
                 // Settings file.
311
-                $importfile = AO_CCSS_DIR . 'settings.json';
311
+                $importfile = AO_CCSS_DIR.'settings.json';
312 312
 
313
-                if ( file_exists( $importfile ) ) {
313
+                if (file_exists($importfile)) {
314 314
                     // Get settings and turn them into an object.
315
-                    $settings = json_decode( file_get_contents( $importfile ), true );
315
+                    $settings = json_decode(file_get_contents($importfile), true);
316 316
 
317 317
                     // Update options.
318
-                    update_option( 'autoptimize_ccss_rules', $settings['rules'] );
319
-                    update_option( 'autoptimize_ccss_additional', $settings['additional'] );
320
-                    update_option( 'autoptimize_ccss_viewport', $settings['viewport'] );
321
-                    update_option( 'autoptimize_ccss_finclude', $settings['finclude'] );
322
-                    update_option( 'autoptimize_ccss_rlimit', $settings['rlimit'] );
323
-                    update_option( 'autoptimize_ccss_noptimize', $settings['noptimize'] );
324
-                    update_option( 'autoptimize_ccss_debug', $settings['debug'] );
325
-                    update_option( 'autoptimize_ccss_key', $settings['key'] );
318
+                    update_option('autoptimize_ccss_rules', $settings['rules']);
319
+                    update_option('autoptimize_ccss_additional', $settings['additional']);
320
+                    update_option('autoptimize_ccss_viewport', $settings['viewport']);
321
+                    update_option('autoptimize_ccss_finclude', $settings['finclude']);
322
+                    update_option('autoptimize_ccss_rlimit', $settings['rlimit']);
323
+                    update_option('autoptimize_ccss_noptimize', $settings['noptimize']);
324
+                    update_option('autoptimize_ccss_debug', $settings['debug']);
325
+                    update_option('autoptimize_ccss_key', $settings['key']);
326 326
                 } else {
327 327
                     // Settings file doesn't exist, update error flag.
328 328
                     $error = 'settings file does not exist';
@@ -333,28 +333,28 @@  discard block
 block discarded – undo
333 333
         }
334 334
 
335 335
         // Prepare response.
336
-        if ( $error ) {
336
+        if ($error) {
337 337
             $response['code'] = '500';
338
-            $response['msg']  = 'Error importing settings: ' . $error;
338
+            $response['msg']  = 'Error importing settings: '.$error;
339 339
         } else {
340 340
             $response['code'] = '200';
341 341
             $response['msg']  = 'Settings imported successfully';
342 342
         }
343 343
 
344 344
         // Dispatch respose.
345
-        echo json_encode( $response );
345
+        echo json_encode($response);
346 346
 
347 347
         // Close ajax request.
348 348
         wp_die();
349 349
     }
350 350
 
351
-    public function critcss_check_filename( $filename ) {
351
+    public function critcss_check_filename($filename) {
352 352
         // Try to avoid directory traversal when reading/writing/deleting critical CSS files.
353
-        if ( strpos( $filename, 'ccss_' ) !== 0 ) {
353
+        if (strpos($filename, 'ccss_') !== 0) {
354 354
             return false;
355
-        } elseif ( substr( $filename, -4, 4 ) !== '.css' ) {
355
+        } elseif (substr($filename, -4, 4) !== '.css') {
356 356
             return false;
357
-        } elseif ( sanitize_file_name( $filename ) !== $filename ) {
357
+        } elseif (sanitize_file_name($filename) !== $filename) {
358 358
             // Use WordPress core's sanitize_file_name to see if anything fishy is going on.
359 359
             return false;
360 360
         } else {
Please login to merge, or discard this patch.