Completed
Push — master ( 8cd4be...fd6893 )
by frank
02:38
created
classes/critcss-inc/admin_settings_rules.js.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Outputs JS code for the rules panel.
4 4
  */
5 5
 
6
-if ( $ao_ccss_debug ) {
6
+if ($ao_ccss_debug) {
7 7
     echo "console.log('[WARN] Autoptimize CriticalCSS Power-Up is in DEBUG MODE!');\n";
8 8
     echo "console.log('[WARN] Avoid using debug mode on production/live environments unless for ad-hoc troubleshooting purposes and make sure to disable it after!');\n";
9 9
 }
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     jQuery(document).ready(function() {
24 24
         critCssArray=JSON.parse(document.getElementById("critCssOrigin").value);
25 25
         <?php
26
-        if ( $ao_ccss_debug ) {
26
+        if ($ao_ccss_debug) {
27 27
             echo "console.log('Rules Object:', critCssArray);\n";
28 28
         }
29 29
         ?>
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
     jQuery("#rules-list").empty();
40 40
     jQuery.each(critCssArray,function(k,v) {
41 41
         if (k=="paths") {
42
-            kstring="<?php _e( 'Path Based Rules', 'autoptimize' ); ?>";
42
+            kstring="<?php _e('Path Based Rules', 'autoptimize'); ?>";
43 43
         } else {
44
-            kstring="<?php _e( 'Conditional Tags, Custom Post Types and Page Templates Rules', 'autoptimize' ); ?>";
44
+            kstring="<?php _e('Conditional Tags, Custom Post Types and Page Templates Rules', 'autoptimize'); ?>";
45 45
         }
46 46
         if (!(jQuery.isEmptyObject(v))) {
47 47
             jQuery("#rules-list").append("<tr><td colspan='5'><h4>" + kstring + "</h4></td></tr>");
48
-            jQuery("#rules-list").append("<tr class='header "+k+"Rule'><th><?php _e( 'Type', 'autoptimize' ); ?></th><th><?php _e( 'Target', 'autoptimize' ); ?></th><th><?php _e( 'Critical CSS File', 'autoptimize' ); ?></th><th colspan='2'><?php _e( 'Actions', 'autoptimize' ); ?></th></tr>");
48
+            jQuery("#rules-list").append("<tr class='header "+k+"Rule'><th><?php _e('Type', 'autoptimize'); ?></th><th><?php _e('Target', 'autoptimize'); ?></th><th><?php _e('Critical CSS File', 'autoptimize'); ?></th><th colspan='2'><?php _e('Actions', 'autoptimize'); ?></th></tr>");
49 49
         }
50 50
         nodeNumber=0;
51 51
         jQuery.each(v,function(i,nv){
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
             file=nv.file;
56 56
             filest=nv.file;
57 57
             if (file == 0) {
58
-                file='<?php _e( 'To be fetched from criticalcss.com in the next queue run...', 'autoptimize' ); ?>';
58
+                file='<?php _e('To be fetched from criticalcss.com in the next queue run...', 'autoptimize'); ?>';
59 59
             }
60 60
             if (nv.hash === 0 && filest != 0) {
61
-                type='<?php _e( 'MANUAL', 'autoptimize' ); ?>';
61
+                type='<?php _e('MANUAL', 'autoptimize'); ?>';
62 62
                 typeClass = 'manual';
63 63
             } else {
64
-                type='<?php _e( 'AUTO', 'autoptimize' ); ?>';
64
+                type='<?php _e('AUTO', 'autoptimize'); ?>';
65 65
                 typeClass = 'auto';
66 66
             }
67 67
             if (file && typeof file == 'string') {
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             } else {
78 78
                 target = i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'');
79 79
             }
80
-            jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e( 'Edit', 'autoptimize' ); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e( 'Remove', 'autoptimize' ); ?></span></td></tr>");
80
+            jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e('Edit', 'autoptimize'); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e('Remove', 'autoptimize'); ?></span></td></tr>");
81 81
             jQuery("#" + nodeId + "_edit").click(function(){addEditRow(this.id);});
82 82
             jQuery("#" + nodeId + "_remove").click(function(){confirmRemove(this.id);});
83 83
         })
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
         height:235,
91 91
         modal: true,
92 92
         buttons: {
93
-            "<?php _e( 'Delete', 'autoptimize' ); ?>": function() {
93
+            "<?php _e('Delete', 'autoptimize'); ?>": function() {
94 94
                 removeRow(idToRemove);
95 95
                 updateAfterChange();
96 96
                 jQuery( this ).dialog( "close" );
97 97
             },
98
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
98
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
99 99
                 jQuery( this ).dialog( "close" );
100 100
             }
101 101
         }
@@ -108,14 +108,14 @@  discard block
 block discarded – undo
108 108
         height:235,
109 109
         modal: true,
110 110
         buttons: {
111
-            "<?php _e( 'Delete All', 'autoptimize' ); ?>": function() {
111
+            "<?php _e('Delete All', 'autoptimize'); ?>": function() {
112 112
                 critCssArray={'paths':[],'types':[]};
113 113
                 drawTable(critCssArray);
114 114
                 updateAfterChange();
115 115
                 removeAllCcssFilesOnServer();
116 116
                 jQuery( this ).dialog( "close" );
117 117
             },
118
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
118
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
119 119
                 jQuery( this ).dialog( "close" );
120 120
             }
121 121
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
     var data = {
134 134
         'action': 'rm_critcss',
135
-        'critcss_rm_nonce': '<?php echo wp_create_nonce( 'rm_critcss_nonce' ); ?>',
135
+        'critcss_rm_nonce': '<?php echo wp_create_nonce('rm_critcss_nonce'); ?>',
136 136
         'cachebustingtimestamp': new Date().getTime(),
137 137
         'critcssfile': crit_file
138 138
     };
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 function removeAllCcssFilesOnServer() {
154 154
     var data = {
155 155
         'action': 'rm_critcss_all',
156
-        'critcss_rm_all_nonce': '<?php echo wp_create_nonce( 'rm_critcss_all_nonce' ); ?>',
156
+        'critcss_rm_all_nonce': '<?php echo wp_create_nonce('rm_critcss_all_nonce'); ?>',
157 157
         'cachebustingtimestamp': new Date().getTime()
158 158
     };
159 159
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 function addEditRow(idToEdit) {
174 174
     resetForm();
175 175
     if (idToEdit) {
176
-        dialogTitle="<?php _e( 'Edit Critical CSS Rule', 'autoptimize' ); ?>";
176
+        dialogTitle="<?php _e('Edit Critical CSS Rule', 'autoptimize'); ?>";
177 177
 
178 178
         splits=idToEdit.split(/_/);
179 179
         crit_type=splits[0];
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         jQuery("#critcss_addedit_id").val(idToEdit);
185 185
         jQuery("#critcss_addedit_type").val(crit_type);
186 186
         jQuery("#critcss_addedit_file").val(crit_file);
187
-        jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'Loading critical CSS...', 'autoptimize' ); ?>");
187
+        jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('Loading critical CSS...', 'autoptimize'); ?>");
188 188
         jQuery("#critcss_addedit_type").attr("disabled",true);
189 189
 
190 190
         if (crit_type==="paths") {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
         var data = {
201 201
             'action': 'fetch_critcss',
202
-            'critcss_fetch_nonce': '<?php echo wp_create_nonce( 'fetch_critcss_nonce' ); ?>',
202
+            'critcss_fetch_nonce': '<?php echo wp_create_nonce('fetch_critcss_nonce'); ?>',
203 203
             'cachebustingtimestamp': new Date().getTime(),
204 204
             'critcssfile': crit_file
205 205
         };
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             }
214 214
         });
215 215
     } else {
216
-        dialogTitle="<?php _e( 'Add Critical CSS Rule', 'autotimize' ); ?>";
216
+        dialogTitle="<?php _e('Add Critical CSS Rule', 'autotimize'); ?>";
217 217
 
218 218
         // default: paths, hide content type field
219 219
         jQuery("#critcss_addedit_type").val("paths");
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
             if(this.value==="types") {
225 225
                 jQuery("#critcss_addedit_pagetype_wrapper").show();
226 226
                 jQuery("#critcss_addedit_path_wrapper").hide();
227
-                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For type based rules, paste your specific and minified critical CSS here and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\".', 'autoptimize' ); ?>");
227
+                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For type based rules, paste your specific and minified critical CSS here and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\".', 'autoptimize'); ?>");
228 228
             } else {
229 229
                 jQuery("#critcss_addedit_path_wrapper").show();
230 230
                 jQuery("#critcss_addedit_pagetype_wrapper").hide();
231
-                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize' ); ?>");
231
+                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize'); ?>");
232 232
             }
233 233
         });
234 234
     }
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
         title: dialogTitle,
241 241
         modal: true,
242 242
         buttons: {
243
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
243
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
244 244
                 rpath = jQuery("#critcss_addedit_path").val();
245 245
                 rtype = jQuery("#critcss_addedit_pagetype option:selected").val();
246 246
                 rccss = jQuery("#critcss_addedit_css").val();
247 247
                 console.log('rpath: ' + rpath, 'rtype: ' + rtype, 'rccss: ' + rccss);
248 248
                 if (rpath === '' && rtype === '') {
249
-                    alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize' ); ?>');
249
+                    alert('<?php _e("RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize'); ?>');
250 250
                 } else if (rtype !== '' && rccss == '') {
251
-                    alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize' ); ?>');
251
+                    alert('<?php _e("RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize'); ?>');
252 252
                 } else {
253 253
                     saveEditCritCss();
254 254
                     jQuery(this).dialog('close');
255 255
                 }
256 256
             },
257
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
257
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
258 258
                 resetForm();
259 259
                 jQuery(this).dialog("close");
260 260
             }
@@ -268,15 +268,15 @@  discard block
 block discarded – undo
268 268
         autoOpen: true,
269 269
         height: 505,
270 270
         width: 700,
271
-        title: "<?php _e( 'Default Critical CSS', 'autoptimize' ); ?>",
271
+        title: "<?php _e('Default Critical CSS', 'autoptimize'); ?>",
272 272
         modal: true,
273 273
         buttons: {
274
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
274
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
275 275
                 document.getElementById("autoptimize_css_defer_inline").value=document.getElementById("dummyDefault").value;
276 276
                 jQuery("#unSavedWarning").show();
277 277
                 jQuery("#default_critcss_wrapper").dialog( "close" );
278 278
             },
279
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
279
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
280 280
                 jQuery("#default_critcss_wrapper").dialog( "close" );
281 281
             }
282 282
         }
@@ -289,15 +289,15 @@  discard block
 block discarded – undo
289 289
         autoOpen: true,
290 290
         height: 505,
291 291
         width: 700,
292
-        title: "<?php _e( 'Additional Critical CSS', 'autoptimize' ); ?>",
292
+        title: "<?php _e('Additional Critical CSS', 'autoptimize'); ?>",
293 293
         modal: true,
294 294
         buttons: {
295
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
295
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
296 296
                 document.getElementById("autoptimize_ccss_additional").value=document.getElementById("dummyAdditional").value;
297 297
                 jQuery("#unSavedWarning").show();
298 298
                 jQuery("#additional_critcss_wrapper").dialog( "close" );
299 299
             },
300
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
300
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
301 301
                 jQuery("#additional_critcss_wrapper").dialog( "close" );
302 302
             }
303 303
         }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     critCssArray[critcsstype][critcsstarget].file=critcssfile;
334 334
 
335 335
     <?php
336
-    if ( $ao_ccss_debug ) {
336
+    if ($ao_ccss_debug) {
337 337
         echo "console.log('[RULE PROPERTIES] Type:', critcsstype, ', Target:', critcsstarget, ', Hash:', 0, ', File:',  critcssfile);";
338 338
     }
339 339
     ?>
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
     var data = {
344 344
         'action': 'save_critcss',
345
-        'critcss_save_nonce': '<?php echo wp_create_nonce( 'save_critcss_nonce' ); ?>',
345
+        'critcss_save_nonce': '<?php echo wp_create_nonce('save_critcss_nonce'); ?>',
346 346
         'critcssfile': critcssfile,
347 347
         'critcsscontents': critcsscontents
348 348
     };
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 }
368 368
 
