Completed
Push — master ( 2ef6f7...6fcb0f )
by frank
01:45
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') {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                     rmark = '';
73 73
                 }
74 74
             }
75
-            jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</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>");
75
+            jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</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>");
76 76
             jQuery("#" + nodeId + "_edit").click(function(){addEditRow(this.id);});
77 77
             jQuery("#" + nodeId + "_remove").click(function(){confirmRemove(this.id);});
78 78
         })
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
         height:235,
86 86
         modal: true,
87 87
         buttons: {
88
-            "<?php _e( 'Delete', 'autoptimize' ); ?>": function() {
88
+            "<?php _e('Delete', 'autoptimize'); ?>": function() {
89 89
                 removeRow(idToRemove);
90 90
                 updateAfterChange();
91 91
                 jQuery( this ).dialog( "close" );
92 92
             },
93
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
93
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
94 94
                 jQuery( this ).dialog( "close" );
95 95
             }
96 96
         }
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
         height:235,
104 104
         modal: true,
105 105
         buttons: {
106
-            "<?php _e( 'Delete All', 'autoptimize' ); ?>": function() {
106
+            "<?php _e('Delete All', 'autoptimize'); ?>": function() {
107 107
                 critCssArray={'paths':[],'types':[]};
108 108
                 drawTable(critCssArray);
109 109
                 updateAfterChange();
110 110
                 removeAllCcssFilesOnServer();
111 111
                 jQuery( this ).dialog( "close" );
112 112
             },
113
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
113
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
114 114
                 jQuery( this ).dialog( "close" );
115 115
             }
116 116
         }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 
128 128
     var data = {
129 129
         'action': 'rm_critcss',
130
-        'critcss_rm_nonce': '<?php echo wp_create_nonce( 'rm_critcss_nonce' ); ?>',
130
+        'critcss_rm_nonce': '<?php echo wp_create_nonce('rm_critcss_nonce'); ?>',
131 131
         'cachebustingtimestamp': new Date().getTime(),
132 132
         'critcssfile': crit_file
133 133
     };
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 function removeAllCcssFilesOnServer() {
149 149
     var data = {
150 150
         'action': 'rm_critcss_all',
151
-        'critcss_rm_all_nonce': '<?php echo wp_create_nonce( 'rm_critcss_all_nonce' ); ?>',
151
+        'critcss_rm_all_nonce': '<?php echo wp_create_nonce('rm_critcss_all_nonce'); ?>',
152 152
         'cachebustingtimestamp': new Date().getTime()
153 153
     };
154 154
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 function addEditRow(idToEdit) {
169 169
     resetForm();
170 170
     if (idToEdit) {
171
-        dialogTitle="<?php _e( 'Edit Critical CSS Rule', 'autoptimize' ); ?>";
171
+        dialogTitle="<?php _e('Edit Critical CSS Rule', 'autoptimize'); ?>";
172 172
 
173 173
         splits=idToEdit.split(/_/);
174 174
         crit_type=splits[0];
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         jQuery("#critcss_addedit_id").val(idToEdit);
180 180
         jQuery("#critcss_addedit_type").val(crit_type);
181 181
         jQuery("#critcss_addedit_file").val(crit_file);
182
-        jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'Loading critical CSS...', 'autoptimize' ); ?>");
182
+        jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('Loading critical CSS...', 'autoptimize'); ?>");
183 183
         jQuery("#critcss_addedit_type").attr("disabled",true);
184 184
 
185 185
         if (crit_type==="paths") {
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
         var data = {
196 196
             'action': 'fetch_critcss',
197
-            'critcss_fetch_nonce': '<?php echo wp_create_nonce( 'fetch_critcss_nonce' ); ?>',
197
+            'critcss_fetch_nonce': '<?php echo wp_create_nonce('fetch_critcss_nonce'); ?>',
198 198
             'cachebustingtimestamp': new Date().getTime(),
199 199
             'critcssfile': crit_file
200 200
         };
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             }
209 209
         });
210 210
     } else {
211
-        dialogTitle="<?php _e( 'Add Critical CSS Rule', 'autotimize' ); ?>";
211
+        dialogTitle="<?php _e('Add Critical CSS Rule', 'autotimize'); ?>";
212 212
 
213 213
         // default: paths, hide content type field
214 214
         jQuery("#critcss_addedit_type").val("paths");
@@ -219,11 +219,11 @@  discard block
 block discarded – undo
219 219
             if(this.value==="types") {
220 220
                 jQuery("#critcss_addedit_pagetype_wrapper").show();
221 221
                 jQuery("#critcss_addedit_path_wrapper").hide();
222
-                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' ); ?>");
222
+                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'); ?>");
223 223
             } else {
224 224
                 jQuery("#critcss_addedit_path_wrapper").show();
225 225
                 jQuery("#critcss_addedit_pagetype_wrapper").hide();
226
-                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' ); ?>");
226
+                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'); ?>");
227 227
             }
228 228
         });
229 229
     }
@@ -235,21 +235,21 @@  discard block
 block discarded – undo
235 235
         title: dialogTitle,
236 236
         modal: true,
237 237
         buttons: {
238
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
238
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
239 239
                 rpath = jQuery("#critcss_addedit_path").val();
240 240
                 rtype = jQuery("#critcss_addedit_pagetype option:selected").val();
241 241
                 rccss = jQuery("#critcss_addedit_css").val();
242 242
                 console.log('rpath: ' + rpath, 'rtype: ' + rtype, 'rccss: ' + rccss);
243 243
                 if (rpath === '' && rtype === '') {
244
-                    alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize' ); ?>');
244
+                    alert('<?php _e("RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize'); ?>');
245 245
                 } else if (rtype !== '' && rccss == '') {
246
-                    alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize' ); ?>');
246
+                    alert('<?php _e("RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize'); ?>');
247 247
                 } else {
248 248
                     saveEditCritCss();
249 249
                     jQuery(this).dialog('close');
250 250
                 }
251 251
             },
252
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
252
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
253 253
                 resetForm();
254 254
                 jQuery(this).dialog("close");
255 255
             }
@@ -263,15 +263,15 @@  discard block
 block discarded – undo
263 263
         autoOpen: true,
264 264
         height: 505,
265 265
         width: 700,
266
-        title: "<?php _e( 'Default Critical CSS', 'autoptimize' ); ?>",
266
+        title: "<?php _e('Default Critical CSS', 'autoptimize'); ?>",
267 267
         modal: true,
268 268
         buttons: {
269
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
269
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
270 270
                 document.getElementById("autoptimize_css_defer_inline").value=document.getElementById("dummyDefault").value;
271 271
                 jQuery("#unSavedWarning").show();
272 272
                 jQuery("#default_critcss_wrapper").dialog( "close" );
273 273
             },
274
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
274
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
275 275
                 jQuery("#default_critcss_wrapper").dialog( "close" );
276 276
             }
277 277
         }
@@ -284,15 +284,15 @@  discard block
 block discarded – undo
284 284
         autoOpen: true,
285 285
         height: 505,
286 286
         width: 700,
287
-        title: "<?php _e( 'Additional Critical CSS', 'autoptimize' ); ?>",
287
+        title: "<?php _e('Additional Critical CSS', 'autoptimize'); ?>",
288 288
         modal: true,
289 289
         buttons: {
290
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
290
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
291 291
                 document.getElementById("autoptimize_ccss_additional").value=document.getElementById("dummyAdditional").value;
292 292
                 jQuery("#unSavedWarning").show();
293 293
                 jQuery("#additional_critcss_wrapper").dialog( "close" );
294 294
             },
295
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
295
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
296 296
                 jQuery("#additional_critcss_wrapper").dialog( "close" );
297 297
             }
298 298
         }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
     critCssArray[critcsstype][critcsstarget].file=critcssfile;
329 329
 
330 330
     <?php
331
-    if ( $ao_ccss_debug ) {
331
+    if ($ao_ccss_debug) {
332 332
         echo "console.log('[RULE PROPERTIES] Type:', critcsstype, ', Target:', critcsstarget, ', Hash:', 0, ', File:',  critcssfile);";
333 333
     }
334 334
     ?>
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
     var data = {
339 339
         'action': 'save_critcss',
340
-        'critcss_save_nonce': '<?php echo wp_create_nonce( 'save_critcss_nonce' ); ?>',
340
+        'critcss_save_nonce': '<?php echo wp_create_nonce('save_critcss_nonce'); ?>',
341 341
         'critcssfile': critcssfile,
342 342
         'critcsscontents': critcsscontents
343 343
     };
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 }
363 363
 
