Completed
Push — master ( 5da188...964b0c )
by frank
01:47
created
classes/critcss-inc/admin_settings_rules.js.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Outputs JS code for the rules panel.
4 4
  */
5 5
 
6
-if ( $ao_ccss_debug ) {
6
+if ($ao_ccss_debug) {
7 7
     echo "console.log('[WARN] Autoptimize CriticalCSS Power-Up is in DEBUG MODE!');\n";
8 8
     echo "console.log('[WARN] Avoid using debug mode on production/live environments unless for ad-hoc troubleshooting purposes and make sure to disable it after!');\n";
9 9
 }
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     jQuery(document).ready(function() {
24 24
         critCssArray=JSON.parse(document.getElementById("critCssOrigin").value);
25 25
         <?php
26
-        if ( $ao_ccss_debug ) {
26
+        if ($ao_ccss_debug) {
27 27
             echo "console.log('Rules Object:', critCssArray);\n";
28 28
         }
29 29
         ?>
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
     jQuery("#rules-list").empty();
40 40
     jQuery.each(critCssArray,function(k,v) {
41 41
         if (k=="paths") {
42
-            kstring="<?php _e( 'Path Based Rules', 'autoptimize' ); ?>";
42
+            kstring="<?php _e('Path Based Rules', 'autoptimize'); ?>";
43 43
         } else {
44
-            kstring="<?php _e( 'Conditional Tags, Custom Post Types and Page Templates Rules', 'autoptimize' ); ?>";
44
+            kstring="<?php _e('Conditional Tags, Custom Post Types and Page Templates Rules', 'autoptimize'); ?>";
45 45
         }
46 46
         if (!(jQuery.isEmptyObject(v))) {
47 47
             jQuery("#rules-list").append("<tr><td colspan='5'><h4>" + kstring + "</h4></td></tr>");
48
-            jQuery("#rules-list").append("<tr class='header "+k+"Rule'><th><?php _e( 'Type', 'autoptimize' ); ?></th><th><?php _e( 'Target', 'autoptimize' ); ?></th><th><?php _e( 'Critical CSS File', 'autoptimize' ); ?></th><th colspan='2'><?php _e( 'Actions', 'autoptimize' ); ?></th></tr>");
48
+            jQuery("#rules-list").append("<tr class='header "+k+"Rule'><th><?php _e('Type', 'autoptimize'); ?></th><th><?php _e('Target', 'autoptimize'); ?></th><th><?php _e('Critical CSS File', 'autoptimize'); ?></th><th colspan='2'><?php _e('Actions', 'autoptimize'); ?></th></tr>");
49 49
         }
50 50
         nodeNumber=0;
51 51
         jQuery.each(v,function(i,nv){
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
             file=nv.file;
56 56
             filest=nv.file;
57 57
             if (file == 0) {
58
-                file='<?php _e( 'To be fetched from criticalcss.com in the next queue run...', 'autoptimize' ); ?>';
58
+                file='<?php _e('To be fetched from criticalcss.com in the next queue run...', 'autoptimize'); ?>';
59 59
             }
60 60
             if (nv.hash === 0 && filest != 0) {
61
-                type='<?php _e( 'MANUAL', 'autoptimize' ); ?>';
61
+                type='<?php _e('MANUAL', 'autoptimize'); ?>';
62 62
                 typeClass = 'manual';
63 63
             } else {
64
-                type='<?php _e( 'AUTO', 'autoptimize' ); ?>';
64
+                type='<?php _e('AUTO', 'autoptimize'); ?>';
65 65
                 typeClass = 'auto';
66 66
             }
67 67
             if (file && typeof file == 'string') {
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             } else {
78 78
                 target = i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'');
79 79
             }
80
-            jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e( 'Edit', 'autoptimize' ); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e( 'Remove', 'autoptimize' ); ?></span></td></tr>");
80
+            jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e('Edit', 'autoptimize'); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e('Remove', 'autoptimize'); ?></span></td></tr>");
81 81
             jQuery("#" + nodeId + "_edit").click(function(){addEditRow(this.id);});
82 82
             jQuery("#" + nodeId + "_remove").click(function(){confirmRemove(this.id);});
83 83
         })
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
         height:235,
91 91
         modal: true,
92 92
         buttons: {
93
-            "<?php _e( 'Delete', 'autoptimize' ); ?>": function() {
93
+            "<?php _e('Delete', 'autoptimize'); ?>": function() {
94 94
                 removeRow(idToRemove);
95 95
                 updateAfterChange();
96 96
                 jQuery( this ).dialog( "close" );
97 97
             },
98
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
98
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
99 99
                 jQuery( this ).dialog( "close" );
100 100
             }
101 101
         }
@@ -108,14 +108,14 @@  discard block
 block discarded – undo
108 108
         height:235,
109 109
         modal: true,
110 110
         buttons: {
111
-            "<?php _e( 'Delete All', 'autoptimize' ); ?>": function() {
111
+            "<?php _e('Delete All', 'autoptimize'); ?>": function() {
112 112
                 critCssArray={'paths':[],'types':[]};
113 113
                 drawTable(critCssArray);
114 114
                 updateAfterChange();
115 115
                 removeAllCcssFilesOnServer();
116 116
                 jQuery( this ).dialog( "close" );
117 117
             },
118
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
118
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
119 119
                 jQuery( this ).dialog( "close" );
120 120
             }
121 121
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
     var data = {
134 134
         'action': 'rm_critcss',
135
-        'critcss_rm_nonce': '<?php echo wp_create_nonce( 'rm_critcss_nonce' ); ?>',
135
+        'critcss_rm_nonce': '<?php echo wp_create_nonce('rm_critcss_nonce'); ?>',
136 136
         'cachebustingtimestamp': new Date().getTime(),
137 137
         'critcssfile': crit_file
138 138
     };
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 function removeAllCcssFilesOnServer() {
154 154
     var data = {
155 155
         'action': 'rm_critcss_all',
156
-        'critcss_rm_all_nonce': '<?php echo wp_create_nonce( 'rm_critcss_all_nonce' ); ?>',
156
+        'critcss_rm_all_nonce': '<?php echo wp_create_nonce('rm_critcss_all_nonce'); ?>',
157 157
         'cachebustingtimestamp': new Date().getTime()
158 158
     };
159 159
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 function addEditRow(idToEdit) {
174 174
     resetForm();
175 175
     if (idToEdit) {
176
-        dialogTitle="<?php _e( 'Edit Critical CSS Rule', 'autoptimize' ); ?>";
176
+        dialogTitle="<?php _e('Edit Critical CSS Rule', 'autoptimize'); ?>";
177 177
 
178 178
         splits=idToEdit.split(/_/);
179 179
         crit_type=splits[0];
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         jQuery("#critcss_addedit_id").val(idToEdit);
185 185
         jQuery("#critcss_addedit_type").val(crit_type);
186 186
         jQuery("#critcss_addedit_file").val(crit_file);
187
-        jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'Loading critical CSS...', 'autoptimize' ); ?>");
187
+        jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('Loading critical CSS...', 'autoptimize'); ?>");
188 188
         jQuery("#critcss_addedit_type").attr("disabled",true);
189 189
 
190 190
         if (crit_type==="paths") {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
         var data = {
201 201
             'action': 'fetch_critcss',
202
-            'critcss_fetch_nonce': '<?php echo wp_create_nonce( 'fetch_critcss_nonce' ); ?>',
202
+            'critcss_fetch_nonce': '<?php echo wp_create_nonce('fetch_critcss_nonce'); ?>',
203 203
             'cachebustingtimestamp': new Date().getTime(),
204 204
             'critcssfile': crit_file
205 205
         };
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             }
214 214
         });
215 215
     } else {
216
-        dialogTitle="<?php _e( 'Add Critical CSS Rule', 'autotimize' ); ?>";
216
+        dialogTitle="<?php _e('Add Critical CSS Rule', 'autotimize'); ?>";
217 217
 
218 218
         // default: paths, hide content type field
219 219
         jQuery("#critcss_addedit_type").val("paths");
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
             if(this.value==="types") {
225 225
                 jQuery("#critcss_addedit_pagetype_wrapper").show();
226 226
                 jQuery("#critcss_addedit_path_wrapper").hide();
227
-                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For type based rules, paste your specific and minified critical CSS here and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\".', 'autoptimize' ); ?>");
227
+                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For type based rules, paste your specific and minified critical CSS here and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\".', 'autoptimize'); ?>");
228 228
             } else {
229 229
                 jQuery("#critcss_addedit_path_wrapper").show();
230 230
                 jQuery("#critcss_addedit_pagetype_wrapper").hide();
231
-                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize' ); ?>");
231
+                jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize'); ?>");
232 232
             }
233 233
         });
234 234
     }
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
         title: dialogTitle,
241 241
         modal: true,
242 242
         buttons: {
243
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
243
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
244 244
                 rpath = jQuery("#critcss_addedit_path").val();
245 245
                 rtype = jQuery("#critcss_addedit_pagetype option:selected").val();
246 246
                 rccss = jQuery("#critcss_addedit_css").val();
247 247
                 console.log('rpath: ' + rpath, 'rtype: ' + rtype, 'rccss: ' + rccss);
248 248
                 if (rpath === '' && rtype === '') {
249
-                    alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize' ); ?>');
249
+                    alert('<?php _e("RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize'); ?>');
250 250
                 } else if (rtype !== '' && rccss == '') {
251
-                    alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize' ); ?>');
251
+                    alert('<?php _e("RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize'); ?>');
252 252
                 } else {
253 253
                     saveEditCritCss();
254 254
                     jQuery(this).dialog('close');
255 255
                 }
256 256
             },
257
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
257
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
258 258
                 resetForm();
259 259
                 jQuery(this).dialog("close");
260 260
             }
@@ -268,15 +268,15 @@  discard block
 block discarded – undo
268 268
         autoOpen: true,
269 269
         height: 505,
270 270
         width: 700,
271
-        title: "<?php _e( 'Default Critical CSS', 'autoptimize' ); ?>",
271
+        title: "<?php _e('Default Critical CSS', 'autoptimize'); ?>",
272 272
         modal: true,
273 273
         buttons: {
274
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
274
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
275 275
                 document.getElementById("autoptimize_css_defer_inline").value=document.getElementById("dummyDefault").value;
276 276
                 jQuery("#unSavedWarning").show();
277 277
                 jQuery("#default_critcss_wrapper").dialog( "close" );
278 278
             },
279
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
279
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
280 280
                 jQuery("#default_critcss_wrapper").dialog( "close" );
281 281
             }
282 282
         }
@@ -289,15 +289,15 @@  discard block
 block discarded – undo
289 289
         autoOpen: true,
290 290
         height: 505,
291 291
         width: 700,
292
-        title: "<?php _e( 'Additional Critical CSS', 'autoptimize' ); ?>",
292
+        title: "<?php _e('Additional Critical CSS', 'autoptimize'); ?>",
293 293
         modal: true,