369 369
 function resetForm() {
370
-    jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize' ); ?>");
370
+    jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize'); ?>");
371 371
     jQuery("#critcss_addedit_type").attr("disabled",false);
372 372
     jQuery("#critcss_addedit_path_wrapper").show();
373 373
     jQuery("#critcss_addedit_id").val("");
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_key.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
  * @param string $message      Message.
13 13
  * @param string $color        Color to highlight message in.
14 14
  */
15
-function ao_ccss_render_key( $key, $status, $status_msg, $message, $color ) {
16
-    if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
17
-        $key = __( 'API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize' );
15
+function ao_ccss_render_key($key, $status, $status_msg, $message, $color) {
16
+    if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
17
+        $key = __('API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize');
18 18
     }
19 19
     ?>
20 20
     <ul id="key-panel">
21 21
         <li class="itemDetail">
22
-            <h2 class="itemTitle fleft"><?php _e( 'API Key', 'autoptimize' ); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2>
22
+            <h2 class="itemTitle fleft"><?php _e('API Key', 'autoptimize'); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2>
23 23
             <button type="button" class="toggle-btn">
24
-                <?php if ( 'valid' != $status ) { ?>
24
+                <?php if ('valid' != $status) { ?>
25 25
                     <span class="toggle-indicator dashicons dashicons-arrow-up"></span>
26 26
                 <?php } else { ?>
27 27
                     <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
28 28
                 <?php } ?>
29 29
             </button>
30
-            <?php if ( 'valid' != $status ) { ?>
30
+            <?php if ('valid' != $status) { ?>
31 31
                 <div class="collapsible">
32 32
             <?php } else { ?>
33 33
                 <div class="collapsible hidden">
34 34
             <?php } ?>
35
-            <?php if ( 'valid' != $status ) { ?>
35
+            <?php if ('valid' != $status) { ?>
36 36
                 <div style="clear:both;padding:2px 10px;border-left:solid;border-left-width:5px;border-left-color:<?php echo $color; ?>;background-color:white;">
37 37
                     <p><?php echo $message; ?></p>
38 38
                 </div>
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
                 <table id="key" class="form-table">
41 41
                     <tr>
42 42
                         <th scope="row">
43
-                            <?php _e( 'Your API Key', 'autoptimize' ); ?>
43
+                            <?php _e('Your API Key', 'autoptimize'); ?>
44 44
                         </th>
45 45
                         <td>
46
-                            <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e( 'Please enter your criticalcss.com API key here.', 'autoptimize' ); ?>"><?php echo trim( $key ); ?></textarea>
46
+                            <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e('Please enter your criticalcss.com API key here.', 'autoptimize'); ?>"><?php echo trim($key); ?></textarea>
47 47
                             <p class="notes">
48
-                                <?php _e( 'Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize' ); ?>
48
+                                <?php _e('Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize'); ?>
49 49
                             </p>
50 50
                         </td>
51 51
                     </tr>
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_queue.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,21 +11,21 @@  discard block
 block discarded – undo
11 11
     global $ao_ccss_queue;
12 12
 
13 13
     // Prepare the queue object.
14
-    if ( empty( $ao_ccss_queue ) ) {
14
+    if (empty($ao_ccss_queue)) {
15 15
         $ao_ccss_queue = '';
16 16
     } else {
17
-        $ao_ccss_queue = json_encode( $ao_ccss_queue );
17
+        $ao_ccss_queue = json_encode($ao_ccss_queue);
18 18
     }
19 19
 ?>
20 20
 
21 21
     <ul id="queue-panel">
22 22
         <li class="itemDetail">
23
-            <h2 class="itemTitle fleft"><?php _e( 'Job Queue', 'autoptimize' ); ?></h2>
23
+            <h2 class="itemTitle fleft"><?php _e('Job Queue', 'autoptimize'); ?></h2>
24 24
             <button type="button" class="toggle-btn">
25 25
                 <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
26 26
             </button>
27 27
             <?php
28
-            if ( autoptimizeCriticalCSSSettings::ao_ccss_has_autorules() ) {
28
+            if (autoptimizeCriticalCSSSettings::ao_ccss_has_autorules()) {
29 29
                 $_queue_visibility = 'hidden';
30 30
             } else {
31 31
                 $_queue_visibility = 'visible';
@@ -34,54 +34,54 @@  discard block
 block discarded – undo
34 34
             <div class="collapsible <?php echo $_queue_visibility; ?>">
35 35
                 <!-- BEGIN Queue dialogs -->
36 36
                 <!-- Retry dialog -->
37
-                <div id="queue-confirm-retry" title="<?php _e( 'Retry Job', 'autoptimize' ); ?>" class="hidden">
38
-                    <p><?php _e( 'Are you sure you want to retry this job?', 'autoptimize' ); ?></p>
37
+                <div id="queue-confirm-retry" title="<?php _e('Retry Job', 'autoptimize'); ?>" class="hidden">
38
+                    <p><?php _e('Are you sure you want to retry this job?', 'autoptimize'); ?></p>
39 39
                 </div>
40 40
 
41 41
                 <!-- Remove dialog -->
42
-                <div id="queue-confirm-rm" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>" class="hidden">
43
-                    <p><?php _e( 'Are you sure you want to delete this job?', 'autoptimize' ); ?></p>
42
+                <div id="queue-confirm-rm" title="<?php _e('Delete Job', 'autoptimize'); ?>" class="hidden">
43
+                    <p><?php _e('Are you sure you want to delete this job?', 'autoptimize'); ?></p>
44 44
                 </div>
45 45
 
46 46
                 <!-- Remove all dialog -->
47
-                <div id="queue-confirm-rm-all" title="<?php _e( 'Delete all jobs', 'autoptimize' ); ?>" class="hidden">
48
-                    <p><?php _e( 'This will delete all jobs, are you sure?', 'autoptimize' ); ?></p>
47
+                <div id="queue-confirm-rm-all" title="<?php _e('Delete all jobs', 'autoptimize'); ?>" class="hidden">
48
+                    <p><?php _e('This will delete all jobs, are you sure?', 'autoptimize'); ?></p>
49 49
                 </div>
50 50
                 <!-- END Queue dialogs -->
51 51
 
52 52
                 <!-- BEGIN Queue UI -->
53 53
                 <div class="howto">
54 54
                     <div class="title-wrap">
55
-                        <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Queue', 'autoptimize' ); ?></h4>
56
-                        <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p>
55
+                        <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Queue', 'autoptimize'); ?></h4>
56
+                        <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p>
57 57
                     </div>
58 58
                     <button type="button" class="toggle-btn">
59 59
                         <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
60 60
                     </button>
61 61
                     <div class="howto-wrap hidden">
62
-                        <p><?php _e( 'TL;DR:<br /><strong>Queue runs every 10 minutes.</strong> Job statuses are <span class="badge new">N</span> for NEW, <span class="badge pending">P</span> for PENDING, <span class="badge error">E</span> for ERROR and <span class="badge unknown">U</span> for UNKOWN.', 'autoptimize' ); ?></p>
62
+                        <p><?php _e('TL;DR:<br /><strong>Queue runs every 10 minutes.</strong> Job statuses are <span class="badge new">N</span> for NEW, <span class="badge pending">P</span> for PENDING, <span class="badge error">E</span> for ERROR and <span class="badge unknown">U</span> for UNKOWN.', 'autoptimize'); ?></p>
63 63
                         <ol>
64
-                            <li><?php _e( 'The queue operates <strong>automatically, asynchronously and on regular intervals of 10 minutes.</strong> To view updated queue status, refresh this page.', 'autoptimize' ); ?></li>
65
-                            <li><?php _e( 'When the conditions to create a job are met (i.e. user not logged in, no matching <span class="badge manual">MANUAL</span> rule or CSS files has changed for an <span class="badge auto">AUTO</span> rule), a <span class="badge new">N</span> job is created in the queue.', 'autoptimize' ); ?></li>
66
-                            <li><?php _e( "Autoptimize CriticalCSS Power-Up constantly query the queue for <span class='badge new'>N</span> jobs. When it finds one, gears spins and jobs becomes <span class='badge pending'>P</span> while they are running and <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> doesn't return a result.", 'autoptimize' ); ?></li>
67
-                            <li><?php _e( 'As soon as <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> returns a valid critical CSS file, the job is then finished and removed from the queue.', 'autoptimize' ); ?></li>
68
-                            <li><?php _e( 'When things go wrong, a job is marked as <span class="badge error">E</span>. You can retry faulty jobs, delete them or get in touch with <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize' ); ?></li>
69
-                            <li><?php _e( 'Sometimes an unknown condition can happen. In this case, the job status becomes <span class="badge unknown">U</span> and you may want to ask <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for help or just delete it.', 'autoptimize' ); ?></li>
70
-                            <li><?php _e( 'To get more information about jobs statuses, specially the ones with <span class="badge error">E</span> and <span class="badge unknown">U</span> status, hover your mouse in the status badge of that job. This information might be crucial when contacting <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize' ); ?></li>
71
-                            <li><?php _e( '<strong>A word about WordPress cron:</strong> Autoptimize CriticalCSS Power-Up watch the queue by using WordPress Cron (or WP-Cron for short.) It <a href="https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/#limitations-of-wordpress-cron-and-solutions-to-fix-em" target="_blank">could be faulty</a> on very light or very heavy loads. If your site receives just a few or thousands visits a day, it might be a good idea to <a href="https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/" target="_blank">turn WP-Cron off and use your system task scheduler</a> to fire it instead.', 'autoptimize' ); ?></li>
64
+                            <li><?php _e('The queue operates <strong>automatically, asynchronously and on regular intervals of 10 minutes.</strong> To view updated queue status, refresh this page.', 'autoptimize'); ?></li>
65
+                            <li><?php _e('When the conditions to create a job are met (i.e. user not logged in, no matching <span class="badge manual">MANUAL</span> rule or CSS files has changed for an <span class="badge auto">AUTO</span> rule), a <span class="badge new">N</span> job is created in the queue.', 'autoptimize'); ?></li>
66
+                            <li><?php _e("Autoptimize CriticalCSS Power-Up constantly query the queue for <span class='badge new'>N</span> jobs. When it finds one, gears spins and jobs becomes <span class='badge pending'>P</span> while they are running and <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> doesn't return a result.", 'autoptimize'); ?></li>
67
+                            <li><?php _e('As soon as <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> returns a valid critical CSS file, the job is then finished and removed from the queue.', 'autoptimize'); ?></li>
68
+                            <li><?php _e('When things go wrong, a job is marked as <span class="badge error">E</span>. You can retry faulty jobs, delete them or get in touch with <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize'); ?></li>
69
+                            <li><?php _e('Sometimes an unknown condition can happen. In this case, the job status becomes <span class="badge unknown">U</span> and you may want to ask <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for help or just delete it.', 'autoptimize'); ?></li>
70
+                            <li><?php _e('To get more information about jobs statuses, specially the ones with <span class="badge error">E</span> and <span class="badge unknown">U</span> status, hover your mouse in the status badge of that job. This information might be crucial when contacting <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize'); ?></li>
71
+                            <li><?php _e('<strong>A word about WordPress cron:</strong> Autoptimize CriticalCSS Power-Up watch the queue by using WordPress Cron (or WP-Cron for short.) It <a href="https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/#limitations-of-wordpress-cron-and-solutions-to-fix-em" target="_blank">could be faulty</a> on very light or very heavy loads. If your site receives just a few or thousands visits a day, it might be a good idea to <a href="https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/" target="_blank">turn WP-Cron off and use your system task scheduler</a> to fire it instead.', 'autoptimize'); ?></li>
72 72
                         </ol>
73 73
                     </div>
74 74
                 </div>
75 75
                 <table id="queue-tbl" class="queue tablesorter" cellspacing="0">
76 76
                     <thead>
77
-                        <tr><th class="status"><?php _e( 'Status', 'autoptimize' ); ?></th><th><?php _e( 'Target Rule', 'autoptimize' ); ?></th><th><?php _e( 'Page Path', 'autoptimize' ); ?></th><th><?php _e( 'Page Type', 'autoptimize' ); ?></th><th><?php _e( 'Creation Date', 'autoptimize' ); ?></th><th><?php _e( 'Finish Date', 'autoptimize' ); ?></th><th class="btn"><?php _e( 'Actions', 'autoptimize' ); ?></th></tr>
77
+                        <tr><th class="status"><?php _e('Status', 'autoptimize'); ?></th><th><?php _e('Target Rule', 'autoptimize'); ?></th><th><?php _e('Page Path', 'autoptimize'); ?></th><th><?php _e('Page Type', 'autoptimize'); ?></th><th><?php _e('Creation Date', 'autoptimize'); ?></th><th><?php _e('Finish Date', 'autoptimize'); ?></th><th class="btn"><?php _e('Actions', 'autoptimize'); ?></th></tr>
78 78
                     </thead>
79 79
                     <tbody id="queue"></tbody>
80 80
                 </table>
81
-                <input class="hidden" type="text" id="ao-ccss-queue" name="autoptimize_ccss_queue" value='<?php echo( $ao_ccss_queue ); ?>'>
81
+                <input class="hidden" type="text" id="ao-ccss-queue" name="autoptimize_ccss_queue" value='<?php echo($ao_ccss_queue); ?>'>
82 82
                 <div class="submit jobs-btn">
83 83
                     <div class="alignright">
84
-                        <span id="removeAllJobs" class="button-secondary" style="color:red;"><?php _e( 'Remove all jobs', 'autoptimize' ); ?></span>
84
+                        <span id="removeAllJobs" class="button-secondary" style="color:red;"><?php _e('Remove all jobs', 'autoptimize'); ?></span>
85 85
                     </div>
86 86
                 </div>
87 87
             </div>
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_explain.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,29 +12,29 @@
 block discarded – undo
12 12
         .ao_settings_div {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;}
13 13
         .ao_settings_div .form-table th {font-weight: normal;}
14 14
     </style>
15
-    <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
15
+    <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
16 16
     <ul id="explain-panel">
17 17
         <div class="ao_settings_div">
18 18
             <?php
19 19
             $ccss_explanation = '';
20 20
 
21 21
             // get the HTML with the explanation of what critical CSS is.
22
-            if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
23
-                $ccss_explanation = get_transient( 'ao_ccss_explain' );
24
-                if ( empty( $ccss_explanation ) ) {
25
-                    $ccss_expl_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
26
-                    if ( ! is_wp_error( $ccss_expl_resp ) ) {
27
-                        if ( '200' == wp_remote_retrieve_response_code( $ccss_expl_resp ) ) {
28
-                            $ccss_explanation = wp_kses_post( wp_remote_retrieve_body( $ccss_expl_resp ) );
29
-                            set_transient( 'ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS );
22
+            if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
23
+                $ccss_explanation = get_transient('ao_ccss_explain');
24
+                if (empty($ccss_explanation)) {
25
+                    $ccss_expl_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
26
+                    if (!is_wp_error($ccss_expl_resp)) {
27
+                        if ('200' == wp_remote_retrieve_response_code($ccss_expl_resp)) {
28
+                            $ccss_explanation = wp_kses_post(wp_remote_retrieve_body($ccss_expl_resp));
29
+                            set_transient('ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS);
30 30
                         }
31 31
                     }
32 32
                 }
33 33
             }
34 34
 
35 35
             // placeholder text in case HTML is empty.
36
-            if ( empty( $ccss_explanation ) ) {
37
-                $ccss_explanation = __( '<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize' );
36
+            if (empty($ccss_explanation)) {
37
+                $ccss_explanation = __('<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize');
38 38
             } else {
39 39
                 // we were able to fetch the explenation, so add the JS to show correct language.
40 40
                 $ccss_explanation .= "<script>jQuery('.ao_i18n').hide();d=document;lang=d.getElementsByTagName('html')[0].getAttribute('lang').substring(0,2);if(d.getElementById(lang)!= null){jQuery('#'+lang).show();}else{jQuery('#default').show();}</script>";
Please login to merge, or discard this patch.
classes/autoptimizeStyles.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
  * Class for CSS optimization.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -161,54 +161,54 @@  discard block
 block discarded – undo
161 161
      *
162 162
      * @param array $options all options.
163 163
      */
164
-    public function read( $options )
164
+    public function read($options)
165 165
     {
166
-        $noptimize_css = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content );
167
-        if ( $noptimize_css ) {
166
+        $noptimize_css = apply_filters('autoptimize_filter_css_noptimize', false, $this->content);
167
+        if ($noptimize_css) {
168 168
             return false;
169 169
         }
170 170
 
171
-        $allowlist_css = apply_filters( 'autoptimize_filter_css_allowlist', '', $this->content );
172
-        $allowlist_css = apply_filters( 'autoptimize_filter_css_whitelist', $allowlist_css, $this->content ); // fixme: to be removed in next version.
173
-        if ( ! empty( $allowlist_css ) ) {
174
-            $this->allowlist = array_filter( array_map( 'trim', explode( ',', $allowlist_css ) ) );
171
+        $allowlist_css = apply_filters('autoptimize_filter_css_allowlist', '', $this->content);
172
+        $allowlist_css = apply_filters('autoptimize_filter_css_whitelist', $allowlist_css, $this->content); // fixme: to be removed in next version.
173
+        if (!empty($allowlist_css)) {
174
+            $this->allowlist = array_filter(array_map('trim', explode(',', $allowlist_css)));
175 175
         }
176 176
 
177
-        $removable_css = apply_filters( 'autoptimize_filter_css_removables', '' );
178
-        if ( ! empty( $removable_css ) ) {
179
-            $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removable_css ) ) );
177
+        $removable_css = apply_filters('autoptimize_filter_css_removables', '');
178
+        if (!empty($removable_css)) {
179
+            $this->cssremovables = array_filter(array_map('trim', explode(',', $removable_css)));
180 180
         }
181 181
 
182
-        $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 );
182
+        $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256);
183 183
 
184 184
         // filter to "late inject minified CSS", default to true for now (it is faster).
185
-        $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true );
185
+        $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true);
186 186
 
187 187
         // Remove everything that's not the header.
188
-        if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) {
189
-            $content             = explode( '</head>', $this->content, 2 );
190
-            $this->content       = $content[0] . '</head>';
188
+        if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) {
189
+            $content             = explode('</head>', $this->content, 2);
190
+            $this->content       = $content[0].'</head>';
191 191
             $this->restofcontent = $content[1];
192 192
         }
193 193
 
194 194
         // Determine whether we're doing CSS-files aggregation or not.
195
-        if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) {
195
+        if (isset($options['aggregate']) && !$options['aggregate']) {
196 196
             $this->aggregate = false;
197 197
         }
198 198
         // Returning true for "dontaggregate" turns off aggregation.
199
-        if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) {
199
+        if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) {
200 200
             $this->aggregate = false;
201 201
         }
202 202
 
203 203
         // include inline?
204
-        if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) {
204
+        if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) {
205 205
             $this->include_inline = true;
206 206
         }
207 207
 
208 208
         // List of CSS strings which are excluded from autoptimization.
209
-        $exclude_css = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content );
210
-        if ( '' !== $exclude_css ) {
211
-            $this->dontmove = array_filter( array_map( 'trim', explode( ',', $exclude_css ) ) );
209
+        $exclude_css = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content);
210
+        if ('' !== $exclude_css) {
211
+            $this->dontmove = array_filter(array_map('trim', explode(',', $exclude_css)));
212 212
         } else {
213 213
             $this->dontmove = array();
214 214
         }
@@ -219,16 +219,16 @@  discard block
 block discarded – undo
219 219
         // Should we defer css?
220 220
         // value: true / false.
221 221
         $this->defer = $options['defer'];
222
-        $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content );
222
+        $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content);
223 223
 
224 224
         // Should we inline while deferring?
225 225
         // value: inlined CSS.
226
-        $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content );
226
+        $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content);
227 227
 
228 228
         // Should we inline?
229 229
         // value: true / false.
230 230
         $this->inline = $options['inline'];
231
-        $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content );
231
+        $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content);
232 232
 
233 233
         // Store cdn url.
234 234
         $this->cdn_url = $options['cdn_url'];
@@ -237,16 +237,16 @@  discard block
 block discarded – undo
237 237
         $this->datauris = $options['datauris'];
238 238
 
239 239
         // Determine whether excluded files should be minified if not yet so.
240
-        if ( ! $options['minify_excluded'] && $options['aggregate'] ) {
240
+        if (!$options['minify_excluded'] && $options['aggregate']) {
241 241
             $this->minify_excluded = false;
242 242
         }
243
-        $this->minify_excluded = apply_filters( 'autoptimize_filter_css_minify_excluded', $this->minify_excluded, '' );
243
+        $this->minify_excluded = apply_filters('autoptimize_filter_css_minify_excluded', $this->minify_excluded, '');
244 244
 
245 245
         // should we force all media-attributes to all?
246
-        $this->media_force_all = apply_filters( 'autoptimize_filter_css_tagmedia_forceall', false );
246
+        $this->media_force_all = apply_filters('autoptimize_filter_css_tagmedia_forceall', false);
247 247
 
248 248
         // noptimize me.
249
-        $this->content = $this->hide_noptimize( $this->content );
249
+        $this->content = $this->hide_noptimize($this->content);
250 250
 
251 251
         // Exclude (no)script, as those may contain CSS which should be left as is.
252 252
         $this->content = $this->replace_contents_with_marker_if_exists(
@@ -257,25 +257,25 @@  discard block
 block discarded – undo
257 257
         );
258 258
 
259 259
         // Save IE hacks.
260
-        $this->content = $this->hide_iehacks( $this->content );
260
+        $this->content = $this->hide_iehacks($this->content);
261 261
 
262 262
         // Hide HTML comments.
263
-        $this->content = $this->hide_comments( $this->content );
263
+        $this->content = $this->hide_comments($this->content);
264 264
 
265 265
         // Get <style> and <link>.
266
-        if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) {
266
+        if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) {
267 267
 
268
-            foreach ( $matches[0] as $tag ) {
269
-                if ( $this->isremovable( $tag, $this->cssremovables ) ) {
270
-                    $this->content = str_replace( $tag, '', $this->content );
271
-                } elseif ( $this->ismovable( $tag ) ) {
268
+            foreach ($matches[0] as $tag) {
269
+                if ($this->isremovable($tag, $this->cssremovables)) {
270
+                    $this->content = str_replace($tag, '', $this->content);
271
+                } elseif ($this->ismovable($tag)) {
272 272
                     // Get the media.
273
-                    if ( false !== strpos( $tag, 'media=' ) ) {
274
-                        preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias );
275
-                        $medias = explode( ',', $medias[1] );
273
+                    if (false !== strpos($tag, 'media=')) {
274
+                        preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias);
275
+                        $medias = explode(',', $medias[1]);
276 276
                         $media  = array();
277
-                        foreach ( $medias as $elem ) {
278
-                            if ( empty( $elem ) ) {
277
+                        foreach ($medias as $elem) {
278
+                            if (empty($elem)) {
279 279
                                 $elem = 'all';
280 280
                             }
281 281
 
@@ -283,68 +283,68 @@  discard block
 block discarded – undo
283 283
                         }
284 284
                     } else {
285 285
                         // No media specified - applies to all.
286
-                        $media = array( 'all' );
286
+                        $media = array('all');
287 287
                     }
288 288
 
289 289
                     // forcing media attribute to all to merge all in one file.
290
-                    if ( $this->media_force_all ) {
291
-                        $media = array( 'all' );
290
+                    if ($this->media_force_all) {
291
+                        $media = array('all');
292 292
                     }
293 293
 
294
-                    $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag );
294
+                    $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag);
295 295
 
296
-                    if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) {
296
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
297 297
                         // <link>.
298
-                        $url  = current( explode( '?', $source[2], 2 ) );
299
-                        $path = $this->getpath( $url );
298
+                        $url  = current(explode('?', $source[2], 2));
299
+                        $path = $this->getpath($url);
300 300
 
301
-                        if ( false !== $path && preg_match( '#\.css$#', $path ) ) {
301
+                        if (false !== $path && preg_match('#\.css$#', $path)) {
302 302
                             // Good link.
303
-                            $this->css[] = array( $media, $path );
303
+                            $this->css[] = array($media, $path);
304 304
                         } else {
305 305
                             // Link is dynamic (.php etc).
306
-                            $new_tag = $this->optionally_defer_excluded( $tag, 'none' );
307
-                            if ( '' !== $new_tag && $new_tag !== $tag ) {
308
-                                $this->content = str_replace( $tag, $new_tag, $this->content );
306
+                            $new_tag = $this->optionally_defer_excluded($tag, 'none');
307
+                            if ('' !== $new_tag && $new_tag !== $tag) {
308
+                                $this->content = str_replace($tag, $new_tag, $this->content);
309 309
                             }
310 310
                             $tag = '';
311 311
                         }
312 312
                     } else {
313 313
                         // Inline css in style tags can be wrapped in comment tags, so restore comments.
314
-                        $tag = $this->restore_comments( $tag );
315
-                        preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code );
314
+                        $tag = $this->restore_comments($tag);
315
+                        preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code);
316 316
 
317 317
                         // And re-hide them to be able to to the removal based on tag.
318
-                        $tag = $this->hide_comments( $tag );
318
+                        $tag = $this->hide_comments($tag);
319 319
 
320
-                        if ( $this->include_inline ) {
321
-                            $code        = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] );
322
-                            $this->css[] = array( $media, 'INLINE;' . $code );
320
+                        if ($this->include_inline) {
321
+                            $code        = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]);
322
+                            $this->css[] = array($media, 'INLINE;'.$code);
323 323
                         } else {
324 324
                             $tag = '';
325 325
                         }
326 326
                     }
327 327
 
328 328
                     // Remove the original style tag.
329
-                    $this->content = str_replace( $tag, '', $this->content );
329
+                    $this->content = str_replace($tag, '', $this->content);
330 330
                 } else {
331
-                    if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) {
332
-                        $exploded_url = explode( '?', $source[2], 2 );
331
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
332
+                        $exploded_url = explode('?', $source[2], 2);
333 333
                         $url          = $exploded_url[0];
334
-                        $path         = $this->getpath( $url );
334
+                        $path         = $this->getpath($url);
335 335
                         $new_tag      = $tag;
336 336
 
337 337
                         // Excluded CSS, minify that file:
338 338
                         // -> if aggregate is on and exclude minify is on
339 339
                         // -> if aggregate is off and the file is not in dontmove.
340
-                        if ( $path && $this->minify_excluded ) {
341
-                            $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false );
342
-                            if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) {
343
-                                $minified_url = $this->minify_single( $path );
344
-                                if ( ! empty( $minified_url ) ) {
340
+                        if ($path && $this->minify_excluded) {
341
+                            $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false);
342
+                            if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) {
343
+                                $minified_url = $this->minify_single($path);
344
+                                if (!empty($minified_url)) {
345 345
                                     // Replace orig URL with cached minified URL.
346
-                                    $new_tag = str_replace( $url, $minified_url, $tag );
347
-                                } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) {
346
+                                    $new_tag = str_replace($url, $minified_url, $tag);
347
+                                } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) {
348 348
                                     // Remove the original style tag, because cache content is empty but only if
349 349
                                     // filter is true-ed because $minified_url is also false if file is minified already.
350 350
                                     $new_tag = '';
@@ -352,14 +352,14 @@  discard block
 block discarded – undo
352 352
                             }
353 353
                         }