364 364
 function resetForm() {
365
-    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' ); ?>");
365
+    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'); ?>");
366 366
     jQuery("#critcss_addedit_type").attr("disabled",false);
367 367
     jQuery("#critcss_addedit_path_wrapper").show();
368 368
     jQuery("#critcss_addedit_id").val("");
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_rules.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 ?>
14 14
     <ul id="rules-panel">
15 15
         <li class="itemDetail">
16
-            <h2 class="itemTitle"><?php _e( 'Rules', 'autoptimize' ); ?></h2>
16
+            <h2 class="itemTitle"><?php _e('Rules', 'autoptimize'); ?></h2>
17 17
 
18 18
             <!-- BEGIN Rule dialogs -->
19 19
             <!-- Unsaved dialog -->
20 20
             <div id="unSavedWarning" class="hidden updated settings-error notice notice-warning is-dismissible">
21
-                <p><?php _e( "<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize' ); ?></p>
21
+                <p><?php _e("<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize'); ?></p>
22 22
             </div>
23 23
 
24 24
             <!-- Create/edit rule dialog -->
@@ -26,97 +26,97 @@  discard block
 block discarded – undo
26 26
                 <table class="form-table rules">
27 27
                     <tr id="critcss_addedit_type_wrapper">
28 28
                         <th scope="row">
29
-                            <?php _e( 'Rule Type', 'autoptimize' ); ?>
29
+                            <?php _e('Rule Type', 'autoptimize'); ?>
30 30
                         </th>
31 31
                         <td>
32 32
                             <select id="critcss_addedit_type" style="width:100%;">
33
-                                <option value="paths"><?php _e( 'Path', 'autoptimize' ); ?></option>
34
-                                <option value="types"><?php _e( 'Conditional Tag', 'autoptimize' ); ?></option>
33
+                                <option value="paths"><?php _e('Path', 'autoptimize'); ?></option>
34
+                                <option value="types"><?php _e('Conditional Tag', 'autoptimize'); ?></option>
35 35
                             </select>
36 36
                         </td>
37 37
                     </tr>
38 38
                     <tr id="critcss_addedit_path_wrapper">
39 39
                         <th scope="row">
40
-                            <?php _e( 'String in Path', 'autoptimize' ); ?>
40
+                            <?php _e('String in Path', 'autoptimize'); ?>
41 41
                         </th>
42 42
                         <td>
43
-                            <input type="text" id="critcss_addedit_path" placeholder="<?php _e( "Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize' ); ?>" style="width:100%;" value="">
43
+                            <input type="text" id="critcss_addedit_path" placeholder="<?php _e("Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize'); ?>" style="width:100%;" value="">
44 44
                         </td>
45 45
                     </tr>
46 46
                     <tr id="critcss_addedit_pagetype_wrapper">
47 47
                         <th scope="row">
48
-                            <?php _e( 'Conditional Tag, Custom Post Type or Page Template', 'autoptimize' ); ?>
48
+                            <?php _e('Conditional Tag, Custom Post Type or Page Template', 'autoptimize'); ?>
49 49
                         </th>
50 50
                         <td>
51 51
                             <select id="critcss_addedit_pagetype" style="width:100%;">
52
-                                <option value="" disabled selected><?php _e( 'Select from the list below...', 'autoptimize' ); ?></option>
53
-                                <optgroup label="<?php _e( 'Standard Conditional Tags', 'autoptimize' ); ?>">
52
+                                <option value="" disabled selected><?php _e('Select from the list below...', 'autoptimize'); ?></option>
53
+                                <optgroup label="<?php _e('Standard Conditional Tags', 'autoptimize'); ?>">
54 54
                                     <?php
55 55
                                     // Render grouped simple conditional tags.
56
-                                    foreach ( $ao_ccss_types as $ctag ) {
57
-                                        $optgrp = substr( $ctag, 0, 3 );
58
-                                        if ( substr( $ctag, 0, 3 ) === 'is_' ) {
59
-                                            echo '<option value="' . $ctag . '">' . $ctag . '</option>';
56
+                                    foreach ($ao_ccss_types as $ctag) {
57
+                                        $optgrp = substr($ctag, 0, 3);
58
+                                        if (substr($ctag, 0, 3) === 'is_') {
59
+                                            echo '<option value="'.$ctag.'">'.$ctag.'</option>';
60 60
                                         }
61
-                                        $prevgrp = substr( $ctag, 0, 3 );
61
+                                        $prevgrp = substr($ctag, 0, 3);
62 62
                                     }
63 63
 
64 64
                                     // Render grouped custom post types, templates and specific conditional tags.
65
-                                    foreach ( $ao_ccss_types as $type ) {
66
-                                        $optgrp = substr( $type, 0, 3 );
65
+                                    foreach ($ao_ccss_types as $type) {
66
+                                        $optgrp = substr($type, 0, 3);
67 67
 
68 68
                                         // Option groups labels.
69
-                                        if ( $optgrp !== $prevgrp && 'is_' !== $optgrp ) {
69
+                                        if ($optgrp !== $prevgrp && 'is_' !== $optgrp) {
70 70
                                             ?>
71 71
                                             </optgroup>
72 72
                                             <?php
73
-                                            if ( substr( $type, 0, 12 ) === 'custom_post_' ) {
73
+                                            if (substr($type, 0, 12) === 'custom_post_') {
74 74
                                                 ?>
75
-                                                <optgroup label="<?php _e( 'Custom Post Types', 'autoptimize' ); ?>">
75
+                                                <optgroup label="<?php _e('Custom Post Types', 'autoptimize'); ?>">
76 76
                                                 <?php
77
-                                            } elseif ( substr( $type, 0, 9 ) === 'template_' ) {
77
+                                            } elseif (substr($type, 0, 9) === 'template_') {
78 78
                                                 ?>
79
-                                                <optgroup label="<?php _e( 'Page Templates', 'autoptimize' ); ?>">
79
+                                                <optgroup label="<?php _e('Page Templates', 'autoptimize'); ?>">
80 80
                                                 <?php
81
-                                            } elseif ( substr( $type, 0, 4 ) === 'bbp_' ) {
81
+                                            } elseif (substr($type, 0, 4) === 'bbp_') {
82 82
                                                 ?>
83
-                                                <optgroup label="<?php _e( 'BBPress Conditional Tags', 'autoptimize' ); ?>">
83
+                                                <optgroup label="<?php _e('BBPress Conditional Tags', 'autoptimize'); ?>">
84 84
                                                 <?php
85
-                                            } elseif ( substr( $type, 0, 3 ) === 'bp_' ) {
85
+                                            } elseif (substr($type, 0, 3) === 'bp_') {
86 86
                                                 ?>
87
-                                                <optgroup label="<?php _e( 'BuddyPress Conditional Tags', 'autoptimize' ); ?>">
87
+                                                <optgroup label="<?php _e('BuddyPress Conditional Tags', 'autoptimize'); ?>">
88 88
                                                 <?php
89
-                                            } elseif ( substr( $type, 0, 4 ) === 'edd_' ) {
89
+                                            } elseif (substr($type, 0, 4) === 'edd_') {
90 90
                                                 ?>
91
-                                                <optgroup label="<?php _e( 'Easy Digital Downloads Conditional Tags', 'autoptimize' ); ?>">
91
+                                                <optgroup label="<?php _e('Easy Digital Downloads Conditional Tags', 'autoptimize'); ?>">
92 92
                                                 <?php
93
-                                            } elseif ( substr( $type, 0, 4 ) === 'woo_' ) {
93
+                                            } elseif (substr($type, 0, 4) === 'woo_') {
94 94
                                                 ?>
95
-                                                <optgroup label="<?php _e( 'WooCommerce Conditional Tags', 'autoptimize' ); ?>">
95
+                                                <optgroup label="<?php _e('WooCommerce Conditional Tags', 'autoptimize'); ?>">
96 96
                                                 <?php
97 97
                                             }
98 98
                                         }
99 99
 
100 100
                                         // Options.
101
-                                        if ( 'is_' !== $optgrp ) {
101
+                                        if ('is_' !== $optgrp) {
102 102
                                             // Remove prefix from custom post types, templates and some specific conditional tags.
103
-                                            if ( substr( $type, 0, 12 ) === 'custom_post_' ) {
104
-                                                $_type = str_replace( 'custom_post_', '', $type );
105
-                                            } elseif ( substr( $type, 0, 9 ) === 'template_' ) {
106
-                                                $_type = str_replace( 'template_', '', $type );
107
-                                            } elseif ( 'bbp_is_bbpress' == $type ) {
108
-                                                $_type = str_replace( 'bbp_', '', $type );
109
-                                            } elseif ( 'bp_is_buddypress' == $type ) {
110
-                                                $_type = str_replace( 'bp_', '', $type );
111
-                                            } elseif ( substr( $type, 0, 4 ) === 'woo_' ) {
112
-                                                $_type = str_replace( 'woo_', '', $type );
113
-                                            } elseif ( substr( $type, 0, 4 ) === 'edd_' ) {
114
-                                                $_type = str_replace( 'edd_', '', $type );
103
+                                            if (substr($type, 0, 12) === 'custom_post_') {
104
+                                                $_type = str_replace('custom_post_', '', $type);
105
+                                            } elseif (substr($type, 0, 9) === 'template_') {
106
+                                                $_type = str_replace('template_', '', $type);
107
+                                            } elseif ('bbp_is_bbpress' == $type) {
108
+                                                $_type = str_replace('bbp_', '', $type);
109
+                                            } elseif ('bp_is_buddypress' == $type) {
110
+                                                $_type = str_replace('bp_', '', $type);
111
+                                            } elseif (substr($type, 0, 4) === 'woo_') {
112
+                                                $_type = str_replace('woo_', '', $type);
113
+                                            } elseif (substr($type, 0, 4) === 'edd_') {
114
+                                                $_type = str_replace('edd_', '', $type);
115 115
                                             } else {
116 116
                                                 $_type = $type;
117 117
                                             }
118 118
 
119
-                                            echo '<option value="' . $type . '">' . $_type . '</option>';
119
+                                            echo '<option value="'.$type.'">'.$_type.'</option>';
120 120
                                             $prevgrp = $optgrp;
121 121
                                         }
122 122
                                     }
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
                     </tr>
128 128
                     <tr>
129 129
                         <th scope="row">
130
-                            <?php _e( 'Custom Critical CSS', 'autoptimize' ); ?>
130
+                            <?php _e('Custom Critical CSS', 'autoptimize'); ?>
131 131
                         </th>
132 132
                         <td>
133
-                            <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your specific critical CSS here and hit submit to save.', 'autoptimize' ); ?>"></textarea>
133
+                            <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e('Paste your specific critical CSS here and hit submit to save.', 'autoptimize'); ?>"></textarea>
134 134
                             <input type="hidden" id="critcss_addedit_file">
135 135
                             <input type="hidden" id="critcss_addedit_id">
136 136
                         </td>
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
             </div>
140 140
 
141 141
             <!-- Remove dialog -->
142
-            <div id="confirm-rm" title="<?php _e( 'Delete Rule', 'autoptimize' ); ?>" class="hidden">
143
-                <p><?php _e( 'This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p>
142
+            <div id="confirm-rm" title="<?php _e('Delete Rule', 'autoptimize'); ?>" class="hidden">
143
+                <p><?php _e('This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p>
144 144
             </div>
145 145
 
146 146
             <!-- Remove All dialog -->
147
-            <div id="confirm-rm-all" title="<?php _e( 'Delete all Rules and Jobs', 'autoptimize' ); ?>" class="hidden">
148
-                <p><?php _e( 'All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p>
147
+            <div id="confirm-rm-all" title="<?php _e('Delete all Rules and Jobs', 'autoptimize'); ?>" class="hidden">
148
+                <p><?php _e('All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p>
149 149
             </div>
150 150
 
151 151
             <!-- Add/edit default critical CSS dialog -->
152 152
             <div id="default_critcss_wrapper" class="hidden">
153
-                <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize' ); ?>"></textarea>
153
+                <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize'); ?>"></textarea>
154 154
             </div>
155 155
 
156 156
             <!-- Add/edit additional critical CSS dialog -->
157 157
             <div id="additional_critcss_wrapper" class="hidden">
158
-                <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea>
158
+                <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize'); ?>"></textarea>
159 159
             </div>
160 160
 
161 161
             <!-- Wrapper for in screen notices -->
@@ -165,38 +165,38 @@  discard block
 block discarded – undo
165 165
             <!-- BEGIN Rules UI -->
166 166
             <div class="howto">
167 167
                 <div class="title-wrap">
168
-                    <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize' ); ?></h4>
169
-                    <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p>
168
+                    <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize'); ?></h4>
169
+                    <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p>
170 170
                 </div>
171 171
                 <button type="button" class="toggle-btn">
172 172
                     <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
173 173
                 </button>
174 174
                 <div class="howto-wrap hidden">
175
-                <p><?php _e( "TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize' ); ?></p>
175
+                <p><?php _e("TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize'); ?></p>
176 176
                     <ol>
177
-                        <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li>
178
-                        <li><?php _e( 'Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize' ); ?></li>
179
-                        <li><?php _e( 'These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize' ); ?></li>
180
-                        <li><?php _e( 'If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize' ); ?></li>
181
-                        <li><?php _e( 'You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize' ); ?></li>
182
-                        <li><?php _e( 'You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize' ); ?></li>
183
-                        <li><?php _e( "If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize' ); ?></li>
184
-                        <li><?php _e( 'At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize' ); ?></li>
177
+                        <li><?php _e('When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize'); ?></li>
178
+                        <li><?php _e('Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize'); ?></li>
179
+                        <li><?php _e('These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize'); ?></li>
180
+                        <li><?php _e('If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize'); ?></li>
181
+                        <li><?php _e('You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize'); ?></li>
182
+                        <li><?php _e('You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize'); ?></li>
183
+                        <li><?php _e("If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize'); ?></li>
184
+                        <li><?php _e('At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize'); ?></li>
185 185
                     </ol>
186 186
                 </div>
187 187
             </div>
188
-            <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_css_defer_inline', '' ); ?></textarea>
189
-            <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_ccss_additional', '' ); ?></textarea>
188
+            <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option('autoptimize_css_defer_inline', ''); ?></textarea>
189
+            <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option('autoptimize_ccss_additional', ''); ?></textarea>
190 190
             <table class="rules-list" cellspacing="0"><tbody id="rules-list"></tbody></table>
191
-            <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo ( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ); ?>'>
191
+            <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo (json_encode($ao_ccss_rules, JSON_FORCE_OBJECT)); ?>'>
192 192
             <div class="submit rules-btn">
193 193
                 <div class="alignleft">
194
-                    <span id="addCritCssButton" class="button-secondary"><?php _e( 'Add New Rule', 'autoptimize' ); ?></span>
195
-                    <span id="editDefaultButton" class="button-secondary"><?php _e( 'Edit Default Rule CSS', 'autoptimize' ); ?></span>
196
-                    <span id="editAdditionalButton" class="button-secondary"><?php _e( 'Add CSS To All Rules', 'autoptimize' ); ?></span>
194
+                    <span id="addCritCssButton" class="button-secondary"><?php _e('Add New Rule', 'autoptimize'); ?></span>
195
+                    <span id="editDefaultButton" class="button-secondary"><?php _e('Edit Default Rule CSS', 'autoptimize'); ?></span>
196
+                    <span id="editAdditionalButton" class="button-secondary"><?php _e('Add CSS To All Rules', 'autoptimize'); ?></span>
197 197
                 </div>
198 198
                 <div class="alignright">
199
-                    <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e( 'Remove all rules', 'autoptimize' ); ?></span>
199
+                    <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e('Remove all rules', 'autoptimize'); ?></span>
200 200
                 </div>
201 201
             </div>
202 202
             <!-- END Rules UI -->
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_debug.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $ao_options = $wpdb->get_results('
11 11
   SELECT option_name  AS name,
12 12
          option_value AS value
13
-  FROM ' . $wpdb->options . '
13
+  FROM ' . $wpdb->options.'
14 14
   WHERE option_name LIKE "autoptimize_%%"
15 15
   ORDER BY name
16 16
 ', ARRAY_A);
@@ -19,27 +19,27 @@  discard block
 block discarded – undo
19 19
 $ao_trans = $wpdb->get_results('
20 20
   SELECT option_name  AS name,
21 21
          option_value AS value
22
-  FROM ' . $wpdb->options . '
22
+  FROM ' . $wpdb->options.'
23 23
   WHERE option_name LIKE "_transient_autoptimize_%%"
24 24
      OR option_name LIKE "_transient_timeout_autoptimize_%%"
25 25
 ', ARRAY_A);
26 26
 
27 27
 // Render debug panel if there's something to show.
28
-if ( $ao_options || $ao_trans ) {
28
+if ($ao_options || $ao_trans) {
29 29
 ?>
30 30
 <!-- BEGIN: Settings Debug -->
31 31
 <ul>
32 32
     <li class="itemDetail">
33
-        <h2 class="itemTitle"><?php _e( 'Debug Information', 'autoptimize' ); ?></h2>
33
+        <h2 class="itemTitle"><?php _e('Debug Information', 'autoptimize'); ?></h2>
34 34
 
35 35
         <?php
36 36
         // Render options.
37
-        if ( $ao_options ) {
37
+        if ($ao_options) {
38 38
         ?>
39
-            <h4><?php _e( 'Options', 'autoptimize' ); ?>:</h4>
39
+            <h4><?php _e('Options', 'autoptimize'); ?>:</h4>
40 40
             <table class="form-table debug">
41 41
             <?php
42
-            foreach ( $ao_options as $option ) {
42
+            foreach ($ao_options as $option) {
43 43
             ?>
44 44
                 <tr>
45 45
                     <th scope="row">
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
                     </th>
48 48
                     <td>
49 49
                         <?php
50
-                        if ( 'autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name'] ) {
51
-                            $value = print_r( json_decode( $option['value'], true ), true );
52
-                            if ( $value ) {
53
-                                echo "Raw JSON:\n<pre>" . $option['value'] . "</pre>\n\nDecoded JSON:\n<pre>" . $value . '</pre>';
50
+                        if ('autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name']) {
51
+                            $value = print_r(json_decode($option['value'], true), true);
52
+                            if ($value) {
53
+                                echo "Raw JSON:\n<pre>".$option['value']."</pre>\n\nDecoded JSON:\n<pre>".$value.'</pre>';
54 54
                             } else {
55 55
                                 echo 'Empty';
56 56
                             }
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
         }
70 70
         // Render WP-Cron intervals and scheduled events.
71 71
         ?>
72
-        <h4><?php _e( 'WP-Cron Intervals', 'autoptimize' ); ?>:</h4>
73
-        <pre><?php print_r( wp_get_schedules() ); ?></pre>
72
+        <h4><?php _e('WP-Cron Intervals', 'autoptimize'); ?>:</h4>
73
+        <pre><?php print_r(wp_get_schedules()); ?></pre>
74 74
         <hr />
75
-        <h4><?php _e( 'WP-Cron Scheduled Events', 'autoptimize' ); ?>:</h4>
76
-        <pre><?php print_r( _get_cron_array() ); ?></pre>
75
+        <h4><?php _e('WP-Cron Scheduled Events', 'autoptimize'); ?>:</h4>
76
+        <pre><?php print_r(_get_cron_array()); ?></pre>
77 77
     </li>
78 78
 </ul>
79 79
 <!-- END: Settings Debug -->
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,56 +52,56 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rlimit' );
62
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' );
63
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' );
64
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' );
65
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' );
66
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' );
67
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' );
68
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' );
69
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rlimit');
62
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize');
63
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug');
64
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_key');
65
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst');
66
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin');
67
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath');
68
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery');
69
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain');
70 70
 
71 71
         // And add submenu-page.
72
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
72
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
73 73
     }
74 74
 
75
-    public function admin_assets( $hook ) {
75
+    public function admin_assets($hook) {
76 76
         // Return if plugin is not hooked.
77
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
77
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
78 78
             return;
79 79
         }
80 80
 
81 81
         // Stylesheets to add.
82
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
83
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
84
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
82
+        wp_enqueue_style('wp-jquery-ui-dialog');
83
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
84
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
85 85
 
86 86
         // Scripts to add.
87
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
88
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
89
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
90
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
87
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
88
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
89
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
90
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
91 91
     }
92 92
 
93 93
     public function ao_criticalcsssettings_page()
94 94
     {
95 95
         // these are not OO yet, simply require for now.
96
-        require_once( 'critcss-inc/admin_settings_rules.php' );
97
-        require_once( 'critcss-inc/admin_settings_queue.php' );
98
-        require_once( 'critcss-inc/admin_settings_key.php' );
99
-        require_once( 'critcss-inc/admin_settings_adv.php' );
100
-        require_once( 'critcss-inc/admin_settings_explain.php' );
96
+        require_once('critcss-inc/admin_settings_rules.php');
97
+        require_once('critcss-inc/admin_settings_queue.php');
98
+        require_once('critcss-inc/admin_settings_key.php');
99
+        require_once('critcss-inc/admin_settings_adv.php');
100
+        require_once('critcss-inc/admin_settings_explain.php');
101 101
 
102 102
         // fetch all options at once and populate them individually explicitely as globals.
103 103
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
104
-        foreach ( $all_options as $_option => $_value ) {
104
+        foreach ($all_options as $_option => $_value) {
105 105
             global ${$_option};
106 106
             ${$_option} = $_value;
107 107
         }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         <div class="wrap">
110 110
             <div id="autoptimize_main">
111 111
                 <div id="ao_title_and_button">
112
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
112
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
113 113
                 </div>
114 114
 
115 115
                 <?php
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
                 echo autoptimizeConfig::ao_admin_tabs();
118 118
 
119 119
                 // Make sure dir to write ao_ccss exists and is writable.
120
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
121
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
122
-                    $fileresp  = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' );
123
-                    if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
120
+                if (!is_dir(AO_CCSS_DIR)) {
121
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
122
+                    $fileresp  = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>');
123
+                    if ((!$mkdirresp) || (!$fileresp)) {
124 124
                         ?>
125 125
                         <div class="notice-error notice"><p>
126 126
                         <?php
127
-                        _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
127
+                        _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
128 128
                         ?>
129 129
                         </p></div>
130 130
                         <?php
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
                 }
133 133
 
134 134
                 // Check for Autoptimize.
135
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
135
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
136 136
                     ?>
137 137
                     <div class="notice-error notice"><p>
138 138
                     <?php
139
-                    _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' );
139
+                    _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize');
140 140
                     ?>
141 141
                     </p></div>
142 142
                     <?php
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
                 }
145 145
 
146 146
                 // check if WordPress cron is disabled and warn if so.
147
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
147
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
148 148
                     ?>
149 149
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
150 150
                     <?php
151
-                    _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
151
+                    _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
152 152
                     ?>
153 153
                     </p></div>
154 154
                     <?php
@@ -156,24 +156,24 @@  discard block
 block discarded – undo
156 156
 
157 157
                 // warn if it looks as though the queue processing job looks isn't running
158 158
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
159
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
160
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
159
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
160
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
161 161
                     $_jobs_all_new         = true;
162
-                    $_oldest_job_timestamp = microtime( true ); // now.
162
+                    $_oldest_job_timestamp = microtime(true); // now.
163 163
                     $_jobs_too_old         = true;
164 164
 
165 165
                     // go over queue array.
166
-                    if ( empty( $ao_ccss_queue ) ) {
166
+                    if (empty($ao_ccss_queue)) {
167 167
                         // no jobs, then no warning.
168 168
                         $_jobs_all_new = false;
169 169
                     } else {
170
-                        foreach ( $ao_ccss_queue as $job ) {
171
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
170
+                        foreach ($ao_ccss_queue as $job) {
171
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
172 172
                                 // we need to catch the oldest job's timestamp.
173 173
                                 $_oldest_job_timestamp = $job['jctime'];
174 174
                             }
175 175
 
176
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
176
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
177 177
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
178 178
                                 $_jobs_all_new = false;
179 179
                                 break;
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
                     }
183 183
 
184 184
                     // is the oldest job too old (4h)?
185
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
185
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
186 186
                         $_jobs_too_old = false;
187 187
                     }
188 188
 
189
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
189
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
190 190
                         $_warn_cron            = 'on';
191 191
                         $_transient_multiplier = 1; // store for 1 hour.
192 192
                     } else {
@@ -194,33 +194,33 @@  discard block
 block discarded – undo
194 194
                         $_transient_multiplier = 4; // store for 4 hours.
195 195
                     }
196 196
                     // and set transient.
197
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
197
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
198 198
                 }
199 199
 
200
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
200
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
201 201
                     ?>
202 202
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
203 203
                     <?php
204
-                    _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
204
+                    _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
205 205
                     ?>
206 206
                     </p></div>
207 207
                     <?php
208
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
208
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
209 209
                     ?>
210 210
                     <div class="notice-success notice"><p>
211 211
                     <?php
212
-                    _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' );
212
+                    _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize');
213 213
                     ?>
214 214
                     </p></div>
215 215
                     <?php
216 216
                 }
217 217
 
218 218
                 // warn if service is down.
219
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
219
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
220 220
                     ?>
221 221
                     <div class="notice-warning notice"><p>
222 222
                     <?php
223
-                    _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' );
223
+                    _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize');
224 224
                     ?>
225 225
                     </p></div>
226 226
                     <?php
@@ -230,24 +230,24 @@  discard block
 block discarded – undo
230 230
                 ?>
231 231
                 <form id="settings" method="post" action="options.php">
232 232
                     <?php
233
-                    settings_fields( 'ao_ccss_options_group' );
233
+                    settings_fields('ao_ccss_options_group');
234 234
 
235 235
                     // Get API key status.
236
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
236
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
237 237
 
238
-                    if ( $this->is_multisite_network_admin() ) {
238
+                    if ($this->is_multisite_network_admin()) {
239 239
                         ?>
240 240
                         <ul id="key-panel">
241 241
                             <li class="itemDetail">
242 242
                             <?php
243 243
                                 // translators: the placesholder is for a line of code in wp-config.php.
244
-                                echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' );
244
+                                echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>');
245 245
                             ?>
246 246
                             </li>
247 247
                         </ul>
248 248
                         <?php
249 249
                     } else {
250
-                        if ( 'valid' == $key['status'] ) {
250
+                        if ('valid' == $key['status']) {
251 251
                             // If key status is valid, render other panels.
252 252
                             // Render rules section.
253 253
                             ao_ccss_render_rules();
@@ -264,23 +264,23 @@  discard block
 block discarded – undo
264 264
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
265 265
 
266 266
                             // Add hidden fields.
267
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
268
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
269
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
270
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
271
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
272
-                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">';
273
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
274
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
275
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
276
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
277
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
267
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
268
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
269
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
270
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
271
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
272
+                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="'.$ao_ccss_rlimit.'">';
273
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
274
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
275
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
276
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
277
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
278 278
                         }
279 279
                         // Render key panel unconditionally.
280
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
280
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
281 281
                         ?>
282 282
                         <p class="submit left">
283
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
283
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
284 284
                         </p>
285 285
                         <?php
286 286
                     }
@@ -298,31 +298,31 @@  discard block
 block discarded – undo
298 298
                     });
299 299
                 }
300 300
                 </script>
301
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
302
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
303
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
301
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
302
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
303
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
304 304
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
305 305
                 </form>
306 306
                 <div id="importdialog"></div>
307 307
             </div><!-- /#autoptimize_main -->
308 308
         </div><!-- /#wrap -->
309 309
         <?php
310
-        if ( ! $this->is_multisite_network_admin() ) {
310
+        if (!$this->is_multisite_network_admin()) {
311 311
             // Include debug panel if debug mode is enable.
312
-            if ( $ao_ccss_debug ) {
312
+            if ($ao_ccss_debug) {
313 313
             ?>
314 314
                 <div id="debug">
315 315
                     <?php
316 316
                     // Include debug panel.
317
-                    include( 'critcss-inc/admin_settings_debug.php' );
317
+                    include('critcss-inc/admin_settings_debug.php');
318 318
                     ?>
319 319
                 </div><!-- /#debug -->
320 320
             <?php
321 321
             }
322 322
             echo '<script>';
323
-            include( 'critcss-inc/admin_settings_rules.js.php' );
324
-            include( 'critcss-inc/admin_settings_queue.js.php' );
325
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
323
+            include('critcss-inc/admin_settings_rules.js.php');
324
+            include('critcss-inc/admin_settings_queue.js.php');
325
+            include('critcss-inc/admin_settings_impexp.js.php');
326 326
             echo '</script>';
327 327
         }
328 328
     }
@@ -330,19 +330,19 @@  discard block
 block discarded – undo
330 330
     public static function ao_ccss_has_autorules() {
331 331
         static $_has_auto_rules = null;
332 332
 
333
-        if ( null === $_has_auto_rules ) {
333
+        if (null === $_has_auto_rules) {
334 334
             global $ao_ccss_rules;
335 335
             $_has_auto_rules = false;
336
-            if ( ! empty( $ao_ccss_rules ) ) {
337
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
338
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
339
-                        if ( ! empty( $rule['hash'] ) ) {
336
+            if (!empty($ao_ccss_rules)) {
337
+                foreach (array('types', 'paths') as $_typat) {
338
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
339
+                        if (!empty($rule['hash'])) {
340 340
                             // we have at least one AUTO job, so all is fine.
341 341
                             $_has_auto_rules = true;
342 342
                             break;
343 343
                         }
344 344
                     }
345
-                    if ( $_has_auto_rules ) {
345
+                    if ($_has_auto_rules) {
346 346
                         break;
347 347
                     }
348 348
                 }
@@ -355,8 +355,8 @@  discard block
 block discarded – undo
355 355
     public function is_multisite_network_admin() {
356 356
         static $_multisite_network_admin = null;
357 357
 
358
-        if ( null === $_multisite_network_admin ) {
359
-            if ( is_multisite() && is_network_admin() ) {
358
+        if (null === $_multisite_network_admin) {
359
+            if (is_multisite() && is_network_admin()) {
360 360
                 $_multisite_network_admin = true;
361 361
             } else {
362 362
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.
classes/autoptimizeConfig.php 1 patch
Spacing   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Main configuration logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -35,32 +35,32 @@  discard block
 block discarded – undo
35 35
      */
36 36
     private function __construct()
37 37
     {
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
             // Add the admin page and settings.
40
-            if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41
-                add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
40
+            if (autoptimizeOptionWrapper::is_ao_active_for_network()) {
41
+                add_action('network_admin_menu', array($this, 'addmenu'));
42 42
             }
43 43
 
44
-            add_action( 'admin_menu', array( $this, 'addmenu' ) );
45
-            add_action( 'admin_init', array( $this, 'registersettings' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46 46
 
47 47
             // Set meta info.
48
-            if ( function_exists( 'plugin_row_meta' ) ) {
48
+            if (function_exists('plugin_row_meta')) {
49 49
                 // 2.8 and higher.
50
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
51
-            } elseif ( function_exists( 'post_class' ) ) {
50
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
51
+            } elseif (function_exists('post_class')) {
52 52
                 // 2.7 and lower.
53
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
54
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
53
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
54
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
55 55
             }
56 56
 
57 57
             // Clean cache?
58
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
58
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
59 59
                 autoptimizeCache::clearall();
60
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
60
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
61 61
             }
62 62
 
63
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
63
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
64 64
         }
65 65
 
66 66
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     static public function instance()
77 77
     {
78 78
         // Only one instance.
79
-        if ( null === self::$instance ) {
79
+        if (null === self::$instance) {
80 80
             self::$instance = new autoptimizeConfig();
81 81
         }
82 82
 
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
     public function show_network_message() {
87 87
         ?>
88 88
         <div class="wrap">
89
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
89
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
90 90
             <?php echo $this->ao_admin_tabs(); ?>
91
-            <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
91
+            <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p>
92 92
         </div>
93 93
         <?php
94 94
     }
@@ -181,32 +181,32 @@  discard block
 block discarded – undo
181 181
 <div class="wrap">
182 182
 
183 183
 <!-- Temporary nudge to disable aoccss power-up. -->
184
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
184
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
185 185
     <div class="notice-info notice"><p>
186
-        <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
186
+        <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?>
187 187
     </p></div>
188 188
 <?php } ?>
189 189
 
190 190
 <div id="autoptimize_main">
191
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
191
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
192 192
     <?php echo $this->ao_admin_tabs(); ?>
193 193
 
194
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
195
-<?php settings_fields( 'autoptimize' ); ?>
194
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
195
+<?php settings_fields('autoptimize'); ?>
196 196
 
197 197
 <ul>
198 198
 
199 199
 <?php
200 200
 // Only show enable site configuration in network site option.
201
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
201
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
202 202
 ?>
203 203
     <li class="itemDetail multiSite">
204
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
204
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
205 205
         <table class="form-table">
206 206
             <tr valign="top">
207
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
208
-                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
209
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
207
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
208
+                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/>
209
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
210 210
             </tr>
211 211
         </table>
212 212
     </li>
@@ -215,115 +215,115 @@  discard block
 block discarded – undo
215 215
 <?php } ?>    
216 216
 
217 217
 <li class="itemDetail">
218
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
218
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
219 219
 <table class="form-table">
220 220
 <tr valign="top">
221
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
222
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
221
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
222
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
223 223
 </tr>
224 224
 <tr valign="top" class="js_sub">
225
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
226
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
227
-<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
225
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
226
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/>
227
+<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
228 228
 </tr>
229 229
 <tr valign="top" class="js_sub js_aggregate">
230
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
231
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
232
-<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td>
230
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
231
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
232
+<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td>
233 233
 </tr>
234 234
 <tr valign="top" class="js_sub js_aggregate">
235
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
236
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
237
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
235
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
236
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
237
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
238 238
 </tr>
239
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
239
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
240 240
 <tr valign="top" class="js_sub js_aggregate">
241 241
 <th scope="row">
242 242
 <?php
243
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
244
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
243
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
244
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
245 245
 ?>
246 246
 </th>
247
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
248
-<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td>
247
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
248
+<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td>
249 249
 </tr>
250 250
 <?php } ?>
251 251
 <tr valign="top" class="js_sub">
252
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
253
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ); ?>"/><br />
252
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
253
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js'); ?>"/><br />
254 254
 <?php
255
-echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
255
+echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
256 256
 ?>
257 257
 </label></td>
258 258
 </tr>
259 259
 <tr valign="top" class="js_sub js_aggregate">
260
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
261
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
262
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
260
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
261
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
262
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
263 263
 </tr>
264 264
 </table>
265 265
 </li>
266 266
 
267 267
 <li class="itemDetail">
268
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
268
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
269 269
 <table class="form-table">
270 270
 <tr valign="top">
271
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
272
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
271
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
272
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
273 273
 </tr>
274 274
 <tr class="css_sub" valign="top">
275
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
276
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
277
-<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
275
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
276
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/>
277
+<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
278 278
 </tr>
279 279
 <tr valign="top" class="css_sub css_aggregate">
280
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
281
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
282
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
280
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
281
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/>
282
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
283 283
 </tr>
284 284
 <tr class="css_sub css_aggregate" valign="top">
285
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
286
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
287
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
285
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
286
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
287
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
288 288
 </tr>
289
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
289
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
290 290
 <tr valign="top" class="css_sub css_aggregate">
291 291
 <th scope="row">
292 292
 <?php
293
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
294
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
293
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
294
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
295 295
 ?>
296 296
 </th>
297
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
298
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
297
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
298
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
299 299
 </tr>
300 300
 <?php } ?>
301 301
 <tr valign="top" class="css_sub">
302
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
303
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
302
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
303
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/>
304 304
 <?php
305
-_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' );
305
+_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize');
306 306
 echo ' ';
307
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
307
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
308 308
 // translators: links "autoptimize critical CSS" tab.
309
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
309
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
310 310
 ?>
311 311
 </label></td>
312 312
 </tr>
313 313
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
314 314
 <th scope="row"></th>
315
-<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td>
315
+<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
316 316
 </tr>
317 317
 <tr valign="top" class="css_sub css_aggregate">
318
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
319
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
320
-<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
318
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
319
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/>
320
+<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td>
321 321
 </tr>
322 322
 <tr valign="top" class="css_sub">
323
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
324
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ); ?>"/><br />
323
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
324
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css'); ?>"/><br />
325 325
 <?php
326
-echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
326
+echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
327 327
 ?>
328 328
 </label></td>
329 329
 </tr>
@@ -331,55 +331,55 @@  discard block
 block discarded – undo
331 331
 </li>
332 332
 
333 333
 <li class="itemDetail">
334
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
334
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
335 335
 <table class="form-table">
336 336
 <tr valign="top">
337
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
338
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
337
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
338
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
339 339
 </tr>
340 340
 <tr class="html_sub" valign="top">
341
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
342
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
343
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
341
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
342
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
343
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
344 344
 </tr>
345 345
 </table>
346 346
 </li>
347 347
 
348 348
 <li class="itemDetail">
349
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
349
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
350 350
 <table class="form-table">
351 351
 <tr valign="top">
352
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
353
-<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
354
-<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td>
352
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
353
+<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br />
354
+<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td>
355 355
 </tr>
356 356
 </table>
357 357
 </li>
358 358
 
359 359
 <li class="itemDetail">
360
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
360
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
361 361
 <table class="form-table" >
362 362
 <tr valign="top" >
363
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
364
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
363
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
364
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
365 365
 </tr>
366 366
 <tr valign="top" >
367
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
368
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
367
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
368
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
369 369
 </tr>
370 370
 <tr valign="top" >
371
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
371
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
372 372
 <td>
373 373
     <?php
374 374
     $ao_stat_arr = autoptimizeCache::stats();
375
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
376
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
375
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
376
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
377 377
         $details       = '';
378
-        if ( $ao_cache_size > 0 ) {
379
-            $details = ', ~' . $ao_cache_size . ' total';
378
+        if ($ao_cache_size > 0) {
379
+            $details = ', ~'.$ao_cache_size.' total';
380 380
         }
381 381
         // translators: Kilobytes + timestamp shown.
382
-        printf( __( '%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
382
+        printf(__('%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2]));
383 383
     }
384 384
     ?>
385 385
 </td>
@@ -388,41 +388,41 @@  discard block
 block discarded – undo
388 388
 </li>
389 389
 
390 390
 <li class="itemDetail">
391
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
391
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
392 392
 <table class="form-table">
393 393
     <tr valign="top" >
394
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
395
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
396
-    <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td>
394
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
395
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
396
+    <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td>
397 397
     </tr>
398 398
     <?php
399 399
     $_min_excl_class = '';
400
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
400
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
401 401
         $_min_excl_class = 'hidden';
402 402
     }
403 403
     ?>
404 404
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
405
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
406
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
407
-        <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td>
405
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
406
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
407
+        <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td>
408 408
     </tr>
409 409
     <tr valign="top">
410
-        <th scope="row"><?php _e( 'Experimental: enable 404 fallbacks.', 'autoptimize' ); ?></th>
411
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) ? 'checked="checked" ' : ''; ?>/>
412
-        <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. This experimental feature tries to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
410
+        <th scope="row"><?php _e('Experimental: enable 404 fallbacks.', 'autoptimize'); ?></th>
411
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '') ? 'checked="checked" ' : ''; ?>/>
412
+        <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. This experimental feature tries to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td>
413 413
     </tr>
414 414
     <tr valign="top">
415
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
416
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
417
-    <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
415
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
416
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
417
+    <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td>
418 418
     </tr>
419 419
     <?php
420
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
420
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
421 421
     ?>
422 422
     <tr valign="top" >
423
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
424
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
425
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
423
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
424
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
425
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
426 426
         </td>
427 427
     </tr>
428 428
     <?php } ?>
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 </ul>
433 433
 
434 434
 <p class="submit">
435
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
436
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
435
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
436
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
437 437
 </p>
438 438
 
439 439
 </form>
@@ -442,46 +442,46 @@  discard block
 block discarded – undo
442 442
     <div class="autoptimize_banner hidden">
443 443
     <ul>
444 444
     <?php
445
-    if ( $this->settings_screen_do_remote_http ) {
446
-        $ao_banner = get_transient( 'autoptimize_banner' );
447
-        if ( empty( $ao_banner ) ) {
448
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
449
-            if ( ! is_wp_error( $banner_resp ) ) {
450
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
451
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
452
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
445
+    if ($this->settings_screen_do_remote_http) {
446
+        $ao_banner = get_transient('autoptimize_banner');
447
+        if (empty($ao_banner)) {
448
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
449
+            if (!is_wp_error($banner_resp)) {
450
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
451
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
452
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
453 453
                 }
454 454
             }
455 455
         }
456 456
         echo $ao_banner;
457 457
     }
458 458
     ?>
459
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
460
-        <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
459
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
460
+        <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li>
461 461
     </ul>
462 462
     </div>
463 463
     <div style="margin-left:10px;margin-top:-5px;">
464 464
         <h2>
465
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
465
+            <?php _e('futtta about', 'autoptimize'); ?>
466 466
             <select id="feed_dropdown" >
467
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
468
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
469
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
467
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
468
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
469
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
470 470
             </select>
471 471
         </h2>
472 472
         <div id="futtta_feed">
473 473
             <div id="autoptimizefeed">
474
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
474
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
475 475
             </div>
476 476
             <div id="wordpressfeed">
477
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
477
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
478 478
             </div>
479 479
             <div id="webtechfeed">
480
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
480
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
481 481
             </div>
482 482
         </div>
483 483
     </div>
484
-    <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
484
+    <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div>
485 485
 </div>
486 486
 
487 487
 <script type="text/javascript">
@@ -630,81 +630,81 @@  discard block
 block discarded – undo
630 630
 
631 631
     public function addmenu()
632 632
     {
633
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
633
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
634 634
             // multisite, network admin, ao network activated: add normal settings page at network level.
635
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
636
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
635
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
636
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
637 637
             // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options.
638
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
638
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
639 639
         } else {
640 640
             // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on.
641
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
641
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
642 642
         }
643 643
 
644
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
645
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
644
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
645
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
646 646
     }
647 647
 
648 648
     public function autoptimize_admin_scripts()
649 649
     {
650
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
651
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
650
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
651
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
652 652
     }
653 653
 
654 654
     public function autoptimize_admin_styles()
655 655
     {
656
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
657
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
656
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
657
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
658 658
     }
659 659
 
660 660
     public function registersettings() {
661
-        register_setting( 'autoptimize', 'autoptimize_html' );
662
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
663
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
664
-        register_setting( 'autoptimize', 'autoptimize_js' );
665
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
666
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
667
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
668
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
669
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
670
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
671
-        register_setting( 'autoptimize', 'autoptimize_css' );
672
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
673
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
674
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
675
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
676
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
677
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
678
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
679
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
680
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
681
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
682
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
683
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
684
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
685
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
686
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
661
+        register_setting('autoptimize', 'autoptimize_html');
662
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
663
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
664
+        register_setting('autoptimize', 'autoptimize_js');
665
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
666
+        register_setting('autoptimize', 'autoptimize_js_exclude');
667
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
668
+        register_setting('autoptimize', 'autoptimize_js_justhead');
669
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
670
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
671
+        register_setting('autoptimize', 'autoptimize_css');
672
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
673
+        register_setting('autoptimize', 'autoptimize_css_exclude');
674
+        register_setting('autoptimize', 'autoptimize_css_justhead');
675
+        register_setting('autoptimize', 'autoptimize_css_datauris');
676
+        register_setting('autoptimize', 'autoptimize_css_defer');
677
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
678
+        register_setting('autoptimize', 'autoptimize_css_inline');
679
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
680
+        register_setting('autoptimize', 'autoptimize_cdn_url');
681
+        register_setting('autoptimize', 'autoptimize_cache_clean');
682
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
683
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
684
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
685
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
686
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
687 687
     }
688 688
 
689
-    public function setmeta( $links, $file = null )
689
+    public function setmeta($links, $file = null)
690 690
     {
691 691
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
692 692
         // Do it only once - saves time.
693 693
         static $plugin;
694
-        if ( empty( $plugin ) ) {
695
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
694
+        if (empty($plugin)) {
695
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
696 696
         }
697 697
 
698
-        if ( null === $file ) {
698
+        if (null === $file) {
699 699
             // 2.7 and lower.
700
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
701
-            array_unshift( $links, $settings_link );
700
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
701
+            array_unshift($links, $settings_link);
702 702
         } else {
703 703
             // 2.8 and higher.
704 704
             // If it's us, add the link.
705
-            if ( $file === $plugin ) {
706
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
707
-                $links   = array_merge( $links, $newlink );
705
+            if ($file === $plugin) {
706
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
707
+                $links   = array_merge($links, $newlink);
708 708
             }
709 709
         }
710 710
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
781 781
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
782 782
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
783
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
783
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
784 784
         );
785 785
         return $defaults;
786 786
     }
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
      */
793 793
     public static function get_ao_css_preload_polyfill()
794 794
     {
795
-        $preload_poly = apply_filters( 'autoptimize_css_preload_polyfill', '<script data-cfasync=\'false\'>!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);</script>' );
795
+        $preload_poly = apply_filters('autoptimize_css_preload_polyfill', '<script data-cfasync=\'false\'>!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);</script>');
796 796
         return $preload_poly;
797 797
     }
798 798
 
@@ -803,56 +803,56 @@  discard block
 block discarded – undo
803 803
      */
804 804
     public static function get_ao_css_preload_onload()
805 805
     {
806
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'" );
806
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'");
807 807
         return $preload_onload;
808 808
     }
809 809
 
810
-    public function get( $key )
810
+    public function get($key)
811 811
     {
812
-        if ( ! is_array( $this->config ) ) {
812
+        if (!is_array($this->config)) {
813 813
             // Default config.
814 814
             $config = self::get_defaults();
815 815
 
816 816
             // Override with user settings.
817
-            foreach ( array_keys( $config ) as $name ) {
818
-                $conf = autoptimizeOptionWrapper::get_option( $name );
819
-                if ( false !== $conf ) {
817
+            foreach (array_keys($config) as $name) {
818
+                $conf = autoptimizeOptionWrapper::get_option($name);
819
+                if (false !== $conf) {
820 820
                     // It was set before!
821
-                    $config[ $name ] = $conf;
821
+                    $config[$name] = $conf;
822 822
                 }
823 823
             }
824 824
 
825 825
             // Save for next call.
826
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
826
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
827 827
         }
828 828
 
829
-        if ( isset( $this->config[ $key ] ) ) {
830
-            return $this->config[ $key ];
829
+        if (isset($this->config[$key])) {
830
+            return $this->config[$key];
831 831
         }
832 832
 
833 833
         return false;
834 834
     }
835 835
 
836
-    private function get_futtta_feeds( $url ) {
837
-        if ( $this->settings_screen_do_remote_http ) {
838
-            $rss      = fetch_feed( $url );
836
+    private function get_futtta_feeds($url) {
837
+        if ($this->settings_screen_do_remote_http) {
838
+            $rss      = fetch_feed($url);
839 839
             $maxitems = 0;
840 840
 
841
-            if ( ! is_wp_error( $rss ) ) {
842
-                $maxitems  = $rss->get_item_quantity( 7 );
843
-                $rss_items = $rss->get_items( 0, $maxitems );
841
+            if (!is_wp_error($rss)) {
842
+                $maxitems  = $rss->get_item_quantity(7);
843
+                $rss_items = $rss->get_items(0, $maxitems);
844 844
             }
845 845
             ?>
846 846
             <ul>
847
-                <?php if ( 0 == $maxitems ) : ?>
848
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
847
+                <?php if (0 == $maxitems) : ?>
848
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
849 849
                 <?php else : ?>
850
-                    <?php foreach ( $rss_items as $item ) : ?>
850
+                    <?php foreach ($rss_items as $item) : ?>
851 851
                         <li>
852
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
852
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
853 853
                                 <?php // translators: the variable contains a date. ?>
854
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
855
-                                <?php echo esc_html( $item->get_title() ); ?>
854
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
855
+                                <?php echo esc_html($item->get_title()); ?>
856 856
                             </a>
857 857
                         </li>
858 858
                     <?php endforeach; ?>
@@ -865,23 +865,23 @@  discard block
 block discarded – undo
865 865
     static function ao_admin_tabs()
866 866
     {
867 867
         // based on http://wordpress.stackexchange.com/a/58826 .
868
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
868
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
869 869
         $tab_content = '';
870
-        $tabs_count  = count( $tabs );
871
-        if ( $tabs_count > 1 ) {
872
-            if ( isset( $_GET['page'] ) ) {
870
+        $tabs_count  = count($tabs);
871
+        if ($tabs_count > 1) {
872
+            if (isset($_GET['page'])) {
873 873
                 $current_id = $_GET['page'];
874 874
             } else {
875 875
                 $current_id = 'autoptimize';
876 876
             }
877 877
             $tab_content .= '<h2 class="nav-tab-wrapper">';
878
-            foreach ( $tabs as $tab_id => $tab_name ) {
879
-                if ( $current_id == $tab_id ) {
878
+            foreach ($tabs as $tab_id => $tab_name) {
879
+                if ($current_id == $tab_id) {
880 880
                     $class = ' nav-tab-active';
881 881
                 } else {
882 882
                     $class = '';
883 883
                 }
884
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
884
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
885 885
             }
886 886
             $tab_content .= '</h2>';
887 887
         } else {
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
      */
899 899
     public static function is_admin_and_not_ajax()
900 900
     {
901
-        return ( is_admin() && ! self::doing_ajax() );
901
+        return (is_admin() && !self::doing_ajax());
902 902
     }
903 903
 
904 904
     /**
@@ -908,10 +908,10 @@  discard block
 block discarded – undo
908 908
      */
909 909
     protected static function doing_ajax()
910 910
     {
911
-        if ( function_exists( 'wp_doing_ajax' ) ) {
911
+        if (function_exists('wp_doing_ajax')) {
912 912
             return wp_doing_ajax();
913 913
         }
914
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
914
+        return (defined('DOING_AJAX') && DOING_AJAX);
915 915
     }
916 916
 
917 917
     /**
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
      * @return bool
921 921
      */
922 922
     public static function should_show_menu_tabs() {
923
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
923
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
924 924
             return true;
925 925
         } else {
926 926
             return false;
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSCore.php 1 patch
Spacing   +136 added lines, -136 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
         }
@@ -27,23 +27,23 @@  discard block
 block discarded – undo
27 27
         global $ao_ccss_key;
28 28
 
29 29
         // add all filters to do CCSS if key present.
30
-        if ( $ao_css_defer && isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) ) {
30
+        if ($ao_css_defer && isset($ao_ccss_key) && !empty($ao_ccss_key)) {
31 31
             // Set AO behavior: disable minification to avoid double minifying and caching.
32
-            add_filter( 'autoptimize_filter_css_critcss_minify', '__return_false' );
33
-            add_filter( 'autoptimize_filter_css_defer_inline', array( $this, 'ao_ccss_frontend' ), 10, 1 );
32
+            add_filter('autoptimize_filter_css_critcss_minify', '__return_false');
33
+            add_filter('autoptimize_filter_css_defer_inline', array($this, 'ao_ccss_frontend'), 10, 1);
34 34
 
35 35
             // Add the action to enqueue jobs for CriticalCSS cron.
36
-            add_action( 'autoptimize_action_css_hash', array( 'autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue' ), 10, 1 );
36
+            add_action('autoptimize_action_css_hash', array('autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue'), 10, 1);
37 37
 
38 38
             // conditionally add the filter to defer jquery and others.
39
-            if ( $ao_ccss_deferjquery ) {
40
-                add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_defer_jquery' ), 11, 1 );
39
+            if ($ao_ccss_deferjquery) {
40
+                add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_defer_jquery'), 11, 1);
41 41
             }
42 42
 
43 43
             // Order paths by length, as longest ones have greater priority in the rules.
44
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
45
-                $keys = array_map( 'strlen', array_keys( $ao_ccss_rules['paths'] ) );
46
-                array_multisort( $keys, SORT_DESC, $ao_ccss_rules['paths'] );
44
+            if (!empty($ao_ccss_rules['paths'])) {
45
+                $keys = array_map('strlen', array_keys($ao_ccss_rules['paths']));
46
+                array_multisort($keys, SORT_DESC, $ao_ccss_rules['paths']);
47 47
             }
48 48
 
49 49
             // Add an array with default WordPress's conditional tags
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
             $ao_ccss_types = $this->get_ao_ccss_core_types();
53 53
 
54 54
             // Extend conditional tags on plugin initalization.
55
-            add_action( apply_filters( 'autoptimize_filter_ccss_extend_types_hook', 'init' ), array( $this, 'ao_ccss_extend_types' ) );
55
+            add_action(apply_filters('autoptimize_filter_ccss_extend_types_hook', 'init'), array($this, 'ao_ccss_extend_types'));
56 56
         }
57 57
     }
58 58
 
59
-    public function ao_ccss_frontend( $inlined ) {
59
+    public function ao_ccss_frontend($inlined) {
60 60
         // Apply CriticalCSS to frontend pages
61 61
         // Attach types and settings arrays.
62 62
         global $ao_ccss_types;
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
68 68
         $no_ccss = '';
69 69
 
70 70
         // Only if keystatus is OK and option to add CCSS for logged on users is on or user is not logged in.
71
-        if ( ( $ao_ccss_keyst && 2 == $ao_ccss_keyst ) && ( $ao_ccss_loggedin || ! is_user_logged_in() ) ) {
71
+        if (($ao_ccss_keyst && 2 == $ao_ccss_keyst) && ($ao_ccss_loggedin || !is_user_logged_in())) {
72 72
             // Check for a valid CriticalCSS based on path to return its contents.
73
-            $req_path = strtok( urldecode( $_SERVER['REQUEST_URI'] ), '?' );
74
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
75
-                foreach ( $ao_ccss_rules['paths'] as $path => $rule ) {
73
+            $req_path = strtok(urldecode($_SERVER['REQUEST_URI']), '?');
74
+            if (!empty($ao_ccss_rules['paths'])) {
75
+                foreach ($ao_ccss_rules['paths'] as $path => $rule) {
76 76
                     // explicit match OR partial match if MANUAL rule.
77
-                    if ( $req_path == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) {
78
-                        if ( file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
79
-                            $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
80
-                            if ( 'none' != $_ccss_contents ) {
81
-                                if ( $ao_ccss_debug ) {
82
-                                    $_ccss_contents = '/* PATH: ' . $path . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
77
+                    if ($req_path == $path || (false == $rule['hash'] && false != $rule['file'] && strpos($req_path, str_replace(site_url(), '', $path)) !== false)) {
78
+                        if (file_exists(AO_CCSS_DIR.$rule['file'])) {
79
+                            $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
80
+                            if ('none' != $_ccss_contents) {
81
+                                if ($ao_ccss_debug) {
82
+                                    $_ccss_contents = '/* PATH: '.$path.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
83 83
                                 }
84
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
84
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
85 85
                             } else {
86 86
                                 $no_ccss = 'none';
87 87
                             }
@@ -91,55 +91,55 @@  discard block
 block discarded – undo
91 91
             }
92 92
 
93 93
             // Check for a valid CriticalCSS based on conditional tags to return its contents.
94
-            if ( ! empty( $ao_ccss_rules['types'] ) && 'none' !== $no_ccss ) {
94
+            if (!empty($ao_ccss_rules['types']) && 'none' !== $no_ccss) {
95 95
                 // 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.
96
-                $ao_ccss_rules['types'] = array_replace( array_intersect_key( array_flip( $ao_ccss_types ), $ao_ccss_rules['types'] ), $ao_ccss_rules['types'] );
96
+                $ao_ccss_rules['types'] = array_replace(array_intersect_key(array_flip($ao_ccss_types), $ao_ccss_rules['types']), $ao_ccss_rules['types']);
97 97
                 $is_front_page          = is_front_page();
98 98
 
99
-                foreach ( $ao_ccss_rules['types'] as $type => $rule ) {
100
-                    if ( in_array( $type, $ao_ccss_types ) && file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
101
-                        $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
102
-                        if ( $is_front_page && 'is_front_page' == $type ) {
103
-                            if ( 'none' != $_ccss_contents ) {
104
-                                if ( $ao_ccss_debug ) {
105
-                                    $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
99
+                foreach ($ao_ccss_rules['types'] as $type => $rule) {
100
+                    if (in_array($type, $ao_ccss_types) && file_exists(AO_CCSS_DIR.$rule['file'])) {
101
+                        $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
102
+                        if ($is_front_page && 'is_front_page' == $type) {
103
+                            if ('none' != $_ccss_contents) {
104
+                                if ($ao_ccss_debug) {
105
+                                    $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
106 106
                                 }
107
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
107
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
108 108
                             } else {
109 109
                                 $no_ccss = 'none';
110 110
                             }
111
-                        } elseif ( strpos( $type, 'custom_post_' ) === 0 && ! $is_front_page ) {
112
-                            if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
113
-                                if ( 'none' != $_ccss_contents ) {
114
-                                    if ( $ao_ccss_debug ) {
115
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
111
+                        } elseif (strpos($type, 'custom_post_') === 0 && !$is_front_page) {
112
+                            if (get_post_type(get_the_ID()) === substr($type, 12)) {
113
+                                if ('none' != $_ccss_contents) {
114
+                                    if ($ao_ccss_debug) {
115
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
116 116
                                     }
117
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
117
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
118 118
                                 } else {
119 119
                                     $no_ccss = 'none';
120 120
                                 }
121 121
                             }
122
-                        } elseif ( 0 === strpos( $type, 'template_' ) && ! $is_front_page ) {
123
-                            if ( is_page_template( substr( $type, 9 ) ) ) {
124
-                                if ( 'none' != $_ccss_contents ) {
125
-                                    if ( $ao_ccss_debug ) {
126
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
122
+                        } elseif (0 === strpos($type, 'template_') && !$is_front_page) {
123
+                            if (is_page_template(substr($type, 9))) {
124
+                                if ('none' != $_ccss_contents) {
125
+                                    if ($ao_ccss_debug) {
126
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
127 127
                                     }
128
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
128
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
129 129
                                 } else {
130 130
                                     $no_ccss = 'none';
131 131
                                 }
132 132
                             }
133
-                        } elseif ( ! $is_front_page ) {
133
+                        } elseif (!$is_front_page) {
134 134
                             // all "normal" conditional tags, core + woo + buddypress + edd + bbpress
135 135
                             // but we have to remove the prefix for the non-core ones for them to function.
136
-                            $type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
137
-                            if ( function_exists( $type ) && call_user_func( $type ) ) {
138
-                                if ( 'none' != $_ccss_contents ) {
139
-                                    if ( $ao_ccss_debug ) {
140
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
136
+                            $type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
137
+                            if (function_exists($type) && call_user_func($type)) {
138
+                                if ('none' != $_ccss_contents) {
139
+                                    if ($ao_ccss_debug) {
140
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
141 141
                                     }
142
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
142
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
143 143
                                 } else {
144 144
                                     $no_ccss = 'none';
145 145
                                 }
@@ -152,26 +152,26 @@  discard block
 block discarded – undo
152 152
 
153 153
         // Finally, inline the default CriticalCSS if any or else the entire CSS for the page
154 154
         // This also applies to logged in users if the option to add CCSS for logged in users has been disabled.
155
-        if ( ! empty( $inlined ) && 'none' !== $no_ccss ) {
156
-            return apply_filters( 'autoptimize_filter_ccss_core_ccss', $inlined . $ao_ccss_additional );
155
+        if (!empty($inlined) && 'none' !== $no_ccss) {
156
+            return apply_filters('autoptimize_filter_ccss_core_ccss', $inlined.$ao_ccss_additional);
157 157
         } else {
158
-            add_filter( 'autoptimize_filter_css_inline', '__return_true' );
158
+            add_filter('autoptimize_filter_css_inline', '__return_true');
159 159
             return;
160 160
         }
161 161
     }
162 162
 
163
-    public function ao_ccss_defer_jquery( $in ) {
163
+    public function ao_ccss_defer_jquery($in) {
164 164
         // try to defer all JS (main goal being jquery.js as AO by default does not aggregate that).
165
-        if ( ( ! is_user_logged_in() || $ao_ccss_loggedin ) && preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) {
166
-            foreach ( $matches as $match ) {
167
-                if ( ( ! preg_match( '/<script.* type\s?=.*>/', $match[0] ) || preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0] ) ) && '' !== $match[1] && ( false !== strpos( $match[1], 'jQuery' ) || false !== strpos( $match[1], '$' ) ) ) {
165
+        if ((!is_user_logged_in() || $ao_ccss_loggedin) && preg_match_all('#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER)) {
166
+            foreach ($matches as $match) {
167
+                if ((!preg_match('/<script.* type\s?=.*>/', $match[0]) || preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0])) && '' !== $match[1] && (false !== strpos($match[1], 'jQuery') || false !== strpos($match[1], '$'))) {
168 168
                     // inline js that requires jquery, wrap deferring JS around it to defer it.
169
-                    $new_match = 'var aoDeferInlineJQuery=function(){' . $match[1] . '}; if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", aoDeferInlineJQuery);} else {aoDeferInlineJQuery();}';
170
-                    $in        = str_replace( $match[1], $new_match, $in );
171
-                } elseif ( '' === $match[1] && false !== strpos( $match[0], 'src=' ) && false === strpos( $match[0], 'defer' ) ) {
169
+                    $new_match = 'var aoDeferInlineJQuery=function(){'.$match[1].'}; if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", aoDeferInlineJQuery);} else {aoDeferInlineJQuery();}';
170
+                    $in        = str_replace($match[1], $new_match, $in);
171
+                } elseif ('' === $match[1] && false !== strpos($match[0], 'src=') && false === strpos($match[0], 'defer')) {
172 172
                     // linked non-aggregated JS, defer it.
173
-                    $new_match = str_replace( '<script ', '<script defer ', $match[0] );
174
-                    $in        = str_replace( $match[0], $new_match, $in );
173
+                    $new_match = str_replace('<script ', '<script defer ', $match[0]);
174
+                    $in        = str_replace($match[0], $new_match, $in);
175 175
                 }
176 176
             }
177 177
         }
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
         global $ao_ccss_types;
185 185
 
186 186
         // in some cases $ao_ccss_types is empty and/or not an array, this should work around that problem.
187
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
187
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
188 188
             $ao_ccss_types = get_ao_ccss_core_types();
189
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Empty types array in extend, refetching array with core conditionals.', 3 );
189
+            autoptimizeCriticalCSSCore::ao_ccss_log('Empty types array in extend, refetching array with core conditionals.', 3);
190 190
         }
191 191
 
192 192
         // Custom Post Types.
@@ -198,18 +198,18 @@  discard block
 block discarded – undo
198 198
             'names',
199 199
             'and'
200 200
         );
201
-        foreach ( $cpts as $cpt ) {
202
-            array_unshift( $ao_ccss_types, 'custom_post_' . $cpt );
201
+        foreach ($cpts as $cpt) {
202
+            array_unshift($ao_ccss_types, 'custom_post_'.$cpt);
203 203
         }
204 204
 
205 205
         // Templates.
206 206
         $templates = wp_get_theme()->get_page_templates();
207
-        foreach ( $templates as $tplfile => $tplname ) {
208
-            array_unshift( $ao_ccss_types, 'template_' . $tplfile );
207
+        foreach ($templates as $tplfile => $tplname) {
208
+            array_unshift($ao_ccss_types, 'template_'.$tplfile);
209 209
         }
210 210
 
211 211
         // bbPress tags.
212
-        if ( function_exists( 'is_bbpress' ) ) {
212
+        if (function_exists('is_bbpress')) {
213 213
             $ao_ccss_types = array_merge(
214 214
                 array(
215 215
                     'bbp_is_bbpress',
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         }
242 242
 
243 243
         // BuddyPress tags.
244
-        if ( function_exists( 'is_buddypress' ) ) {
244
+        if (function_exists('is_buddypress')) {
245 245
             $ao_ccss_types = array_merge(
246 246
                 array(
247 247
                     'bp_is_activation_page',
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         }
284 284
 
285 285
         // Easy Digital Downloads (EDD) tags.
286
-        if ( function_exists( 'edd_is_checkout' ) ) {
286
+        if (function_exists('edd_is_checkout')) {
287 287
             $ao_ccss_types = array_merge(
288 288
                 array(
289 289
                     'edd_is_checkout',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
         }
296 296
 
297 297
         // WooCommerce tags.
298
-        if ( class_exists( 'WooCommerce' ) ) {
298
+        if (class_exists('WooCommerce')) {
299 299
             $ao_ccss_types = array_merge(
300 300
                 array(
301 301
                     'woo_is_account_page',
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
     public function get_ao_ccss_core_types() {
316 316
         global $ao_ccss_types;
317
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
317
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
318 318
             return array(
319 319
                 'is_404',
320 320
                 'is_archive',
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         }
336 336
     }
337 337
 
338
-    public static function ao_ccss_key_status( $render ) {
338
+    public static function ao_ccss_key_status($render) {
339 339
         // Provide key status
340 340
         // Get key and key status.
341 341
         global $ao_ccss_key;
@@ -348,55 +348,55 @@  discard block
 block discarded – undo
348 348
         $key_return = array();
349 349
         $status     = false;
350 350
 
351
-        if ( $key && 2 == $key_status ) {
351
+        if ($key && 2 == $key_status) {
352 352
             // Key exists and its status is valid.
353 353
             // Set valid key status.
354 354
             $status     = 'valid';
355
-            $status_msg = __( 'Valid' );
355
+            $status_msg = __('Valid');
356 356
             $color      = '#46b450'; // Green.
357 357
             $message    = null;
358
-        } elseif ( $key && 1 == $key_status ) {
358
+        } elseif ($key && 1 == $key_status) {
359 359
             // Key exists but its validation has failed.
360 360
             // Set invalid key status.
361 361
             $status     = 'invalid';
362
-            $status_msg = __( 'Invalid' );
362
+            $status_msg = __('Invalid');
363 363
             $color      = '#dc3232'; // Red.
364
-            $message    = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
365
-        } elseif ( $key && ! $key_status ) {
364
+            $message    = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
365
+        } elseif ($key && !$key_status) {
366 366
             // Key exists but it has no valid status yet
367 367
             // Perform key validation.
368
-            $key_check = $self->ao_ccss_key_validation( $key );
368
+            $key_check = $self->ao_ccss_key_validation($key);
369 369
 
370 370
             // Key is valid, set valid status.
371
-            if ( $key_check ) {
371
+            if ($key_check) {
372 372
                 $status     = 'valid';
373
-                $status_msg = __( 'Valid' );
373
+                $status_msg = __('Valid');
374 374
                 $color      = '#46b450'; // Green.
375 375
                 $message    = null;
376 376
             } else {
377 377
                 // Key is invalid, set invalid status.
378 378
                 $status     = 'invalid';
379
-                $status_msg = __( 'Invalid' );
379
+                $status_msg = __('Invalid');
380 380
                 $color      = '#dc3232'; // Red.
381
-                if ( get_option( 'autoptimize_ccss_keyst' ) == 1 ) {
382
-                    $message = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
381
+                if (get_option('autoptimize_ccss_keyst') == 1) {
382
+                    $message = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
383 383
                 } else {
384
-                    $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' );
384
+                    $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');
385 385
                 }
386 386
             }
387 387
         } else {
388 388
             // No key nor status
389 389
             // Set no key status.
390 390
             $status     = 'nokey';
391
-            $status_msg = __( 'None' );
391
+            $status_msg = __('None');
392 392
             $color      = '#ffb900'; // Yellow.
393
-            $message    = __( 'Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize' );
393
+            $message    = __('Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize');
394 394
         }
395 395
 
396 396
         // Fill returned values.
397 397
         $key_return['status'] = $status;
398 398
         // Provide rendering information if required.
399
-        if ( $render ) {
399
+        if ($render) {
400 400
             $key_return['stmsg'] = $status_msg;
401 401
             $key_return['color'] = $color;
402 402
             $key_return['msg']   = $message;
@@ -406,19 +406,19 @@  discard block
 block discarded – undo
406 406
         return $key_return;
407 407
     }
408 408
 
409
-    public function ao_ccss_key_validation( $key ) {
409
+    public function ao_ccss_key_validation($key) {
410 410
         // POST a dummy job to criticalcss.com to check for key validation
411 411
         // Prepare home URL for the request.
412 412
         $src_url = get_home_url();
413
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
413
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
414 414
 
415 415
         // Prepare the request.
416
-        $url  = esc_url_raw( AO_CCSS_API . 'generate' );
416
+        $url  = esc_url_raw(AO_CCSS_API.'generate');
417 417
         $args = array(
418 418
             'headers' => array(
419
-                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER,
419
+                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v'.AO_CCSS_VER,
420 420
                 'Content-type'  => 'application/json; charset=utf-8',
421
-                'Authorization' => 'JWT ' . $key,
421
+                'Authorization' => 'JWT '.$key,
422 422
                 'Connection'    => 'close',
423 423
             ),
424 424
             // Body must be JSON.
@@ -432,23 +432,23 @@  discard block
 block discarded – undo
432 432
         );
433 433
 
434 434
         // Dispatch the request and store its response code.
435
-        $req  = wp_safe_remote_post( $url, $args );
436
-        $code = wp_remote_retrieve_response_code( $req );
437
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
435
+        $req  = wp_safe_remote_post($url, $args);
436
+        $code = wp_remote_retrieve_response_code($req);
437
+        $body = json_decode(wp_remote_retrieve_body($req), true);
438 438
 
439
-        if ( 200 == $code ) {
439
+        if (200 == $code) {
440 440
             // Response is OK.
441 441
             // Set key status as valid and log key check.
442
-            update_option( 'autoptimize_ccss_keyst', 2 );
443
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
442
+            update_option('autoptimize_ccss_keyst', 2);
443
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
444 444
 
445 445
             // extract job-id from $body and put it in the queue as a P job
446 446
             // but only if no jobs and no rules!
447 447
             global $ao_ccss_queue;
448 448
             global $ao_ccss_rules;
449 449
 
450
-            if ( 0 == count( $ao_ccss_queue ) && 0 == count( $ao_ccss_rules['types'] ) && 0 == count( $ao_ccss_rules['paths'] ) ) {
451
-                if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] ) {
450
+            if (0 == count($ao_ccss_queue) && 0 == count($ao_ccss_rules['types']) && 0 == count($ao_ccss_rules['paths'])) {
451
+                if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status']) {
452 452
                     $jprops['ljid']     = 'firstrun';
453 453
                     $jprops['rtarget']  = 'types|is_front_page';
454 454
                     $jprops['ptype']    = 'is_front_page';
@@ -459,30 +459,30 @@  discard block
 block discarded – undo
459 459
                     $jprops['jqstat']   = $body['job']['status'];
460 460
                     $jprops['jrstat']   = null;
461 461
                     $jprops['jvstat']   = null;
462
-                    $jprops['jctime']   = microtime( true );
462
+                    $jprops['jctime']   = microtime(true);
463 463
                     $jprops['jftime']   = null;
464 464
                     $ao_ccss_queue['/'] = $jprops;
465
-                    $ao_ccss_queue_raw  = json_encode( $ao_ccss_queue );
466
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
467
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Created P job for is_front_page based on API key check response.', 3 );
465
+                    $ao_ccss_queue_raw  = json_encode($ao_ccss_queue);
466
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
467
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Created P job for is_front_page based on API key check response.', 3);
468 468
                 }
469 469
             }
470 470
             return true;
471
-        } elseif ( 401 == $code ) {
471
+        } elseif (401 == $code) {
472 472
             // Response is unauthorized
473 473
             // Set key status as invalid and log key check.
474
-            update_option( 'autoptimize_ccss_keyst', 1 );
475
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
474
+            update_option('autoptimize_ccss_keyst', 1);
475
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
476 476
             return false;
477 477
         } else {
478 478
             // Response unkown
479 479
             // Log key check attempt.
480
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2 );
481
-            if ( ! empty( $body ) ) {
482
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
480
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2);
481
+            if (!empty($body)) {
482
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
483 483
             }
484
-            if ( is_wp_error( $req ) ) {
485
-                autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
484
+            if (is_wp_error($req)) {
485
+                autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
486 486
             }
487 487
             return false;
488 488
         }
@@ -497,14 +497,14 @@  discard block
 block discarded – undo
497 497
         $viewport = array();
498 498
 
499 499
         // Viewport Width.
500
-        if ( ! empty( $ao_ccss_viewport['w'] ) ) {
500
+        if (!empty($ao_ccss_viewport['w'])) {
501 501
             $viewport['w'] = $ao_ccss_viewport['w'];
502 502
         } else {
503 503
             $viewport['w'] = '';
504 504
         }
505 505
 
506 506
         // Viewport Height.
507
-        if ( ! empty( $ao_ccss_viewport['h'] ) ) {
507
+        if (!empty($ao_ccss_viewport['h'])) {
508 508
             $viewport['h'] = $ao_ccss_viewport['h'];
509 509
         } else {
510 510
             $viewport['h'] = '';
@@ -513,23 +513,23 @@  discard block
 block discarded – undo
513 513
         return $viewport;
514 514
     }
515 515
 
516
-    public static function ao_ccss_check_contents( $ccss ) {
516
+    public static function ao_ccss_check_contents($ccss) {
517 517
         // Perform basic exploit avoidance and CSS validation.
518
-        if ( ! empty( $ccss ) ) {
518
+        if (!empty($ccss)) {
519 519
             // Try to avoid code injection.
520
-            $blacklist = array( '#!/', 'function(', '<script', '<?php' );
521
-            foreach ( $blacklist as $blacklisted ) {
522
-                if ( strpos( $ccss, $blacklisted ) !== false ) {
523
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received contained blacklisted content.', 2 );
520
+            $blacklist = array('#!/', 'function(', '<script', '<?php');
521
+            foreach ($blacklist as $blacklisted) {
522
+                if (strpos($ccss, $blacklisted) !== false) {
523
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received contained blacklisted content.', 2);
524 524
                     return false;
525 525
                 }
526 526
             }
527 527
 
528 528
             // Check for most basics CSS structures.
529
-            $pinklist = array( '{', '}', ':' );
530
-            foreach ( $pinklist as $needed ) {
531
-                if ( false === strpos( $ccss, $needed ) && 'none' !== $ccss ) {
532
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not seem to contain real CSS.', 2 );
529
+            $pinklist = array('{', '}', ':');
530
+            foreach ($pinklist as $needed) {
531
+                if (false === strpos($ccss, $needed) && 'none' !== $ccss) {
532
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not seem to contain real CSS.', 2);
533 533
                     return false;
534 534
                 }
535 535
             }
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         return true;
540 540
     }
541 541
 
542
-    public static function ao_ccss_log( $msg, $lvl ) {
542
+    public static function ao_ccss_log($msg, $lvl) {
543 543
         // Commom logging facility
544 544
         // Attach debug option.
545 545
         global $ao_ccss_debug;
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
         // 3: DD (for debug)
551 551
         // Default: UU (for unkown).
552 552
         $level = false;
553
-        switch ( $lvl ) {
553
+        switch ($lvl) {
554 554
             case 1:
555 555
                 $level = 'II';
556 556
                 break;
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
                 break;
560 560
             case 3:
561 561
                 // Output debug messages only if debug mode is enabled.
562
-                if ( $ao_ccss_debug ) {
562
+                if ($ao_ccss_debug) {
563 563
                     $level = 'DD';
564 564
                 }
565 565
                 break;
@@ -568,13 +568,13 @@  discard block
 block discarded – undo
568 568
         }
569 569
 
570 570
         // Prepare and write a log message if there's a valid level.
571
-        if ( $level ) {
571
+        if ($level) {
572 572
 
573 573
             // Prepare message.
574
-            $message = date( 'c' ) . ' - [' . $level . '] ' . htmlentities( $msg ) . '<br>';
574
+            $message = date('c').' - ['.$level.'] '.htmlentities($msg).'<br>';
575 575
 
576 576
             // Write message to log file.
577
-            error_log( $message, 3, AO_CCSS_LOG );
577
+            error_log($message, 3, AO_CCSS_LOG);
578 578
         }
579 579
     }
580 580
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettingsAjax.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS settings AJAX logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
@@ -21,47 +21,47 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function run() {
23 23
         // add filters.
24
-        add_action( 'wp_ajax_fetch_critcss', array( $this, 'critcss_fetch_callback' ) );
25
-        add_action( 'wp_ajax_save_critcss', array( $this, 'critcss_save_callback' ) );
26
-        add_action( 'wp_ajax_rm_critcss', array( $this, 'critcss_rm_callback' ) );
27
-        add_action( 'wp_ajax_rm_critcss_all', array( $this, 'critcss_rm_all_callback' ) );
28
-        add_action( 'wp_ajax_ao_ccss_export', array( $this, 'ao_ccss_export_callback' ) );
29
-        add_action( 'wp_ajax_ao_ccss_import', array( $this, 'ao_ccss_import_callback' ) );
24
+        add_action('wp_ajax_fetch_critcss', array($this, 'critcss_fetch_callback'));
25
+        add_action('wp_ajax_save_critcss', array($this, 'critcss_save_callback'));
26
+        add_action('wp_ajax_rm_critcss', array($this, 'critcss_rm_callback'));
27
+        add_action('wp_ajax_rm_critcss_all', array($this, 'critcss_rm_all_callback'));
28
+        add_action('wp_ajax_ao_ccss_export', array($this, 'ao_ccss_export_callback'));
29
+        add_action('wp_ajax_ao_ccss_import', array($this, 'ao_ccss_import_callback'));
30 30
     }
31 31
 
32 32
     public function critcss_fetch_callback() {
33 33
         // Ajax handler to obtain a critical CSS file from the filesystem.
34 34
         // Check referer.
35
-        check_ajax_referer( 'fetch_critcss_nonce', 'critcss_fetch_nonce' );
35
+        check_ajax_referer('fetch_critcss_nonce', 'critcss_fetch_nonce');
36 36
 
37 37
         // Initialize error flag.
38 38
         $error = true;
39 39
 
40 40
         // Allow no content for MANUAL rules (as they may not exist just yet).
41
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
41
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
42 42
             $content = '';
43 43
             $error   = false;
44
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
44
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
45 45
             // Or check user permissios and filename.
46 46
             // Set file path and obtain its content.
47
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
48
-            if ( file_exists( $critcssfile ) ) {
49
-                $content = file_get_contents( $critcssfile );
47
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
48
+            if (file_exists($critcssfile)) {
49
+                $content = file_get_contents($critcssfile);
50 50
                 $error   = false;
51 51
             }
52 52
         }
53 53
 
54 54
         // Prepare response.
55
-        if ( $error ) {
55
+        if ($error) {
56 56
             $response['code']   = '500';
57
-            $response['string'] = 'Error reading file ' . $critcssfile . '.';
57
+            $response['string'] = 'Error reading file '.$critcssfile.'.';
58 58
         } else {
59 59
             $response['code']   = '200';
60 60
             $response['string'] = $content;
61 61
         }
62 62
 
63 63
         // Dispatch respose.
64
-        echo json_encode( $response );
64
+        echo json_encode($response);
65 65
 
66 66
         // Close ajax request.
67 67
         wp_die();
@@ -74,22 +74,22 @@  discard block
 block discarded – undo
74 74
 
75 75
         // Ajax handler to write a critical CSS to the filesystem
76 76
         // Check referer.
77
-        check_ajax_referer( 'save_critcss_nonce', 'critcss_save_nonce' );
77
+        check_ajax_referer('save_critcss_nonce', 'critcss_save_nonce');
78 78
 
79 79
         // Allow empty contents for MANUAL rules (as they are fetched later).
80
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
80
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
81 81
             $critcssfile = false;
82 82
             $status      = true;
83
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
83
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
84 84
             // Or check user permissios and filename
85 85
             // Set critical CSS content.
86
-            $critcsscontents = stripslashes( $_POST['critcsscontents'] );
86
+            $critcsscontents = stripslashes($_POST['critcsscontents']);
87 87
 
88 88
             // If there is content and it's valid, write the file.
89
-            if ( $critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents( $critcsscontents ) ) {
89
+            if ($critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents($critcsscontents)) {
90 90
                 // Set file path and status.
91
-                $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
92
-                $status      = file_put_contents( $critcssfile, $critcsscontents, LOCK_EX );
91
+                $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
92
+                $status      = file_put_contents($critcssfile, $critcsscontents, LOCK_EX);
93 93
                 // Or set as error.
94 94
             } else {
95 95
                 $error = true;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
         }
101 101
 
102 102
         // Prepare response.
103
-        if ( ! $status || $error ) {
103
+        if (!$status || $error) {
104 104
             $response['code']   = '500';
105
-            $response['string'] = 'Error saving file ' . $critcssfile . '.';
105
+            $response['string'] = 'Error saving file '.$critcssfile.'.';
106 106
         } else {
107 107
             $response['code'] = '200';
108
-            if ( $critcssfile ) {
109
-                $response['string'] = 'File ' . $critcssfile . ' saved.';
108
+            if ($critcssfile) {
109
+                $response['string'] = 'File '.$critcssfile.' saved.';
110 110
             } else {
111 111
                 $response['string'] = 'Empty content do not need to be saved.';
112 112
             }
113 113
         }
114 114
 
115 115
         // Dispatch respose.
116
-        echo json_encode( $response );
116
+        echo json_encode($response);
117 117
 
118 118
         // Close ajax request.
119 119
         wp_die();
@@ -123,40 +123,40 @@  discard block
 block discarded – undo
123 123
     public function critcss_rm_callback() {
124 124
         // Ajax handler to delete a critical CSS from the filesystem
125 125
         // Check referer.
126
-        check_ajax_referer( 'rm_critcss_nonce', 'critcss_rm_nonce' );
126
+        check_ajax_referer('rm_critcss_nonce', 'critcss_rm_nonce');
127 127
 
128 128
         // Initialize error and status flags.
129 129
         $error  = true;
130 130
         $status = false;
131 131
 
132 132
         // Allow no file for MANUAL rules (as they may not exist just yet).
133
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
133
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
134 134
             $error = false;
135
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
135
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
136 136
             // Or check user permissios and filename
137 137
             // Set file path and delete it.
138
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
139
-            if ( file_exists( $critcssfile ) ) {
140
-                $status = unlink( $critcssfile );
138
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
139
+            if (file_exists($critcssfile)) {
140
+                $status = unlink($critcssfile);
141 141
                 $error  = false;
142 142
             }
143 143
         }
144 144
 
145 145
         // Prepare response.
146
-        if ( $error ) {
146
+        if ($error) {
147 147
             $response['code']   = '500';
148
-            $response['string'] = 'Error removing file ' . $critcssfile . '.';
148
+            $response['string'] = 'Error removing file '.$critcssfile.'.';
149 149
         } else {
150 150
             $response['code'] = '200';
151
-            if ( $status ) {
152
-                $response['string'] = 'File ' . $critcssfile . ' removed.';
151
+            if ($status) {
152
+                $response['string'] = 'File '.$critcssfile.' removed.';
153 153
             } else {
154 154
                 $response['string'] = 'No file to be removed.';
155 155
             }
156 156
         }
157 157
 
158 158
         // Dispatch respose.
159
-        echo json_encode( $response );
159
+        echo json_encode($response);
160 160
 
161 161
         // Close ajax request.
162 162
         wp_die();
@@ -165,28 +165,28 @@  discard block
 block discarded – undo
165 165
     public function critcss_rm_all_callback() {
166 166
         // Ajax handler to delete a critical CSS from the filesystem
167 167
         // Check referer.
168
-        check_ajax_referer( 'rm_critcss_all_nonce', 'critcss_rm_all_nonce' );
168
+        check_ajax_referer('rm_critcss_all_nonce', 'critcss_rm_all_nonce');
169 169
 
170 170
         // Initialize error and status flags.
171 171
         $error  = true;
172 172
         $status = false;
173 173
 
174 174
         // Remove all ccss files on filesystem.
175
-        if ( current_user_can( 'manage_options' ) ) {
176
-            if ( file_exists( AO_CCSS_DIR ) && is_dir( AO_CCSS_DIR ) ) {
177
-                array_map( 'unlink', glob( AO_CCSS_DIR . 'ccss_*.css', GLOB_BRACE ) );
175
+        if (current_user_can('manage_options')) {
176
+            if (file_exists(AO_CCSS_DIR) && is_dir(AO_CCSS_DIR)) {
177
+                array_map('unlink', glob(AO_CCSS_DIR.'ccss_*.css', GLOB_BRACE));
178 178
                 $error  = false;
179 179
                 $status = true;
180 180
             }
181 181
         }
182 182
 
183 183
         // Prepare response.
184
-        if ( $error ) {
184
+        if ($error) {
185 185
             $response['code']   = '500';
186 186
             $response['string'] = 'Error removing all critical CSS files.';
187 187
         } else {
188 188
             $response['code'] = '200';
189
-            if ( $status ) {
189
+            if ($status) {
190 190
                 $response['string'] = 'Critical CSS Files removed.';
191 191
             } else {
192 192
                 $response['string'] = 'No file removed.';
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Dispatch respose.
197
-        echo json_encode( $response );
197
+        echo json_encode($response);
198 198
 
199 199
         // Close ajax request.
200 200
         wp_die();
@@ -203,70 +203,70 @@  discard block
 block discarded – undo
203 203
     public function ao_ccss_export_callback() {
204 204
         // Ajax handler export settings
205 205
         // Check referer.
206
-        check_ajax_referer( 'ao_ccss_export_nonce', 'ao_ccss_export_nonce' );
206
+        check_ajax_referer('ao_ccss_export_nonce', 'ao_ccss_export_nonce');
207 207
 
208
-        if ( ! class_exists( 'ZipArchive' ) ) {
208
+        if (!class_exists('ZipArchive')) {
209 209
             $response['code'] = '500';
210 210
             $response['msg']  = 'PHP ZipArchive not present, cannot create zipfile';
211
-            echo json_encode( $response );
211
+            echo json_encode($response);
212 212
             wp_die();
213 213
         }
214 214
 
215 215
         // Init array, get options and prepare the raw object.
216 216
         $settings               = array();
217
-        $settings['rules']      = get_option( 'autoptimize_ccss_rules' );
218
-        $settings['additional'] = get_option( 'autoptimize_ccss_additional' );
219
-        $settings['viewport']   = get_option( 'autoptimize_ccss_viewport' );
220
-        $settings['finclude']   = get_option( 'autoptimize_ccss_finclude' );
221
-        $settings['rlimit']     = get_option( 'autoptimize_ccss_rlimit' );
222
-        $settings['noptimize']  = get_option( 'autoptimize_ccss_noptimize' );
223
-        $settings['debug']      = get_option( 'autoptimize_ccss_debug' );
224
-        $settings['key']        = get_option( 'autoptimize_ccss_key' );
217
+        $settings['rules']      = get_option('autoptimize_ccss_rules');
218
+        $settings['additional'] = get_option('autoptimize_ccss_additional');
219
+        $settings['viewport']   = get_option('autoptimize_ccss_viewport');
220
+        $settings['finclude']   = get_option('autoptimize_ccss_finclude');
221
+        $settings['rlimit']     = get_option('autoptimize_ccss_rlimit');
222
+        $settings['noptimize']  = get_option('autoptimize_ccss_noptimize');
223
+        $settings['debug']      = get_option('autoptimize_ccss_debug');
224
+        $settings['key']        = get_option('autoptimize_ccss_key');
225 225
 
226 226
         // Initialize error flag.
227 227
         $error = true;
228 228
 
229 229
         // Check user permissions.
230
-        if ( current_user_can( 'manage_options' ) ) {
230
+        if (current_user_can('manage_options')) {
231 231
             // Prepare settings file path and content.
232
-            $exportfile = AO_CCSS_DIR . 'settings.json';
233
-            $contents   = json_encode( $settings );
234
-            $status     = file_put_contents( $exportfile, $contents, LOCK_EX );
232
+            $exportfile = AO_CCSS_DIR.'settings.json';
233
+            $contents   = json_encode($settings);
234
+            $status     = file_put_contents($exportfile, $contents, LOCK_EX);
235 235
             $error      = false;
236 236
         }
237 237
 
238 238
         // Prepare archive.
239
-        $zipfile = AO_CCSS_DIR . date( 'Ymd-H\hi' ) . '_ao_ccss_settings.zip';
240
-        $file    = pathinfo( $zipfile, PATHINFO_BASENAME );
239
+        $zipfile = AO_CCSS_DIR.date('Ymd-H\hi').'_ao_ccss_settings.zip';
240
+        $file    = pathinfo($zipfile, PATHINFO_BASENAME);
241 241
         $zip     = new ZipArchive();
242
-        $ret     = $zip->open( $zipfile, ZipArchive::CREATE );
243
-        if ( true !== $ret ) {
242
+        $ret     = $zip->open($zipfile, ZipArchive::CREATE);
243
+        if (true !== $ret) {
244 244
             $error = true;
245 245
         } else {
246
-            $zip->addFile( AO_CCSS_DIR . 'settings.json', 'settings.json' );
247
-            if ( file_exists( AO_CCSS_DIR . 'queue.json' ) ) {
248
-                $zip->addFile( AO_CCSS_DIR . 'queue.json', 'queue.json' );
246
+            $zip->addFile(AO_CCSS_DIR.'settings.json', 'settings.json');
247
+            if (file_exists(AO_CCSS_DIR.'queue.json')) {
248
+                $zip->addFile(AO_CCSS_DIR.'queue.json', 'queue.json');
249 249
             }
250 250
             $options = array(
251 251
                 'add_path'        => './',
252 252
                 'remove_all_path' => true,
253 253
             );
254
-            $zip->addGlob( AO_CCSS_DIR . '*.css', 0, $options );
254
+            $zip->addGlob(AO_CCSS_DIR.'*.css', 0, $options);
255 255
             $zip->close();
256 256
         }
257 257
 
258 258
         // Prepare response.
259
-        if ( ! $status || $error ) {
259
+        if (!$status || $error) {
260 260
             $response['code'] = '500';
261
-            $response['msg']  = 'Error saving file ' . $file . ', code: ' . $ret;
261
+            $response['msg']  = 'Error saving file '.$file.', code: '.$ret;
262 262
         } else {
263 263
             $response['code'] = '200';
264
-            $response['msg']  = 'File ' . $file . ' saved.';
264
+            $response['msg']  = 'File '.$file.' saved.';
265 265
             $response['file'] = $file;
266 266
         }
267 267
 
268 268
         // Dispatch respose.
269
-        echo json_encode( $response );
269
+        echo json_encode($response);
270 270
 
271 271
         // Close ajax request.
272 272
         wp_die();
@@ -275,44 +275,44 @@  discard block
 block discarded – undo
275 275
     public function ao_ccss_import_callback() {
276 276
         // Ajax handler import settings
277 277
         // Check referer.
278
-        check_ajax_referer( 'ao_ccss_import_nonce', 'ao_ccss_import_nonce' );
278
+        check_ajax_referer('ao_ccss_import_nonce', 'ao_ccss_import_nonce');
279 279
 
280 280
         // Initialize error flag.
281 281
         $error = false;
282 282
 
283 283
         // Process an uploaded file with no errors.
284
-        if ( ! $_FILES['file']['error'] ) {
284
+        if (!$_FILES['file']['error']) {
285 285
             // Save file to the cache directory.
286
-            $zipfile = AO_CCSS_DIR . $_FILES['file']['name'];
287
-            move_uploaded_file( $_FILES['file']['tmp_name'], $zipfile );
286
+            $zipfile = AO_CCSS_DIR.$_FILES['file']['name'];
287
+            move_uploaded_file($_FILES['file']['tmp_name'], $zipfile);
288 288
 
289 289
             // Extract archive.
290 290
             $zip = new ZipArchive;
291
-            if ( $zip->open( $zipfile ) === true ) {
292
-                $zip->extractTo( AO_CCSS_DIR );
291
+            if ($zip->open($zipfile) === true) {
292
+                $zip->extractTo(AO_CCSS_DIR);
293 293
                 $zip->close();
294 294
             } else {
295 295
                 $error = 'extracting';
296 296
             }
297 297
 
298
-            if ( ! $error ) {
298
+            if (!$error) {
299 299
                 // Archive extraction ok, continue settings importing
300 300
                 // Settings file.
301
-                $importfile = AO_CCSS_DIR . 'settings.json';
301
+                $importfile = AO_CCSS_DIR.'settings.json';
302 302
 
303
-                if ( file_exists( $importfile ) ) {
303
+                if (file_exists($importfile)) {
304 304
                     // Get settings and turn them into an object.
305
-                    $settings = json_decode( file_get_contents( $importfile ), true );
305
+                    $settings = json_decode(file_get_contents($importfile), true);
306 306
 
307 307
                     // Update options.
308
-                    update_option( 'autoptimize_ccss_rules', $settings['rules'] );
309
-                    update_option( 'autoptimize_ccss_additional', $settings['additional'] );
310
-                    update_option( 'autoptimize_ccss_viewport', $settings['viewport'] );
311
-                    update_option( 'autoptimize_ccss_finclude', $settings['finclude'] );
312
-                    update_option( 'autoptimize_ccss_rlimit', $settings['rlimit'] );
313
-                    update_option( 'autoptimize_ccss_noptimize', $settings['noptimize'] );
314
-                    update_option( 'autoptimize_ccss_debug', $settings['debug'] );
315
-                    update_option( 'autoptimize_ccss_key', $settings['key'] );
308
+                    update_option('autoptimize_ccss_rules', $settings['rules']);
309
+                    update_option('autoptimize_ccss_additional', $settings['additional']);
310
+                    update_option('autoptimize_ccss_viewport', $settings['viewport']);
311
+                    update_option('autoptimize_ccss_finclude', $settings['finclude']);
312
+                    update_option('autoptimize_ccss_rlimit', $settings['rlimit']);
313
+                    update_option('autoptimize_ccss_noptimize', $settings['noptimize']);
314
+                    update_option('autoptimize_ccss_debug', $settings['debug']);
315
+                    update_option('autoptimize_ccss_key', $settings['key']);
316 316
                 } else {
317 317
                     // Settings file doesn't exist, update error flag.
318 318
                     $error = 'settings file does not exist';
@@ -321,28 +321,28 @@  discard block
 block discarded – undo
321 321
         }
322 322
 
323 323
         // Prepare response.
324
-        if ( $error ) {
324
+        if ($error) {
325 325
             $response['code'] = '500';
326
-            $response['msg']  = 'Error importing settings: ' . $error;
326
+            $response['msg']  = 'Error importing settings: '.$error;
327 327
         } else {
328 328
             $response['code'] = '200';
329 329
             $response['msg']  = 'Settings imported successfully';
330 330
         }
331 331
 
332 332
         // Dispatch respose.
333
-        echo json_encode( $response );
333
+        echo json_encode($response);
334 334
 
335 335
         // Close ajax request.
336 336
         wp_die();
337 337
     }
338 338
 
339
-    public function critcss_check_filename( $filename ) {
339
+    public function critcss_check_filename($filename) {
340 340
         // Try to avoid directory traversal when reading/writing/deleting critical CSS files.
341
-        if ( strpos( $filename, 'ccss_' ) !== 0 ) {
341
+        if (strpos($filename, 'ccss_') !== 0) {
342 342
             return false;
343
-        } elseif ( substr( $filename, -4, 4 ) !== '.css' ) {
343
+        } elseif (substr($filename, -4, 4) !== '.css') {
344 344
             return false;
345
-        } elseif ( sanitize_file_name( $filename ) !== $filename ) {
345
+        } elseif (sanitize_file_name($filename) !== $filename) {
346 346
             // Use WordPress core's sanitize_file_name to see if anything fishy is going on.
347 347
             return false;
348 348
         } else {
Please login to merge, or discard this patch.
classes/autoptimizeCache.php 1 patch
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles disk-cache-related operations.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
      * @param string $md5 Hash.
39 39
      * @param string $ext Extension.
40 40
      */
41
-    public function __construct( $md5, $ext = 'php' )
41
+    public function __construct($md5, $ext = 'php')
42 42
     {
43 43
         $_min_ext = '';
44
-        if ( apply_filters( 'autoptimize_filter_cache_url_add_min_ext', false ) ) {
44
+        if (apply_filters('autoptimize_filter_cache_url_add_min_ext', false)) {
45 45
             $_min_ext = '.min';
46 46
         }
47 47
 
48 48
         $this->cachedir = AUTOPTIMIZE_CACHE_DIR;
49 49
         $this->nogzip   = AUTOPTIMIZE_CACHE_NOGZIP;
50
-        if ( ! $this->nogzip ) {
51
-            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.php';
50
+        if (!$this->nogzip) {
51
+            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.php';
52 52
         } else {
53
-            if ( in_array( $ext, array( 'js', 'css' ) ) ) {
54
-                $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
53
+            if (in_array($ext, array('js', 'css'))) {
54
+                $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
55 55
             } else {
56
-                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
56
+                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
57 57
             }
58 58
         }
59 59
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function check()
67 67
     {
68
-        return file_exists( $this->cachedir . $this->filename );
68
+        return file_exists($this->cachedir.$this->filename);
69 69
     }
70 70
 
71 71
     /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function retrieve()
77 77
     {
78
-        if ( $this->check() ) {
79
-            if ( false == $this->nogzip ) {
80
-                return file_get_contents( $this->cachedir . $this->filename . '.none' );
78
+        if ($this->check()) {
79
+            if (false == $this->nogzip) {
80
+                return file_get_contents($this->cachedir.$this->filename.'.none');
81 81
             } else {
82
-                return file_get_contents( $this->cachedir . $this->filename );
82
+                return file_get_contents($this->cachedir.$this->filename);
83 83
             }
84 84
         }
85 85
         return false;
@@ -93,50 +93,50 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return void
95 95
      */
96
-    public function cache( $data, $mime )
96
+    public function cache($data, $mime)
97 97
     {
98 98
         // off by default; check if cachedirs exist every time before caching
99 99
         //
100 100
         // to be activated for users that experience these ugly errors;
101 101
         // PHP Warning: file_put_contents failed to open stream: No such file or directory.
102
-        if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) {
102
+        if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) {
103 103
             $this->check_and_create_dirs();
104 104
         }
105 105
 
106
-        if ( false === $this->nogzip ) {
106
+        if (false === $this->nogzip) {
107 107
             // We handle gzipping ourselves.
108 108
             $file    = 'default.php';
109
-            $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file );
110
-            $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode );
109
+            $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file);
110
+            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode);
111 111
 
112
-            file_put_contents( $this->cachedir . $this->filename, $phpcode );
113
-            file_put_contents( $this->cachedir . $this->filename . '.none', $data );
112
+            file_put_contents($this->cachedir.$this->filename, $phpcode);
113
+            file_put_contents($this->cachedir.$this->filename.'.none', $data);
114 114
         } else {
115 115
             // Write code to cache without doing anything else.
116
-            file_put_contents( $this->cachedir . $this->filename, $data );
116
+            file_put_contents($this->cachedir.$this->filename, $data);
117 117
 
118 118
             // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single.
119
-            if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) {
120
-                $_extension     = pathinfo( $this->filename, PATHINFO_EXTENSION );
121
-                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension;
122
-                if ( ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) {
123
-                    file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data );
119
+            if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) {
120
+                $_extension     = pathinfo($this->filename, PATHINFO_EXTENSION);
121
+                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension;
122
+                if (!file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) {
123
+                    file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data);
124 124
                 }
125 125
             }
126 126
 
127
-            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) {
127
+            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) {
128 128
                 // Create an additional cached gzip file.
129
-                file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) );
129
+                file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP));
130 130
                 // If PHP Brotli extension is installed, create an additional cached Brotli file.
131
-                if ( function_exists( 'brotli_compress' ) ) {
132
-                    file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) );
131
+                if (function_exists('brotli_compress')) {
132
+                    file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC));
133 133
                 }
134 134
             }
135 135
         }
136 136
 
137 137
         // Provide 3rd party action hook for every cache file that is created.
138 138
         // This hook can for example be used to inject a copy of the created cache file to a other domain.
139
-        do_action( 'autoptimize_action_cache_file_created', $this->cachedir . $this->filename );
139
+        do_action('autoptimize_action_cache_file_created', $this->cachedir.$this->filename);
140 140
     }
141 141
 
142 142
     /**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         // The original idea here was to provide 3rd party code a hook so that
152 152
         // it can "listen" to all the complete autoptimized-urls that the page
153 153
         // will emit... Or something to that effect I think?
154
-        apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename );
154
+        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename);
155 155
 
156 156
         return $this->filename;
157 157
     }
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
      * @param string $file Filename.
165 165
      * @return bool
166 166
      */
167
-    protected static function is_valid_cache_file( $dir, $file )
167
+    protected static function is_valid_cache_file($dir, $file)
168 168
     {
169
-        if ( '.' !== $file && '..' !== $file &&
170
-            false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) &&
171
-            is_file( $dir . $file ) ) {
169
+        if ('.' !== $file && '..' !== $file &&
170
+            false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) &&
171
+            is_file($dir.$file)) {
172 172
 
173 173
             // It's a valid file!
174 174
             return true;
@@ -186,16 +186,16 @@  discard block
 block discarded – undo
186 186
     protected static function clear_cache_classic()
187 187
     {
188 188
         $contents = self::get_cache_contents();
189
-        foreach ( $contents as $name => $files ) {
190
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
191
-            foreach ( $files as $file ) {
192
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
193
-                    @unlink( $dir . $file ); // @codingStandardsIgnoreLine
189
+        foreach ($contents as $name => $files) {
190
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
191
+            foreach ($files as $file) {
192
+                if (self::is_valid_cache_file($dir, $file)) {
193
+                    @unlink($dir.$file); // @codingStandardsIgnoreLine
194 194
                 }
195 195
             }
196 196
         }
197 197
 
198
-        @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine
198
+        @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine
199 199
     }
200 200
 
201 201
     /**
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
      *
207 207
      * @return bool
208 208
      */
209
-    protected static function rmdir( $pathname )
209
+    protected static function rmdir($pathname)
210 210
     {
211
-        $files = self::get_dir_contents( $pathname );
212
-        foreach ( $files as $file ) {
213
-            $path = $pathname . '/' . $file;
214
-            if ( is_dir( $path ) ) {
215
-                self::rmdir( $path );
211
+        $files = self::get_dir_contents($pathname);
212
+        foreach ($files as $file) {
213
+            $path = $pathname.'/'.$file;
214
+            if (is_dir($path)) {
215
+                self::rmdir($path);
216 216
             } else {
217
-                unlink( $path );
217
+                unlink($path);
218 218
             }
219 219
         }
220 220
 
221
-        return rmdir( $pathname );
221
+        return rmdir($pathname);
222 222
     }
223 223
 
224 224
     /**
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
         $new_name = self::get_unique_name();
240 240
 
241 241
         // Makes sure the new pathname is on the same level...
242
-        $new_pathname = dirname( $dir ) . '/' . $new_name;
243
-        $renamed      = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine
242
+        $new_pathname = dirname($dir).'/'.$new_name;
243
+        $renamed      = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine
244 244
 
245 245
         // When renamed, re-create the default cache directory back so it's
246 246
         // available again...
247
-        if ( $renamed ) {
247
+        if ($renamed) {
248 248
             $ok = self::cacheavail();
249 249
         }
250 250
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public static function advanced_cache_clear_enabled()
260 260
     {
261
-        return apply_filters( 'autoptimize_filter_cache_clear_advanced', false );
261
+        return apply_filters('autoptimize_filter_cache_clear_advanced', false);
262 262
     }
263 263
 
264 264
     /**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     protected static function get_unique_name()
270 270
     {
271 271
         $prefix   = self::get_advanced_cache_clear_prefix();
272
-        $new_name = uniqid( $prefix, true );
272
+        $new_name = uniqid($prefix, true);
273 273
 
274 274
         return $new_name;
275 275
     }
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
     protected static function get_advanced_cache_clear_prefix()
283 283
     {
284 284
         $pathname = self::get_pathname_base();
285
-        $basename = basename( $pathname );
286
-        $prefix   = $basename . '-artifact-';
285
+        $basename = basename($pathname);
286
+        $prefix   = $basename.'-artifact-';
287 287
 
288 288
         return $prefix;
289 289
     }
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return array
298 298
      */
299
-    protected static function get_dir_contents( $pathname )
299
+    protected static function get_dir_contents($pathname)
300 300
     {
301
-        return array_slice( scandir( $pathname ), 2 );
301
+        return array_slice(scandir($pathname), 2);
302 302
     }
303 303
 
304 304
     /**
@@ -311,24 +311,24 @@  discard block
 block discarded – undo
311 311
     public static function delete_advanced_cache_clear_artifacts()
312 312
     {
313 313
         // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active.
314
-        if ( ! self::advanced_cache_clear_enabled() ) {
314
+        if (!self::advanced_cache_clear_enabled()) {
315 315
             return false;
316 316
         }
317 317
 
318 318
         $dir    = self::get_pathname_base();
319 319
         $prefix = self::get_advanced_cache_clear_prefix();
320
-        $parent = dirname( $dir );
320
+        $parent = dirname($dir);
321 321
         $ok     = false;
322 322
 
323 323
         // Returns the list of files without '.' and '..' elements.
324
-        $files = self::get_dir_contents( $parent );
325
-        if ( is_array( $files ) && ! empty( $files ) ) {
326
-            foreach ( $files as $file ) {
327
-                $path     = $parent . '/' . $file;
328
-                $prefixed = ( false !== strpos( $path, $prefix ) );
324
+        $files = self::get_dir_contents($parent);
325
+        if (is_array($files) && !empty($files)) {
326
+            foreach ($files as $file) {
327
+                $path     = $parent.'/'.$file;
328
+                $prefixed = (false !== strpos($path, $prefix));
329 329
                 // Removing only our own (prefixed) directories...
330
-                if ( is_dir( $path ) && $prefixed ) {
331
-                    $ok = self::rmdir( $path );
330
+                if (is_dir($path) && $prefixed) {
331
+                    $ok = self::rmdir($path);
332 332
                 }
333 333
             }
334 334
         }
@@ -348,9 +348,9 @@  discard block
 block discarded – undo
348 348
     {
349 349
         $pathname = self::get_pathname_base();
350 350
 
351
-        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
351
+        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
352 352
             $blog_id   = get_current_blog_id();
353
-            $pathname .= $blog_id . '/';
353
+            $pathname .= $blog_id.'/';
354 354
         }
355 355
 
356 356
         return $pathname;
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      */
364 364
     protected static function get_pathname_base()
365 365
     {
366
-        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
366
+        $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR;
367 367
 
368 368
         return $pathname;
369 369
     }
@@ -375,46 +375,46 @@  discard block
 block discarded – undo
375 375
      *
376 376
      * @return bool
377 377
      */
378
-    public static function clearall( $propagate = true )
378
+    public static function clearall($propagate = true)
379 379
     {
380
-        if ( ! self::cacheavail() ) {
380
+        if (!self::cacheavail()) {
381 381
             return false;
382 382
         }
383 383
 
384 384
         // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
385
-        if ( self::advanced_cache_clear_enabled() ) {
385
+        if (self::advanced_cache_clear_enabled()) {
386 386
             self::clear_cache_via_rename();
387 387
         } else {
388 388
             self::clear_cache_classic();
389 389
         }
390 390
 
391 391
         // Remove 404 handler if required.
392
-        if ( self::do_fallback() ) {
393
-            $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php';
394
-            @unlink( $_fallback_php ); // @codingStandardsIgnoreLine
392
+        if (self::do_fallback()) {
393
+            $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php';
394
+            @unlink($_fallback_php); // @codingStandardsIgnoreLine
395 395
         }
396 396
 
397 397
         // Remove the transient so it gets regenerated...
398
-        delete_transient( 'autoptimize_stats' );
398
+        delete_transient('autoptimize_stats');
399 399
 
400 400
         // Cache was just purged, clear page cache and allow others to hook into our purging...
401
-        if ( true === $propagate ) {
402
-            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) {
401
+        if (true === $propagate) {
402
+            if (!function_exists('autoptimize_do_cachepurged_action')) {
403 403
                 function autoptimize_do_cachepurged_action() {
404
-                    do_action( 'autoptimize_action_cachepurged' );
404
+                    do_action('autoptimize_action_cachepurged');
405 405
                 }
406 406
             }
407
-            add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 );
408
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 );
407
+            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11);
408
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0);
409 409
         }
410 410
 
411 411
         // Warm cache (part of speedupper)!
412
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) {
413
-            set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 );
414
-            $url   = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 );
415
-            $url   = apply_filters( 'autoptimize_filter_cache_warmer_url', $url );
416
-            $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine
417
-            unset( $cache );
412
+        if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) {
413
+            set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10);
414
+            $url   = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000);
415
+            $url   = apply_filters('autoptimize_filter_cache_warmer_url', $url);
416
+            $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine
417
+            unset($cache);
418 418
         }
419 419
 
420 420
         return true;
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
      */
430 430
     public static function clearall_actionless()
431 431
     {
432
-        return self::clearall( false );
432
+        return self::clearall(false);
433 433
     }
434 434
 
435 435
     /**
@@ -441,8 +441,8 @@  discard block
 block discarded – undo
441 441
     {
442 442
         $contents = array();
443 443
 
444
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
445
-            $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir );
444
+        foreach (array('', 'js', 'css') as $dir) {
445
+            $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir);
446 446
         }
447 447
 
448 448
         return $contents;
@@ -455,21 +455,21 @@  discard block
 block discarded – undo
455 455
      */
456 456
     public static function stats()
457 457
     {
458
-        $stats = get_transient( 'autoptimize_stats' );
458
+        $stats = get_transient('autoptimize_stats');
459 459
 
460 460
         // If no transient, do the actual scan!
461
-        if ( ! is_array( $stats ) ) {
462
-            if ( ! self::cacheavail() ) {
461
+        if (!is_array($stats)) {
462
+            if (!self::cacheavail()) {
463 463
                 return 0;
464 464
             }
465 465
             $stats = self::stats_scan();
466 466
             $count = $stats[0];
467
-            if ( $count > 100 ) {
467
+            if ($count > 100) {
468 468
                 // Store results in transient.
469 469
                 set_transient(
470 470
                     'autoptimize_stats',
471 471
                     $stats,
472
-                    apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS )
472
+                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS)
473 473
                 );
474 474
             }
475 475
         }
@@ -492,30 +492,30 @@  discard block
 block discarded – undo
492 492
         $size  = 0;
493 493
 
494 494
         // Scan everything in our cache directories.
495
-        foreach ( self::get_cache_contents() as $name => $files ) {
496
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
497
-            foreach ( $files as $file ) {
498
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
499
-                    if ( AUTOPTIMIZE_CACHE_NOGZIP &&
495
+        foreach (self::get_cache_contents() as $name => $files) {
496
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
497
+            foreach ($files as $file) {
498
+                if (self::is_valid_cache_file($dir, $file)) {
499
+                    if (AUTOPTIMIZE_CACHE_NOGZIP &&
500 500
                         (
501
-                            false !== strpos( $file, '.js' ) ||
502
-                            false !== strpos( $file, '.css' ) ||
503
-                            false !== strpos( $file, '.img' ) ||
504
-                            false !== strpos( $file, '.txt' )
501
+                            false !== strpos($file, '.js') ||
502
+                            false !== strpos($file, '.css') ||
503
+                            false !== strpos($file, '.img') ||
504
+                            false !== strpos($file, '.txt')
505 505
                         )
506 506
                     ) {
507 507
                         // Web server is gzipping, we count .js|.css|.img|.txt files.
508 508
                         $count++;
509
-                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) {
509
+                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) {
510 510
                         // We are gzipping ourselves via php, counting only .none files.
511 511
                         $count++;
512 512
                     }
513
-                    $size += filesize( $dir . $file );
513
+                    $size += filesize($dir.$file);
514 514
                 }
515 515
             }
516 516
         }
517 517
 
518
-        $stats = array( $count, $size, time() );
518
+        $stats = array($count, $size, time());
519 519
 
520 520
         return $stats;
521 521
     }
@@ -529,22 +529,22 @@  discard block
 block discarded – undo
529 529
      */
530 530
     public static function cacheavail()
531 531
     {
532
-        if ( false === autoptimizeCache::check_and_create_dirs() ) {
532
+        if (false === autoptimizeCache::check_and_create_dirs()) {
533 533
             return false;
534 534
         }
535 535
 
536 536
         // Using .htaccess inside our cache folder to overrule wp-super-cache.
537
-        $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
538
-        if ( ! is_file( $htaccess ) ) {
537
+        $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess';
538
+        if (!is_file($htaccess)) {
539 539
             /**
540 540
              * Create `wp-content/AO_htaccess_tmpl` file with
541 541
              * whatever htaccess rules you might need
542 542
              * if you want to override default AO htaccess
543 543
              */
544
-            $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl';
545
-            if ( is_file( $htaccess_tmpl ) ) {
546
-                $content = file_get_contents( $htaccess_tmpl );
547
-            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) {
544
+            $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl';
545
+            if (is_file($htaccess_tmpl)) {
546
+                $content = file_get_contents($htaccess_tmpl);
547
+            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) {
548 548
                 $content = '<IfModule mod_expires.c>
549 549
         ExpiresActive On
550 550
         ExpiresByType text/css A30672000
@@ -598,13 +598,13 @@  discard block
 block discarded – undo
598 598
 </IfModule>';
599 599
             }
600 600
 
601
-            if ( self::do_fallback() === true ) {
602
-                $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
601
+            if (self::do_fallback() === true) {
602
+                $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php';
603 603
             }
604
-            @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
604
+            @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine
605 605
         }
606 606
 
607
-        if ( self::do_fallback() ) {
607
+        if (self::do_fallback()) {
608 608
             self::check_fallback_php();
609 609
         }
610 610
 
@@ -619,17 +619,17 @@  discard block
 block discarded – undo
619 619
      */
620 620
     public static function check_fallback_php() {
621 621
         $_fallback_filename = 'autoptimize_404_handler.php';
622
-        $_fallback_php      = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename;
622
+        $_fallback_php      = trailingslashit(WP_CONTENT_DIR).$_fallback_filename;
623 623
         $_fallback_status   = true;
624 624
 
625
-        if ( ! file_exists( $_fallback_php ) ) {
626
-            $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
627
-            $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
628
-            $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
629
-            if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
630
-                $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
625
+        if (!file_exists($_fallback_php)) {
626
+            $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename);
627
+            $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents);
628
+            $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents);
629
+            if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) {
630
+                $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents);
631 631
             }
632
-            $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
632
+            $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents);
633 633
         }
634 634
 
635 635
         return $_fallback_status;
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
     public static function do_fallback() {
647 647
         static $_do_fallback = null;
648 648
 
649
-        if ( null === $_do_fallback ) {
650
-            $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) );
649
+        if (null === $_do_fallback) {
650
+            $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', ''));
651 651
         }
652 652
 
653 653
         return $_do_fallback;
@@ -659,26 +659,26 @@  discard block
 block discarded – undo
659 659
      * and 410'ing ("Gone") if fallback not available.
660 660
      */
661 661
     public static function wordpress_notfound_fallback() {
662
-        $original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
663
-        if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) {
662
+        $original_request = strtok($_SERVER['REQUEST_URI'], '?');
663
+        if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) {
664 664
             // make sure this is not considered a 404.
665 665
             global $wp_query;
666 666
             $wp_query->is_404 = false;
667 667
 
668 668
             // set fallback path.
669
-            $js_or_css     = pathinfo( $original_request, PATHINFO_EXTENSION );
670
-            $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
669
+            $js_or_css     = pathinfo($original_request, PATHINFO_EXTENSION);
670
+            $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
671 671
 
672 672
             // set fallback URL.
673
-            $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
673
+            $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
674 674
 
675 675
             // redirect to fallback if possible.
676
-            if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
676
+            if ($original_request !== $fallback_target && file_exists($fallback_path)) {
677 677
                 // redirect to fallback.
678
-                wp_redirect( $fallback_target, 302 );
678
+                wp_redirect($fallback_target, 302);
679 679
             } else {
680 680
                 // return HTTP 410 (gone) reponse.
681
-                status_header( 410 );
681
+                status_header(410);
682 682
             }
683 683
         }
684 684
     }
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
      * @return bool
691 691
      */
692 692
     public static function check_and_create_dirs() {
693
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
693
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
694 694
             // We didn't set a cache.
695 695
             return false;
696 696
         }
697 697
 
698
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
699
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
698
+        foreach (array('', 'js', 'css') as $dir) {
699
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
700 700
                 return false;
701 701
             }
702 702
         }
@@ -711,25 +711,25 @@  discard block
 block discarded – undo
711 711
      *
712 712
      * @return bool
713 713
      */
714
-    protected static function check_cache_dir( $dir )
714
+    protected static function check_cache_dir($dir)
715 715
     {
716 716
         // Try creating the dir if it doesn't exist.
717
-        if ( ! file_exists( $dir ) ) {
718
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
719
-            if ( ! file_exists( $dir ) ) {
717
+        if (!file_exists($dir)) {
718
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
719
+            if (!file_exists($dir)) {
720 720
                 return false;
721 721
             }
722 722
         }
723 723
 
724 724
         // If we still cannot write, bail.
725
-        if ( ! is_writable( $dir ) ) {
725
+        if (!is_writable($dir)) {
726 726
             return false;
727 727
         }
728 728
 
729 729
         // Create an index.html in there to avoid prying eyes!
730
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
731
-        if ( ! is_file( $idx_file ) ) {
732
-            @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine
730
+        $idx_file = rtrim($dir, '/\\').'/index.html';
731
+        if (!is_file($idx_file)) {
732
+            @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine
733 733
         }
734 734
 
735 735
         return true;
@@ -743,50 +743,50 @@  discard block
 block discarded – undo
743 743
     // @codingStandardsIgnoreStart
744 744
     public static function flushPageCache()
745 745
     {
746
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
747
-            if ( is_multisite() ) {
746
+        if (function_exists('wp_cache_clear_cache')) {
747
+            if (is_multisite()) {
748 748
                 $blog_id = get_current_blog_id();
749
-                wp_cache_clear_cache( $blog_id );
749
+                wp_cache_clear_cache($blog_id);
750 750
             } else {
751 751
                 wp_cache_clear_cache();
752 752
             }
753
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
754
-            do_action( 'cachify_flush_cache' );
755
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
753
+        } elseif (has_action('cachify_flush_cache')) {
754
+            do_action('cachify_flush_cache');
755
+        } elseif (function_exists('w3tc_pgcache_flush')) {
756 756
             w3tc_pgcache_flush();
757
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
757
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
758 758
             wp_fast_cache_bulk_delete_all();
759
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
759
+        } elseif (class_exists('WpFastestCache')) {
760 760
             $wpfc = new WpFastestCache();
761 761
             $wpfc->deleteCache();
762
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
762
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
763 763
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
764
-        } elseif ( class_exists( 'zencache' ) ) {
764
+        } elseif (class_exists('zencache')) {
765 765
             zencache::clear();
766
-        } elseif ( class_exists( 'comet_cache' ) ) {
766
+        } elseif (class_exists('comet_cache')) {
767 767
             comet_cache::clear();
768
-        } elseif ( class_exists( 'WpeCommon' ) ) {
768
+        } elseif (class_exists('WpeCommon')) {
769 769
             // WPEngine cache purge/flush methods to call by default
770 770
             $wpe_methods = array(
771 771
                 'purge_varnish_cache',
772 772
             );
773 773
 
774 774
             // More agressive clear/flush/purge behind a filter
775
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
776
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
775
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
776
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
777 777
             }
778 778
 
779 779
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
780
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
780
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
781 781
 
782
-            foreach ( $wpe_methods as $wpe_method ) {
783
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
782
+            foreach ($wpe_methods as $wpe_method) {
783
+                if (method_exists('WpeCommon', $wpe_method)) {
784 784
                     WpeCommon::$wpe_method();
785 785
                 }
786 786
             }
787
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
787
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
788 788
             sg_cachepress_purge_cache();
789
-        } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
789
+        } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) {
790 790
             $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
791 791
             $_kinsta_response        = wp_remote_get(
792 792
                 $_kinsta_clear_cache_url,
@@ -795,18 +795,18 @@  discard block
 block discarded – undo
795 795
                     'timeout' => 5,
796 796
                     )
797 797
             );
798
-        } elseif ( defined('NGINX_HELPER_BASENAME') ) {
799
-            do_action( 'rt_nginx_helper_purge_all' );
800
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
798
+        } elseif (defined('NGINX_HELPER_BASENAME')) {
799
+            do_action('rt_nginx_helper_purge_all');
800
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
801 801
             // fallback for WP-Super-Cache
802 802
             global $cache_path;
803
-            if ( is_multisite() ) {
803
+            if (is_multisite()) {
804 804
                 $blog_id = get_current_blog_id();
805
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
806
-                prune_super_cache( $cache_path . 'blogs/', true );
805
+                prune_super_cache(get_supercache_dir($blog_id), true);
806
+                prune_super_cache($cache_path.'blogs/', true);
807 807
             } else {
808
-                prune_super_cache( $cache_path . 'supercache/', true );
809
-                prune_super_cache( $cache_path, true );
808
+                prune_super_cache($cache_path.'supercache/', true);
809
+                prune_super_cache($cache_path, true);
810 810
             }
811 811
         }
812 812
     }
Please login to merge, or discard this patch.
classes/autoptimizeUtils.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * General helpers.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @return bool
18 18
      */
19
-    public static function mbstring_available( $override = null )
19
+    public static function mbstring_available($override = null)
20 20
     {
21 21
         static $available = null;
22 22
 
23
-        if ( null === $available ) {
24
-            $available = \extension_loaded( 'mbstring' );
23
+        if (null === $available) {
24
+            $available = \extension_loaded('mbstring');
25 25
         }
26 26
 
27
-        if ( null !== $override ) {
27
+        if (null !== $override) {
28 28
             $available = $override;
29 29
         }
30 30
 
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return int|false
44 44
      */
45
-    public static function strpos( $haystack, $needle, $offset = 0, $encoding = null )
45
+    public static function strpos($haystack, $needle, $offset = 0, $encoding = null)
46 46
     {
47
-        if ( self::mbstring_available() ) {
48
-            return ( null === $encoding ) ? \mb_strpos( $haystack, $needle, $offset ) : \mb_strpos( $haystack, $needle, $offset, $encoding );
47
+        if (self::mbstring_available()) {
48
+            return (null === $encoding) ? \mb_strpos($haystack, $needle, $offset) : \mb_strpos($haystack, $needle, $offset, $encoding);
49 49
         } else {
50
-            return \strpos( $haystack, $needle, $offset );
50
+            return \strpos($haystack, $needle, $offset);
51 51
         }
52 52
     }
53 53
 
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
      * @return int Number of characters or bytes in given $string
63 63
      *             (characters if/when supported, bytes otherwise).
64 64
      */
65
-    public static function strlen( $string, $encoding = null )
65
+    public static function strlen($string, $encoding = null)
66 66
     {
67
-        if ( self::mbstring_available() ) {
68
-            return ( null === $encoding ) ? \mb_strlen( $string ) : \mb_strlen( $string, $encoding );
67
+        if (self::mbstring_available()) {
68
+            return (null === $encoding) ? \mb_strlen($string) : \mb_strlen($string, $encoding);
69 69
         } else {
70
-            return \strlen( $string );
70
+            return \strlen($string);
71 71
         }
72 72
     }
73 73
 
@@ -85,44 +85,44 @@  discard block
 block discarded – undo
85 85
      *
86 86
      * @return string
87 87
      */
88
-    public static function substr_replace( $string, $replacement, $start, $length = null, $encoding = null )
88
+    public static function substr_replace($string, $replacement, $start, $length = null, $encoding = null)
89 89
     {
90
-        if ( self::mbstring_available() ) {
91
-            $strlen = self::strlen( $string, $encoding );
90
+        if (self::mbstring_available()) {
91
+            $strlen = self::strlen($string, $encoding);
92 92
 
93
-            if ( $start < 0 ) {
93
+            if ($start < 0) {
94 94
                 if ( -$start < $strlen ) {
95 95
                     $start = $strlen + $start;
96 96
                 } else {
97 97
                     $start = 0;
98 98
                 }
99
-            } elseif ( $start > $strlen ) {
99
+            } elseif ($start > $strlen) {
100 100
                 $start = $strlen;
101 101
             }
102 102
 
103
-            if ( null === $length || '' === $length ) {
103
+            if (null === $length || '' === $length) {
104 104
                 $start2 = $strlen;
105
-            } elseif ( $length < 0 ) {
105
+            } elseif ($length < 0) {
106 106
                 $start2 = $strlen + $length;
107
-                if ( $start2 < $start ) {
107
+                if ($start2 < $start) {
108 108
                     $start2 = $start;
109 109
                 }
110 110
             } else {
111 111
                 $start2 = $start + $length;
112 112
             }
113 113
 
114
-            if ( null === $encoding ) {
115
-                $leader  = $start ? \mb_substr( $string, 0, $start ) : '';
116
-                $trailer = ( $start2 < $strlen ) ? \mb_substr( $string, $start2, null ) : '';
114
+            if (null === $encoding) {
115
+                $leader  = $start ? \mb_substr($string, 0, $start) : '';
116
+                $trailer = ($start2 < $strlen) ? \mb_substr($string, $start2, null) : '';
117 117
             } else {
118
-                $leader  = $start ? \mb_substr( $string, 0, $start, $encoding ) : '';
119
-                $trailer = ( $start2 < $strlen ) ? \mb_substr( $string, $start2, null, $encoding ) : '';
118
+                $leader  = $start ? \mb_substr($string, 0, $start, $encoding) : '';
119
+                $trailer = ($start2 < $strlen) ? \mb_substr($string, $start2, null, $encoding) : '';
120 120
             }
121 121
 
122 122
             return "{$leader}{$replacement}{$trailer}";
123 123
         }
124 124
 
125
-        return ( null === $length ) ? \substr_replace( $string, $replacement, $start ) : \substr_replace( $string, $replacement, $start, $length );
125
+        return (null === $length) ? \substr_replace($string, $replacement, $start) : \substr_replace($string, $replacement, $start, $length);
126 126
     }
127 127
 
128 128
     /**
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @return bool
134 134
      */
135
-    public static function siteurl_not_root( $override = null )
135
+    public static function siteurl_not_root($override = null)
136 136
     {
137 137
         static $subdir = null;
138 138
 
139
-        if ( null === $subdir ) {
139
+        if (null === $subdir) {
140 140
             $parts  = self::get_ao_wp_site_url_parts();
141
-            $subdir = ( isset( $parts['path'] ) && ( '/' !== $parts['path'] ) );
141
+            $subdir = (isset($parts['path']) && ('/' !== $parts['path']));
142 142
         }
143 143
 
144
-        if ( null !== $override ) {
144
+        if (null !== $override) {
145 145
             $subdir = $override;
146 146
         }
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
     {
159 159
         static $parts = array();
160 160
 
161
-        if ( empty( $parts ) ) {
162
-            $parts = \parse_url( AUTOPTIMIZE_WP_SITE_URL );
161
+        if (empty($parts)) {
162
+            $parts = \parse_url(AUTOPTIMIZE_WP_SITE_URL);
163 163
         }
164 164
 
165 165
         return $parts;
@@ -174,33 +174,33 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @return string
176 176
      */
177
-    public static function tweak_cdn_url_if_needed( $cdn_url, $force_cache_miss = false )
177
+    public static function tweak_cdn_url_if_needed($cdn_url, $force_cache_miss = false)
178 178
     {
179 179
         static $results = array();
180 180
 
181
-        if ( ! isset( $results[ $cdn_url ] ) || $force_cache_miss ) {
181
+        if (!isset($results[$cdn_url]) || $force_cache_miss) {
182 182
 
183 183
             // In order to return unmodified input when there's no need to tweak.
184
-            $results[ $cdn_url ] = $cdn_url;
184
+            $results[$cdn_url] = $cdn_url;
185 185
 
186 186
             // Behind a default true filter for backcompat, and only for sites
187 187
             // in a subfolder/subdirectory, but still easily turned off if
188 188
             // not wanted/needed...
189
-            if ( autoptimizeUtils::siteurl_not_root() ) {
190
-                $check = apply_filters( 'autoptimize_filter_cdn_magic_path_check', true, $cdn_url );
191
-                if ( $check ) {
189
+            if (autoptimizeUtils::siteurl_not_root()) {
190
+                $check = apply_filters('autoptimize_filter_cdn_magic_path_check', true, $cdn_url);
191
+                if ($check) {
192 192
                     $site_url_parts = autoptimizeUtils::get_ao_wp_site_url_parts();
193
-                    $cdn_url_parts  = \parse_url( $cdn_url );
194
-                    $schemeless     = self::is_protocol_relative( $cdn_url );
195
-                    $cdn_url_parts  = self::maybe_replace_cdn_path( $site_url_parts, $cdn_url_parts );
196
-                    if ( false !== $cdn_url_parts ) {
197
-                        $results[ $cdn_url ] = self::assemble_parsed_url( $cdn_url_parts, $schemeless );
193
+                    $cdn_url_parts  = \parse_url($cdn_url);
194
+                    $schemeless     = self::is_protocol_relative($cdn_url);
195
+                    $cdn_url_parts  = self::maybe_replace_cdn_path($site_url_parts, $cdn_url_parts);
196
+                    if (false !== $cdn_url_parts) {
197
+                        $results[$cdn_url] = self::assemble_parsed_url($cdn_url_parts, $schemeless);
198 198
                     }
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203
-        return $results[ $cdn_url ];
203
+        return $results[$cdn_url];
204 204
     }
205 205
 
206 206
     /**
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return array|false
216 216
      */
217
-    public static function maybe_replace_cdn_path( array $site_url_parts, array $cdn_url_parts )
217
+    public static function maybe_replace_cdn_path(array $site_url_parts, array $cdn_url_parts)
218 218
     {
219
-        if ( isset( $site_url_parts['path'] ) && '/' !== $site_url_parts['path'] ) {
220
-            if ( ! isset( $cdn_url_parts['path'] ) || '/' === $cdn_url_parts['path'] ) {
219
+        if (isset($site_url_parts['path']) && '/' !== $site_url_parts['path']) {
220
+            if (!isset($cdn_url_parts['path']) || '/' === $cdn_url_parts['path']) {
221 221
                 $cdn_url_parts['path'] = $site_url_parts['path'];
222 222
                 return $cdn_url_parts;
223 223
             }
@@ -237,20 +237,20 @@  discard block
 block discarded – undo
237 237
      *
238 238
      * @return string
239 239
      */
240
-    public static function assemble_parsed_url( array $parsed_url, $schemeless = false )
240
+    public static function assemble_parsed_url(array $parsed_url, $schemeless = false)
241 241
     {
242
-        $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
243
-        if ( $schemeless ) {
242
+        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
243
+        if ($schemeless) {
244 244
             $scheme = '//';
245 245
         }
246
-        $host     = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
247
-        $port     = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
248
-        $user     = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
249
-        $pass     = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
250
-        $pass     = ( $user || $pass ) ? "$pass@" : '';
251
-        $path     = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
252
-        $query    = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
253
-        $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
246
+        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
247
+        $port     = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
248
+        $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
249
+        $pass     = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
250
+        $pass     = ($user || $pass) ? "$pass@" : '';
251
+        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
252
+        $query    = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
253
+        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
254 254
 
255 255
         return "$scheme$user$pass$host$port$path$query$fragment";
256 256
     }
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
      *
263 263
      * @return bool
264 264
      */
265
-    public static function is_protocol_relative( $url )
265
+    public static function is_protocol_relative($url)
266 266
     {
267 267
         $result = false;
268 268
 
269
-        if ( ! empty( $url ) ) {
270
-            $result = ( 0 === strpos( $url, '//' ) );
269
+        if (!empty($url)) {
270
+            $result = (0 === strpos($url, '//'));
271 271
         }
272 272
 
273 273
         return $result;
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
      *
281 281
      * @return string
282 282
      */
283
-    public static function path_canonicalize( $path )
283
+    public static function path_canonicalize($path)
284 284
     {
285
-        $patterns     = array(
285
+        $patterns = array(
286 286
             '~/{2,}~',
287 287
             '~/(\./)+~',
288 288
             '~([^/\.]+/(?R)*\.{2,}/)~',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             '',
296 296
         );
297 297
 
298
-        return preg_replace( $patterns, $replacements, $path );
298
+        return preg_replace($patterns, $replacements, $path);
299 299
     }
300 300
 
301 301
     /**
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return null|array Service status or null.
309 309
      */
310
-    public static function check_service_availability( $return_result = false )
310
+    public static function check_service_availability($return_result = false)
311 311
     {
312
-        $service_availability_resp = wp_remote_get( 'https://misc.optimizingmatters.com/api/autoptimize_service_availablity.json?from=aomain&ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
313
-        if ( ! is_wp_error( $service_availability_resp ) ) {
314
-            if ( '200' == wp_remote_retrieve_response_code( $service_availability_resp ) ) {
315
-                $availabilities = json_decode( wp_remote_retrieve_body( $service_availability_resp ), true );
316
-                if ( is_array( $availabilities ) ) {
317
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_service_availablity', $availabilities );
318
-                    if ( $return_result ) {
312
+        $service_availability_resp = wp_remote_get('https://misc.optimizingmatters.com/api/autoptimize_service_availablity.json?from=aomain&ver='.AUTOPTIMIZE_PLUGIN_VERSION);
313
+        if (!is_wp_error($service_availability_resp)) {
314
+            if ('200' == wp_remote_retrieve_response_code($service_availability_resp)) {
315
+                $availabilities = json_decode(wp_remote_retrieve_body($service_availability_resp), true);
316
+                if (is_array($availabilities)) {
317
+                    autoptimizeOptionWrapper::update_option('autoptimize_service_availablity', $availabilities);
318
+                    if ($return_result) {
319 319
                         return $availabilities;
320 320
                     }
321 321
                 }
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
      *
332 332
      * @return bool
333 333
      */
334
-    public static function str_is_valid_regex( $string )
334
+    public static function str_is_valid_regex($string)
335 335
     {
336
-        set_error_handler( function() {}, E_WARNING );
337
-        $is_regex = ( false !== preg_match( $string, '' ) );
336
+        set_error_handler(function() {}, E_WARNING);
337
+        $is_regex = (false !== preg_match($string, ''));
338 338
         restore_error_handler();
339 339
 
340 340
         return $is_regex;
@@ -347,17 +347,17 @@  discard block
 block discarded – undo
347 347
      *
348 348
      * @return bool
349 349
      */
350
-    public static function is_plugin_active( $plugin_file )
350
+    public static function is_plugin_active($plugin_file)
351 351
     {
352 352
         static $ipa_exists = null;
353
-        if ( null === $ipa_exists ) {
354
-            if ( ! function_exists( '\is_plugin_active' ) ) {
355
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
353
+        if (null === $ipa_exists) {
354
+            if (!function_exists('\is_plugin_active')) {
355
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
356 356
             }
357
-            $ipa_exists = function_exists( '\is_plugin_active' );
357
+            $ipa_exists = function_exists('\is_plugin_active');
358 358
         }
359 359
 
360
-        return $ipa_exists && \is_plugin_active( $plugin_file );
360
+        return $ipa_exists && \is_plugin_active($plugin_file);
361 361
     }
362 362
 
363 363
     /**
@@ -367,11 +367,11 @@  discard block
 block discarded – undo
367 367
      *
368 368
      * @return string
369 369
      */
370
-    public static function remove_id_from_node( $node ) {
371
-        if ( strpos( $node, 'id=' ) === false || apply_filters( 'autoptimize_filter_utils_keep_ids', false ) ) {
370
+    public static function remove_id_from_node($node) {
371
+        if (strpos($node, 'id=') === false || apply_filters('autoptimize_filter_utils_keep_ids', false)) {
372 372
             return $node;
373 373
         } else {
374
-            return preg_replace( '#(.*) id=[\'|"].*[\'|"] (.*)#Um', '$1 $2', $node );
374
+            return preg_replace('#(.*) id=[\'|"].*[\'|"] (.*)#Um', '$1 $2', $node);
375 375
         }
376 376
     }
377 377
 
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
      *
384 384
      * @return bool
385 385
      */
386
-    public static function str_ends_in( $str, $test )
386
+    public static function str_ends_in($str, $test)
387 387
     {
388 388
         // @codingStandardsIgnoreStart
389 389
         // substr_compare() is bugged on 5.5.11: https://3v4l.org/qGYBH
390 390
         // return ( 0 === substr_compare( $str, $test, -strlen( $test ) ) );
391 391
         // @codingStandardsIgnoreEnd
392 392
 
393
-        $length = strlen( $test );
393
+        $length = strlen($test);
394 394
 
395
-        return ( substr( $str, -$length, $length ) === $test );
395
+        return (substr($str, -$length, $length) === $test);
396 396
     }
397 397
 }
Please login to merge, or discard this patch.