294 294
         buttons: {
295
-            "<?php _e( 'Submit', 'autoptimize' ); ?>": function() {
295
+            "<?php _e('Submit', 'autoptimize'); ?>": function() {
296 296
                 document.getElementById("autoptimize_ccss_additional").value=document.getElementById("dummyAdditional").value;
297 297
                 jQuery("#unSavedWarning").show();
298 298
                 jQuery("#additional_critcss_wrapper").dialog( "close" );
299 299
             },
300
-            "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
300
+            "<?php _e('Cancel', 'autoptimize'); ?>": function() {
301 301
                 jQuery("#additional_critcss_wrapper").dialog( "close" );
302 302
             }
303 303
         }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     critCssArray[critcsstype][critcsstarget].file=critcssfile;
334 334
 
335 335
     <?php
336
-    if ( $ao_ccss_debug ) {
336
+    if ($ao_ccss_debug) {
337 337
         echo "console.log('[RULE PROPERTIES] Type:', critcsstype, ', Target:', critcsstarget, ', Hash:', 0, ', File:',  critcssfile);";
338 338
     }
339 339
     ?>
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
     var data = {
344 344
         'action': 'save_critcss',
345
-        'critcss_save_nonce': '<?php echo wp_create_nonce( 'save_critcss_nonce' ); ?>',
345
+        'critcss_save_nonce': '<?php echo wp_create_nonce('save_critcss_nonce'); ?>',
346 346
         'critcssfile': critcssfile,
347 347
         'critcsscontents': critcsscontents
348 348
     };
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 }
368 368
 
369 369
 function resetForm() {
370
-    jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize' ); ?>");
370
+    jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize'); ?>");
371 371
     jQuery("#critcss_addedit_type").attr("disabled",false);
372 372
     jQuery("#critcss_addedit_path_wrapper").show();
373 373
     jQuery("#critcss_addedit_id").val("");
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_key.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
  * @param string $message      Message.
13 13
  * @param string $color        Color to highlight message in.
14 14
  */
15
-function ao_ccss_render_key( $key, $status, $status_msg, $message, $color ) {
16
-    if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
17
-        $key = __( 'API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize' );
15
+function ao_ccss_render_key($key, $status, $status_msg, $message, $color) {
16
+    if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
17
+        $key = __('API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize');
18 18
     }
19 19
     ?>
20 20
     <ul id="key-panel">
21 21
         <li class="itemDetail">
22
-            <h2 class="itemTitle fleft"><?php _e( 'API Key', 'autoptimize' ); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2>
22
+            <h2 class="itemTitle fleft"><?php _e('API Key', 'autoptimize'); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2>
23 23
             <button type="button" class="toggle-btn">
24
-                <?php if ( 'valid' != $status ) { ?>
24
+                <?php if ('valid' != $status) { ?>
25 25
                     <span class="toggle-indicator dashicons dashicons-arrow-up"></span>
26 26
                 <?php } else { ?>
27 27
                     <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
28 28
                 <?php } ?>
29 29
             </button>
30
-            <?php if ( 'valid' != $status ) { ?>
30
+            <?php if ('valid' != $status) { ?>
31 31
                 <div class="collapsible">
32 32
             <?php } else { ?>
33 33
                 <div class="collapsible hidden">
34 34
             <?php } ?>
35
-            <?php if ( 'valid' != $status ) { ?>
35
+            <?php if ('valid' != $status) { ?>
36 36
                 <div style="clear:both;padding:2px 10px;border-left:solid;border-left-width:5px;border-left-color:<?php echo $color; ?>;background-color:white;">
37 37
                     <p><?php echo $message; ?></p>
38 38
                 </div>
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
                 <table id="key" class="form-table">
41 41
                     <tr>
42 42
                         <th scope="row">
43
-                            <?php _e( 'Your API Key', 'autoptimize' ); ?>
43
+                            <?php _e('Your API Key', 'autoptimize'); ?>
44 44
                         </th>
45 45
                         <td>
46
-                            <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e( 'Please enter your criticalcss.com API key here.', 'autoptimize' ); ?>"><?php echo trim( $key ); ?></textarea>
46
+                            <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e('Please enter your criticalcss.com API key here.', 'autoptimize'); ?>"><?php echo trim($key); ?></textarea>
47 47
                             <p class="notes">
48
-                                <?php _e( 'Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize' ); ?>
48
+                                <?php _e('Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize'); ?>
49 49
                             </p>
50 50
                         </td>
51 51
                     </tr>
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_queue.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,21 +11,21 @@  discard block
 block discarded – undo
11 11
     global $ao_ccss_queue;
12 12
 
13 13
     // Prepare the queue object.
14
-    if ( empty( $ao_ccss_queue ) ) {
14
+    if (empty($ao_ccss_queue)) {
15 15
         $ao_ccss_queue = '';
16 16
     } else {
17
-        $ao_ccss_queue = json_encode( $ao_ccss_queue );
17
+        $ao_ccss_queue = json_encode($ao_ccss_queue);
18 18
     }
19 19
 ?>
20 20
 
21 21
     <ul id="queue-panel">
22 22
         <li class="itemDetail">
23
-            <h2 class="itemTitle fleft"><?php _e( 'Job Queue', 'autoptimize' ); ?></h2>
23
+            <h2 class="itemTitle fleft"><?php _e('Job Queue', 'autoptimize'); ?></h2>
24 24
             <button type="button" class="toggle-btn">
25 25
                 <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
26 26
             </button>
27 27
             <?php
28
-            if ( autoptimizeCriticalCSSSettings::ao_ccss_has_autorules() ) {
28
+            if (autoptimizeCriticalCSSSettings::ao_ccss_has_autorules()) {
29 29
                 $_queue_visibility = 'hidden';
30 30
             } else {
31 31
                 $_queue_visibility = 'visible';
@@ -34,54 +34,54 @@  discard block
 block discarded – undo
34 34
             <div class="collapsible <?php echo $_queue_visibility; ?>">
35 35
                 <!-- BEGIN Queue dialogs -->
36 36
                 <!-- Retry dialog -->
37
-                <div id="queue-confirm-retry" title="<?php _e( 'Retry Job', 'autoptimize' ); ?>" class="hidden">
38
-                    <p><?php _e( 'Are you sure you want to retry this job?', 'autoptimize' ); ?></p>
37
+                <div id="queue-confirm-retry" title="<?php _e('Retry Job', 'autoptimize'); ?>" class="hidden">
38
+                    <p><?php _e('Are you sure you want to retry this job?', 'autoptimize'); ?></p>
39 39
                 </div>
40 40
 
41 41
                 <!-- Remove dialog -->
42
-                <div id="queue-confirm-rm" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>" class="hidden">
43
-                    <p><?php _e( 'Are you sure you want to delete this job?', 'autoptimize' ); ?></p>
42
+                <div id="queue-confirm-rm" title="<?php _e('Delete Job', 'autoptimize'); ?>" class="hidden">
43
+                    <p><?php _e('Are you sure you want to delete this job?', 'autoptimize'); ?></p>
44 44
                 </div>
45 45
 
46 46
                 <!-- Remove all dialog -->
47
-                <div id="queue-confirm-rm-all" title="<?php _e( 'Delete all jobs', 'autoptimize' ); ?>" class="hidden">
48
-                    <p><?php _e( 'This will delete all jobs, are you sure?', 'autoptimize' ); ?></p>
47
+                <div id="queue-confirm-rm-all" title="<?php _e('Delete all jobs', 'autoptimize'); ?>" class="hidden">
48
+                    <p><?php _e('This will delete all jobs, are you sure?', 'autoptimize'); ?></p>
49 49
                 </div>
50 50
                 <!-- END Queue dialogs -->
51 51
 
52 52
                 <!-- BEGIN Queue UI -->
53 53
                 <div class="howto">
54 54
                     <div class="title-wrap">
55
-                        <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Queue', 'autoptimize' ); ?></h4>
56
-                        <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p>
55
+                        <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Queue', 'autoptimize'); ?></h4>
56
+                        <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p>
57 57
                     </div>
58 58
                     <button type="button" class="toggle-btn">
59 59
                         <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
60 60
                     </button>
61 61
                     <div class="howto-wrap hidden">
62
-                        <p><?php _e( 'TL;DR:<br /><strong>Queue runs every 10 minutes.</strong> Job statuses are <span class="badge new">N</span> for NEW, <span class="badge pending">P</span> for PENDING, <span class="badge error">E</span> for ERROR and <span class="badge unknown">U</span> for UNKOWN.', 'autoptimize' ); ?></p>
62
+                        <p><?php _e('TL;DR:<br /><strong>Queue runs every 10 minutes.</strong> Job statuses are <span class="badge new">N</span> for NEW, <span class="badge pending">P</span> for PENDING, <span class="badge error">E</span> for ERROR and <span class="badge unknown">U</span> for UNKOWN.', 'autoptimize'); ?></p>
63 63
                         <ol>
64
-                            <li><?php _e( 'The queue operates <strong>automatically, asynchronously and on regular intervals of 10 minutes.</strong> To view updated queue status, refresh this page.', 'autoptimize' ); ?></li>
65
-                            <li><?php _e( 'When the conditions to create a job are met (i.e. user not logged in, no matching <span class="badge manual">MANUAL</span> rule or CSS files has changed for an <span class="badge auto">AUTO</span> rule), a <span class="badge new">N</span> job is created in the queue.', 'autoptimize' ); ?></li>
66
-                            <li><?php _e( "Autoptimize CriticalCSS Power-Up constantly query the queue for <span class='badge new'>N</span> jobs. When it finds one, gears spins and jobs becomes <span class='badge pending'>P</span> while they are running and <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> doesn't return a result.", 'autoptimize' ); ?></li>
67
-                            <li><?php _e( 'As soon as <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> returns a valid critical CSS file, the job is then finished and removed from the queue.', 'autoptimize' ); ?></li>
68
-                            <li><?php _e( 'When things go wrong, a job is marked as <span class="badge error">E</span>. You can retry faulty jobs, delete them or get in touch with <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize' ); ?></li>
69
-                            <li><?php _e( 'Sometimes an unknown condition can happen. In this case, the job status becomes <span class="badge unknown">U</span> and you may want to ask <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for help or just delete it.', 'autoptimize' ); ?></li>
70
-                            <li><?php _e( 'To get more information about jobs statuses, specially the ones with <span class="badge error">E</span> and <span class="badge unknown">U</span> status, hover your mouse in the status badge of that job. This information might be crucial when contacting <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize' ); ?></li>
71
-                            <li><?php _e( '<strong>A word about WordPress cron:</strong> Autoptimize CriticalCSS Power-Up watch the queue by using WordPress Cron (or WP-Cron for short.) It <a href="https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/#limitations-of-wordpress-cron-and-solutions-to-fix-em" target="_blank">could be faulty</a> on very light or very heavy loads. If your site receives just a few or thousands visits a day, it might be a good idea to <a href="https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/" target="_blank">turn WP-Cron off and use your system task scheduler</a> to fire it instead.', 'autoptimize' ); ?></li>
64
+                            <li><?php _e('The queue operates <strong>automatically, asynchronously and on regular intervals of 10 minutes.</strong> To view updated queue status, refresh this page.', 'autoptimize'); ?></li>
65
+                            <li><?php _e('When the conditions to create a job are met (i.e. user not logged in, no matching <span class="badge manual">MANUAL</span> rule or CSS files has changed for an <span class="badge auto">AUTO</span> rule), a <span class="badge new">N</span> job is created in the queue.', 'autoptimize'); ?></li>
66
+                            <li><?php _e("Autoptimize CriticalCSS Power-Up constantly query the queue for <span class='badge new'>N</span> jobs. When it finds one, gears spins and jobs becomes <span class='badge pending'>P</span> while they are running and <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> doesn't return a result.", 'autoptimize'); ?></li>
67
+                            <li><?php _e('As soon as <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> returns a valid critical CSS file, the job is then finished and removed from the queue.', 'autoptimize'); ?></li>
68
+                            <li><?php _e('When things go wrong, a job is marked as <span class="badge error">E</span>. You can retry faulty jobs, delete them or get in touch with <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize'); ?></li>
69
+                            <li><?php _e('Sometimes an unknown condition can happen. In this case, the job status becomes <span class="badge unknown">U</span> and you may want to ask <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for help or just delete it.', 'autoptimize'); ?></li>
70
+                            <li><?php _e('To get more information about jobs statuses, specially the ones with <span class="badge error">E</span> and <span class="badge unknown">U</span> status, hover your mouse in the status badge of that job. This information might be crucial when contacting <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize'); ?></li>
71
+                            <li><?php _e('<strong>A word about WordPress cron:</strong> Autoptimize CriticalCSS Power-Up watch the queue by using WordPress Cron (or WP-Cron for short.) It <a href="https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/#limitations-of-wordpress-cron-and-solutions-to-fix-em" target="_blank">could be faulty</a> on very light or very heavy loads. If your site receives just a few or thousands visits a day, it might be a good idea to <a href="https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/" target="_blank">turn WP-Cron off and use your system task scheduler</a> to fire it instead.', 'autoptimize'); ?></li>
72 72
                         </ol>
73 73
                     </div>
74 74
                 </div>
75 75
                 <table id="queue-tbl" class="queue tablesorter" cellspacing="0">
76 76
                     <thead>
77
-                        <tr><th class="status"><?php _e( 'Status', 'autoptimize' ); ?></th><th><?php _e( 'Target Rule', 'autoptimize' ); ?></th><th><?php _e( 'Page Path', 'autoptimize' ); ?></th><th><?php _e( 'Page Type', 'autoptimize' ); ?></th><th><?php _e( 'Creation Date', 'autoptimize' ); ?></th><th><?php _e( 'Finish Date', 'autoptimize' ); ?></th><th class="btn"><?php _e( 'Actions', 'autoptimize' ); ?></th></tr>
77
+                        <tr><th class="status"><?php _e('Status', 'autoptimize'); ?></th><th><?php _e('Target Rule', 'autoptimize'); ?></th><th><?php _e('Page Path', 'autoptimize'); ?></th><th><?php _e('Page Type', 'autoptimize'); ?></th><th><?php _e('Creation Date', 'autoptimize'); ?></th><th><?php _e('Finish Date', 'autoptimize'); ?></th><th class="btn"><?php _e('Actions', 'autoptimize'); ?></th></tr>
78 78
                     </thead>
79 79
                     <tbody id="queue"></tbody>
80 80
                 </table>
81
-                <input class="hidden" type="text" id="ao-ccss-queue" name="autoptimize_ccss_queue" value='<?php echo( $ao_ccss_queue ); ?>'>
81
+                <input class="hidden" type="text" id="ao-ccss-queue" name="autoptimize_ccss_queue" value='<?php echo($ao_ccss_queue); ?>'>
82 82
                 <div class="submit jobs-btn">
83 83
                     <div class="alignright">
84
-                        <span id="removeAllJobs" class="button-secondary" style="color:red;"><?php _e( 'Remove all jobs', 'autoptimize' ); ?></span>
84
+                        <span id="removeAllJobs" class="button-secondary" style="color:red;"><?php _e('Remove all jobs', 'autoptimize'); ?></span>
85 85
                     </div>
86 86
                 </div>
87 87
             </div>
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_explain.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,29 +12,29 @@
 block discarded – undo
12 12
         .ao_settings_div {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;}
13 13
         .ao_settings_div .form-table th {font-weight: normal;}
14 14
     </style>
15
-    <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
15
+    <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
16 16
     <ul id="explain-panel">
17 17
         <div class="ao_settings_div">
18 18
             <?php
19 19
             $ccss_explanation = '';
20 20
 
21 21
             // get the HTML with the explanation of what critical CSS is.
22
-            if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
23
-                $ccss_explanation = get_transient( 'ao_ccss_explain' );
24
-                if ( empty( $ccss_explanation ) ) {
25
-                    $ccss_expl_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
26
-                    if ( ! is_wp_error( $ccss_expl_resp ) ) {
27
-                        if ( '200' == wp_remote_retrieve_response_code( $ccss_expl_resp ) ) {
28
-                            $ccss_explanation = wp_kses_post( wp_remote_retrieve_body( $ccss_expl_resp ) );
29
-                            set_transient( 'ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS );
22
+            if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
23
+                $ccss_explanation = get_transient('ao_ccss_explain');
24
+                if (empty($ccss_explanation)) {
25
+                    $ccss_expl_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
26
+                    if (!is_wp_error($ccss_expl_resp)) {
27
+                        if ('200' == wp_remote_retrieve_response_code($ccss_expl_resp)) {
28
+                            $ccss_explanation = wp_kses_post(wp_remote_retrieve_body($ccss_expl_resp));
29
+                            set_transient('ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS);
30 30
                         }
31 31
                     }
32 32
                 }
33 33
             }
34 34
 
35 35
             // placeholder text in case HTML is empty.
36
-            if ( empty( $ccss_explanation ) ) {
37
-                $ccss_explanation = __( '<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize' );
36
+            if (empty($ccss_explanation)) {
37
+                $ccss_explanation = __('<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize');
38 38
             } else {
39 39
                 // we were able to fetch the explenation, so add the JS to show correct language.
40 40
                 $ccss_explanation .= "<script>jQuery('.ao_i18n').hide();d=document;lang=d.getElementsByTagName('html')[0].getAttribute('lang').substring(0,2);if(d.getElementById(lang)!= null){jQuery('#'+lang).show();}else{jQuery('#default').show();}</script>";
Please login to merge, or discard this patch.
classes/autoptimizeImages.php 2 patches
Doc Comments   +13 added lines, -1 removed lines patch added patch discarded remove patch
@@ -378,6 +378,9 @@  discard block
 block discarded – undo
378 378
         }
379 379
     }
380 380
 
381
+    /**
382
+     * @return string
383
+     */
381 384
     private function get_imgopt_base_url()
382 385
     {
383 386
         static $imgopt_base_url = null;
@@ -750,6 +753,9 @@  discard block
 block discarded – undo
750 753
         return $out;
751 754
     }
752 755
 
756
+    /**
757
+     * @param string $tag
758
+     */
753 759
     public function add_lazyload( $tag, $placeholder = '' ) {
754 760
         // adds actual lazyload-attributes to an image node.
755 761
         if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
@@ -832,6 +838,9 @@  discard block
 block discarded – undo
832 838
         }
833 839
     }
834 840
 
841
+    /**
842
+     * @return string
843
+     */
835 844
     public function get_cdn_url() {
836 845
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
837 846
         static $cdn_url = null;
@@ -935,6 +944,9 @@  discard block
 block discarded – undo
935 944
         return $out;
936 945
     }
937 946
 
947
+    /**
948
+     * @return string
949
+     */
938 950
     public function process_bgimage( $in ) {
939 951
         if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
940 952
             $out = preg_replace_callback(
@@ -1279,7 +1291,7 @@  discard block
 block discarded – undo
1279 1291
     /**
1280 1292
      * Determines and returns the service launch status.
1281 1293
      *
1282
-     * @return bool
1294
+     * @return null|boolean
1283 1295
      */
1284 1296
     public function launch_ok()
1285 1297
     {
Please login to merge, or discard this patch.
Spacing   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles optimizing images.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
      */
24 24
     protected static $instance = null;
25 25
 
26
-    public function __construct( array $options = array() )
26
+    public function __construct(array $options = array())
27 27
     {
28 28
         // If options are not provided, fetch them.
29
-        if ( empty( $options ) ) {
29
+        if (empty($options)) {
30 30
             $options = $this->fetch_options();
31 31
         }
32 32
 
33
-        $this->set_options( $options );
33
+        $this->set_options($options);
34 34
     }
35 35
 
36
-    public function set_options( array $options )
36
+    public function set_options(array $options)
37 37
     {
38 38
         $this->options = $options;
39 39
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 
43 43
     public static function fetch_options()
44 44
     {
45
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
46
-        if ( empty( $value ) ) {
45
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
46
+        if (empty($value)) {
47 47
             // Fallback to returning defaults when no stored option exists yet.
48 48
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
49 49
         }
50 50
 
51 51
         // get service availability and add it to the options-array.
52
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
52
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
53 53
 
54
-        if ( empty( $value['availabilities'] ) ) {
55
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
54
+        if (empty($value['availabilities'])) {
55
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
56 56
         }
57 57
 
58 58
         return $value;
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         // and does not use/ request the availablity data (which could slow things down).
66 66
         static $imgopt_active = null;
67 67
 
68
-        if ( null === $imgopt_active ) {
69
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
70
-            if ( ! empty( $opts ) && is_array( $opts ) && array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $opts ) && ! empty( $opts['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $opts['autoptimize_imgopt_checkbox_field_1'] ) {
68
+        if (null === $imgopt_active) {
69
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
70
+            if (!empty($opts) && is_array($opts) && array_key_exists('autoptimize_imgopt_checkbox_field_1', $opts) && !empty($opts['autoptimize_imgopt_checkbox_field_1']) && '1' === $opts['autoptimize_imgopt_checkbox_field_1']) {
71 71
                 $imgopt_active = true;
72 72
             } else {
73 73
                 $imgopt_active = false;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public static function instance()
89 89
     {
90
-        if ( null === self::$instance ) {
90
+        if (null === self::$instance) {
91 91
             self::$instance = new self();
92 92
         }
93 93
 
@@ -96,34 +96,34 @@  discard block
 block discarded – undo
96 96
 
97 97
     public function run()
98 98
     {
99
-        if ( is_admin() ) {
100
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
101
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
99
+        if (is_admin()) {
100
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
101
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
102 102
             } else {
103
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
103
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
104 104
             }
105
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
105
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
106 106
         } else {
107
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
107
+            add_action('wp', array($this, 'run_on_frontend'));
108 108
         }
109 109
     }
110 110
 
111 111
     public function run_on_frontend() {
112
-        if ( ! $this->should_run() ) {
113
-            if ( $this->should_lazyload() ) {
112
+        if (!$this->should_run()) {
113
+            if ($this->should_lazyload()) {
114 114
                 add_filter(
115 115
                     'wp_lazy_loading_enabled',
116 116
                     '__return_false'
117 117
                 );
118 118
                 add_filter(
119 119
                     'autoptimize_html_after_minify',
120
-                    array( $this, 'filter_lazyload_images' ),
120
+                    array($this, 'filter_lazyload_images'),
121 121
                     10,
122 122
                     1
123 123
                 );
124 124
                 add_action(
125 125
                     'wp_footer',
126
-                    array( $this, 'add_lazyload_js_footer' ),
126
+                    array($this, 'add_lazyload_js_footer'),
127 127
                     10,
128 128
                     0
129 129
                 );
@@ -133,43 +133,43 @@  discard block
 block discarded – undo
133 133
 
134 134
         $active = false;
135 135
 
136
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
136
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
137 137
             add_filter(
138 138
                 'autoptimize_html_after_minify',
139
-                array( $this, 'filter_optimize_images' ),
139
+                array($this, 'filter_optimize_images'),
140 140
                 10,
141 141
                 1
142 142
             );
143 143
             $active = true;
144 144
         }
145 145
 
146
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
146
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
147 147
             add_filter(
148 148
                 'autoptimize_filter_base_replace_cdn',
149
-                array( $this, 'filter_optimize_css_images' ),
149
+                array($this, 'filter_optimize_css_images'),
150 150
                 10,
151 151
                 1
152 152
             );
153 153
             $active = true;
154 154
         }
155 155
 
156
-        if ( $active ) {
156
+        if ($active) {
157 157
             add_filter(
158 158
                 'autoptimize_extra_filter_tobepreconn',
159
-                array( $this, 'filter_preconnect_imgopt_url' ),
159
+                array($this, 'filter_preconnect_imgopt_url'),
160 160
                 10,
161 161
                 1
162 162
             );
163 163
         }
164 164
 
165
-        if ( $this->should_lazyload() ) {
165
+        if ($this->should_lazyload()) {
166 166
             add_filter(
167 167
                 'wp_lazy_loading_enabled',
168 168
                 '__return_false'
169 169
             );
170 170
             add_action(
171 171
                 'wp_footer',
172
-                array( $this, 'add_lazyload_js_footer' ),
172
+                array($this, 'add_lazyload_js_footer'),
173 173
                 10,
174 174
                 0
175 175
             );
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
     protected function should_run()
185 185
     {
186 186
         $opts              = $this->options;
187
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
188
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
187
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
188
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
189 189
 
190 190
         $do_cdn      = true;
191 191
         $_userstatus = $this->get_imgopt_provider_userstatus();
192
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
192
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
193 193
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
194 194
             $do_cdn = false;
195 195
         }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $this->imgopt_active()
199 199
             && $do_cdn
200 200
             && $service_not_down
201
-            && ( $not_launch_status || $this->launch_ok() )
201
+            && ($not_launch_status || $this->launch_ok())
202 202
         ) {
203 203
             return true;
204 204
         }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     {
210 210
         static $imgopt_host = null;
211 211
 
212
-        if ( null === $imgopt_host ) {
212
+        if (null === $imgopt_host) {
213 213
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
214 214
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
215
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
216
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
215
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
216
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
217 217
             }
218
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
218
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
219 219
         }
220 220
 
221 221
         return $imgopt_host;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
     public static function get_service_url_suffix()
232 232
     {
233
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
233
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
234 234
 
235 235
         return $suffix;
236 236
     }
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
     {
240 240
         static $quality = null;
241 241
 
242
-        if ( null === $quality ) {
242
+        if (null === $quality) {
243 243
             $q_array = $this->get_img_quality_array();
244 244
             $setting = $this->get_img_quality_setting();
245 245
             $quality = apply_filters(
246 246
                 'autoptimize_filter_imgopt_quality',
247
-                'q_' . $q_array[ $setting ]
247
+                'q_'.$q_array[$setting]
248 248
             );
249 249
         }
250 250
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     {
256 256
         static $map = null;
257 257
 
258
-        if ( null === $map ) {
258
+        if (null === $map) {
259 259
             $map = array(
260 260
                 '1' => 'lossy',
261 261
                 '2' => 'glossy',
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
     {
275 275
         static $q = null;
276 276
 
277
-        if ( null === $q ) {
278
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
277
+        if (null === $q) {
278
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
279 279
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
280 280
             }
281 281
 
282
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
282
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
283 283
                 // default image opt. value is 2 ("glossy").
284 284
                 $q = '2';
285 285
             } else {
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
         return $q;
291 291
     }
292 292
 
293
-    public function filter_preconnect_imgopt_url( array $in )
293
+    public function filter_preconnect_imgopt_url(array $in)
294 294
     {
295
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
296
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
295
+        $url_parts = parse_url($this->get_imgopt_base_url());
296
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
297 297
 
298 298
         return $in;
299 299
     }
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
      *
307 307
      * @return string
308 308
      */
309
-    private function normalize_img_url( $in )
309
+    private function normalize_img_url($in)
310 310
     {
311 311
         // Only parse the site url once.
312 312
         static $parsed_site_url = null;
313
-        if ( null === $parsed_site_url ) {
314
-            $parsed_site_url = parse_url( site_url() );
313
+        if (null === $parsed_site_url) {
314
+            $parsed_site_url = parse_url(site_url());
315 315
         }
316 316
 
317 317
         // get CDN domain once.
318 318
         static $cdn_domain = null;
319
-        if ( is_null( $cdn_domain ) ) {
319
+        if (is_null($cdn_domain)) {
320 320
             $cdn_url = $this->get_cdn_url();
321
-            if ( ! empty( $cdn_url ) ) {
322
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
321
+            if (!empty($cdn_url)) {
322
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
323 323
             } else {
324 324
                 $cdn_domain = '';
325 325
             }
@@ -335,44 +335,44 @@  discard block
 block discarded – undo
335 335
          * identical string operations).
336 336
          */
337 337
         static $cache = null;
338
-        if ( null === $cache ) {
338
+        if (null === $cache) {
339 339
             $cache = array();
340 340
         }
341 341
 
342 342
         // Do the work on cache miss only.
343
-        if ( ! isset( $cache[ $in ] ) ) {
343
+        if (!isset($cache[$in])) {
344 344
             // Default to (the trimmed version of) what was given to us.
345
-            $result = trim( $in );
345
+            $result = trim($in);
346 346
 
347 347
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
348
-            if ( strpos( $result, '&quot;' ) !== false ) {
349
-                $result = str_replace( '&quot;', '', $result );
348
+            if (strpos($result, '&quot;') !== false) {
349
+                $result = str_replace('&quot;', '', $result);
350 350
             }
351 351
 
352
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
353
-                $result = $parsed_site_url['scheme'] . ':' . $result;
354
-            } elseif ( 0 === strpos( $result, '/' ) ) {
352
+            if (autoptimizeUtils::is_protocol_relative($result)) {
353
+                $result = $parsed_site_url['scheme'].':'.$result;
354
+            } elseif (0 === strpos($result, '/')) {
355 355
                 // Root-relative...
356
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
357
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
358
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
356
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
357
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
358
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
359 359
             }
360 360
 
361
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
361
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
362 362
 
363 363
             // Store in cache.
364
-            $cache[ $in ] = $result;
364
+            $cache[$in] = $result;
365 365
         }
366 366
 
367
-        return $cache[ $in ];
367
+        return $cache[$in];
368 368
     }
369 369
 
370
-    public function filter_optimize_css_images( $in )
370
+    public function filter_optimize_css_images($in)
371 371
     {
372
-        $in = $this->normalize_img_url( $in );
372
+        $in = $this->normalize_img_url($in);
373 373
 
374
-        if ( $this->can_optimize_image( $in ) ) {
375
-            return $this->build_imgopt_url( $in, '', '' );
374
+        if ($this->can_optimize_image($in)) {
375
+            return $this->build_imgopt_url($in, '', '');
376 376
         } else {
377 377
             return $in;
378 378
         }
@@ -382,50 +382,50 @@  discard block
 block discarded – undo
382 382
     {
383 383
         static $imgopt_base_url = null;
384 384
 
385
-        if ( null === $imgopt_base_url ) {
385
+        if (null === $imgopt_base_url) {
386 386
             $imgopt_host     = $this->get_imgopt_host();
387 387
             $quality         = $this->get_img_quality_string();
388
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
389
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
390
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
388
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
389
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
390
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
391 391
         }
392 392
 
393 393
         return $imgopt_base_url;
394 394
     }
395 395
 
396
-    private function can_optimize_image( $url, $tag = '' )
396
+    private function can_optimize_image($url, $tag = '')
397 397
     {
398 398
         static $cdn_url      = null;
399 399
         static $nopti_images = null;
400 400
 
401
-        if ( null === $cdn_url ) {
401
+        if (null === $cdn_url) {
402 402
             $cdn_url = apply_filters(
403 403
                 'autoptimize_filter_base_cdnurl',
404
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
404
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
405 405
             );
406 406
         }
407 407
 
408
-        if ( null === $nopti_images ) {
409
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' );
408
+        if (null === $nopti_images) {
409
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', '');
410 410
         }
411 411
 
412 412
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
413
-        $url        = $this->normalize_img_url( $url );
414
-        $url_parsed = parse_url( $url );
413
+        $url        = $this->normalize_img_url($url);
414
+        $url_parsed = parse_url($url);
415 415
 
416
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
416
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
417 417
             return false;
418
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
418
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
419 419
             return false;
420
-        } elseif ( strpos( $url, '.php' ) !== false ) {
420
+        } elseif (strpos($url, '.php') !== false) {
421 421
             return false;
422
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
422
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp'), '', $url_parsed['path']) === $url_parsed['path']) {
423 423
             // fixme: better check against end of string.
424 424
             return false;
425
-        } elseif ( ! empty( $nopti_images ) ) {
426
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
427
-            foreach ( $nopti_images_array as $nopti_image ) {
428
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
425
+        } elseif (!empty($nopti_images)) {
426
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
427
+            foreach ($nopti_images_array as $nopti_image) {
428
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
429 429
                     return false;
430 430
                 }
431 431
             }
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
         return true;
434 434
     }
435 435
 
436
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
436
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
437 437
     {
438 438
         // sanitize width and height.
439
-        if ( strpos( $width, '%' ) !== false ) {
439
+        if (strpos($width, '%') !== false) {
440 440
             $width = 0;
441 441
         }
442
-        if ( strpos( $height, '%' ) !== false ) {
442
+        if (strpos($height, '%') !== false) {
443 443
             $height = 0;
444 444
         }
445 445
         $width  = (int) $width;
@@ -453,56 +453,56 @@  discard block
 block discarded – undo
453 453
         );
454 454
 
455 455
         // If filter modified the url, return that.
456
-        if ( $filtered_url !== $orig_url ) {
456
+        if ($filtered_url !== $orig_url) {
457 457
             return $filtered_url;
458 458
         }
459 459
 
460
-        $orig_url        = $this->normalize_img_url( $orig_url );
460
+        $orig_url        = $this->normalize_img_url($orig_url);
461 461
         $imgopt_base_url = $this->get_imgopt_base_url();
462 462
         $imgopt_size     = '';
463 463
 
464
-        if ( $width && 0 !== $width ) {
465
-            $imgopt_size = ',w_' . $width;
464
+        if ($width && 0 !== $width) {
465
+            $imgopt_size = ',w_'.$width;
466 466
         }
467 467
 
468
-        if ( $height && 0 !== $height ) {
469
-            $imgopt_size .= ',h_' . $height;
468
+        if ($height && 0 !== $height) {
469
+            $imgopt_size .= ',h_'.$height;
470 470
         }
471 471
 
472
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
472
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
473 473
 
474 474
         return $url;
475 475
     }
476 476
 
477
-    public function replace_data_thumbs( $matches )
477
+    public function replace_data_thumbs($matches)
478 478
     {
479
-        return $this->replace_img_callback( $matches, 150, 150 );
479
+        return $this->replace_img_callback($matches, 150, 150);
480 480
     }
481 481
 
482
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
482
+    public function replace_img_callback($matches, $width = 0, $height = 0)
483 483
     {
484
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
485
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
486
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
484
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
485
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
486
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
487 487
         } else {
488 488
             return $matches[0];
489 489
         }
490 490
     }
491 491
 
492
-    public function replace_icon_callback( $matches )
492
+    public function replace_icon_callback($matches)
493 493
     {
494
-        if ( array_key_exists( '2', $matches ) ) {
495
-            $sizes  = explode( 'x', $matches[2] );
494
+        if (array_key_exists('2', $matches)) {
495
+            $sizes  = explode('x', $matches[2]);
496 496
             $width  = $sizes[0];
497 497
             $height = $sizes[1];
498 498
         } else {
499 499
             $width  = 180;
500 500
             $height = 180;
501 501
         }
502
-        return $this->replace_img_callback( $matches, $width, $height );
502
+        return $this->replace_img_callback($matches, $width, $height);
503 503
     }
504 504
 
505
-    public function filter_optimize_images( $in )
505
+    public function filter_optimize_images($in)
506 506
     {
507 507
         /*
508 508
          * potential future functional improvements:
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         $to_replace = array();
513 513
 
514 514
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
515
-        if ( $this->should_lazyload() ) {
515
+        if ($this->should_lazyload()) {
516 516
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
517 517
                 'SCRIPT',
518 518
                 '<script',
@@ -522,25 +522,25 @@  discard block
 block discarded – undo
522 522
         }
523 523
 
524 524
         // extract img tags.
525
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
526
-            foreach ( $matches[0] as $tag ) {
525
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
526
+            foreach ($matches[0] as $tag) {
527 527
                 $orig_tag = $tag;
528 528
                 $imgopt_w = '';
529 529
                 $imgopt_h = '';
530 530
 
531 531
                 // first do (data-)srcsets.
532
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
533
-                    foreach ( $allsrcsets as $srcset ) {
532
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
533
+                    foreach ($allsrcsets as $srcset) {
534 534
                         $srcset  = $srcset[2];
535
-                        $srcsets = explode( ',', $srcset );
536
-                        foreach ( $srcsets as $indiv_srcset ) {
537
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
538
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
539
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
535
+                        $srcsets = explode(',', $srcset);
536
+                        foreach ($srcsets as $indiv_srcset) {
537
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
538
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
539
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
540 540
                             }
541
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag ) ) {
542
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
543
-                                $tag        = str_replace( $indiv_srcset_parts[0], $imgopt_url, $tag );
541
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag)) {
542
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
543
+                                $tag        = str_replace($indiv_srcset_parts[0], $imgopt_url, $tag);
544 544
                             }
545 545
                         }
546 546
                     }
@@ -548,133 +548,133 @@  discard block
 block discarded – undo
548 548
 
549 549
                 // proceed with img src.
550 550
                 // get width and height and add to $imgopt_size.
551
-                $_get_size = $this->get_size_from_tag( $tag );
551
+                $_get_size = $this->get_size_from_tag($tag);
552 552
                 $imgopt_w  = $_get_size['width'];
553 553
                 $imgopt_h  = $_get_size['height'];
554 554
 
555 555
                 // then start replacing images src.
556
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
557
-                    foreach ( $urls as $url ) {
556
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
557
+                    foreach ($urls as $url) {
558 558
                         $full_src_orig = $url[0];
559 559
                         $url           = $url[1];
560
-                        if ( $this->can_optimize_image( $url, $full_src_orig ) ) {
561
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
562
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
563
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
560
+                        if ($this->can_optimize_image($url, $full_src_orig)) {
561
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
562
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
563
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
564 564
                         }
565 565
                     }
566 566
                 }
567 567
 
568 568
                 // do lazyload stuff.
569
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
569
+                if ($this->should_lazyload($in) && !empty($url)) {
570 570
                     // first do lpiq placeholder logic.
571
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
571
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
572 572
                         // if all img src have been replaced during srcset, we have to extract the
573 573
                         // origin url from the imgopt one to be able to set a lqip placeholder.
574
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
574
+                        $_url = substr($url, strpos($url, '/http') + 1);
575 575
                     } else {
576 576
                         $_url = $url;
577 577
                     }
578 578
 
579
-                    $_url = $this->normalize_img_url( $_url );
579
+                    $_url = $this->normalize_img_url($_url);
580 580
 
581 581
                     $placeholder = '';
582
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
582
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
583 583
                         $lqip_w = '';
584 584
                         $lqip_h = '';
585
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
586
-                            $lqip_w = ',w_' . $imgopt_w;
585
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
586
+                            $lqip_w = ',w_'.$imgopt_w;
587 587
                         }
588
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
589
-                            $lqip_h = ',h_' . $imgopt_h;
588
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
589
+                            $lqip_h = ',h_'.$imgopt_h;
590 590
                         }
591
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
591
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
592 592
                     }
593 593
                     // then call add_lazyload-function with lpiq placeholder if set.
594
-                    $tag = $this->add_lazyload( $tag, $placeholder );
594
+                    $tag = $this->add_lazyload($tag, $placeholder);
595 595
                 }
596 596
 
597 597
                 // and add tag to array for later replacement.
598
-                if ( $tag !== $orig_tag ) {
599
-                    $to_replace[ $orig_tag ] = $tag;
598
+                if ($tag !== $orig_tag) {
599
+                    $to_replace[$orig_tag] = $tag;
600 600
                 }
601 601
             }
602 602
         }
603 603
 
604 604
         // and replace all.
605
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
605
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
606 606
 
607 607
         // img thumbnails in e.g. woocommerce.
608
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
608
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
609 609
             $out = preg_replace_callback(
610 610
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
611
-                array( $this, 'replace_data_thumbs' ),
611
+                array($this, 'replace_data_thumbs'),
612 612
                 $out
613 613
             );
614 614
         }
615 615
 
616 616
         // background-image in inline style.
617
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
617
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
618 618
             $out = preg_replace_callback(
619 619
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
620
-                array( $this, 'replace_img_callback' ),
620
+                array($this, 'replace_img_callback'),
621 621
                 $out
622 622
             );
623 623
         }
624 624
 
625 625
         // act on icon links.
626
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
626
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
627 627
             $out = preg_replace_callback(
628 628
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
629
-                array( $this, 'replace_icon_callback' ),
629
+                array($this, 'replace_icon_callback'),
630 630
                 $out
631 631
             );
632 632
         }
633 633
 
634 634
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
635
-        if ( $this->should_lazyload() ) {
635
+        if ($this->should_lazyload()) {
636 636
             $out = autoptimizeBase::restore_marked_content(
637 637
                 'SCRIPT',
638 638
                 $out
639 639
             );
640 640
 
641
-            $out = $this->process_picture_tag( $out, true, true );
642
-            $out = $this->process_bgimage( $out );
641
+            $out = $this->process_picture_tag($out, true, true);
642
+            $out = $this->process_bgimage($out);
643 643
         } else {
644
-            $out = $this->process_picture_tag( $out, true, false );
644
+            $out = $this->process_picture_tag($out, true, false);
645 645
         }
646 646
 
647 647
         return $out;
648 648
     }
649 649
 
650
-    public function get_size_from_tag( $tag ) {
650
+    public function get_size_from_tag($tag) {
651 651
         // reusable function to extract widht and height from an image tag
652 652
         // enforcing a filterable maximum width and height (default 4999X4999).
653 653
         $width  = '';
654 654
         $height = '';
655 655
 
656
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
657
-            if ( strpos( $_width[2], '%' ) === false ) {
656
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
657
+            if (strpos($_width[2], '%') === false) {
658 658
                 $width = (int) $_width[2];
659 659
             }
660 660
         }
661
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
662
-            if ( strpos( $_height[2], '%' ) === false ) {
661
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
662
+            if (strpos($_height[2], '%') === false) {
663 663
                 $height = (int) $_height[2];
664 664
             }
665 665
         }
666 666
 
667 667
         // check for and enforce (filterable) max sizes.
668
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
669
-        if ( $width > $_max_width ) {
668
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
669
+        if ($width > $_max_width) {
670 670
             $_width = $_max_width;
671
-            $height = $_width / $width * $height;
671
+            $height = $_width/$width*$height;
672 672
             $width  = $_width;
673 673
         }
674
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
675
-        if ( $height > $_max_height ) {
674
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
675
+        if ($height > $_max_height) {
676 676
             $_height = $_max_height;
677
-            $width   = $_height / $height * $width;
677
+            $width   = $_height/$height*$width;
678 678
             $height  = $_height;
679 679
         }
680 680
 
@@ -693,26 +693,26 @@  discard block
 block discarded – undo
693 693
         return $self->should_lazyload();
694 694
     }
695 695
 
696
-    public function should_lazyload( $context = '' ) {
697
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
696
+    public function should_lazyload($context = '') {
697
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
698 698
             $lazyload_return = true;
699 699
         } else {
700 700
             $lazyload_return = false;
701 701
         }
702
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
702
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
703 703
 
704 704
         return $lazyload_return;
705 705
     }
706 706
 
707 707
     public function check_nolazy() {
708
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
708
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
709 709
             return true;
710 710
         } else {
711 711
             return false;
712 712
         }
713 713
     }
714 714
 
715
-    public function filter_lazyload_images( $in )
715
+    public function filter_lazyload_images($in)
716 716
     {
717 717
         // only used is image optimization is NOT active but lazyload is.
718 718
         $to_replace = array();
@@ -726,20 +726,20 @@  discard block
 block discarded – undo
726 726
         );
727 727
 
728 728
         // extract img tags and add lazyload attribs.
729
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
730
-            foreach ( $matches[0] as $tag ) {
731
-                if ( $this->should_lazyload( $out ) ) {
732
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
729
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
730
+            foreach ($matches[0] as $tag) {
731
+                if ($this->should_lazyload($out)) {
732
+                    $to_replace[$tag] = $this->add_lazyload($tag);
733 733
                 }
734 734
             }
735
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
735
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
736 736
         }
737 737
 
738 738
         // and also lazyload picture tag.
739
-        $out = $this->process_picture_tag( $out, false, true );
739
+        $out = $this->process_picture_tag($out, false, true);
740 740
 
741 741
         // and inline style blocks with background-image.
742
-        $out = $this->process_bgimage( $out );
742
+        $out = $this->process_bgimage($out);
743 743
 
744 744
         // restore noscript tags.
745 745
         $out = autoptimizeBase::restore_marked_content(
@@ -750,85 +750,85 @@  discard block
 block discarded – undo
750 750
         return $out;
751 751
     }
752 752
 
753
-    public function add_lazyload( $tag, $placeholder = '' ) {
753
+    public function add_lazyload($tag, $placeholder = '') {
754 754
         // adds actual lazyload-attributes to an image node.
755
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
756
-            $tag = $this->maybe_fix_missing_quotes( $tag );
755
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) {
756
+            $tag = $this->maybe_fix_missing_quotes($tag);
757 757
 
758 758
             // store original tag for use in noscript version.
759
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
759
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
760 760
 
761
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
761
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
762 762
 
763 763
             // insert lazyload class.
764
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
764
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
765 765
 
766
-            if ( ! $placeholder || empty( $placeholder ) ) {
766
+            if (!$placeholder || empty($placeholder)) {
767 767
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
768
-                $_get_size = $this->get_size_from_tag( $tag );
768
+                $_get_size = $this->get_size_from_tag($tag);
769 769
                 $width     = $_get_size['width'];
770 770
                 $height    = $_get_size['height'];
771
-                if ( false === $width || empty( $width ) ) {
771
+                if (false === $width || empty($width)) {
772 772
                     $width = 210; // default width for SVG placeholder.
773 773
                 }
774
-                if ( false === $height || empty( $height ) ) {
775
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
774
+                if (false === $height || empty($height)) {
775
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
776 776
                 }
777 777
 
778 778
                 // insert the actual lazyload stuff.
779 779
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
780
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
780
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
781 781
             }
782 782
 
783
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
784
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
783
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
784
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
785 785
 
786 786
             // move sizes to data-sizes unless filter says no.
787
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
788
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
787
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
788
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
789 789
             }
790 790
 
791 791
             // add the noscript-tag from earlier.
792
-            $tag = $noscript_tag . $tag;
793
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
792
+            $tag = $noscript_tag.$tag;
793
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
794 794
         }
795 795
 
796 796
         return $tag;
797 797
     }
798 798
 
799 799
     public function add_lazyload_js_footer() {
800
-        if ( false === autoptimizeMain::should_buffer() ) {
800
+        if (false === autoptimizeMain::should_buffer()) {
801 801
             return;
802 802
         }
803 803
 
804 804
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
805 805
         $noptimize_flag = '';
806
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
806
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
807 807
             $noptimize_flag = ' data-noptimize="1"';
808 808
         }
809 809
 
810
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
810
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
811 811
         $cdn_url      = $this->get_cdn_url();
812
-        if ( ! empty( $cdn_url ) ) {
813
-            $cdn_url      = rtrim( $cdn_url, '/' );
814
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
812
+        if (!empty($cdn_url)) {
813
+            $cdn_url      = rtrim($cdn_url, '/');
814
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
815 815
         }
816 816
 
817 817
         $type_js = '';
818
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
818
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
819 819
             $type_js = ' type="text/javascript"';
820 820
         }
821 821
 
822 822
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
823
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
824
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
825
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
823
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
824
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
825
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
826 826
 
827 827
         // And add webp detection and loading JS.
828
-        if ( $this->should_webp() ) {
828
+        if ($this->should_webp()) {
829 829
             $_webp_detect = "function c_webp(A){var n=new Image;n.onload=function(){var e=0<n.width&&0<n.height;A(e)},n.onerror=function(){A(!1)},n.src='data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA=='}function s_webp(e){window.supportsWebP=e}c_webp(s_webp);";
830 830
             $_webp_load   = "document.addEventListener('lazybeforeunveil',function({target:b}){window.supportsWebP&&['data-src','data-srcset'].forEach(function(c){attr=b.getAttribute(c),null!==attr&&-1==attr.indexOf('/client/to_webp')&&b.setAttribute(c,attr.replace(/\/client\//,'/client/to_webp,'))})});";
831
-            echo apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_webp_detect . $_webp_load . '</script>' );
831
+            echo apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_webp_detect.$_webp_load.'</script>');
832 832
         }
833 833
     }
834 834
 
@@ -836,10 +836,10 @@  discard block
 block discarded – undo
836 836
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
837 837
         static $cdn_url = null;
838 838
 
839
-        if ( null === $cdn_url ) {
840
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
841
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
842
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
839
+        if (null === $cdn_url) {
840
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
841
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
842
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
843 843
         }
844 844
 
845 845
         return $cdn_url;
@@ -849,47 +849,47 @@  discard block
 block discarded – undo
849 849
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
850 850
         static $exclude_lazyload_array = null;
851 851
 
852
-        if ( null === $exclude_lazyload_array ) {
852
+        if (null === $exclude_lazyload_array) {
853 853
             $options = $this->options;
854 854
 
855 855
             // set default exclusions.
856
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
856
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
857 857
 
858 858
             // add from setting.
859
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
859
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
860 860
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
861
-                if ( ! empty( $exclude_lazyload_option ) ) {
862
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
861
+                if (!empty($exclude_lazyload_option)) {
862
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
863 863
                 }
864 864
             }
865 865
 
866 866
             // and filter for developer-initiated changes.
867
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
867
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
868 868
         }
869 869
 
870 870
         return $exclude_lazyload_array;
871 871
     }
872 872
 
873
-    public function inject_classes_in_tag( $tag, $target_class ) {
874
-        if ( strpos( $tag, 'class=' ) !== false ) {
875
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
873
+    public function inject_classes_in_tag($tag, $target_class) {
874
+        if (strpos($tag, 'class=') !== false) {
875
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
876 876
         } else {
877
-            $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
877
+            $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag);
878 878
         }
879 879
 
880 880
         return $tag;
881 881
     }
882 882
 
883
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
884
-        return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20' . $imgopt_w . '%20' . $imgopt_h . '%22%3E%3C/svg%3E';
883
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
884
+        return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20'.$imgopt_w.'%20'.$imgopt_h.'%22%3E%3C/svg%3E';
885 885
     }
886 886
 
887 887
     public function should_webp() {
888 888
         static $webp_return = null;
889 889
 
890
-        if ( is_null( $webp_return ) ) {
890
+        if (is_null($webp_return)) {
891 891
             // webp only works if imgopt and lazyload are also active.
892
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
892
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
893 893
                 $webp_return = true;
894 894
             } else {
895 895
                 $webp_return = false;
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
         return $webp_return;
900 900
     }
901 901
 
902
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
902
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
903 903
         // check if "<picture" is present and if filter allows us to process <picture>.
904
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
904
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
905 905
             return $in;
906 906
         }
907 907
 
@@ -909,37 +909,37 @@  discard block
 block discarded – undo
909 909
         $to_replace_pict = array();
910 910
 
911 911
         // extract and process each picture-node.
912
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
913
-        foreach ( $_pictures as $_picture ) {
914
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
915
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
916
-                foreach ( $_sources as $_source ) {
912
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
913
+        foreach ($_pictures as $_picture) {
914
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
915
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
916
+                foreach ($_sources as $_source) {
917 917
                     $_picture_replacement = $_source[0];
918 918
 
919 919
                     // should we optimize the image?
920
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
921
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
920
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
921
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
922 922
                     }
923 923
                     // should we lazy-load?
924
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
925
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
924
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
925
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
926 926
                     }
927
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
927
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
928 928
                 }
929 929
             }
930 930
         }
931 931
 
932 932
         // and return the fully procesed $in.
933
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
933
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
934 934
 
935 935
         return $out;
936 936
     }
937 937
 
938
-    public function process_bgimage( $in ) {
939
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
938
+    public function process_bgimage($in) {
939
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
940 940
             $out = preg_replace_callback(
941 941
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
942
-                array( $this, 'lazyload_bgimg_callback' ),
942
+                array($this, 'lazyload_bgimg_callback'),
943 943
                 $in
944 944
             );
945 945
             return $out;
@@ -947,27 +947,27 @@  discard block
 block discarded – undo
947 947
         return $in;
948 948
     }
949 949
 
950
-    public function lazyload_bgimg_callback( $matches ) {
951
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
950
+    public function lazyload_bgimg_callback($matches) {
951
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
952 952
             // get placeholder & lazyload class strings.
953
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
954
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
953
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
954
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
955 955
             // replace background-image URL with SVG placeholder.
956
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
956
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
957 957
             // add data-bg attribute with real background-image URL for lazyload to pick up.
958
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
958
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
959 959
             // add lazyload class to tag.
960
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
960
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
961 961
             return $out;
962 962
         }
963 963
         return $matches[0];
964 964
     }
965 965
 
966
-    public function maybe_fix_missing_quotes( $tag_in ) {
966
+    public function maybe_fix_missing_quotes($tag_in) {
967 967
         // W3TC's Minify_HTML class removes quotes around attribute value, this re-adds them for the class and width/height attributes so we can lazyload properly.
968
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
969
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
970
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
968
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
969
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
970
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
971 971
             return $tag_out;
972 972
         } else {
973 973
             return $tag_in;
@@ -980,23 +980,23 @@  discard block
 block discarded – undo
980 980
     public function imgopt_admin_menu()
981 981
     {
982 982
         // no acces if multisite and not network admin and no site config allowed.
983
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
983
+        if (autoptimizeConfig::should_show_menu_tabs()) {
984 984
             add_submenu_page(
985 985
                 null,
986 986
                 'autoptimize_imgopt',
987 987
                 'autoptimize_imgopt',
988 988
                 'manage_options',
989 989
                 'autoptimize_imgopt',
990
-                array( $this, 'imgopt_options_page' )
990
+                array($this, 'imgopt_options_page')
991 991
             );
992 992
         }
993
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
993
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
994 994
     }
995 995
 
996
-    public function add_imgopt_tab( $in )
996
+    public function add_imgopt_tab($in)
997 997
     {
998
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
999
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
998
+        if (autoptimizeConfig::should_show_menu_tabs()) {
999
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1000 1000
         }
1001 1001
 
1002 1002
         return $in;
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     public function imgopt_options_page()
1006 1006
     {
1007 1007
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1008
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1008
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1009 1009
             $this->query_img_provider_stats();
1010 1010
         }
1011 1011
 
@@ -1017,47 +1017,47 @@  discard block
 block discarded – undo
1017 1017
         #ao_settings_form .form-table th {font-weight: normal;}
1018 1018
         #autoptimize_imgopt_descr{font-size: 120%;}
1019 1019
     </style>
1020
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1020
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1021 1021
     <div class="wrap">
1022
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1022
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1023 1023
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1024
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1024
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1025 1025
             <div class="notice-warning notice"><p>
1026 1026
             <?php
1027 1027
             // translators: "Autoptimize support forum" will appear in a "a href".
1028
-            echo sprintf( __( 'The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize' ), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>' );
1028
+            echo sprintf(__('The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize'), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>');
1029 1029
             ?>
1030 1030
             </p></div>
1031 1031
         <?php } ?>
1032 1032
 
1033
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1033
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1034 1034
             <div class="notice-warning notice"><p>
1035
-            <?php _e( 'The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize' ); ?>
1035
+            <?php _e('The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize'); ?>
1036 1036
             </p></div>
1037 1037
         <?php } ?>
1038 1038
 
1039
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1039
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1040 1040
             <div class="notice-warning notice"><p>
1041 1041
             <?php
1042 1042
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1043
-            echo sprintf( __( 'Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize' ), '<a href="admin.php?page=jetpack#/settings">', '</a>' );
1043
+            echo sprintf(__('Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize'), '<a href="admin.php?page=jetpack#/settings">', '</a>');
1044 1044
             ?>
1045 1045
             </p></div>
1046 1046
         <?php } ?>
1047
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1048
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1049
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1050
-        <span id='autoptimize_imgopt_descr'><?php _e( 'Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize' ); ?></span>
1047
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1048
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1049
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1050
+        <span id='autoptimize_imgopt_descr'><?php _e('Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize'); ?></span>
1051 1051
         <table class="form-table">
1052 1052
             <tr>
1053
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1053
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1054 1054
                 <td>
1055
-                    <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize' ); ?></label>
1055
+                    <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_1']) && '1' === $options['autoptimize_imgopt_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize'); ?></label>
1056 1056
                     <?php
1057 1057
                     // show shortpixel status.
1058 1058
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1059
-                    if ( $_notice ) {
1060
-                        switch ( $_notice['status'] ) {
1059
+                    if ($_notice) {
1060
+                        switch ($_notice['status']) {
1061 1061
                             case 2:
1062 1062
                                 $_notice_color = 'green';
1063 1063
                                 break;
@@ -1072,29 +1072,29 @@  discard block
 block discarded – undo
1072 1072
                             default:
1073 1073
                                 $_notice_color = 'green';
1074 1074
                         }
1075
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1075
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1076 1076
                     } else {
1077 1077
                         // translators: link points to shortpixel.
1078
-                        $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1079
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1080
-                            $upsell_msg_2 = __( 'For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize' );
1078
+                        $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1079
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1080
+                            $upsell_msg_2 = __('For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize');
1081 1081
                         } else {
1082 1082
                             // translators: link points to shortpixel.
1083
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive a 1 000 bonus + 50&#37; more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1083
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive a 1 000 bonus + 50&#37; more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1084 1084
                         }
1085
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1085
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1086 1086
                     }
1087 1087
                     // translators: link points to shortpixel FAQ.
1088
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>' );
1089
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1088
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>');
1089
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1090 1090
                     // translators: links points to shortpixel TOS & Privacy Policy.
1091
-                    $toscopy = sprintf( __( 'Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize' ), '<a href="https://shortpixel.com/tos' . $sp_url_suffix . '" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp' . $sp_url_suffix . '" target="_blank">', '</a>' );
1092
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1091
+                    $toscopy = sprintf(__('Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize'), '<a href="https://shortpixel.com/tos'.$sp_url_suffix.'" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp'.$sp_url_suffix.'" target="_blank">', '</a>');
1092
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1093 1093
                     ?>
1094 1094
                 </td>
1095 1095
             </tr>
1096
-            <tr id='autoptimize_imgopt_quality' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1097
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1096
+            <tr id='autoptimize_imgopt_quality' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1097
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1098 1098
                 <td>
1099 1099
                     <label>
1100 1100
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1102,12 +1102,12 @@  discard block
 block discarded – undo
1102 1102
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1103 1103
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1104 1104
 
1105
-                        foreach ( $_imgopt_array as $key => $value ) {
1106
-                            echo '<option value="' . $key . '"';
1107
-                            if ( $_imgopt_val == $key ) {
1105
+                        foreach ($_imgopt_array as $key => $value) {
1106
+                            echo '<option value="'.$key.'"';
1107
+                            if ($_imgopt_val == $key) {
1108 1108
                                 echo ' selected';
1109 1109
                             }
1110
-                            echo '>' . ucfirst( $value ) . '</option>';
1110
+                            echo '>'.ucfirst($value).'</option>';
1111 1111
                         }
1112 1112
                         echo "\n";
1113 1113
                         ?>
@@ -1116,31 +1116,31 @@  discard block
 block discarded – undo
1116 1116
                     <p>
1117 1117
                         <?php
1118 1118
                             // translators: link points to shortpixel image test page.
1119
-                            echo apply_filters( 'autoptimize_imgopt_imgopt_quality_copy', sprintf( __( 'You can %1$stest compression levels here%2$s.', 'autoptimize' ), '<a href="https://shortpixel.com/oic' . $sp_url_suffix . '" target="_blank">', '</a>' ) );
1119
+                            echo apply_filters('autoptimize_imgopt_imgopt_quality_copy', sprintf(__('You can %1$stest compression levels here%2$s.', 'autoptimize'), '<a href="https://shortpixel.com/oic'.$sp_url_suffix.'" target="_blank">', '</a>'));
1120 1120
                         ?>
1121 1121
                     </p>
1122 1122
                 </td>
1123 1123
             </tr>
1124
-            <tr id='autoptimize_imgopt_webp' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1125
-                <th scope="row"><?php _e( 'Load WebP in supported browsers?', 'autoptimize' ); ?></th>
1124
+            <tr id='autoptimize_imgopt_webp' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1125
+                <th scope="row"><?php _e('Load WebP in supported browsers?', 'autoptimize'); ?></th>
1126 1126
                 <td>
1127
-                    <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_4'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label>
1127
+                    <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_4']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label>
1128 1128
                 </td>
1129 1129
             </tr>
1130 1130
             <tr>
1131
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1131
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1132 1132
                 <td>
1133
-                    <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize' ); ?></label>
1133
+                    <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_3']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize'); ?></label>
1134 1134
                 </td>
1135 1135
             </tr>
1136
-            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="hidden"'; } ?>>
1137
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1136
+            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="hidden"'; } ?>>
1137
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1138 1138
                 <td>
1139
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label>
1139
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label>
1140 1140
                 </td>
1141 1141
             </tr>
1142 1142
         </table>
1143
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1143
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1144 1144
     </form>
1145 1145
     <script>
1146 1146
         jQuery(document).ready(function() {
@@ -1176,50 +1176,50 @@  discard block
 block discarded – undo
1176 1176
      * Ïmg opt status as used on dashboard.
1177 1177
      */
1178 1178
     public function get_imgopt_status_notice() {
1179
-        if ( $this->imgopt_active() ) {
1179
+        if ($this->imgopt_active()) {
1180 1180
             $_imgopt_notice  = '';
1181
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1181
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1182 1182
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1183
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1183
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1184 1184
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1185 1185
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1186 1186
 
1187
-            if ( is_array( $_stat ) ) {
1188
-                if ( 1 == $_stat['Status'] ) {
1187
+            if (is_array($_stat)) {
1188
+                if (1 == $_stat['Status']) {
1189 1189
                     // translators: "add more credits" will appear in a "a href".
1190
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1190
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1191 1191
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1192 1192
                     // translators: "add more credits" will appear in a "a href".
1193
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1193
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1194 1194
                     // translators: "associate your domain" will appear in a "a href".
1195
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '<a rel="noopener noreferrer" href="' . $_imgopt_assoc . '" target="_blank">', '</a>' );
1195
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize'), '<a rel="noopener noreferrer" href="'.$_imgopt_assoc.'" target="_blank">', '</a>');
1196 1196
                 } elseif ( -3 == $_stat['Status'] ) {
1197 1197
                     // translators: "check the documentation here" will appear in a "a href".
1198
-                    $_imgopt_notice = sprintf( __( 'It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize' ), '<a href="' . $_imgopt_unreach . '" target="_blank">', '</a>' );
1198
+                    $_imgopt_notice = sprintf(__('It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize'), '<a href="'.$_imgopt_unreach.'" target="_blank">', '</a>');
1199 1199
                 } else {
1200 1200
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1201 1201
                     // translators: "log in to check your account" will appear in a "a href".
1202
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1202
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1203 1203
                 }
1204 1204
 
1205 1205
                 // add info on freshness + refresh link if status is not 2 (good shape).
1206
-                if ( 2 != $_stat['Status'] ) {
1207
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1206
+                if (2 != $_stat['Status']) {
1207
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1208 1208
                         'page'                => 'autoptimize_imgopt',
1209 1209
                         'refreshImgProvStats' => '1',
1210
-                    ), admin_url( 'options-general.php' ) );
1211
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1212
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1210
+                    ), admin_url('options-general.php'));
1211
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1212
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1213 1213
                     } else {
1214
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1214
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1215 1215
                     }
1216
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1216
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1217 1217
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1218
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1218
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1219 1219
                 }
1220 1220
 
1221 1221
                 // and make the full notice filterable.
1222
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1222
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1223 1223
 
1224 1224
                 return array(
1225 1225
                     'status' => $_stat['Status'],
@@ -1240,14 +1240,14 @@  discard block
 block discarded – undo
1240 1240
      * Get img provider stats (used to display notice).
1241 1241
      */
1242 1242
     public function query_img_provider_stats() {
1243
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1243
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1244 1244
             $url      = '';
1245
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1245
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1246 1246
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1247 1247
 
1248 1248
             // make sure parse_url result makes sense, keeping $url empty if not.
1249
-            if ( $domain && ! empty( $domain ) ) {
1250
-                $url = $endpoint . $domain;
1249
+            if ($domain && !empty($domain)) {
1250
+                $url = $endpoint.$domain;
1251 1251
             }
1252 1252
 
1253 1253
             $url = apply_filters(
@@ -1257,12 +1257,12 @@  discard block
 block discarded – undo
1257 1257
 
1258 1258
             // only do the remote call if $url is not empty to make sure no parse_url
1259 1259
             // weirdness results in useless calls.
1260
-            if ( ! empty( $url ) ) {
1261
-                $response = wp_remote_get( $url );
1262
-                if ( ! is_wp_error( $response ) ) {
1263
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1264
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1265
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1260
+            if (!empty($url)) {
1261
+                $response = wp_remote_get($url);
1262
+                if (!is_wp_error($response)) {
1263
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1264
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1265
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1266 1266
                     }
1267 1267
                 }
1268 1268
             }
@@ -1285,15 +1285,15 @@  discard block
 block discarded – undo
1285 1285
     {
1286 1286
         static $launch_status = null;
1287 1287
 
1288
-        if ( null === $launch_status ) {
1288
+        if (null === $launch_status) {
1289 1289
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1290
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1291
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1290
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1291
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1292 1292
             $launch_status = false;
1293
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1293
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1294 1294
                 $launch_status = true;
1295
-                if ( ! $has_launched ) {
1296
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1295
+                if (!$has_launched) {
1296
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1297 1297
                 }
1298 1298
             }
1299 1299
         }
@@ -1310,16 +1310,16 @@  discard block
 block discarded – undo
1310 1310
     public function get_imgopt_provider_userstatus() {
1311 1311
         static $_provider_userstatus = null;
1312 1312
 
1313
-        if ( is_null( $_provider_userstatus ) ) {
1314
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1315
-            if ( is_array( $_stat ) ) {
1316
-                if ( array_key_exists( 'Status', $_stat ) ) {
1313
+        if (is_null($_provider_userstatus)) {
1314
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1315
+            if (is_array($_stat)) {
1316
+                if (array_key_exists('Status', $_stat)) {
1317 1317
                     $_provider_userstatus['Status'] = $_stat['Status'];
1318 1318
                 } else {
1319 1319
                     // if no stats then we assume all is well.
1320 1320
                     $_provider_userstatus['Status'] = 2;
1321 1321
                 }
1322
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1322
+                if (array_key_exists('timestamp', $_stat)) {
1323 1323
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1324 1324
                 } else {
1325 1325
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeExtra.php 1 patch
Spacing   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles autoptimizeExtra frontend features + admin options page
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @param array $options Optional. Allows overriding options without having to specify them via admin options page.
30 30
      */
31
-    public function __construct( $options = array() )
31
+    public function __construct($options = array())
32 32
     {
33
-        if ( empty( $options ) ) {
33
+        if (empty($options)) {
34 34
             $options = self::fetch_options();
35 35
         }
36 36
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public static function instance()
49 49
     {
50
-        if ( null === self::$instance ) {
50
+        if (null === self::$instance) {
51 51
             self::$instance = new self();
52 52
         }
53 53
 
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
 
57 57
     public function run()
58 58
     {
59
-        if ( is_admin() ) {
60
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
61
-                add_action( 'network_admin_menu', array( $this, 'admin_menu' ) );
59
+        if (is_admin()) {
60
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
61
+                add_action('network_admin_menu', array($this, 'admin_menu'));
62 62
             } else {
63
-                add_action( 'admin_menu', array( $this, 'admin_menu' ) );
63
+                add_action('admin_menu', array($this, 'admin_menu'));
64 64
             }
65
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) );
65
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab'));
66 66
         } else {
67
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
67
+            add_action('wp', array($this, 'run_on_frontend'));
68 68
         }
69 69
     }
70 70
 
71
-    public function set_options( array $options )
71
+    public function set_options(array $options)
72 72
     {
73 73
         $this->options = $options;
74 74
 
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 
78 78
     public static function fetch_options()
79 79
     {
80
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings' );
81
-        if ( empty( $value ) ) {
80
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings');
81
+        if (empty($value)) {
82 82
             // Fallback to returning defaults when no stored option exists yet.
83 83
             $value = autoptimizeConfig::get_ao_extra_default_options();
84 84
         }
@@ -89,55 +89,55 @@  discard block
 block discarded – undo
89 89
     public function disable_emojis()
90 90
     {
91 91
         // Removing all actions related to emojis!
92
-        remove_action( 'admin_print_styles', 'print_emoji_styles' );
93
-        remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
94
-        remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
95
-        remove_action( 'wp_print_styles', 'print_emoji_styles' );
96
-        remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
97
-        remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
98
-        remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
92
+        remove_action('admin_print_styles', 'print_emoji_styles');
93
+        remove_action('wp_head', 'print_emoji_detection_script', 7);
94
+        remove_action('admin_print_scripts', 'print_emoji_detection_script');
95
+        remove_action('wp_print_styles', 'print_emoji_styles');
96
+        remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
97
+        remove_filter('the_content_feed', 'wp_staticize_emoji');
98
+        remove_filter('comment_text_rss', 'wp_staticize_emoji');
99 99
 
100 100
         // Removes TinyMCE emojis.
101
-        add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) );
101
+        add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce'));
102 102
 
103 103
         // Removes emoji dns-preftech.
104
-        add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 );
104
+        add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2);
105 105
     }
106 106
 
107
-    public function filter_disable_emojis_tinymce( $plugins )
107
+    public function filter_disable_emojis_tinymce($plugins)
108 108
     {
109
-        if ( is_array( $plugins ) ) {
110
-            return array_diff( $plugins, array( 'wpemoji' ) );
109
+        if (is_array($plugins)) {
110
+            return array_diff($plugins, array('wpemoji'));
111 111
         } else {
112 112
             return array();
113 113
         }
114 114
     }
115 115
 
116
-    public function filter_remove_qs( $src )
116
+    public function filter_remove_qs($src)
117 117
     {
118
-        if ( strpos( $src, '?ver=' ) ) {
119
-            $src = remove_query_arg( 'ver', $src );
118
+        if (strpos($src, '?ver=')) {
119
+            $src = remove_query_arg('ver', $src);
120 120
         }
121 121
 
122 122
         return $src;
123 123
     }
124 124
 
125
-    public function extra_async_js( $in )
125
+    public function extra_async_js($in)
126 126
     {
127 127
         $exclusions = array();
128
-        if ( ! empty( $in ) ) {
129
-            $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' );
128
+        if (!empty($in)) {
129
+            $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), '');
130 130
         }
131 131
 
132 132
         $settings = $this->options['autoptimize_extra_text_field_3'];
133
-        $async    = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' );
134
-        $attr     = apply_filters( 'autoptimize_filter_extra_async', 'async' );
135
-        foreach ( $async as $k => $v ) {
136
-            $async[ $k ] = $attr;
133
+        $async    = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), '');
134
+        $attr     = apply_filters('autoptimize_filter_extra_async', 'async');
135
+        foreach ($async as $k => $v) {
136
+            $async[$k] = $attr;
137 137
         }
138 138
 
139 139
         // Merge exclusions & asyncs in one array and return to AO API.
140
-        $merged = array_merge( $exclusions, $async );
140
+        $merged = array_merge($exclusions, $async);
141 141
 
142 142
         return $merged;
143 143
     }
@@ -148,68 +148,68 @@  discard block
 block discarded – undo
148 148
         // for optimizations are met, this to ensure e.g. removing querystrings
149 149
         // is not done when optimizing for logged in users is off, breaking
150 150
         // some pagebuilders (Divi & Elementor).
151
-        if ( false === autoptimizeMain::should_buffer() ) {
151
+        if (false === autoptimizeMain::should_buffer()) {
152 152
             return;
153 153
         }
154 154
 
155 155
         $options = $this->options;
156 156
 
157 157
         // Disable emojis if specified.
158
-        if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) {
158
+        if (!empty($options['autoptimize_extra_checkbox_field_1'])) {
159 159
             $this->disable_emojis();
160 160
         }
161 161
 
162 162
         // Remove version query parameters.
163
-        if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) {
164
-            add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 );
165
-            add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 );
163
+        if (!empty($options['autoptimize_extra_checkbox_field_0'])) {
164
+            add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1);
165
+            add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1);
166 166
         }
167 167
 
168 168
         // Avoiding conflicts of interest when async-javascript plugin is active!
169
-        $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' );
170
-        if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) {
171
-            add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 );
169
+        $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php');
170
+        if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) {
171
+            add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1);
172 172
         }
173 173
 
174 174
         // Optimize google fonts!
175
-        if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) {
176
-            add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 );
177
-            add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 );
178
-            add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 );
175
+        if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) {
176
+            add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2);
177
+            add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1);
178
+            add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1);
179 179
         }
180 180
 
181 181
         // Preconnect!
182
-        if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) {
183
-            add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 );
182
+        if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) {
183
+            add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2);
184 184
         }
185 185
 
186 186
         // Preload!
187
-        if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) ) {
188
-            add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 );
187
+        if (!empty($options['autoptimize_extra_text_field_7']) || has_filter('autoptimize_filter_extra_tobepreloaded')) {
188
+            add_filter('autoptimize_html_after_minify', array($this, 'filter_preload'), 10, 2);
189 189
         }
190 190
     }
191 191
 
192
-    public function filter_remove_emoji_dns_prefetch( $urls, $relation_type )
192
+    public function filter_remove_emoji_dns_prefetch($urls, $relation_type)
193 193
     {
194
-        $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' );
194
+        $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/');
195 195
 
196
-        return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url );
196
+        return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url);
197 197
     }
198 198
 
199
-    public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type )
199
+    public function filter_remove_gfonts_dnsprefetch($urls, $relation_type)
200 200
     {
201
-        return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' );
201
+        return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com');
202 202
     }
203 203
 
204
-    public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove )
204
+    public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove)
205 205
     {
206 206
         $url_to_remove = (string) $url_to_remove;
207 207
 
208
-        if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) {
208
+        if (!empty($url_to_remove) && 'dns-prefetch' === $relation_type) {
209 209
             $cnt = 0;
210
-            foreach ( $urls as $url ) {
211
-                if ( false !== strpos( $url, $url_to_remove ) ) {
212
-                    unset( $urls[ $cnt ] );
210
+            foreach ($urls as $url) {
211
+                if (false !== strpos($url, $url_to_remove)) {
212
+                    unset($urls[$cnt]);
213 213
                 }
214 214
                 $cnt++;
215 215
             }
@@ -218,151 +218,151 @@  discard block
 block discarded – undo
218 218
         return $urls;
219 219
     }
220 220
 
221
-    public function filter_optimize_google_fonts( $in )
221
+    public function filter_optimize_google_fonts($in)
222 222
     {
223 223
         // Extract fonts, partly based on wp rocket's extraction code.
224
-        $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in );
225
-        preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches );
224
+        $markup = preg_replace('/<!--(.*)-->/Uis', '', $in);
225
+        preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches);
226 226
 
227 227
         $fonts_collection = array();
228
-        if ( ! $matches[2] ) {
228
+        if (!$matches[2]) {
229 229
             return $in;
230 230
         }
231 231
 
232 232
         // Store them in $fonts array.
233 233
         $i = 0;
234
-        foreach ( $matches[2] as $font ) {
235
-            if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) {
234
+        foreach ($matches[2] as $font) {
235
+            if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) {
236 236
                 // Get fonts name.
237
-                $font = str_replace( array( '%7C', '%7c' ), '|', $font );
238
-                if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) {
237
+                $font = str_replace(array('%7C', '%7c'), '|', $font);
238
+                if (strpos($font, 'fonts.googleapis.com/css2') !== false) {
239 239
                     // (Somewhat) change Google Fonts APIv2 syntax back to v1.
240
-                    $font = str_replace( array( 'wght@', 'wght%40', ';', '%3B' ), array( '', '', ',', ',' ), $font );
240
+                    $font = str_replace(array('wght@', 'wght%40', ';', '%3B'), array('', '', ',', ','), $font);
241 241
                 }
242
-                $font = explode( 'family=', $font );
243
-                $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
242
+                $font = explode('family=', $font);
243
+                $font = (isset($font[1])) ? explode('&', $font[1]) : array();
244 244
                 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
245
-                $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) );
246
-                if ( ! empty( $_thisfont ) ) {
247
-                    $fonts_collection[ $i ]['fonts'] = $_thisfont;
245
+                $_thisfont = array_values(array_filter(explode('|', reset($font))));
246
+                if (!empty($_thisfont)) {
247
+                    $fonts_collection[$i]['fonts'] = $_thisfont;
248 248
                     // And add subset if any!
249
-                    $subset = ( is_array( $font ) ) ? end( $font ) : '';
250
-                    if ( false !== strpos( $subset, 'subset=' ) ) {
251
-                        $subset                            = str_replace( array( '%2C', '%2c' ), ',', $subset );
252
-                        $subset                            = explode( 'subset=', $subset );
253
-                        $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] );
249
+                    $subset = (is_array($font)) ? end($font) : '';
250
+                    if (false !== strpos($subset, 'subset=')) {
251
+                        $subset                            = str_replace(array('%2C', '%2c'), ',', $subset);
252
+                        $subset                            = explode('subset=', $subset);
253
+                        $fonts_collection[$i]['subsets'] = explode(',', $subset[1]);
254 254
                     }
255 255
                 }
256 256
                 // And remove Google Fonts.
257
-                $in = str_replace( $matches[0][ $i ], '', $in );
257
+                $in = str_replace($matches[0][$i], '', $in);
258 258
             }
259 259
             $i++;
260 260
         }
261 261
 
262 262
         $options      = $this->options;
263 263
         $fonts_markup = '';
264
-        if ( '2' === $options['autoptimize_extra_radio_field_4'] ) {
264
+        if ('2' === $options['autoptimize_extra_radio_field_4']) {
265 265
             // Remove Google Fonts.
266
-            unset( $fonts_collection );
266
+            unset($fonts_collection);
267 267
             return $in;
268
-        } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) {
268
+        } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) {
269 269
             // Aggregate & link!
270 270
             $fonts_string  = '';
271 271
             $subset_string = '';
272
-            foreach ( $fonts_collection as $font ) {
273
-                $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' );
274
-                if ( ! empty( $font['subsets'] ) ) {
275
-                    $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' );
272
+            foreach ($fonts_collection as $font) {
273
+                $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|');
274
+                if (!empty($font['subsets'])) {
275
+                    $subset_string .= ','.trim(implode(',', $font['subsets']), ',');
276 276
                 }
277 277
             }
278 278
 
279
-            if ( ! empty( $subset_string ) ) {
280
-                $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) );
281
-                $fonts_string  = $fonts_string . '&#038;subset=' . $subset_string;
279
+            if (!empty($subset_string)) {
280
+                $subset_string = str_replace(',', '%2C', ltrim($subset_string, ','));
281
+                $fonts_string  = $fonts_string.'&#038;subset='.$subset_string;
282 282
             }
283 283
 
284
-            $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) );
284
+            $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|')));
285 285
             // only add display parameter if there is none in $fonts_string (by virtue of the filter).
286
-            if ( strpos( $fonts_string, 'display=' ) === false ) {
287
-                $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&amp;display=swap' );
286
+            if (strpos($fonts_string, 'display=') === false) {
287
+                $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&amp;display=swap');
288 288
             }
289 289
 
290
-            if ( ! empty( $fonts_string ) ) {
291
-                if ( '5' === $options['autoptimize_extra_radio_field_4'] ) {
292
-                    $rel_string = 'rel="stylesheet" media="print" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
290
+            if (!empty($fonts_string)) {
291
+                if ('5' === $options['autoptimize_extra_radio_field_4']) {
292
+                    $rel_string = 'rel="stylesheet" media="print" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"';
293 293
                 } else {
294 294
                     $rel_string = 'rel="stylesheet"';
295 295
                 }
296
-                $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />';
296
+                $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />';
297 297
             }
298
-        } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) {
298
+        } elseif ('4' === $options['autoptimize_extra_radio_field_4']) {
299 299
             // Aggregate & load async (webfont.js impl.)!
300 300
             $fonts_array = array();
301
-            foreach ( $fonts_collection as $_fonts ) {
302
-                if ( ! empty( $_fonts['subsets'] ) ) {
303
-                    $_subset = implode( ',', $_fonts['subsets'] );
304
-                    foreach ( $_fonts['fonts'] as $key => $_one_font ) {
305
-                        $_one_font               = $_one_font . ':' . $_subset;
306
-                        $_fonts['fonts'][ $key ] = $_one_font;
301
+            foreach ($fonts_collection as $_fonts) {
302
+                if (!empty($_fonts['subsets'])) {
303
+                    $_subset = implode(',', $_fonts['subsets']);
304
+                    foreach ($_fonts['fonts'] as $key => $_one_font) {
305
+                        $_one_font               = $_one_font.':'.$_subset;
306
+                        $_fonts['fonts'][$key] = $_one_font;
307 307
                     }
308 308
                 }
309
-                $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
309
+                $fonts_array = array_merge($fonts_array, $_fonts['fonts']);
310 310
             }
311 311
 
312
-            $fonts_array = array_map( 'urldecode', $fonts_array );
312
+            $fonts_array = array_map('urldecode', $fonts_array);
313 313
             $fonts_array = array_map(
314
-                function( $_f ) {
315
-                    return trim( $_f, ',' );
314
+                function($_f) {
315
+                    return trim($_f, ',');
316 316
                 },
317 317
                 $fonts_array
318 318
             );
319 319
 
320 320
             // type attrib on <script not added by default.
321 321
             $type_js = '';
322
-            if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
322
+            if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
323 323
                 $type_js = 'type="text/javascript" ';
324 324
             }
325 325
 
326
-            $fonts_markup         = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>';
327
-            $fonts_library_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
328
-            $in                   = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
326
+            $fonts_markup         = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>';
327
+            $fonts_library_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
328
+            $in                   = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>'));
329 329
         }
330 330
 
331 331
         // Replace back in markup.
332
-        $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
333
-        $out          = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
334
-        unset( $fonts_collection );
332
+        $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link');
333
+        $out          = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point));
334
+        unset($fonts_collection);
335 335
 
336 336
         return $out;
337 337
     }
338 338
 
339
-    public function filter_preconnect( $hints, $relation_type )
339
+    public function filter_preconnect($hints, $relation_type)
340 340
     {
341 341
         $options  = $this->options;
342 342
         $preconns = array();
343 343
 
344 344
         // Get settings and store in array.
345
-        if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) {
346
-            $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
345
+        if (array_key_exists('autoptimize_extra_text_field_2', $options)) {
346
+            $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2'])));
347 347
         }
348
-        $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
348
+        $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns);
349 349
 
350 350
         // Walk array, extract domain and add to new array with crossorigin attribute.
351
-        foreach ( $preconns as $preconn ) {
351
+        foreach ($preconns as $preconn) {
352 352
             $domain = '';
353
-            $parsed = parse_url( $preconn );
354
-            if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) {
355
-                $domain = '//' . $parsed['host'];
356
-            } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) {
357
-                $domain = $parsed['scheme'] . '://' . $parsed['host'];
353
+            $parsed = parse_url($preconn);
354
+            if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) {
355
+                $domain = '//'.$parsed['host'];
356
+            } elseif (is_array($parsed) && !empty($parsed['host'])) {
357
+                $domain = $parsed['scheme'].'://'.$parsed['host'];
358 358
             }
359 359
 
360
-            if ( ! empty( $domain ) ) {
361
-                $hint = array( 'href' => $domain );
360
+            if (!empty($domain)) {
361
+                $hint = array('href' => $domain);
362 362
                 // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set
363 363
                 // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed.
364
-                $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) );
365
-                if ( in_array( $domain, $crossorigins ) ) {
364
+                $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com'));
365
+                if (in_array($domain, $crossorigins)) {
366 366
                     $hint['crossorigin'] = 'anonymous';
367 367
                 }
368 368
                 $new_hints[] = $hint;
@@ -370,21 +370,21 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Merge in WP's preconnect hints.
373
-        if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) {
374
-            $hints = array_merge( $hints, $new_hints );
373
+        if ('preconnect' === $relation_type && !empty($new_hints)) {
374
+            $hints = array_merge($hints, $new_hints);
375 375
         }
376 376
 
377 377
         return $hints;
378 378
     }
379 379
 
380
-    public function filter_preconnect_google_fonts( $in )
380
+    public function filter_preconnect_google_fonts($in)
381 381
     {
382
-        if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) {
382
+        if ('2' !== $this->options['autoptimize_extra_radio_field_4']) {
383 383
             // Preconnect to fonts.gstatic.com unless we remove gfonts.
384 384
             $in[] = 'https://fonts.gstatic.com';
385 385
         }
386 386
 
387
-        if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) {
387
+        if ('4' === $this->options['autoptimize_extra_radio_field_4']) {
388 388
             // Preconnect even more hosts for webfont.js!
389 389
             $in[] = 'https://ajax.googleapis.com';
390 390
             $in[] = 'https://fonts.googleapis.com';
@@ -393,76 +393,76 @@  discard block
 block discarded – undo
393 393
         return $in;
394 394
     }
395 395
 
396
-    public function filter_preload( $in ) {
396
+    public function filter_preload($in) {
397 397
         // make array from comma separated list.
398 398
         $options  = $this->options;
399 399
         $preloads = array();
400
-        if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) {
401
-            $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) );
400
+        if (array_key_exists('autoptimize_extra_text_field_7', $options)) {
401
+            $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7'])));
402 402
         }
403
-        $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads );
403
+        $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads);
404 404
 
405 405
         // immediately return if nothing to be preloaded.
406
-        if ( empty( $preloads ) ) {
406
+        if (empty($preloads)) {
407 407
             return $in;
408 408
         }
409 409
 
410 410
         // iterate through array and add preload link to tmp string.
411 411
         $preload_output = '';
412
-        foreach ( $preloads as $preload ) {
412
+        foreach ($preloads as $preload) {
413 413
             $crossorigin = '';
414 414
             $preload_as  = '';
415 415
             $mime_type   = '';
416
-            $_preload    = strtok( $preload, '?' );
416
+            $_preload    = strtok($preload, '?');
417 417
 
418
-            if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) {
418
+            if (autoptimizeUtils::str_ends_in($_preload, '.css')) {
419 419
                 $preload_as = 'style';
420
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) {
420
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) {
421 421
                 $preload_as = 'script';
422
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.woff' ) || autoptimizeUtils::str_ends_in( $_preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $_preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $_preload, '.eot' ) ) {
422
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.woff') || autoptimizeUtils::str_ends_in($_preload, '.woff2') || autoptimizeUtils::str_ends_in($_preload, '.ttf') || autoptimizeUtils::str_ends_in($_preload, '.eot')) {
423 423
                 $preload_as  = 'font';
424 424
                 $crossorigin = ' crossorigin';
425
-                $mime_type   = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
426
-                if ( ' type="font/eot"' === $mime_type ) {
425
+                $mime_type   = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"';
426
+                if (' type="font/eot"' === $mime_type) {
427 427
                     $mime_type = 'application/vnd.ms-fontobject';
428 428
                 }
429
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $_preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $_preload, '.webp' ) || autoptimizeUtils::str_ends_in( $_preload, '.png' ) || autoptimizeUtils::str_ends_in( $_preload, '.gif' ) ) {
429
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.jpeg') || autoptimizeUtils::str_ends_in($_preload, '.jpg') || autoptimizeUtils::str_ends_in($_preload, '.webp') || autoptimizeUtils::str_ends_in($_preload, '.png') || autoptimizeUtils::str_ends_in($_preload, '.gif')) {
430 430
                 $preload_as = 'image';
431 431
             } else {
432 432
                 $preload_as = 'other';
433 433
             }
434 434
 
435
-            $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
435
+            $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>';
436 436
         }
437
-        $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output );
437
+        $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output);
438 438
 
439 439
         // add string to head (before first link node by default).
440
-        $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' );
441
-        $position       = autoptimizeUtils::strpos( $in, $preload_inject );
440
+        $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link');
441
+        $position       = autoptimizeUtils::strpos($in, $preload_inject);
442 442
 
443
-        return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) );
443
+        return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject));
444 444
     }
445 445
 
446 446
     public function admin_menu()
447 447
     {
448 448
         // no acces if multisite and not network admin and no site config allowed.
449
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
449
+        if (autoptimizeConfig::should_show_menu_tabs()) {
450 450
             add_submenu_page(
451 451
                 null,
452 452
                 'autoptimize_extra',
453 453
                 'autoptimize_extra',
454 454
                 'manage_options',
455 455
                 'autoptimize_extra',
456
-                array( $this, 'options_page' )
456
+                array($this, 'options_page')
457 457
             );
458 458
         }
459
-        register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
459
+        register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings');
460 460
     }
461 461
 
462
-    public function add_extra_tab( $in )
462
+    public function add_extra_tab($in)
463 463
     {
464
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
465
-            $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) );
464
+        if (autoptimizeConfig::should_show_menu_tabs()) {
465
+            $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize')));
466 466
         }
467 467
 
468 468
         return $in;
@@ -482,97 +482,97 @@  discard block
 block discarded – undo
482 482
         #ao_settings_form .form-table th {font-weight: normal;}
483 483
         #autoptimize_extra_descr{font-size: 120%;}
484 484
     </style>
485
-    <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
485
+    <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script>
486 486
     <div class="wrap">
487
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
487
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
488 488
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
489
-        <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
489
+        <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?>
490 490
             <div class="notice-warning notice"><p>
491
-            <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
491
+            <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?>
492 492
             </p></div>
493 493
         <?php } ?>
494 494
 
495
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
496
-        <?php settings_fields( 'autoptimize_extra_settings' ); ?>
497
-        <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
498
-        <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
495
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
496
+        <?php settings_fields('autoptimize_extra_settings'); ?>
497
+        <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2>
498
+        <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span>
499 499
         <table class="form-table">
500 500
             <tr>
501
-                <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th>
501
+                <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th>
502 502
                 <td>
503
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/>
504
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/>
503
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/>
504
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/>
505 505
                     <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
506
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo __( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
506
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php echo __('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/>
507 507
                     <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
508
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
509
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php echo __( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ) . ' ' . __( '(deprecated)', 'autoptimize' ); ?><br/>
508
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php echo __('Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/>
509
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php echo __('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize').' '.__('(deprecated)', 'autoptimize'); ?><br/>
510 510
                 </td>
511 511
             </tr>
512 512
             <tr>
513
-                <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th>
513
+                <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th>
514 514
                 <td>
515
-                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label>
515
+                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label>
516 516
                 </td>
517 517
             </tr>
518 518
             <tr>
519
-                <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
519
+                <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th>
520 520
                 <td>
521
-                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label>
521
+                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label>
522 522
                 </td>
523 523
             </tr>
524 524
             <tr>
525
-                <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>
525
+                <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th>
526 526
                 <td>
527
-                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label>
527
+                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label>
528 528
                 </td>
529 529
             </tr>
530 530
             <tr>
531
-                <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th>
531
+                <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th>
532 532
                 <td>
533
-                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php _e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label>
533
+                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if (array_key_exists('autoptimize_extra_text_field_7', $options)) { echo esc_attr($options['autoptimize_extra_text_field_7']); } ?>'><br /><?php _e('Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize'); ?></label>
534 534
                 </td>
535 535
             </tr>
536 536
             <tr>
537
-                <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th>
537
+                <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th>
538 538
                 <td>
539 539
                     <?php
540
-                    if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) {
540
+                    if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) {
541 541
                         // translators: link points Async Javascript settings page.
542
-                        printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' );
542
+                        printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>');
543 543
                     } else {
544 544
                         ?>
545
-                        <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'>
545
+                        <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'>
546 546
                         <br />
547 547
                         <?php
548
-                            _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' );
548
+                            _e('Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize');
549 549
                             // translators: %s will be replaced by a link to the "async javascript" plugin.
550
-                            echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' );
551
-                            $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term';
552
-                            echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
550
+                            echo sprintf(__('Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize'), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"');
551
+                            $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term';
552
+                            echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
553 553
                     }
554 554
                     ?>
555 555
                 </td>
556 556
             </tr>
557 557
             <tr>
558
-                <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
558
+                <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th>
559 559
                 <td>
560 560
                     <?php
561
-                    if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) {
562
-                        _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
561
+                    if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) {
562
+                        _e('Great, you have WP YouTube Lyte installed.', 'autoptimize');
563 563
                         $lyte_config_url = 'options-general.php?page=lyte_settings_page';
564
-                        echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) );
564
+                        echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize'));
565 565
                     } else {
566 566
                         // translators: %s will be replaced by a link to "wp youtube lyte" plugin.
567
-                        echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' );
568
-                        $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term';
569
-                        echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
567
+                        echo sprintf(__('%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize'), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>');
568
+                        $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term';
569
+                        echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
570 570
                     }
571 571
                     ?>
572 572
                 </td>
573 573
             </tr>
574 574
         </table>
575
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
575
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
576 576
     </form>
577 577
         <?php
578 578
     }
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_adv.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     global $ao_ccss_unloadccss;
20 20
 
21 21
     // In case domain is not set yet (done in cron.php).
22
-    if ( empty( $ao_ccss_domain ) ) {
22
+    if (empty($ao_ccss_domain)) {
23 23
         $ao_ccss_domain = get_site_url();
24 24
     }
25 25
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 ?>
29 29
     <ul id="adv-panel">
30 30
         <li class="itemDetail">
31
-            <h2 class="itemTitle fleft"><?php _e( 'Advanced Settings', 'autoptimize' ); ?></h2>
31
+            <h2 class="itemTitle fleft"><?php _e('Advanced Settings', 'autoptimize'); ?></h2>
32 32
             <button type="button" class="toggle-btn">
33 33
                 <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
34 34
             </button>
@@ -36,114 +36,114 @@  discard block
 block discarded – undo
36 36
                 <table id="key" class="form-table">
37 37
                     <tr>
38 38
                         <th scope="row">
39
-                            <?php _e( 'Viewport Size', 'autoptimize' ); ?>
39
+                            <?php _e('Viewport Size', 'autoptimize'); ?>
40 40
                         </th>
41 41
                         <td>
42
-                            <label for="autoptimize_ccss_vw"><?php _e( 'Width', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" />&nbsp;&nbsp;
43
-                            <label for="autoptimize_ccss_vh"><?php _e( 'Height', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" />
42
+                            <label for="autoptimize_ccss_vw"><?php _e('Width', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" />&nbsp;&nbsp;
43
+                            <label for="autoptimize_ccss_vh"><?php _e('Height', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" />
44 44
                             <p class="notes">
45
-                                <?php _e( '<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize' ); ?>
45
+                                <?php _e('<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize'); ?>
46 46
                             </p>
47 47
                         </td>
48 48
                     </tr>
49 49
                     <tr>
50 50
                         <th scope="row">
51
-                            <?php _e( 'Force Include CSS selectors', 'autoptimize' ); ?>
51
+                            <?php _e('Force Include CSS selectors', 'autoptimize'); ?>
52 52
                         </th>
53 53
                         <td>
54
-                            <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e( '.button-special,//#footer', 'autoptimize' ); ?>"><?php echo trim( $ao_ccss_finclude ); ?></textarea>
54
+                            <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e('.button-special,//#footer', 'autoptimize'); ?>"><?php echo trim($ao_ccss_finclude); ?></textarea>
55 55
                             <p class="notes">
56
-                                <?php _e( 'Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize' ); ?>
56
+                                <?php _e('Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize'); ?>
57 57
                             </p>
58 58
                         </td>
59 59
                     </tr>
60 60
                     <tr>
61 61
                         <th scope="row">
62
-                            <?php _e( 'Request Limit', 'autoptimize' ); ?>
62
+                            <?php _e('Request Limit', 'autoptimize'); ?>
63 63
                         </th>
64 64
                         <td>
65 65
                             <input type="number" id="autoptimize_ccss_rlimit" name="autoptimize_ccss_rlimit" min="1" max="240" placeholder="0" value="<?php echo $ao_ccss_rlimit; ?>" />
66 66
                             <p class="notes">
67
-                                <?php _e( 'Certain hosting services impose hard limitations to background processes on either execution time, requests made from your server to any third party services, or both. This could lead to a faulty operation of the queue background process triggered by WP-Cron. If automated rules are not being created, you may be facing this limitation from your hosting provider. In that case, set the request limit to a reasonable number between 1 and 240. The queue fire a request to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> on every 15 seconds (due to service limitations). If your hosting provider allows a 60 seconds time span to background processes runtime, set this value to 3 or 4 so the queue can operate within the boundaries. The maximum value of 240 allows enough requests for one hour long. To disable this limit and to let requests be made at will, just delete any values in this setting (a grey 0 will show).', 'autoptimize' ); ?>
67
+                                <?php _e('Certain hosting services impose hard limitations to background processes on either execution time, requests made from your server to any third party services, or both. This could lead to a faulty operation of the queue background process triggered by WP-Cron. If automated rules are not being created, you may be facing this limitation from your hosting provider. In that case, set the request limit to a reasonable number between 1 and 240. The queue fire a request to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> on every 15 seconds (due to service limitations). If your hosting provider allows a 60 seconds time span to background processes runtime, set this value to 3 or 4 so the queue can operate within the boundaries. The maximum value of 240 allows enough requests for one hour long. To disable this limit and to let requests be made at will, just delete any values in this setting (a grey 0 will show).', 'autoptimize'); ?>
68 68
                             </p>
69 69
                         </td>
70 70
                     </tr>
71 71
                     <tr>
72 72
                         <th scope="row">
73
-                            <?php _e( 'Fetch Original CSS', 'autoptimize' ); ?>
73
+                            <?php _e('Fetch Original CSS', 'autoptimize'); ?>
74 74
                         </th>
75 75
                         <td>
76
-                            <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked( 1 == $ao_ccss_noptimize ); ?>>
76
+                            <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked(1 == $ao_ccss_noptimize); ?>>
77 77
                             <p class="notes">
78
-                                <?php _e( 'In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize' ); ?>
78
+                                <?php _e('In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize'); ?>
79 79
                             </p>
80 80
                         </td>
81 81
                     </tr>
82 82
                     <tr>
83 83
                         <th scope="row">
84
-                            <?php _e( 'Add CCSS for logged in users?', 'autoptimize' ); ?>
84
+                            <?php _e('Add CCSS for logged in users?', 'autoptimize'); ?>
85 85
                         </th>
86 86
                         <td>
87
-                            <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked( 1 == $ao_ccss_loggedin ); ?>>
87
+                            <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked(1 == $ao_ccss_loggedin); ?>>
88 88
                             <p class="notes">
89
-                                <?php _e( 'Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize' ); ?>
89
+                                <?php _e('Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize'); ?>
90 90
                             </p>
91 91
                         </td>
92 92
                     </tr>
93 93
                     <tr>
94 94
                         <th scope="row">
95
-                            <?php _e( 'Force path-based rules to be generated for pages?', 'autoptimize' ); ?>
95
+                            <?php _e('Force path-based rules to be generated for pages?', 'autoptimize'); ?>
96 96
                         </th>
97 97
                         <td>
98
-                            <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked( 1 == $ao_ccss_forcepath ); ?>>
98
+                            <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked(1 == $ao_ccss_forcepath); ?>>
99 99
                             <p class="notes">
100
-                                <?php _e( 'By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize' ); ?>
100
+                                <?php _e('By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize'); ?>
101 101
                             </p>
102 102
                         </td>
103 103
                     </tr>
104 104
                     <tr>
105 105
                         <th scope="row">
106
-                            <?php _e( 'Defer jQuery and other non-aggregated JS-files?', 'autoptimize' ); ?>
106
+                            <?php _e('Defer jQuery and other non-aggregated JS-files?', 'autoptimize'); ?>
107 107
                         </th>
108 108
                         <td>
109
-                            <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked( 1 == $ao_ccss_deferjquery ); ?>>
109
+                            <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked(1 == $ao_ccss_deferjquery); ?>>
110 110
                             <p class="notes">
111
-                                <?php _e( 'Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize' ); ?>
111
+                                <?php _e('Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize'); ?>
112 112
                             </p>
113 113
                         </td>
114 114
                     </tr>
115 115
                     <tr>
116 116
                         <th scope="row">
117
-                            <?php _e( 'Unload critical CSS after page load?', 'autoptimize' ); ?>
117
+                            <?php _e('Unload critical CSS after page load?', 'autoptimize'); ?>
118 118
                         </th>
119 119
                         <td>
120
-                            <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked( 1 == $ao_ccss_unloadccss ); ?>>
120
+                            <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked(1 == $ao_ccss_unloadccss); ?>>
121 121
                             <p class="notes">
122
-                                <?php _e( 'In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize' ); ?>
122
+                                <?php _e('In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize'); ?>
123 123
                             </p>
124 124
                         </td>
125 125
                     </tr>
126 126
                     <tr>
127 127
                         <th scope="row">
128
-                            <?php _e( 'Bound domain', 'autoptimize' ); ?>
128
+                            <?php _e('Bound domain', 'autoptimize'); ?>
129 129
                         </th>
130 130
                         <td>
131
-                            <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e( 'Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize' ); ?>" value="<?php echo trim( $ao_ccss_domain ); ?>">
131
+                            <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e('Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize'); ?>" value="<?php echo trim($ao_ccss_domain); ?>">
132 132
                             <p class="notes">
133
-                                <?php _e( 'Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize' ); ?>
133
+                                <?php _e('Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize'); ?>
134 134
                             </p>
135 135
                         </td>
136 136
                     </tr>
137 137
                     <tr>
138 138
                         <th scope="row">
139
-                            <?php _e( 'Debug Mode', 'autoptimize' ); ?>
139
+                            <?php _e('Debug Mode', 'autoptimize'); ?>
140 140
                         </th>
141 141
                         <td>
142
-                            <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked( 1 == $ao_ccss_debug ); ?>>
142
+                            <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked(1 == $ao_ccss_debug); ?>>
143 143
                             <p class="notes">
144 144
                                 <?php
145
-                                _e( '<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize' );
146
-                                echo '<code>' . AO_CCSS_LOG . '</code>';
145
+                                _e('<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize');
146
+                                echo '<code>'.AO_CCSS_LOG.'</code>';
147 147
                                 ?>
148 148
                             </p>
149 149
                         </td>
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,66 +52,66 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_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
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_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
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss');
71 71
 
72 72
         // And add submenu-page.
73
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
73
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
74 74
     }
75 75
 
76
-    public function admin_assets( $hook ) {
76
+    public function admin_assets($hook) {
77 77
         // Return if plugin is not hooked.
78
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
78
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
79 79
             return;
80 80
         }
81 81
 
82 82
         // Stylesheets to add.
83
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
84
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
85
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
83
+        wp_enqueue_style('wp-jquery-ui-dialog');
84
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
85
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
86 86
 
87 87
         // Scripts to add.
88
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
89
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
90
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
91
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
88
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
89
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
90
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
91
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
92 92
     }
93 93
 
94 94
     public function ao_criticalcsssettings_page()
95 95
     {
96 96
         // these are not OO yet, simply require for now.
97
-        require_once( 'critcss-inc/admin_settings_rules.php' );
98
-        require_once( 'critcss-inc/admin_settings_queue.php' );
99
-        require_once( 'critcss-inc/admin_settings_key.php' );
100
-        require_once( 'critcss-inc/admin_settings_adv.php' );
101
-        require_once( 'critcss-inc/admin_settings_explain.php' );
97
+        require_once('critcss-inc/admin_settings_rules.php');
98
+        require_once('critcss-inc/admin_settings_queue.php');
99
+        require_once('critcss-inc/admin_settings_key.php');
100
+        require_once('critcss-inc/admin_settings_adv.php');
101
+        require_once('critcss-inc/admin_settings_explain.php');
102 102
 
103 103
         // fetch all options at once and populate them individually explicitely as globals.
104 104
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
105
-        foreach ( $all_options as $_option => $_value ) {
105
+        foreach ($all_options as $_option => $_value) {
106 106
             global ${$_option};
107 107
             ${$_option} = $_value;
108 108
         }
109 109
         ?>
110
-        <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
110
+        <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
111 111
         <div class="wrap">
112 112
             <div id="autoptimize_main">
113 113
                 <div id="ao_title_and_button">
114
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
114
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
115 115
                 </div>
116 116
 
117 117
                 <?php
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
                 echo autoptimizeConfig::ao_admin_tabs();
120 120
 
121 121
                 // Make sure dir to write ao_ccss exists and is writable.
122
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
123
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
124
-                    $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>' );
125
-                    if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
122
+                if (!is_dir(AO_CCSS_DIR)) {
123
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
124
+                    $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>');
125
+                    if ((!$mkdirresp) || (!$fileresp)) {
126 126
                         ?>
127 127
                         <div class="notice-error notice"><p>
128 128
                         <?php
129
-                        _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
129
+                        _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
130 130
                         ?>
131 131
                         </p></div>
132 132
                         <?php
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
                 }
135 135
 
136 136
                 // Check for Autoptimize.
137
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
137
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
138 138
                     ?>
139 139
                     <div class="notice-error notice"><p>
140 140
                     <?php
141
-                    _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' );
141
+                    _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize');
142 142
                     ?>
143 143
                     </p></div>
144 144
                     <?php
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
                 }
147 147
 
148 148
                 // check if WordPress cron is disabled and warn if so.
149
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
149
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
150 150
                     ?>
151 151
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
152 152
                     <?php
153
-                    _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' );
153
+                    _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');
154 154
                     ?>
155 155
                     </p></div>
156 156
                     <?php
@@ -158,24 +158,24 @@  discard block
 block discarded – undo
158 158
 
159 159
                 // warn if it looks as though the queue processing job looks isn't running
160 160
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
161
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
162
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
161
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
162
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
163 163
                     $_jobs_all_new         = true;
164
-                    $_oldest_job_timestamp = microtime( true ); // now.
164
+                    $_oldest_job_timestamp = microtime(true); // now.
165 165
                     $_jobs_too_old         = true;
166 166
 
167 167
                     // go over queue array.
168
-                    if ( empty( $ao_ccss_queue ) ) {
168
+                    if (empty($ao_ccss_queue)) {
169 169
                         // no jobs, then no warning.
170 170
                         $_jobs_all_new = false;
171 171
                     } else {
172
-                        foreach ( $ao_ccss_queue as $job ) {
173
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
172
+                        foreach ($ao_ccss_queue as $job) {
173
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
174 174
                                 // we need to catch the oldest job's timestamp.
175 175
                                 $_oldest_job_timestamp = $job['jctime'];
176 176
                             }
177 177
 
178
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
178
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
179 179
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
180 180
                                 $_jobs_all_new = false;
181 181
                                 break;
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
                     }
185 185
 
186 186
                     // is the oldest job too old (4h)?
187
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
187
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
188 188
                         $_jobs_too_old = false;
189 189
                     }
190 190
 
191
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
191
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
192 192
                         $_warn_cron            = 'on';
193 193
                         $_transient_multiplier = 1; // store for 1 hour.
194 194
                     } else {
@@ -196,33 +196,33 @@  discard block
 block discarded – undo
196 196
                         $_transient_multiplier = 4; // store for 4 hours.
197 197
                     }
198 198
                     // and set transient.
199
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
199
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
200 200
                 }
201 201
 
202
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
202
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
203 203
                     ?>
204 204
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
205 205
                     <?php
206
-                    _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' );
206
+                    _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');
207 207
                     ?>
208 208
                     </p></div>
209 209
                     <?php
210
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
210
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
211 211
                     ?>
212 212
                     <div class="notice-success notice"><p>
213 213
                     <?php
214
-                    _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' );
214
+                    _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');
215 215
                     ?>
216 216
                     </p></div>
217 217
                     <?php
218 218
                 }
219 219
 
220 220
                 // warn if service is down.
221
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
221
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
222 222
                     ?>
223 223
                     <div class="notice-warning notice"><p>
224 224
                     <?php
225
-                    _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' );
225
+                    _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');
226 226
                     ?>
227 227
                     </p></div>
228 228
                     <?php
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
                 ?>
233 233
                 <form id="settings" method="post" action="options.php">
234 234
                     <?php
235
-                    settings_fields( 'ao_ccss_options_group' );
235
+                    settings_fields('ao_ccss_options_group');
236 236
 
237 237
                     // Get API key status.
238
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
238
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
239 239
 
240
-                    if ( $this->is_multisite_network_admin() ) {
240
+                    if ($this->is_multisite_network_admin()) {
241 241
                         ?>
242 242
                         <ul id="key-panel">
243 243
                             <li class="itemDetail">
244 244
                             <?php
245 245
                                 // translators: the placesholder is for a line of code in wp-config.php.
246
-                                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>' );
246
+                                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>');
247 247
                             ?>
248 248
                             </li>
249 249
                         </ul>
250 250
                         <?php
251 251
                     } else {
252
-                        if ( 'valid' == $key['status'] ) {
252
+                        if ('valid' == $key['status']) {
253 253
                             // If key status is valid, render other panels.
254 254
                             // Render rules section.
255 255
                             ao_ccss_render_rules();
@@ -266,23 +266,23 @@  discard block
 block discarded – undo
266 266
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
267 267
 
268 268
                             // Add hidden fields.
269
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
270
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
271
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
272
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
273
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
274
-                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">';
275
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
276
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
277
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
278
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
279
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
269
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
270
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
271
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
272
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
273
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
274
+                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="'.$ao_ccss_rlimit.'">';
275
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
276
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
277
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
278
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
279
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
280 280
                         }
281 281
                         // Render key panel unconditionally.
282
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
282
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
283 283
                         ?>
284 284
                         <p class="submit left">
285
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
285
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
286 286
                         </p>
287 287
                         <?php
288 288
                     }
@@ -300,31 +300,31 @@  discard block
 block discarded – undo
300 300
                     });
301 301
                 }
302 302
                 </script>
303
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
304
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
305
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
303
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
304
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
305
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
306 306
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
307 307
                 </form>
308 308
                 <div id="importdialog"></div>
309 309
             </div><!-- /#autoptimize_main -->
310 310
         </div><!-- /#wrap -->
311 311
         <?php
312
-        if ( ! $this->is_multisite_network_admin() ) {
312
+        if (!$this->is_multisite_network_admin()) {
313 313
             // Include debug panel if debug mode is enable.
314
-            if ( $ao_ccss_debug ) {
314
+            if ($ao_ccss_debug) {
315 315
             ?>
316 316
                 <div id="debug">
317 317
                     <?php
318 318
                     // Include debug panel.
319
-                    include( 'critcss-inc/admin_settings_debug.php' );
319
+                    include('critcss-inc/admin_settings_debug.php');
320 320
                     ?>
321 321
                 </div><!-- /#debug -->
322 322
             <?php
323 323
             }
324 324
             echo '<script>';
325
-            include( 'critcss-inc/admin_settings_rules.js.php' );
326
-            include( 'critcss-inc/admin_settings_queue.js.php' );
327
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
325
+            include('critcss-inc/admin_settings_rules.js.php');
326
+            include('critcss-inc/admin_settings_queue.js.php');
327
+            include('critcss-inc/admin_settings_impexp.js.php');
328 328
             echo '</script>';
329 329
         }
330 330
     }
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
     public static function ao_ccss_has_autorules() {
333 333
         static $_has_auto_rules = null;
334 334
 
335
-        if ( null === $_has_auto_rules ) {
335
+        if (null === $_has_auto_rules) {
336 336
             global $ao_ccss_rules;
337 337
             $_has_auto_rules = false;
338
-            if ( ! empty( $ao_ccss_rules ) ) {
339
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
340
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
341
-                        if ( ! empty( $rule['hash'] ) ) {
338
+            if (!empty($ao_ccss_rules)) {
339
+                foreach (array('types', 'paths') as $_typat) {
340
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
341
+                        if (!empty($rule['hash'])) {
342 342
                             // we have at least one AUTO job, so all is fine.
343 343
                             $_has_auto_rules = true;
344 344
                             break;
345 345
                         }
346 346
                     }
347
-                    if ( $_has_auto_rules ) {
347
+                    if ($_has_auto_rules) {
348 348
                         break;
349 349
                     }
350 350
                 }
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
     public function is_multisite_network_admin() {
358 358
         static $_multisite_network_admin = null;
359 359
 
360
-        if ( null === $_multisite_network_admin ) {
361
-            if ( is_multisite() && is_network_admin() ) {
360
+        if (null === $_multisite_network_admin) {
361
+            if (is_multisite() && is_network_admin()) {
362 362
                 $_multisite_network_admin = true;
363 363
             } else {
364 364
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSBase.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS base file (initializes all ccss files).
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -19,35 +19,35 @@  discard block
 block discarded – undo
19 19
     public function __construct()
20 20
     {
21 21
         // define constant, but only once.
22
-        if ( ! defined( 'AO_CCSS_DIR' ) ) {
22
+        if (!defined('AO_CCSS_DIR')) {
23 23
             // Define a constant with the directory to store critical CSS in.
24
-            if ( is_multisite() ) {
24
+            if (is_multisite()) {
25 25
                 $blog_id = get_current_blog_id();
26
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' . $blog_id . '/' );
26
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'.$blog_id.'/');
27 27
             } else {
28
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' );
28
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/');
29 29
             }
30 30
         }
31
-        if ( ! defined( 'AO_CCSS_VER' ) ) {
31
+        if (!defined('AO_CCSS_VER')) {
32 32
             // Define plugin version.
33
-            define( 'AO_CCSS_VER', 'AO_' . AUTOPTIMIZE_PLUGIN_VERSION );
33
+            define('AO_CCSS_VER', 'AO_'.AUTOPTIMIZE_PLUGIN_VERSION);
34 34
 
35 35
             // Define constants for criticalcss.com base path and API endpoints.
36 36
             // fixme: AO_CCSS_URL should be read from the autoptimize availability json stored as option.
37
-            define( 'AO_CCSS_URL', 'https://criticalcss.com' );
38
-            define( 'AO_CCSS_API', AO_CCSS_URL . '/api/premium/' );
39
-            define( 'AO_CCSS_SLEEP', 10 );
37
+            define('AO_CCSS_URL', 'https://criticalcss.com');
38
+            define('AO_CCSS_API', AO_CCSS_URL.'/api/premium/');
39
+            define('AO_CCSS_SLEEP', 10);
40 40
         }
41 41
 
42 42
         // Define support files locations, in case they are not already defined.
43
-        if ( ! defined( 'AO_CCSS_LOCK' ) ) {
44
-            define( 'AO_CCSS_LOCK', AO_CCSS_DIR . 'queue.lock' );
43
+        if (!defined('AO_CCSS_LOCK')) {
44
+            define('AO_CCSS_LOCK', AO_CCSS_DIR.'queue.lock');
45 45
         }
46
-        if ( ! defined( 'AO_CCSS_LOG' ) ) {
47
-            define( 'AO_CCSS_LOG', AO_CCSS_DIR . 'queuelog.html' );
46
+        if (!defined('AO_CCSS_LOG')) {
47
+            define('AO_CCSS_LOG', AO_CCSS_DIR.'queuelog.html');
48 48
         }
49
-        if ( ! defined( 'AO_CCSS_DEBUG' ) ) {
50
-            define( 'AO_CCSS_DEBUG', AO_CCSS_DIR . 'queue.json' );
49
+        if (!defined('AO_CCSS_DEBUG')) {
50
+            define('AO_CCSS_DEBUG', AO_CCSS_DIR.'queue.json');
51 51
         }
52 52
 
53 53
         $this->filepath = __FILE__;
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
     {
61 61
         // get all options.
62 62
         $all_options = $this->fetch_options();
63
-        foreach ( $all_options as $option => $value ) {
63
+        foreach ($all_options as $option => $value) {
64 64
             ${$option} = $value;
65 65
         }
66 66
 
67 67
         // make sure the 10 minutes cron schedule is added.
68
-        add_filter( 'cron_schedules', array( $this, 'ao_ccss_interval' ) );
68
+        add_filter('cron_schedules', array($this, 'ao_ccss_interval'));
69 69
 
70 70
         // check if we need to upgrade.
71 71
         $this->check_upgrade();
72 72
 
73 73
         // make sure ao_ccss_queue is scheduled OK if an API key is set.
74
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
75
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
74
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
75
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
76 76
         }
77 77
     }
78 78
 
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
         // Required libs, core is always needed.
81 81
         $criticalcss_core = new autoptimizeCriticalCSSCore();
82 82
 
83
-        if ( defined( 'DOING_CRON' ) || is_admin() ) {
83
+        if (defined('DOING_CRON') || is_admin()) {
84 84
             // TODO: also include if overridden somehow to force queue processing to be executed?
85 85
             $criticalcss_cron = new autoptimizeCriticalCSSCron();
86 86
         }
87 87
 
88
-        if ( is_admin() ) {
88
+        if (is_admin()) {
89 89
             $criticalcss_settings = new autoptimizeCriticalCSSSettings();
90 90
         } else {
91 91
             // enqueuing only done when not wp-admin.
@@ -96,51 +96,51 @@  discard block
 block discarded – undo
96 96
     public static function fetch_options() {
97 97
         static $autoptimize_ccss_options = null;
98 98
 
99
-        if ( null === $autoptimize_ccss_options ) {
99
+        if (null === $autoptimize_ccss_options) {
100 100
             // not cached yet, fetching from WordPress options.
101
-            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' );
102
-            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' );
103
-            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option( 'autoptimize_ccss_rules', false );
104
-            $autoptimize_ccss_options['ao_ccss_additional']    = get_option( 'autoptimize_ccss_additional' );
105
-            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option( 'autoptimize_ccss_queue', false );
106
-            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option( 'autoptimize_ccss_viewport', false );
107
-            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option( 'autoptimize_ccss_finclude', false );
108
-            $autoptimize_ccss_options['ao_ccss_rlimit']        = get_option( 'autoptimize_ccss_rlimit', '5' );
109
-            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option( 'autoptimize_ccss_noptimize', false );
110
-            $autoptimize_ccss_options['ao_ccss_debug']         = get_option( 'autoptimize_ccss_debug', false );
111
-            $autoptimize_ccss_options['ao_ccss_key']           = get_option( 'autoptimize_ccss_key' );
112
-            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option( 'autoptimize_ccss_keyst' );
113
-            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option( 'autoptimize_ccss_loggedin', '1' );
114
-            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option( 'autoptimize_ccss_forcepath', '1' );
115
-            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' );
116
-            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option( 'autoptimize_ccss_deferjquery', false );
117
-            $autoptimize_ccss_options['ao_ccss_domain']        = get_option( 'autoptimize_ccss_domain' );
118
-            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option( 'autoptimize_ccss_unloadccss', false );
119
-
120
-            if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) {
121
-                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] );
122
-            } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) {
101
+            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option('autoptimize_css_defer');
102
+            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline');
103
+            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option('autoptimize_ccss_rules', false);
104
+            $autoptimize_ccss_options['ao_ccss_additional']    = get_option('autoptimize_ccss_additional');
105
+            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option('autoptimize_ccss_queue', false);
106
+            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option('autoptimize_ccss_viewport', false);
107
+            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option('autoptimize_ccss_finclude', false);
108
+            $autoptimize_ccss_options['ao_ccss_rlimit']        = get_option('autoptimize_ccss_rlimit', '5');
109
+            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option('autoptimize_ccss_noptimize', false);
110
+            $autoptimize_ccss_options['ao_ccss_debug']         = get_option('autoptimize_ccss_debug', false);
111
+            $autoptimize_ccss_options['ao_ccss_key']           = get_option('autoptimize_ccss_key');
112
+            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option('autoptimize_ccss_keyst');
113
+            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option('autoptimize_ccss_loggedin', '1');
114
+            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option('autoptimize_ccss_forcepath', '1');
115
+            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option('autoptimize_service_availablity');
116
+            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option('autoptimize_ccss_deferjquery', false);
117
+            $autoptimize_ccss_options['ao_ccss_domain']        = get_option('autoptimize_ccss_domain');
118
+            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option('autoptimize_ccss_unloadccss', false);
119
+
120
+            if (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') === false && strpos($autoptimize_ccss_options['ao_ccss_domain'], 'uggc') === 0) {
121
+                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13($autoptimize_ccss_options['ao_ccss_domain']);
122
+            } elseif (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') !== false) {
123 123
                 // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain).
124
-                update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) );
124
+                update_option('autoptimize_ccss_domain', str_rot13($autoptimize_ccss_options['ao_ccss_domain']));
125 125
             }
126 126
 
127 127
             // Setup the rules array.
128
-            if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) {
128
+            if (empty($autoptimize_ccss_options['ao_ccss_rules_raw'])) {
129 129
                 $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array();
130 130
                 $autoptimize_ccss_options['ao_ccss_rules']['types'] = array();
131 131
             } else {
132
-                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true );
132
+                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode($autoptimize_ccss_options['ao_ccss_rules_raw'], true);
133 133
             }
134 134
 
135 135
             // Setup the queue array.
136
-            if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) {
136
+            if (empty($autoptimize_ccss_options['ao_ccss_queue_raw'])) {
137 137
                 $autoptimize_ccss_options['ao_ccss_queue'] = array();
138 138
             } else {
139
-                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true );
139
+                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode($autoptimize_ccss_options['ao_ccss_queue_raw'], true);
140 140
             }
141 141
 
142 142
             // Override API key if constant is defined.
143
-            if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
143
+            if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
144 144
                 $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY;
145 145
             }
146 146
         }
@@ -152,49 +152,49 @@  discard block
 block discarded – undo
152 152
         global $ao_ccss_key;
153 153
 
154 154
         // Create the cache directory if it doesn't exist already.
155
-        if ( ! file_exists( AO_CCSS_DIR ) ) {
156
-            mkdir( AO_CCSS_DIR, 0755, true );
155
+        if (!file_exists(AO_CCSS_DIR)) {
156
+            mkdir(AO_CCSS_DIR, 0755, true);
157 157
         }
158 158
 
159 159
         // Create a scheduled event for the queue.
160
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
161
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
160
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
161
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
162 162
         }
163 163
 
164 164
         // Create a scheduled event for log maintenance.
165
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) {
166
-            wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' );
165
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_maintenance')) {
166
+            wp_schedule_event(time(), 'twicedaily', 'ao_ccss_maintenance');
167 167
         }
168 168
     }
169 169
 
170 170
     public function check_upgrade() {
171
-        $db_version = get_option( 'autoptimize_ccss_version', '' );
172
-        if ( AO_CCSS_VER !== $db_version ) {
171
+        $db_version = get_option('autoptimize_ccss_version', '');
172
+        if (AO_CCSS_VER !== $db_version) {
173 173
             // check schedules & re-schedule if needed.
174 174
             $this->on_upgrade();
175 175
             // and update db_version.
176
-            update_option( 'autoptimize_ccss_version', AO_CCSS_VER );
176
+            update_option('autoptimize_ccss_version', AO_CCSS_VER);
177 177
         }
178 178
     }
179 179
 
180
-    public function ao_ccss_interval( $schedules ) {
180
+    public function ao_ccss_interval($schedules) {
181 181
         // Let interval be configurable.
182
-        if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) {
182
+        if (!defined('AO_CCSS_DEBUG_INTERVAL')) {
183 183
             $intsec = 600;
184 184
         } else {
185 185
             $intsec = AO_CCSS_DEBUG_INTERVAL;
186
-            if ( $intsec >= 120 ) {
187
-                $inttxt = $intsec / 60 . ' minutes';
186
+            if ($intsec >= 120) {
187
+                $inttxt = $intsec/60.' minutes';
188 188
             } else {
189
-                $inttxt = $intsec . ' second(s)';
189
+                $inttxt = $intsec.' second(s)';
190 190
             }
191
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 );
191
+            autoptimizeCriticalCSSCore::ao_ccss_log('Using custom WP-Cron interval of '.$inttxt, 3);
192 192
         }
193 193
 
194 194
         // Attach interval to schedule.
195 195
         $schedules['ao_ccss'] = array(
196 196
             'interval' => $intsec,
197
-            'display'  => __( 'Autoptimize CriticalCSS' ),
197
+            'display'  => __('Autoptimize CriticalCSS'),
198 198
         );
199 199
         return $schedules;
200 200
     }
Please login to merge, or discard this patch.