354 354
 
355
-                        if ( '' !== $new_tag ) {
355
+                        if ('' !== $new_tag) {
356 356
                             // Optionally defer (preload) non-aggregated CSS.
357
-                            $new_tag = $this->optionally_defer_excluded( $new_tag, $url );
357
+                            $new_tag = $this->optionally_defer_excluded($new_tag, $url);
358 358
                         }
359 359
 
360 360
                         // And replace!
361
-                        if ( ( '' !== $new_tag && $new_tag !== $tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_css_remove_empty_files', false ) ) ) {
362
-                            $this->content = str_replace( $tag, $new_tag, $this->content );
361
+                        if (('' !== $new_tag && $new_tag !== $tag) || ('' === $new_tag && apply_filters('autoptimize_filter_css_remove_empty_files', false))) {
362
+                            $this->content = str_replace($tag, $new_tag, $this->content);
363 363
                         }
364 364
                     }
365 365
                 }
@@ -380,30 +380,30 @@  discard block
 block discarded – undo
380 380
      *
381 381
      * @return string $new_tag
382 382
      */
383
-    private function optionally_defer_excluded( $tag, $url = '' )
383
+    private function optionally_defer_excluded($tag, $url = '')
384 384
     {
385 385
         // Defer single CSS if "inline & defer" is ON and there is inline CSS.
386
-        if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) {
386
+        if (!empty($tag) && false === strpos($tag, ' onload=') && $this->defer && !empty($this->defer_inline) && apply_filters('autoptimize_filter_css_defer_excluded', true, $tag)) {
387 387
             // get media attribute and based on that create onload JS attribute value.
388
-            if ( false === strpos( $tag, 'media=' ) ) {
389
-                $tag = str_replace( '<link', "<link media='all'", $tag );
388
+            if (false === strpos($tag, 'media=')) {
389
+                $tag = str_replace('<link', "<link media='all'", $tag);
390 390
             }
391 391
 
392
-            preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias );
392
+            preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias);
393 393
             $_media          = $_medias[1];
394
-            $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $_media );
394
+            $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload($_media);
395 395
 
396
-            if ( 'print' !== $_media ) {
396
+            if ('print' !== $_media) {
397 397
                 // If not media=print, adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback.
398
-                $new_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>' . str_replace(
398
+                $new_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'.str_replace(
399 399
                     $_medias[0],
400
-                    "media='print' onload=\"" . $_preload_onload . '"',
400
+                    "media='print' onload=\"".$_preload_onload.'"',
401 401
                     $tag
402 402
                 );
403 403
 
404 404
                 // Optionally (but default false) preload the (excluded) CSS-file.
405
-                if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) && 'none' !== $url ) {
406
-                    $new_tag = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $new_tag;
405
+                if (apply_filters('autoptimize_fitler_css_preload_and_print', false) && 'none' !== $url) {
406
+                    $new_tag = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$new_tag;
407 407
                 }
408 408
             } else {
409 409
                 $new_tag = $tag;
@@ -423,22 +423,22 @@  discard block
 block discarded – undo
423 423
      * @param string $path image path.
424 424
      * @return boolean
425 425
      */
426
-    private function is_datauri_candidate( $path )
426
+    private function is_datauri_candidate($path)
427 427
     {
428 428
         // Call only once since it's called from a loop.
429 429
         static $max_size = null;
430
-        if ( null === $max_size ) {
430
+        if (null === $max_size) {
431 431
             $max_size = $this->get_datauri_maxsize();
432 432
         }
433 433
 
434
-        if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) &&
435
-            file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) {
434
+        if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) &&
435
+            file_exists($path) && is_readable($path) && filesize($path) <= $max_size) {
436 436
 
437 437
             // Seems we have a candidate.
438 438
             $is_candidate = true;
439 439
         } else {
440 440
             // Filter allows overriding default decision (which checks for local file existence).
441
-            $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path );
441
+            $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path);
442 442
         }
443 443
 
444 444
         return $is_candidate;
@@ -463,29 +463,29 @@  discard block
 block discarded – undo
463 463
          * of thing you're probably better of building assets completely
464 464
          * outside of WordPress anyway.
465 465
          */
466
-        if ( null === $max_size ) {
467
-            $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 );
466
+        if (null === $max_size) {
467
+            $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096);
468 468
         }
469 469
 
470 470
         return $max_size;
471 471
     }
472 472
 
473
-    private function check_datauri_exclude_list( $url )
473
+    private function check_datauri_exclude_list($url)
474 474
     {
475 475
         static $exclude_list = null;
476 476
         $no_datauris         = array();
477 477
 
478 478
         // Again, skip doing certain stuff repeatedly when loop-called.
479
-        if ( null === $exclude_list ) {
480
-            $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' );
481
-            $no_datauris  = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) );
479
+        if (null === $exclude_list) {
480
+            $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', '');
481
+            $no_datauris  = array_filter(array_map('trim', explode(',', $exclude_list)));
482 482
         }
483 483
 
484 484
         $matched = false;
485 485
 
486
-        if ( ! empty( $exclude_list ) ) {
487
-            foreach ( $no_datauris as $no_datauri ) {
488
-                if ( false !== strpos( $url, $no_datauri ) ) {
486
+        if (!empty($exclude_list)) {
487
+            foreach ($no_datauris as $no_datauri) {
488
+                if (false !== strpos($url, $no_datauri)) {
489 489
                     $matched = true;
490 490
                     break;
491 491
                 }
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
         return $matched;
496 496
     }
497 497
 
498
-    private function build_or_get_datauri_image( $path )
498
+    private function build_or_get_datauri_image($path)
499 499
     {
500 500
         /**
501 501
          * TODO/FIXME: document the required return array format, or better yet,
@@ -504,27 +504,27 @@  discard block
 block discarded – undo
504 504
          */
505 505
 
506 506
         // Allows short-circuiting datauri generation for an image.
507
-        $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path );
508
-        if ( ! empty( $result ) ) {
509
-            if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) {
507
+        $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path);
508
+        if (!empty($result)) {
509
+            if (is_array($result) && isset($result['full']) && isset($result['base64data'])) {
510 510
                 return $result;
511 511
             }
512 512
         }
513 513
 
514
-        $hash  = md5( $path );
515
-        $check = new autoptimizeCache( $hash, 'img' );
516
-        if ( $check->check() ) {
514
+        $hash  = md5($path);
515
+        $check = new autoptimizeCache($hash, 'img');
516
+        if ($check->check()) {
517 517
             // we have the base64 image in cache.
518 518
             $head_and_data = $check->retrieve();
519
-            $_base64data   = explode( ';base64,', $head_and_data );
519
+            $_base64data   = explode(';base64,', $head_and_data);
520 520
             $base64data    = $_base64data[1];
521
-            unset( $_base64data );
521
+            unset($_base64data);
522 522
         } else {
523 523
             // It's an image and we don't have it in cache, get the type by extension.
524
-            $exploded_path = explode( '.', $path );
525
-            $type          = end( $exploded_path );
524
+            $exploded_path = explode('.', $path);
525
+            $type          = end($exploded_path);
526 526
 
527
-            switch ( $type ) {
527
+            switch ($type) {
528 528
                 case 'jpg':
529 529
                 case 'jpeg':
530 530
                     $dataurihead = 'data:image/jpeg;base64,';
@@ -546,13 +546,13 @@  discard block
 block discarded – undo
546 546
             }
547 547
 
548 548
             // Encode the data.
549
-            $base64data    = base64_encode( file_get_contents( $path ) );
550
-            $head_and_data = $dataurihead . $base64data;
549
+            $base64data    = base64_encode(file_get_contents($path));
550
+            $head_and_data = $dataurihead.$base64data;
551 551
 
552 552
             // Save in cache.
553
-            $check->cache( $head_and_data, 'text/plain' );
553
+            $check->cache($head_and_data, 'text/plain');
554 554
         }
555
-        unset( $check );
555
+        unset($check);
556 556
 
557 557
         return array(
558 558
             'full'       => $head_and_data,
@@ -569,13 +569,13 @@  discard block
 block discarded – undo
569 569
      *
570 570
      * @return string
571 571
      */
572
-    protected static function replace_longest_matches_first( $string, $replacements = array() )
572
+    protected static function replace_longest_matches_first($string, $replacements = array())
573 573
     {
574
-        if ( ! empty( $replacements ) ) {
574
+        if (!empty($replacements)) {
575 575
             // Sort the replacements array by key length in desc order (so that the longest strings are replaced first).
576
-            $keys = array_map( 'strlen', array_keys( $replacements ) );
577
-            array_multisort( $keys, SORT_DESC, $replacements );
578
-            $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string );
576
+            $keys = array_map('strlen', array_keys($replacements));
577
+            array_multisort($keys, SORT_DESC, $replacements);
578
+            $string = str_replace(array_keys($replacements), array_values($replacements), $string);
579 579
         }
580 580
 
581 581
         return $string;
@@ -591,15 +591,15 @@  discard block
 block discarded – undo
591 591
      *
592 592
      * @return string
593 593
      */
594
-    public function replace_urls( $code = '' )
594
+    public function replace_urls($code = '')
595 595
     {
596 596
         $replacements = array();
597 597
 
598
-        preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches );
599
-        if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) {
600
-            foreach ( $url_src_matches[1] as $count => $original_url ) {
598
+        preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches);
599
+        if (is_array($url_src_matches) && !empty($url_src_matches)) {
600
+            foreach ($url_src_matches[1] as $count => $original_url) {
601 601
                 // Removes quotes and other cruft.
602
-                $url = trim( $original_url, " \t\n\r\0\x0B\"'" );
602
+                $url = trim($original_url, " \t\n\r\0\x0B\"'");
603 603
 
604 604
                 /**
605 605
                  * TODO/FIXME: Add a way for other code / callable to be called here
@@ -617,17 +617,17 @@  discard block
 block discarded – undo
617 617
                  */
618 618
 
619 619
                 // Do CDN replacement if needed.
620
-                if ( ! empty( $this->cdn_url ) ) {
621
-                    $replacement_url = $this->url_replace_cdn( $url );
620
+                if (!empty($this->cdn_url)) {
621
+                    $replacement_url = $this->url_replace_cdn($url);
622 622
                     // Prepare replacements array.
623
-                    $replacements[ $url_src_matches[1][ $count ] ] = str_replace(
624
-                        $original_url, $replacement_url, $url_src_matches[1][ $count ]
623
+                    $replacements[$url_src_matches[1][$count]] = str_replace(
624
+                        $original_url, $replacement_url, $url_src_matches[1][$count]
625 625
                     );
626 626
                 }
627 627
             }
628 628
         }
629 629
 
630
-        $code = self::replace_longest_matches_first( $code, $replacements );
630
+        $code = self::replace_longest_matches_first($code, $replacements);
631 631
 
632 632
         return $code;
633 633
     }
@@ -640,26 +640,26 @@  discard block
 block discarded – undo
640 640
      * @param string $code HTML being processed to hide fonts.
641 641
      * @return string
642 642
      */
643
-    public function hide_fontface_and_maybe_cdn( $code )
643
+    public function hide_fontface_and_maybe_cdn($code)
644 644
     {
645 645
         // Proceed only if @font-face declarations exist within $code.
646
-        preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces );
647
-        if ( isset( $fontfaces[0] ) ) {
646
+        preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces);
647
+        if (isset($fontfaces[0])) {
648 648
             // Check if we need to cdn fonts or not.
649
-            $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false );
649
+            $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false);
650 650
 
651
-            foreach ( $fontfaces[0] as $full_match ) {
651
+            foreach ($fontfaces[0] as $full_match) {
652 652
                 // Keep original match so we can search/replace it.
653 653
                 $match_search = $full_match;
654 654
 
655 655
                 // Do font cdn if needed.
656
-                if ( $do_font_cdn ) {
657
-                    $full_match = $this->replace_urls( $full_match );
656
+                if ($do_font_cdn) {
657
+                    $full_match = $this->replace_urls($full_match);
658 658
                 }
659 659
 
660 660
                 // Replace declaration with its base64 encoded string.
661
-                $replacement = self::build_marker( 'FONTFACE', $full_match );
662
-                $code        = str_replace( $match_search, $replacement, $code );
661
+                $replacement = self::build_marker('FONTFACE', $full_match);
662
+                $code        = str_replace($match_search, $replacement, $code);
663 663
             }
664 664
         }
665 665
 
@@ -673,9 +673,9 @@  discard block
 block discarded – undo
673 673
      * @param string $code HTML being processed to unhide fonts.
674 674
      * @return string
675 675
      */
676
-    public function restore_fontface( $code )
676
+    public function restore_fontface($code)
677 677
     {
678
-        return $this->restore_marked_content( 'FONTFACE', $code );
678
+        return $this->restore_marked_content('FONTFACE', $code);
679 679
     }
680 680
 
681 681
     /**
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
      * @param string $code HTML being processed rewrite assets.
685 685
      * @return string
686 686
      */
687
-    public function rewrite_assets( $code )
687
+    public function rewrite_assets($code)
688 688
     {
689 689
         // Handle @font-face rules by hiding and processing them separately.
690
-        $code = $this->hide_fontface_and_maybe_cdn( $code );
690
+        $code = $this->hide_fontface_and_maybe_cdn($code);
691 691
 
692 692
         /**
693 693
          * TODO/FIXME:
@@ -704,35 +704,35 @@  discard block
 block discarded – undo
704 704
         $imgreplace      = array();
705 705
 
706 706
         // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs.
707
-        preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches );
708
-        if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) {
709
-            foreach ( $url_src_matches[1] as $count => $original_url ) {
707
+        preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches);
708
+        if (is_array($url_src_matches) && !empty($url_src_matches)) {
709
+            foreach ($url_src_matches[1] as $count => $original_url) {
710 710
                 // Removes quotes and other cruft.
711
-                $url = trim( $original_url, " \t\n\r\0\x0B\"'" );
711
+                $url = trim($original_url, " \t\n\r\0\x0B\"'");
712 712
 
713 713
                 // If datauri inlining is turned on, do it.
714 714
                 $inlined = false;
715
-                if ( $this->datauris ) {
715
+                if ($this->datauris) {
716 716
                     $iurl = $url;
717
-                    if ( false !== strpos( $iurl, '?' ) ) {
718
-                        $iurl = strtok( $iurl, '?' );
717
+                    if (false !== strpos($iurl, '?')) {
718
+                        $iurl = strtok($iurl, '?');
719 719
                     }
720 720
 
721
-                    $ipath = $this->getpath( $iurl );
721
+                    $ipath = $this->getpath($iurl);
722 722
 
723
-                    $excluded = $this->check_datauri_exclude_list( $ipath );
724
-                    if ( ! $excluded ) {
725
-                        $is_datauri_candidate = $this->is_datauri_candidate( $ipath );
726
-                        if ( $is_datauri_candidate ) {
727
-                            $datauri    = $this->build_or_get_datauri_image( $ipath );
723
+                    $excluded = $this->check_datauri_exclude_list($ipath);
724
+                    if (!$excluded) {
725
+                        $is_datauri_candidate = $this->is_datauri_candidate($ipath);
726
+                        if ($is_datauri_candidate) {
727
+                            $datauri    = $this->build_or_get_datauri_image($ipath);
728 728
                             $base64data = $datauri['base64data'];
729 729
                             // Add it to the list for replacement.
730
-                            $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace(
730
+                            $imgreplace[$url_src_matches[1][$count]] = str_replace(
731 731
                                 $original_url,
732 732
                                 $datauri['full'],
733
-                                $url_src_matches[1][ $count ]
733
+                                $url_src_matches[1][$count]
734 734
                             );
735
-                            $inlined                                     = true;
735
+                            $inlined = true;
736 736
                         }
737 737
                     }
738 738
                 }
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
                  * inlining isn't turned on, or if a resource is skipped from
744 744
                  * being inlined for whatever reason above.
745 745
                  */
746
-                if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) {
746
+                if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) {
747 747
                     // Just do the "simple" CDN replacement.
748
-                    $replacement_url                             = $this->url_replace_cdn( $url );
749
-                    $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace(
750
-                        $original_url, $replacement_url, $url_src_matches[1][ $count ]
748
+                    $replacement_url                             = $this->url_replace_cdn($url);
749
+                    $imgreplace[$url_src_matches[1][$count]] = str_replace(
750
+                        $original_url, $replacement_url, $url_src_matches[1][$count]
751 751
                     );
752 752
                 }
753 753
             }
754 754
         }
755 755
 
756
-        $code = self::replace_longest_matches_first( $code, $imgreplace );
756
+        $code = self::replace_longest_matches_first($code, $imgreplace);
757 757
 
758 758
         // Replace back font-face markers with actual font-face declarations.
759
-        $code = $this->restore_fontface( $code );
759
+        $code = $this->restore_fontface($code);
760 760
 
761 761
         return $code;
762 762
     }
@@ -766,29 +766,29 @@  discard block
 block discarded – undo
766 766
      */
767 767
     public function minify()
768 768
     {
769
-        foreach ( $this->css as $group ) {
770
-            list( $media, $css ) = $group;
771
-            if ( preg_match( '#^INLINE;#', $css ) ) {
769
+        foreach ($this->css as $group) {
770
+            list($media, $css) = $group;
771
+            if (preg_match('#^INLINE;#', $css)) {
772 772
                 // <style>.
773
-                $css      = preg_replace( '#^INLINE;#', '', $css );
774
-                $css      = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash.
775
-                $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' );
776
-                if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
773
+                $css      = preg_replace('#^INLINE;#', '', $css);
774
+                $css      = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash.
775
+                $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, '');
776
+                if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
777 777
                     $css                   = $tmpstyle;
778 778
                     $this->alreadyminified = true;
779 779
                 }
780 780
             } else {
781 781
                 // <link>
782
-                if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) {
782
+                if (false !== $css && file_exists($css) && is_readable($css)) {
783 783
                     $css_path = $css;
784
-                    $css      = self::fixurls( $css_path, file_get_contents( $css_path ) );
785
-                    $css      = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css );
786
-                    $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $css_path );
787
-                    if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
784
+                    $css      = self::fixurls($css_path, file_get_contents($css_path));
785
+                    $css      = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css);
786
+                    $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $css_path);
787
+                    if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
788 788
                         $css                   = $tmpstyle;
789 789
                         $this->alreadyminified = true;
790
-                    } elseif ( $this->can_inject_late( $css_path, $css ) ) {
791
-                        $css = self::build_injectlater_marker( $css_path, md5( $css ) );
790
+                    } elseif ($this->can_inject_late($css_path, $css)) {
791
+                        $css = self::build_injectlater_marker($css_path, md5($css));
792 792
                     }
793 793
                 } else {
794 794
                     // Couldn't read CSS. Maybe getpath isn't working?
@@ -796,12 +796,12 @@  discard block
 block discarded – undo
796 796
                 }
797 797
             }
798 798
 
799
-            foreach ( $media as $elem ) {
800
-                if ( ! empty( $css ) ) {
801
-                    if ( ! isset( $this->csscode[ $elem ] ) ) {
802
-                        $this->csscode[ $elem ] = '';
799
+            foreach ($media as $elem) {
800
+                if (!empty($css)) {
801
+                    if (!isset($this->csscode[$elem])) {
802
+                        $this->csscode[$elem] = '';
803 803
                     }
804
-                    $this->csscode[ $elem ] .= "\n/*FILESTART*/" . $css;
804
+                    $this->csscode[$elem] .= "\n/*FILESTART*/".$css;
805 805
                 }
806 806
             }
807 807
         }
@@ -809,133 +809,133 @@  discard block
 block discarded – undo
809 809
         // Check for duplicate code.
810 810
         $md5list = array();
811 811
         $tmpcss  = $this->csscode;
812
-        foreach ( $tmpcss as $media => $code ) {
813
-            $md5sum    = md5( $code );
812
+        foreach ($tmpcss as $media => $code) {
813
+            $md5sum    = md5($code);
814 814
             $medianame = $media;
815
-            foreach ( $md5list as $med => $sum ) {
815
+            foreach ($md5list as $med => $sum) {
816 816
                 // If same code.
817
-                if ( $sum === $md5sum ) {
817
+                if ($sum === $md5sum) {
818 818
                     // Add the merged code.
819
-                    $medianame                   = $med . ', ' . $media;
820
-                    $this->csscode[ $medianame ] = $code;
821
-                    $md5list[ $medianame ]       = $md5list[ $med ];
822
-                    unset( $this->csscode[ $med ], $this->csscode[ $media ], $md5list[ $med ] );
819
+                    $medianame                   = $med.', '.$media;
820
+                    $this->csscode[$medianame] = $code;
821
+                    $md5list[$medianame]       = $md5list[$med];
822
+                    unset($this->csscode[$med], $this->csscode[$media], $md5list[$med]);
823 823
                 }
824 824
             }
825
-            $md5list[ $medianame ] = $md5sum;
825
+            $md5list[$medianame] = $md5sum;
826 826
         }
827
-        unset( $tmpcss );
827
+        unset($tmpcss);
828 828
 
829 829
         // Manage @imports, while is for recursive import management.
830
-        foreach ( $this->csscode as &$thiscss ) {
830
+        foreach ($this->csscode as &$thiscss) {
831 831
             // Flag to trigger import reconstitution and var to hold external imports.
832 832
             $fiximports       = false;
833 833
             $external_imports = '';
834 834
 
835 835
             // remove comments to avoid importing commented-out imports.
836
-            $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss );
837
-            while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) {
838
-                foreach ( $matches[0] as $import ) {
839
-                    if ( $this->isremovable( $import, $this->cssremovables ) ) {
840
-                        $thiscss   = str_replace( $import, '', $thiscss );
836
+            $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
837
+            while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) {
838
+                foreach ($matches[0] as $import) {
839
+                    if ($this->isremovable($import, $this->cssremovables)) {
840
+                        $thiscss   = str_replace($import, '', $thiscss);
841 841
                         $import_ok = true;
842 842
                     } else {
843
-                        $url       = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" );
844
-                        $path      = $this->getpath( $url );
843
+                        $url       = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'");
844
+                        $path      = $this->getpath($url);
845 845
                         $import_ok = false;
846
-                        if ( file_exists( $path ) && is_readable( $path ) ) {
847
-                            $code     = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), '\\' );
848
-                            $code     = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code );
849
-                            $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' );
850
-                            if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
846
+                        if (file_exists($path) && is_readable($path)) {
847
+                            $code     = addcslashes(self::fixurls($path, file_get_contents($path)), '\\');
848
+                            $code     = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code);
849
+                            $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, '');
850
+                            if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
851 851
                                 $code                  = $tmpstyle;
852 852
                                 $this->alreadyminified = true;
853
-                            } elseif ( $this->can_inject_late( $path, $code ) ) {
854
-                                $code = self::build_injectlater_marker( $path, md5( $code ) );
853
+                            } elseif ($this->can_inject_late($path, $code)) {
854
+                                $code = self::build_injectlater_marker($path, md5($code));
855 855
                             }
856 856
 
857
-                            if ( ! empty( $code ) ) {
858
-                                $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss );
859
-                                if ( ! empty( $tmp_thiscss ) ) {
857
+                            if (!empty($code)) {
858
+                                $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss);
859
+                                if (!empty($tmp_thiscss)) {
860 860
                                     $thiscss   = $tmp_thiscss;
861 861
                                     $import_ok = true;
862
-                                    unset( $tmp_thiscss );
862
+                                    unset($tmp_thiscss);
863 863
                                 }
864 864
                             }
865
-                            unset( $code );
865
+                            unset($code);
866 866
                         }
867 867
                     }
868
-                    if ( ! $import_ok ) {
868
+                    if (!$import_ok) {
869 869
                         // External imports and general fall-back.
870 870
                         $external_imports .= $import;
871 871
 
872
-                        $thiscss    = str_replace( $import, '', $thiscss );
872
+                        $thiscss    = str_replace($import, '', $thiscss);
873 873
                         $fiximports = true;
874 874
                     }
875 875
                 }
876
-                $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss );
877
-                $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss );
876
+                $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss);
877
+                $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss);
878 878
 
879 879
                 // and update $thiscss_nocomments before going into next iteration in while loop.
880
-                $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss );
880
+                $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
881 881
             }
882
-            unset( $thiscss_nocomments );
882
+            unset($thiscss_nocomments);
883 883
 
884 884
             // Add external imports to top of aggregated CSS.
885
-            if ( $fiximports ) {
886
-                $thiscss = $external_imports . $thiscss;
885
+            if ($fiximports) {
886
+                $thiscss = $external_imports.$thiscss;
887 887
             }
888 888
         }
889
-        unset( $thiscss );
889
+        unset($thiscss);
890 890
 
891 891
         // $this->csscode has all the uncompressed code now.
892
-        foreach ( $this->csscode as &$code ) {
892
+        foreach ($this->csscode as &$code) {
893 893
             // Check for already-minified code.
894
-            $hash = md5( $code );
895
-            do_action( 'autoptimize_action_css_hash', $hash );
896
-            $ccheck = new autoptimizeCache( $hash, 'css' );
897
-            if ( $ccheck->check() ) {
894
+            $hash = md5($code);
895
+            do_action('autoptimize_action_css_hash', $hash);
896
+            $ccheck = new autoptimizeCache($hash, 'css');
897
+            if ($ccheck->check()) {
898 898
                 $code                          = $ccheck->retrieve();
899
-                $this->hashmap[ md5( $code ) ] = $hash;
899
+                $this->hashmap[md5($code)] = $hash;
900 900
                 continue;
901 901
             }
902
-            unset( $ccheck );
902
+            unset($ccheck);
903 903
 
904 904
             // Rewrite and/or inline referenced assets.
905
-            $code = $this->rewrite_assets( $code );
905
+            $code = $this->rewrite_assets($code);
906 906
 
907 907
             // Minify.
908
-            $code = $this->run_minifier_on( $code );
908
+            $code = $this->run_minifier_on($code);
909 909
 
910 910
             // Bring back INJECTLATER stuff.
911
-            $code = $this->inject_minified( $code );
911
+            $code = $this->inject_minified($code);
912 912
 
913 913
             // Filter results.
914
-            $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code );
915
-            if ( ! empty( $tmp_code ) ) {
914
+            $tmp_code = apply_filters('autoptimize_css_after_minify', $code);
915
+            if (!empty($tmp_code)) {
916 916
                 $code = $tmp_code;
917
-                unset( $tmp_code );
917
+                unset($tmp_code);
918 918
             }
919 919
 
920
-            $this->hashmap[ md5( $code ) ] = $hash;
920
+            $this->hashmap[md5($code)] = $hash;
921 921
         }
922 922
 
923
-        unset( $code );
923
+        unset($code);
924 924
         return true;
925 925
     }
926 926
 
927
-    public function run_minifier_on( $code )
927
+    public function run_minifier_on($code)
928 928
     {
929
-        if ( ! $this->alreadyminified ) {
930
-            $do_minify = apply_filters( 'autoptimize_css_do_minify', true );
929
+        if (!$this->alreadyminified) {
930
+            $do_minify = apply_filters('autoptimize_css_do_minify', true);
931 931
 
932
-            if ( $do_minify ) {
932
+            if ($do_minify) {
933 933
                 $cssmin   = new autoptimizeCSSmin();
934
-                $tmp_code = trim( $cssmin->run( $code ) );
934
+                $tmp_code = trim($cssmin->run($code));
935 935
 
936
-                if ( ! empty( $tmp_code ) ) {
936
+                if (!empty($tmp_code)) {
937 937
                     $code = $tmp_code;
938
-                    unset( $tmp_code );
938
+                    unset($tmp_code);
939 939
                 }
940 940
             }
941 941
         }
@@ -949,18 +949,18 @@  discard block
 block discarded – undo
949 949
     public function cache()
950 950
     {
951 951
         // CSS cache.
952
-        foreach ( $this->csscode as $media => $code ) {
953
-            if ( empty( $code ) ) {
952
+        foreach ($this->csscode as $media => $code) {
953
+            if (empty($code)) {
954 954
                 continue;
955 955
             }
956 956
 
957
-            $md5   = $this->hashmap[ md5( $code ) ];
958
-            $cache = new autoptimizeCache( $md5, 'css' );
959
-            if ( ! $cache->check() ) {
957
+            $md5   = $this->hashmap[md5($code)];
958
+            $cache = new autoptimizeCache($md5, 'css');
959
+            if (!$cache->check()) {
960 960
                 // Cache our code.
961
-                $cache->cache( $code, 'text/css' );
961
+                $cache->cache($code, 'text/css');
962 962
             }
963
-            $this->url[ $media ] = AUTOPTIMIZE_CACHE_URL . $cache->getname();
963
+            $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname();
964 964
         }
965 965
     }
966 966
 
@@ -970,95 +970,95 @@  discard block
 block discarded – undo
970 970
     public function getcontent()
971 971
     {
972 972
         // Restore the full content (only applies when "autoptimize_filter_css_justhead" filter is true).
973
-        if ( ! empty( $this->restofcontent ) ) {
973
+        if (!empty($this->restofcontent)) {
974 974
             $this->content      .= $this->restofcontent;
975 975
             $this->restofcontent = '';
976 976
         }
977 977
 
978 978
         // type is not added by default.
979 979
         $type_css = '';
980
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
980
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
981 981
             $type_css = 'type="text/css" ';
982 982
         }
983 983
 
984 984
         // Inject the new stylesheets.
985
-        $replace_tag = array( '<title', 'before' );
986
-        $replace_tag = apply_filters( 'autoptimize_filter_css_replacetag', $replace_tag, $this->content );
985
+        $replace_tag = array('<title', 'before');
986
+        $replace_tag = apply_filters('autoptimize_filter_css_replacetag', $replace_tag, $this->content);
987 987
 
988
-        if ( $this->inline ) {
989
-            foreach ( $this->csscode as $media => $code ) {
990
-                $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $code . '</style>' ), $replace_tag );
988
+        if ($this->inline) {
989
+            foreach ($this->csscode as $media => $code) {
990
+                $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$code.'</style>'), $replace_tag);
991 991
             }
992 992
         } else {
993
-            if ( $this->defer ) {
993
+            if ($this->defer) {
994 994
                 $preload_css_block  = '';
995 995
                 $inlined_ccss_block = '';
996 996
                 $noscript_css_block = '<noscript id="aonoscrcss">';
997 997
 
998 998
                 $defer_inline_code = $this->defer_inline;
999
-                if ( ! empty( $defer_inline_code ) ) {
1000
-                    if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) {
1001
-                        $icss_hash  = md5( $defer_inline_code );
1002
-                        $icss_cache = new autoptimizeCache( $icss_hash, 'css' );
1003
-                        if ( $icss_cache->check() ) {
999
+                if (!empty($defer_inline_code)) {
1000
+                    if (apply_filters('autoptimize_filter_css_critcss_minify', true)) {
1001
+                        $icss_hash  = md5($defer_inline_code);
1002
+                        $icss_cache = new autoptimizeCache($icss_hash, 'css');
1003
+                        if ($icss_cache->check()) {
1004 1004
                             // we have the optimized inline CSS in cache.
1005 1005
                             $defer_inline_code = $icss_cache->retrieve();
1006 1006
                         } else {
1007 1007
                             $cssmin   = new autoptimizeCSSmin();
1008
-                            $tmp_code = trim( $cssmin->run( $defer_inline_code ) );
1008
+                            $tmp_code = trim($cssmin->run($defer_inline_code));
1009 1009
 
1010
-                            if ( ! empty( $tmp_code ) ) {
1010
+                            if (!empty($tmp_code)) {
1011 1011
                                 $defer_inline_code = $tmp_code;
1012
-                                $icss_cache->cache( $defer_inline_code, 'text/css' );
1013
-                                unset( $tmp_code );
1012
+                                $icss_cache->cache($defer_inline_code, 'text/css');
1013
+                                unset($tmp_code);
1014 1014
                             }
1015 1015
                         }
1016 1016
                     }
1017 1017
                     // inlined critical css set here, but injected when full CSS is injected
1018 1018
                     // to avoid CSS containing SVG with <title tag receiving the full CSS link.
1019
-                    $inlined_ccss_block = '<style ' . $type_css . 'id="aoatfcss" media="all">' . $defer_inline_code . '</style>';
1019
+                    $inlined_ccss_block = '<style '.$type_css.'id="aoatfcss" media="all">'.$defer_inline_code.'</style>';
1020 1020
                 }
1021 1021
             }
1022 1022
 
1023
-            foreach ( $this->url as $media => $url ) {
1024
-                $url = $this->url_replace_cdn( $url );
1023
+            foreach ($this->url as $media => $url) {
1024
+                $url = $this->url_replace_cdn($url);
1025 1025
 
1026 1026
                 // Add the stylesheet either deferred (import at bottom) or normal links in head.
1027
-                if ( $this->defer && 'print' !== $media ) {
1028
-                    $preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $media );
1027
+                if ($this->defer && 'print' !== $media) {
1028
+                    $preload_onload = autoptimizeConfig::get_ao_css_preload_onload($media);
1029 1029
 
1030
-                    $preload_css_block .= '<link rel="stylesheet" media="print" href="' . $url . '" onload="' . $preload_onload . '" />';
1031
-                    if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) ) {
1032
-                        $preload_css_block = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $preload_css_block;
1030
+                    $preload_css_block .= '<link rel="stylesheet" media="print" href="'.$url.'" onload="'.$preload_onload.'" />';
1031
+                    if (apply_filters('autoptimize_fitler_css_preload_and_print', false)) {
1032
+                        $preload_css_block = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$preload_css_block;
1033 1033
                     }
1034
-                    $noscript_css_block .= '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />';
1034
+                    $noscript_css_block .= '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />';
1035 1035
                 } else {
1036
-                    if ( strlen( $this->csscode[ $media ] ) > $this->cssinlinesize ) {
1037
-                        $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />' ), $replace_tag );
1038
-                    } elseif ( strlen( $this->csscode[ $media ] ) > 0 ) {
1039
-                        $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $this->csscode[ $media ] . '</style>' ), $replace_tag );
1036
+                    if (strlen($this->csscode[$media]) > $this->cssinlinesize) {
1037
+                        $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'), $replace_tag);
1038
+                    } elseif (strlen($this->csscode[$media]) > 0) {
1039
+                        $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$this->csscode[$media].'</style>'), $replace_tag);
1040 1040
                     }
1041 1041
                 }
1042 1042
             }
1043 1043
 
1044
-            if ( $this->defer ) {
1044
+            if ($this->defer) {
1045 1045
                 $noscript_css_block .= '</noscript>';
1046 1046
                 // Inject inline critical CSS, the preloaded full CSS and the noscript-CSS.
1047
-                $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block . $preload_css_block . $noscript_css_block ), $replace_tag );
1047
+                $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block.$preload_css_block.$noscript_css_block), $replace_tag);
1048 1048
             }
1049 1049
         }
1050 1050
 
1051 1051
         // restore comments.
1052
-        $this->content = $this->restore_comments( $this->content );
1052
+        $this->content = $this->restore_comments($this->content);
1053 1053
 
1054 1054
         // restore IE hacks.
1055
-        $this->content = $this->restore_iehacks( $this->content );
1055
+        $this->content = $this->restore_iehacks($this->content);
1056 1056
 
1057 1057
         // restore (no)script.
1058
-        $this->content = $this->restore_marked_content( 'SCRIPT', $this->content );
1058
+        $this->content = $this->restore_marked_content('SCRIPT', $this->content);
1059 1059
 
1060 1060
         // Restore noptimize.
1061
-        $this->content = $this->restore_noptimize( $this->content );
1061
+        $this->content = $this->restore_noptimize($this->content);
1062 1062
 
1063 1063
         // Return the modified stylesheet.
1064 1064
         return $this->content;
@@ -1070,44 +1070,44 @@  discard block
 block discarded – undo
1070 1070
      * @param string $file filename of optimized CSS-file.
1071 1071
      * @param string $code CSS-code in which to fix URL's.
1072 1072
      */
1073
-    static function fixurls( $file, $code )
1073
+    static function fixurls($file, $code)
1074 1074
     {
1075 1075
         // Switch all imports to the url() syntax.
1076
-        $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code );
1076
+        $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code);
1077 1077
 
1078
-        if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) {
1079
-            $file = str_replace( WP_ROOT_DIR, '/', $file );
1078
+        if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) {
1079
+            $file = str_replace(WP_ROOT_DIR, '/', $file);
1080 1080
             /**
1081 1081
              * Rollback as per https://github.com/futtta/autoptimize/issues/94
1082 1082
              * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file );
1083 1083
              */
1084
-            $dir = dirname( $file ); // Like /themes/expound/css.
1084
+            $dir = dirname($file); // Like /themes/expound/css.
1085 1085
 
1086 1086
             /**
1087 1087
              * $dir should not contain backslashes, since it's used to replace
1088 1088
              * urls, but it can contain them when running on Windows because
1089 1089
              * fixurls() is sometimes called with `ABSPATH . 'index.php'`
1090 1090
              */
1091
-            $dir = str_replace( '\\', '/', $dir );
1092
-            unset( $file ); // not used below at all.
1091
+            $dir = str_replace('\\', '/', $dir);
1092
+            unset($file); // not used below at all.
1093 1093
 
1094 1094
             $replace = array();
1095
-            foreach ( $matches[1] as $k => $url ) {
1095
+            foreach ($matches[1] as $k => $url) {
1096 1096
                 // Remove quotes.
1097
-                $url      = trim( $url, " \t\n\r\0\x0B\"'" );
1098
-                $no_q_url = trim( $url, "\"'" );
1099
-                if ( $url !== $no_q_url ) {
1097
+                $url      = trim($url, " \t\n\r\0\x0B\"'");
1098
+                $no_q_url = trim($url, "\"'");
1099
+                if ($url !== $no_q_url) {
1100 1100
                     $removed_quotes = true;
1101 1101
                 } else {
1102 1102
                     $removed_quotes = false;
1103 1103
                 }
1104 1104
 
1105
-                if ( '' === $no_q_url ) {
1105
+                if ('' === $no_q_url) {
1106 1106
                     continue;
1107 1107
                 }
1108 1108
 
1109 1109
                 $url = $no_q_url;
1110
-                if ( '/' === $url[0] || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) {
1110
+                if ('/' === $url[0] || preg_match('#^(https?://|ftp://|data:)#i', $url)) {
1111 1111
                     // URL is protocol-relative, host-relative or something we don't touch.
1112 1112
                     continue;
1113 1113
                 } else { // Relative URL.
@@ -1116,49 +1116,49 @@  discard block
 block discarded – undo
1116 1116
                      * rollback as per https://github.com/futtta/autoptimize/issues/94
1117 1117
                      * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
1118 1118
                      */
1119
-                    $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
1120
-                    $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl );
1119
+                    $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url)));
1120
+                    $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl);
1121 1121
 
1122 1122
                     /**
1123 1123
                      * Hash the url + whatever was behind potentially for replacement
1124 1124
                      * We must do this, or different css classes referencing the same bg image (but
1125 1125
                      * different parts of it, say, in sprites and such) loose their stuff...
1126 1126
                      */
1127
-                    $hash = md5( $url . $matches[2][ $k ] );
1128
-                    $code = str_replace( $matches[0][ $k ], $hash, $code );
1127
+                    $hash = md5($url.$matches[2][$k]);
1128
+                    $code = str_replace($matches[0][$k], $hash, $code);
1129 1129
 
1130
-                    if ( $removed_quotes ) {
1131
-                        $replace[ $hash ] = "url('" . $newurl . "')" . $matches[2][ $k ];
1130
+                    if ($removed_quotes) {
1131
+                        $replace[$hash] = "url('".$newurl."')".$matches[2][$k];
1132 1132
                     } else {
1133
-                        $replace[ $hash ] = 'url(' . $newurl . ')' . $matches[2][ $k ];
1133
+                        $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k];
1134 1134
                     }
1135 1135
                 }
1136 1136
             }
1137 1137
 
1138
-            $code = self::replace_longest_matches_first( $code, $replace );
1138
+            $code = self::replace_longest_matches_first($code, $replace);
1139 1139
         }
1140 1140
 
1141 1141
         return $code;
1142 1142
     }
1143 1143
 
1144
-    private function ismovable( $tag )
1144
+    private function ismovable($tag)
1145 1145
     {
1146
-        if ( ! $this->aggregate ) {
1146
+        if (!$this->aggregate) {
1147 1147
             return false;
1148 1148
         }
1149 1149
 
1150
-        if ( ! empty( $this->allowlist ) ) {
1151
-            foreach ( $this->allowlist as $match ) {
1152
-                if ( false !== strpos( $tag, $match ) ) {
1150
+        if (!empty($this->allowlist)) {
1151
+            foreach ($this->allowlist as $match) {
1152
+                if (false !== strpos($tag, $match)) {
1153 1153
                     return true;
1154 1154
                 }
1155 1155
             }
1156 1156
             // no match with allowlist.
1157 1157
             return false;
1158 1158
         } else {
1159
-            if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) {
1160
-                foreach ( $this->dontmove as $match ) {
1161
-                    if ( false !== strpos( $tag, $match ) ) {
1159
+            if (is_array($this->dontmove) && !empty($this->dontmove)) {
1160
+                foreach ($this->dontmove as $match) {
1161
+                    if (false !== strpos($tag, $match)) {
1162 1162
                         // Matched something.
1163 1163
                         return false;
1164 1164
                     }
@@ -1170,22 +1170,22 @@  discard block
 block discarded – undo
1170 1170
         }
1171 1171
     }
1172 1172
 
1173
-    private function can_inject_late( $css_path, $css )
1173
+    private function can_inject_late($css_path, $css)
1174 1174
     {
1175
-        $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path );
1176
-        if ( true !== $this->inject_min_late ) {
1175
+        $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $css_path);
1176
+        if (true !== $this->inject_min_late) {
1177 1177
             // late-inject turned off.
1178 1178
             return false;
1179
-        } elseif ( ( false === strpos( $css_path, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $css_path ) === $css_path ) ) {
1179
+        } elseif ((false === strpos($css_path, 'min.css')) && (str_replace($consider_minified_array, '', $css_path) === $css_path)) {
1180 1180
             // file not minified based on filename & filter.
1181 1181
             return false;
1182
-        } elseif ( false !== strpos( $css, '@import' ) ) {
1182
+        } elseif (false !== strpos($css, '@import')) {
1183 1183
             // can't late-inject files with imports as those need to be aggregated.
1184 1184
             return false;
1185
-        } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) {
1185
+        } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) {
1186 1186
             // don't late-inject CSS with font-src's if fonts are set to be CDN'ed.
1187 1187
             return false;
1188
-        } elseif ( ( ( true == $this->datauris ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) {
1188
+        } elseif (((true == $this->datauris) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) {
1189 1189
             // don't late-inject CSS with images if CDN is set OR if image inlining is on.
1190 1190
             return false;
1191 1191
         } else {
@@ -1203,44 +1203,44 @@  discard block
 block discarded – undo
1203 1203
      *
1204 1204
      * @return bool|string Url pointing to the minified css file or false.
1205 1205
      */
1206
-    public function minify_single( $filepath, $cache_miss = false )
1206
+    public function minify_single($filepath, $cache_miss = false)
1207 1207
     {
1208
-        $contents = $this->prepare_minify_single( $filepath );
1208
+        $contents = $this->prepare_minify_single($filepath);
1209 1209
 
1210
-        if ( empty( $contents ) ) {
1210
+        if (empty($contents)) {
1211 1211
             return false;
1212 1212
         }
1213 1213
 
1214 1214
         // Check cache.
1215
-        $hash  = 'single_' . md5( $contents );
1216
-        $cache = new autoptimizeCache( $hash, 'css' );
1217
-        do_action( 'autoptimize_action_css_hash', $hash );
1215
+        $hash  = 'single_'.md5($contents);
1216
+        $cache = new autoptimizeCache($hash, 'css');
1217
+        do_action('autoptimize_action_css_hash', $hash);
1218 1218
 
1219 1219
         // If not in cache already, minify...
1220
-        if ( ! $cache->check() || $cache_miss ) {
1220
+        if (!$cache->check() || $cache_miss) {
1221 1221
             // Fixurls...
1222
-            $contents = self::fixurls( $filepath, $contents );
1222
+            $contents = self::fixurls($filepath, $contents);
1223 1223
             // CDN-replace any referenced assets if needed...
1224
-            $contents = $this->hide_fontface_and_maybe_cdn( $contents );
1225
-            $contents = $this->replace_urls( $contents );
1226
-            $contents = $this->restore_fontface( $contents );
1224
+            $contents = $this->hide_fontface_and_maybe_cdn($contents);
1225
+            $contents = $this->replace_urls($contents);
1226
+            $contents = $this->restore_fontface($contents);
1227 1227
             // Now minify...
1228 1228
             $cssmin   = new autoptimizeCSSmin();
1229
-            $contents = trim( $cssmin->run( $contents ) );
1229
+            $contents = trim($cssmin->run($contents));
1230 1230
 
1231 1231
             // Check if minified cache content is empty.
1232
-            if ( empty( $contents ) ) {
1232
+            if (empty($contents)) {
1233 1233
                 return false;
1234 1234
             }
1235 1235
 
1236 1236
             // Filter contents of excluded minified CSS.
1237
-            $contents = apply_filters( 'autoptimize_filter_css_single_after_minify', $contents );
1237
+            $contents = apply_filters('autoptimize_filter_css_single_after_minify', $contents);
1238 1238
 
1239 1239
             // Store in cache.
1240
-            $cache->cache( $contents, 'text/css' );
1240
+            $cache->cache($contents, 'text/css');
1241 1241
         }
1242 1242
 
1243
-        $url = $this->build_minify_single_url( $cache );
1243
+        $url = $this->build_minify_single_url($cache);
1244 1244
 
1245 1245
         return $url;
1246 1246
     }
@@ -1260,19 +1260,19 @@  discard block
 block discarded – undo
1260 1260
         return $this->options;
1261 1261
     }
1262 1262
 
1263
-    public function replaceOptions( $options )
1263
+    public function replaceOptions($options)
1264 1264
     {
1265 1265
         $this->options = $options;
1266 1266
     }
1267 1267
 
1268
-    public function setOption( $name, $value )
1268
+    public function setOption($name, $value)
1269 1269
     {
1270
-        $this->options[ $name ] = $value;
1270
+        $this->options[$name] = $value;
1271 1271
         $this->$name            = $value;
1272 1272
     }
1273 1273
 
1274
-    public function getOption( $name )
1274
+    public function getOption($name)
1275 1275
     {
1276
-        return $this->options[ $name ];
1276
+        return $this->options[$name];
1277 1277
     }
1278 1278
 }
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/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.
config/autoptimize_404_handler.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,24 +20,24 @@
 block discarded – undo
20 20
  * to files that don't exist in AO's cache.
21 21
  */
22 22
 
23
-$original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
23
+$original_request = strtok($_SERVER['REQUEST_URI'], '?');
24 24
 
25
-if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
26
-    $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
25
+if (strpos($original_request, 'uucss/uucss-') !== false) {
26
+    $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
27 27
 }
28 28
 
29
-$fallback_target  = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
29
+$fallback_target  = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
30 30
 $ao_cache_dir     = '<!--ao-cache-dir-->';
31
-$js_or_css        = pathinfo( $original_request, PATHINFO_EXTENSION );
32
-$fallback_path    = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
31
+$js_or_css        = pathinfo($original_request, PATHINFO_EXTENSION);
32
+$fallback_path    = $ao_cache_dir.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
33 33
 
34
-if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
34
+if ($original_request !== $fallback_target && file_exists($fallback_path)) {
35 35
     // error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' );
36
-    header( 'HTTP/1.1 301 Moved Permanently' );
37
-    header( 'Location: ' . $fallback_target );
36
+    header('HTTP/1.1 301 Moved Permanently');
37
+    header('Location: '.$fallback_target);
38 38
 } else {
39 39
     // error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' );
40
-    header( 'HTTP/1.1 410 Gone' );
40
+    header('HTTP/1.1 410 Gone');
41 41
 }
42 42
 
43 43
 exit();
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,101 +50,101 @@  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' ) );
67
+        add_action('init', array($this, 'load_textdomain'));
68 68
 
69
-        if ( is_multisite() && is_admin() ) {
69
+        if (is_multisite() && is_admin()) {
70 70
             // Only if multisite and if in admin we want to check if we need to save options on network level.
71
-            add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' );
71
+            add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options');
72 72
         }
73 73
 
74 74
         // register uninstall & deactivation hooks.
75
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
76
-        register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' );
75
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
76
+        register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation');
77 77
     }
78 78
 
79 79
     public function load_textdomain()
80 80
     {
81
-        load_plugin_textdomain( 'autoptimize' );
81
+        load_plugin_textdomain('autoptimize');
82 82
     }
83 83
 
84 84
     public function setup()
85 85
     {
86 86
         // Do we gzip in php when caching or is the webserver doing it?
87
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) );
87
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip'));
88 88
 
89 89
         // These can be overridden by specifying them in wp-config.php or such.
90
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
91
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
90
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
91
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
92 92
         }
93
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
94
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
93
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
94
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
95 95
         }
96
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
97
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
96
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
97
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
98 98
         }
99 99
         // Note: trailing slash is not optional!
100
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
101
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
100
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
101
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
102 102
         }
103 103
 
104
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
104
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
105 105
 
106
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
107
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
108
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
106
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
107
+            if (function_exists('domain_mapping_siteurl')) {
108
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
109 109
             } else {
110
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
110
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
111 111
             }
112 112
         }
113
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
114
-            if ( function_exists( 'get_original_url' ) ) {
115
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
113
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
114
+            if (function_exists('get_original_url')) {
115
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
116 116
             } else {
117
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
117
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
118 118
             }
119 119
         }
120
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
121
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
120
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
121
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
122 122
                 $blog_id = get_current_blog_id();
123
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
123
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
124 124
             } else {
125
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
125
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
126 126
             }
127 127
         }
128
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
129
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
128
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
129
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
130 130
         }
131
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
132
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
131
+        if (!defined('AUTOPTIMIZE_HASH')) {
132
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
133 133
         }
134
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
135
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
134
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
135
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
136 136
         }
137 137
 
138 138
         // Multibyte-capable string replacements are available with a filter.
139 139
         // Also requires 'mbstring' extension.
140
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
141
-        if ( $with_mbstring ) {
142
-            autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) );
140
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
141
+        if ($with_mbstring) {
142
+            autoptimizeUtils::mbstring_available(\extension_loaded('mbstring'));
143 143
         } else {
144
-            autoptimizeUtils::mbstring_available( false );
144
+            autoptimizeUtils::mbstring_available(false);
145 145
         }
146 146
 
147
-        do_action( 'autoptimize_setup_done' );
147
+        do_action('autoptimize_setup_done');
148 148
     }
149 149
 
150 150
     /**
@@ -154,61 +154,61 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public function version_upgrades_check()
156 156
     {
157
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
157
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
158 158
     }
159 159
 
160 160
     public function check_cache_and_run()
161 161
     {
162
-        if ( autoptimizeCache::cacheavail() ) {
162
+        if (autoptimizeCache::cacheavail()) {
163 163
             $conf = autoptimizeConfig::instance();
164
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) {
165
-                if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) {
164
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) {
165
+                if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) {
166 166
                     // Hook into WordPress frontend.
167
-                    if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
167
+                    if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
168 168
                         add_action(
169 169
                             'init',
170
-                            array( $this, 'start_buffering' ),
170
+                            array($this, 'start_buffering'),
171 171
                             self::INIT_EARLIER_PRIORITY
172 172
                         );
173 173
                     } else {
174
-                        if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
175
-                            define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
174
+                        if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
175
+                            define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
176 176
                         }
177 177
                         add_action(
178
-                            constant( 'AUTOPTIMIZE_HOOK_INTO' ),
179
-                            array( $this, 'start_buffering' ),
178
+                            constant('AUTOPTIMIZE_HOOK_INTO'),
179
+                            array($this, 'start_buffering'),
180 180
                             self::DEFAULT_HOOK_PRIORITY
181 181
                         );
182 182
                     }
183 183
                 }
184 184
 
185 185
                 // And disable Jetpack's site accelerator if JS or CSS opt. are active.
186
-                if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) {
187
-                    add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
186
+                if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) {
187
+                    add_filter('jetpack_force_disable_site_accelerator', '__return_true');
188 188
                 }
189 189
             }
190 190
         } else {
191
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
191
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
192 192
         }
193 193
     }
194 194
 
195 195
     public function maybe_run_ao_extra()
196 196
     {
197
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
197
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
198 198
             $ao_imgopt = new autoptimizeImages();
199 199
             $ao_imgopt->run();
200 200
             $ao_extra = new autoptimizeExtra();
201 201
             $ao_extra->run();
202 202
 
203 203
             // And show the imgopt notice.
204
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
204
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
205 205
         }
206 206
     }
207 207
 
208 208
     public function maybe_run_partners_tab()
209 209
     {
210 210
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
211
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
211
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
212 212
             new autoptimizePartners();
213 213
         }
214 214
     }
@@ -216,22 +216,22 @@  discard block
 block discarded – undo
216 216
     public function maybe_run_criticalcss()
217 217
     {
218 218
         // Loads criticalcss if the power-up is not active and if the filter returns true.
219
-        if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
219
+        if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) {
220 220
             new autoptimizeCriticalCSSBase();
221 221
         }
222 222
     }
223 223
 
224 224
     public function maybe_run_notfound_fallback()
225 225
     {
226
-        if ( autoptimizeCache::do_fallback() ) {
227
-            add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) );
226
+        if (autoptimizeCache::do_fallback()) {
227
+            add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback'));
228 228
         }
229 229
     }
230 230
 
231 231
     public function hook_page_cache_purge()
232 232
     {
233 233
         // hook into a collection of page cache purge actions if filter allows.
234
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
234
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
235 235
             $page_cache_purge_actions = array(
236 236
                 'after_rocket_clean_domain', // exists.
237 237
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
                 'wpo_cache_flush', // wp-optimize.
247 247
                 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper.
248 248
             );
249
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
250
-            foreach ( $page_cache_purge_actions as $purge_action ) {
251
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
249
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
250
+            foreach ($page_cache_purge_actions as $purge_action) {
251
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
252 252
             }
253 253
         }
254 254
     }
@@ -260,38 +260,38 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function start_buffering()
262 262
     {
263
-        if ( $this->should_buffer() ) {
263
+        if ($this->should_buffer()) {
264 264
 
265 265
             // Load speedupper conditionally (true by default).
266
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
266
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
267 267
                 $ao_speedupper = new autoptimizeSpeedupper();
268 268
             }
269 269
 
270 270
             $conf = autoptimizeConfig::instance();
271 271
 
272
-            if ( $conf->get( 'autoptimize_js' ) ) {
273
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
274
-                    define( 'CONCATENATE_SCRIPTS', false );
272
+            if ($conf->get('autoptimize_js')) {
273
+                if (!defined('CONCATENATE_SCRIPTS')) {
274
+                    define('CONCATENATE_SCRIPTS', false);
275 275
                 }
276
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
277
-                    define( 'COMPRESS_SCRIPTS', false );
276
+                if (!defined('COMPRESS_SCRIPTS')) {
277
+                    define('COMPRESS_SCRIPTS', false);
278 278
                 }
279 279
             }
280 280
 
281
-            if ( $conf->get( 'autoptimize_css' ) ) {
282
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
283
-                    define( 'COMPRESS_CSS', false );
281
+            if ($conf->get('autoptimize_css')) {
282
+                if (!defined('COMPRESS_CSS')) {
283
+                    define('COMPRESS_CSS', false);
284 284
                 }
285 285
             }
286 286
 
287
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
288
-                while ( ob_get_level() > 0 ) {
287
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
288
+                while (ob_get_level() > 0) {
289 289
                     ob_end_clean();
290 290
                 }
291 291
             }
292 292
 
293 293
             // Now, start the real thing!
294
-            ob_start( array( $this, 'end_buffering' ) );
294
+            ob_start(array($this, 'end_buffering'));
295 295
         }
296 296
     }
297 297
 
@@ -302,31 +302,31 @@  discard block
 block discarded – undo
302 302
      *                          deciding once per request (for use in tests).
303 303
      * @return bool
304 304
      */
305
-    public static function should_buffer( $doing_tests = false )
305
+    public static function should_buffer($doing_tests = false)
306 306
     {
307 307
         static $do_buffering = null;
308 308
 
309 309
         // Only check once in case we're called multiple times by others but
310 310
         // still allows multiple calls when doing tests.
311
-        if ( null === $do_buffering || $doing_tests ) {
311
+        if (null === $do_buffering || $doing_tests) {
312 312
 
313 313
             $ao_noptimize = false;
314 314
 
315 315
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
316
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
316
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
317 317
                 $ao_noptimize = true;
318 318
             }
319 319
 
320 320
             // Skip checking query strings if they're disabled.
321
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
321
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
322 322
                 // Check for `ao_noptimize` (and other) keys in the query string
323 323
                 // to get non-optimized page for debugging.
324 324
                 $keys = array(
325 325
                     'ao_noptimize',
326 326
                     'ao_noptirocket',
327 327
                 );
328
-                foreach ( $keys as $key ) {
329
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
328
+                foreach ($keys as $key) {
329
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
330 330
                         $ao_noptimize = true;
331 331
                         break;
332 332
                     }
@@ -334,15 +334,15 @@  discard block
 block discarded – undo
334 334
             }
335 335
 
336 336
             // If setting says not to optimize logged in user and user is logged in...
337
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
337
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
338 338
                 $ao_noptimize = true;
339 339
             }
340 340
 
341 341
             // If setting says not to optimize cart/checkout.
342
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) {
342
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) {
343 343
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
344
-                foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
345
-                    if ( function_exists( $func ) && $func() ) {
344
+                foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
345
+                    if (function_exists($func) && $func()) {
346 346
                         $ao_noptimize = true;
347 347
                         break;
348 348
                     }
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
             }
351 351
 
352 352
             // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
353
-            if ( false === $ao_noptimize ) {
354
-                $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
355
-                foreach ( $_qs_pagebuilders as $_pagebuilder ) {
356
-                    if ( array_key_exists( $_pagebuilder, $_GET ) ) {
353
+            if (false === $ao_noptimize) {
354
+                $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor');
355
+                foreach ($_qs_pagebuilders as $_pagebuilder) {
356
+                    if (array_key_exists($_pagebuilder, $_GET)) {
357 357
                         $ao_noptimize = true;
358 358
                         break;
359 359
                     }
@@ -362,16 +362,16 @@  discard block
 block discarded – undo
362 362
 
363 363
             // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
364 364
             // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
365
-            if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
365
+            if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
366 366
                 $ao_noptimize = true;
367 367
             }
368 368
 
369 369
             // And finally allows blocking of autoptimization on your own terms regardless of above decisions.
370
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
370
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
371 371
 
372 372
             // Check for site being previewed in the Customizer (available since WP 4.0).
373 373
             $is_customize_preview = false;
374
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
374
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
375 375
                 $is_customize_preview = is_customize_preview();
376 376
             }
377 377
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
              * while the main query hasn't been ran yet. Thats why we use
383 383
              * AUTOPTIMIZE_INIT_EARLIER in tests.
384 384
              */
385
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview );
385
+            $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview);
386 386
         }
387 387
 
388 388
         return $do_buffering;
@@ -395,25 +395,25 @@  discard block
 block discarded – undo
395 395
      *
396 396
      * @return bool
397 397
      */
398
-    public function is_valid_buffer( $content )
398
+    public function is_valid_buffer($content)
399 399
     {
400 400
         // Defaults to true.
401 401
         $valid = true;
402 402
 
403
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
404
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) );
405
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 );
406
-        $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) );
403
+        $has_no_html_tag    = (false === stripos($content, '<html'));
404
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet'));
405
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0);
406
+        $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->'));
407 407
 
408
-        if ( $has_no_html_tag ) {
408
+        if ($has_no_html_tag) {
409 409
             // Can't be valid amp markup without an html tag preceding it.
410 410
             $is_amp_markup = false;
411 411
         } else {
412
-            $is_amp_markup = self::is_amp_markup( $content );
412
+            $is_amp_markup = self::is_amp_markup($content);
413 413
         }
414 414
 
415 415
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
416
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) {
416
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) {
417 417
             $valid = false;
418 418
         }
419 419
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
      *
429 429
      * @return bool
430 430
      */
431
-    public static function is_amp_markup( $content )
431
+    public static function is_amp_markup($content)
432 432
     {
433 433
         // Short-circuit if the page is already AMP from the start.
434 434
         if (
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
         }
447 447
 
448 448
         // Or else short-circuit if the AMP plugin will be processing the output to be an AMP page.
449
-        if ( function_exists( 'amp_is_request' ) ) {
449
+        if (function_exists('amp_is_request')) {
450 450
             return amp_is_request(); // For AMP plugin v2.0+.
451
-        } elseif ( function_exists( 'is_amp_endpoint' ) ) {
451
+        } elseif (function_exists('is_amp_endpoint')) {
452 452
             return is_amp_endpoint(); // For older/other AMP plugins (still supported in 2.0 as an alias).
453 453
         }
454 454
 
@@ -463,10 +463,10 @@  discard block
 block discarded – undo
463 463
      *
464 464
      * @return string
465 465
      */
466
-    public function end_buffering( $content )
466
+    public function end_buffering($content)
467 467
     {
468 468
         // Bail early without modifying anything if we can't handle the content.
469
-        if ( ! $this->is_valid_buffer( $content ) ) {
469
+        if (!$this->is_valid_buffer($content)) {
470 470
             return $content;
471 471
         }
472 472
 
@@ -474,74 +474,74 @@  discard block
 block discarded – undo
474 474
 
475 475
         // Determine what needs to be ran.
476 476
         $classes = array();
477
-        if ( $conf->get( 'autoptimize_js' ) ) {
477
+        if ($conf->get('autoptimize_js')) {
478 478
             $classes[] = 'autoptimizeScripts';
479 479
         }
480
-        if ( $conf->get( 'autoptimize_css' ) ) {
480
+        if ($conf->get('autoptimize_css')) {
481 481
             $classes[] = 'autoptimizeStyles';
482 482
         }
483
-        if ( $conf->get( 'autoptimize_html' ) ) {
483
+        if ($conf->get('autoptimize_html')) {
484 484
             $classes[] = 'autoptimizeHTML';
485 485
         }
486 486
 
487 487
         $classoptions = array(
488 488
             'autoptimizeScripts' => array(
489
-                'aggregate'           => $conf->get( 'autoptimize_js_aggregate' ),
490
-                'defer_not_aggregate' => $conf->get( 'autoptimize_js_defer_not_aggregate' ),
491
-                'justhead'            => $conf->get( 'autoptimize_js_justhead' ),
492
-                'forcehead'           => $conf->get( 'autoptimize_js_forcehead' ),
493
-                'trycatch'            => $conf->get( 'autoptimize_js_trycatch' ),
494
-                'js_exclude'          => $conf->get( 'autoptimize_js_exclude' ),
495
-                'cdn_url'             => $conf->get( 'autoptimize_cdn_url' ),
496
-                'include_inline'      => $conf->get( 'autoptimize_js_include_inline' ),
497
-                'minify_excluded'     => $conf->get( 'autoptimize_minify_excluded' ),
489
+                'aggregate'           => $conf->get('autoptimize_js_aggregate'),
490
+                'defer_not_aggregate' => $conf->get('autoptimize_js_defer_not_aggregate'),
491
+                'justhead'            => $conf->get('autoptimize_js_justhead'),
492
+                'forcehead'           => $conf->get('autoptimize_js_forcehead'),
493
+                'trycatch'            => $conf->get('autoptimize_js_trycatch'),
494
+                'js_exclude'          => $conf->get('autoptimize_js_exclude'),
495
+                'cdn_url'             => $conf->get('autoptimize_cdn_url'),
496
+                'include_inline'      => $conf->get('autoptimize_js_include_inline'),
497
+                'minify_excluded'     => $conf->get('autoptimize_minify_excluded'),
498 498
             ),
499 499
             'autoptimizeStyles'  => array(
500
-                'aggregate'       => $conf->get( 'autoptimize_css_aggregate' ),
501
-                'justhead'        => $conf->get( 'autoptimize_css_justhead' ),
502
-                'datauris'        => $conf->get( 'autoptimize_css_datauris' ),
503
-                'defer'           => $conf->get( 'autoptimize_css_defer' ),
504
-                'defer_inline'    => $conf->get( 'autoptimize_css_defer_inline' ),
505
-                'inline'          => $conf->get( 'autoptimize_css_inline' ),
506
-                'css_exclude'     => $conf->get( 'autoptimize_css_exclude' ),
507
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
508
-                'include_inline'  => $conf->get( 'autoptimize_css_include_inline' ),
509
-                'nogooglefont'    => $conf->get( 'autoptimize_css_nogooglefont' ),
510
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
500
+                'aggregate'       => $conf->get('autoptimize_css_aggregate'),
501
+                'justhead'        => $conf->get('autoptimize_css_justhead'),
502
+                'datauris'        => $conf->get('autoptimize_css_datauris'),
503
+                'defer'           => $conf->get('autoptimize_css_defer'),
504
+                'defer_inline'    => $conf->get('autoptimize_css_defer_inline'),
505
+                'inline'          => $conf->get('autoptimize_css_inline'),
506
+                'css_exclude'     => $conf->get('autoptimize_css_exclude'),
507
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
508
+                'include_inline'  => $conf->get('autoptimize_css_include_inline'),
509
+                'nogooglefont'    => $conf->get('autoptimize_css_nogooglefont'),
510
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
511 511
             ),
512 512
             'autoptimizeHTML'    => array(
513
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
513
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
514 514
             ),
515 515
         );
516 516
 
517
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
517
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
518 518
 
519 519
         // Run the classes!
520
-        foreach ( $classes as $name ) {
521
-            $instance = new $name( $content );
522
-            if ( $instance->read( $classoptions[ $name ] ) ) {
520
+        foreach ($classes as $name) {
521
+            $instance = new $name($content);
522
+            if ($instance->read($classoptions[$name])) {
523 523
                 $instance->minify();
524 524
                 $instance->cache();
525 525
                 $content = $instance->getcontent();
526 526
             }
527
-            unset( $instance );
527
+            unset($instance);
528 528
         }
529 529
 
530
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
530
+        $content = apply_filters('autoptimize_html_after_minify', $content);
531 531
 
532 532
         return $content;
533 533
     }
534 534
 
535
-    public static function autoptimize_nobuffer_optimize( $html_in ) {
535
+    public static function autoptimize_nobuffer_optimize($html_in) {
536 536
         $html_out = $html_in;
537 537
 
538
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
538
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
539 539
             $ao_speedupper = new autoptimizeSpeedupper();
540 540
         }
541 541
 
542
-        $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
543
-        if ( $self->should_buffer() ) {
544
-            $html_out = $self->end_buffering( $html_in );
542
+        $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
543
+        if ($self->should_buffer()) {
544
+            $html_out = $self->end_buffering($html_in);
545 545
         }
546 546
         return $html_out;
547 547
     }
@@ -605,45 +605,45 @@  discard block
 block discarded – undo
605 605
             'autoptimize_ccss_unloadccss',
606 606
         );
607 607
 
608
-        if ( ! is_multisite() ) {
609
-            foreach ( $delete_options as $del_opt ) {
610
-                delete_option( $del_opt );
608
+        if (!is_multisite()) {
609
+            foreach ($delete_options as $del_opt) {
610
+                delete_option($del_opt);
611 611
             }
612 612
             autoptimizeMain::remove_cronjobs();
613 613
         } else {
614 614
             global $wpdb;
615
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
615
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
616 616
             $original_blog_id = get_current_blog_id();
617
-            foreach ( $blog_ids as $blog_id ) {
618
-                switch_to_blog( $blog_id );
619
-                foreach ( $delete_options as $del_opt ) {
620
-                    delete_option( $del_opt );
617
+            foreach ($blog_ids as $blog_id) {
618
+                switch_to_blog($blog_id);
619
+                foreach ($delete_options as $del_opt) {
620
+                    delete_option($del_opt);
621 621
                 }
622 622
                 autoptimizeMain::remove_cronjobs();
623 623
             }
624
-            switch_to_blog( $original_blog_id );
624
+            switch_to_blog($original_blog_id);
625 625
         }
626 626
 
627 627
         // Remove AO CCSS cached files and directory.
628
-        $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/';
629
-        if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) {
628
+        $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/';
629
+        if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) {
630 630
             // fixme: should check for subdirs when in multisite and remove contents of those as well.
631
-            array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) );
632
-            rmdir( $ao_ccss_dir );
631
+            array_map('unlink', glob($ao_ccss_dir.'*.{css,html,json,log,zip,lock}', GLOB_BRACE));
632
+            rmdir($ao_ccss_dir);
633 633
         }
634 634
     }
635 635
 
636 636
     public static function on_deactivation()
637 637
     {
638
-        if ( is_multisite() && is_network_admin() ) {
638
+        if (is_multisite() && is_network_admin()) {
639 639
             global $wpdb;
640
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
640
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
641 641
             $original_blog_id = get_current_blog_id();
642
-            foreach ( $blog_ids as $blog_id ) {
643
-                switch_to_blog( $blog_id );
642
+            foreach ($blog_ids as $blog_id) {
643
+                switch_to_blog($blog_id);
644 644
                 autoptimizeMain::remove_cronjobs();
645 645
             }
646
-            switch_to_blog( $original_blog_id );
646
+            switch_to_blog($original_blog_id);
647 647
         } else {
648 648
             autoptimizeMain::remove_cronjobs();
649 649
         }
@@ -652,9 +652,9 @@  discard block
 block discarded – undo
652 652
 
653 653
     public static function remove_cronjobs() {
654 654
         // Remove scheduled events.
655
-        foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) {
656
-            if ( wp_get_schedule( $_event ) ) {
657
-                wp_clear_scheduled_hook( $_event );
655
+        foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) {
656
+            if (wp_get_schedule($_event)) {
657
+                wp_clear_scheduled_hook($_event);
658 658
             }
659 659
         }
660 660
     }
@@ -663,35 +663,35 @@  discard block
 block discarded – undo
663 663
     {
664 664
         echo '<div class="error"><p>';
665 665
         // Translators: %s is the cache directory location.
666
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
666
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
667 667
         echo '</p></div>';
668 668
     }
669 669
 
670 670
     public static function notice_installed()
671 671
     {
672 672
         echo '<div class="updated"><p>';
673
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
673
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
674 674
         echo '</p></div>';
675 675
     }
676 676
 
677 677
     public static function notice_updated()
678 678
     {
679 679
         echo '<div class="updated"><p>';
680
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
680
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
681 681
         echo '</p></div>';
682 682
     }
683 683
 
684 684
     public static function notice_plug_imgopt()
685 685
     {
686 686
         // Translators: the URL added points to the Autopmize Extra settings.
687
-        $_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>' );
688
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
687
+        $_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>');
688
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
689 689
         $_ao_imgopt_launch_ok        = autoptimizeImages::launch_ok_wrapper();
690 690
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
691 691
         $_ao_imgopt_active           = autoptimizeImages::imgopt_active();
692 692
 
693
-        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 ) ) {
694
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
693
+        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)) {
694
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
695 695
             echo $_ao_imgopt_plug_notice;
696 696
             echo '</p></div>';
697 697
         }
Please login to merge, or discard this patch.