Completed
Push — master ( f1d861...5b581f )
by frank
01:49
created
classes/critcss-inc/admin_settings_impexp.js.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
9 9
     console.log('Exporting...');
10 10
     var data = {
11 11
         'action': 'ao_ccss_export',
12
-        'ao_ccss_export_nonce': '<?php echo wp_create_nonce( 'ao_ccss_export_nonce' ); ?>',
12
+        'ao_ccss_export_nonce': '<?php echo wp_create_nonce('ao_ccss_export_nonce'); ?>',
13 13
     };
14 14
 
15 15
     jQuery.post(ajaxurl, data, function(response) {
16 16
         response_array=JSON.parse(response);
17 17
         if (response_array['code'] == 200) {
18 18
             <?php
19
-            if ( is_multisite() ) {
20
-                $blog_id = '/' . get_current_blog_id() . '/';
19
+            if (is_multisite()) {
20
+                $blog_id = '/'.get_current_blog_id().'/';
21 21
             } else {
22 22
                 $blog_id = '/';
23 23
             }
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             autoOpen: true,
33 33
             height: 210,
34 34
             width: 700,
35
-            title: "<?php _e( 'Export settings result', 'autoptimize' ); ?>",
35
+            title: "<?php _e('Export settings result', 'autoptimize'); ?>",
36 36
             modal: true,
37 37
             buttons: {
38 38
                 OK: function() {
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     var settings_file = file[0].files[0];
51 51
     fd.append('file', settings_file);
52 52
     fd.append('action', 'ao_ccss_import');
53
-    fd.append('ao_ccss_import_nonce', '<?php echo wp_create_nonce( 'ao_ccss_import_nonce' ); ?>');
53
+    fd.append('ao_ccss_import_nonce', '<?php echo wp_create_nonce('ao_ccss_import_nonce'); ?>');
54 54
 
55 55
     jQuery.ajax({
56 56
         url: ajaxurl,
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_rules.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 ?>
14 14
     <ul id="rules-panel">
15 15
         <li class="itemDetail">
16
-            <h2 class="itemTitle"><?php _e( 'Rules', 'autoptimize' ); ?></h2>
16
+            <h2 class="itemTitle"><?php _e('Rules', 'autoptimize'); ?></h2>
17 17
 
18 18
             <!-- BEGIN Rule dialogs -->
19 19
             <!-- Unsaved dialog -->
20 20
             <div id="unSavedWarning" class="hidden updated settings-error notice notice-warning is-dismissible">
21
-                <p><?php _e( "<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize' ); ?></p>
21
+                <p><?php _e("<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize'); ?></p>
22 22
             </div>
23 23
 
24 24
             <!-- Create/edit rule dialog -->
@@ -26,97 +26,97 @@  discard block
 block discarded – undo
26 26
                 <table class="form-table rules">
27 27
                     <tr id="critcss_addedit_type_wrapper">
28 28
                         <th scope="row">
29
-                            <?php _e( 'Rule Type', 'autoptimize' ); ?>
29
+                            <?php _e('Rule Type', 'autoptimize'); ?>
30 30
                         </th>
31 31
                         <td>
32 32
                             <select id="critcss_addedit_type" style="width:100%;">
33
-                                <option value="paths"><?php _e( 'Path', 'autoptimize' ); ?></option>
34
-                                <option value="types"><?php _e( 'Conditional Tag', 'autoptimize' ); ?></option>
33
+                                <option value="paths"><?php _e('Path', 'autoptimize'); ?></option>
34
+                                <option value="types"><?php _e('Conditional Tag', 'autoptimize'); ?></option>
35 35
                             </select>
36 36
                         </td>
37 37
                     </tr>
38 38
                     <tr id="critcss_addedit_path_wrapper">
39 39
                         <th scope="row">
40
-                            <?php _e( 'String in Path', 'autoptimize' ); ?>
40
+                            <?php _e('String in Path', 'autoptimize'); ?>
41 41
                         </th>
42 42
                         <td>
43
-                            <input type="text" id="critcss_addedit_path" placeholder="<?php _e( "Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize' ); ?>" style="width:100%;" value="">
43
+                            <input type="text" id="critcss_addedit_path" placeholder="<?php _e("Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize'); ?>" style="width:100%;" value="">
44 44
                         </td>
45 45
                     </tr>
46 46
                     <tr id="critcss_addedit_pagetype_wrapper">
47 47
                         <th scope="row">
48
-                            <?php _e( 'Conditional Tag, Custom Post Type or Page Template', 'autoptimize' ); ?>
48
+                            <?php _e('Conditional Tag, Custom Post Type or Page Template', 'autoptimize'); ?>
49 49
                         </th>
50 50
                         <td>
51 51
                             <select id="critcss_addedit_pagetype" style="width:100%;">
52
-                                <option value="" disabled selected><?php _e( 'Select from the list below...', 'autoptimize' ); ?></option>
53
-                                <optgroup label="<?php _e( 'Standard Conditional Tags', 'autoptimize' ); ?>">
52
+                                <option value="" disabled selected><?php _e('Select from the list below...', 'autoptimize'); ?></option>
53
+                                <optgroup label="<?php _e('Standard Conditional Tags', 'autoptimize'); ?>">
54 54
                                     <?php
55 55
                                     // Render grouped simple conditional tags.
56
-                                    foreach ( $ao_ccss_types as $ctag ) {
57
-                                        $optgrp = substr( $ctag, 0, 3 );
58
-                                        if ( substr( $ctag, 0, 3 ) === 'is_' ) {
59
-                                            echo '<option value="' . $ctag . '">' . $ctag . '</option>';
56
+                                    foreach ($ao_ccss_types as $ctag) {
57
+                                        $optgrp = substr($ctag, 0, 3);
58
+                                        if (substr($ctag, 0, 3) === 'is_') {
59
+                                            echo '<option value="'.$ctag.'">'.$ctag.'</option>';
60 60
                                         }
61
-                                        $prevgrp = substr( $ctag, 0, 3 );
61
+                                        $prevgrp = substr($ctag, 0, 3);
62 62
                                     }
63 63
 
64 64
                                     // Render grouped custom post types, templates and specific conditional tags.
65
-                                    foreach ( $ao_ccss_types as $type ) {
66
-                                        $optgrp = substr( $type, 0, 3 );
65
+                                    foreach ($ao_ccss_types as $type) {
66
+                                        $optgrp = substr($type, 0, 3);
67 67
 
68 68
                                         // Option groups labels.
69
-                                        if ( $optgrp !== $prevgrp && 'is_' !== $optgrp ) {
69
+                                        if ($optgrp !== $prevgrp && 'is_' !== $optgrp) {
70 70
                                             ?>
71 71
                                             </optgroup>
72 72
                                             <?php
73
-                                            if ( substr( $type, 0, 12 ) === 'custom_post_' ) {
73
+                                            if (substr($type, 0, 12) === 'custom_post_') {
74 74
                                                 ?>
75
-                                                <optgroup label="<?php _e( 'Custom Post Types', 'autoptimize' ); ?>">
75
+                                                <optgroup label="<?php _e('Custom Post Types', 'autoptimize'); ?>">
76 76
                                                 <?php
77
-                                            } elseif ( substr( $type, 0, 9 ) === 'template_' ) {
77
+                                            } elseif (substr($type, 0, 9) === 'template_') {
78 78
                                                 ?>
79
-                                                <optgroup label="<?php _e( 'Page Templates', 'autoptimize' ); ?>">
79
+                                                <optgroup label="<?php _e('Page Templates', 'autoptimize'); ?>">
80 80
                                                 <?php
81
-                                            } elseif ( substr( $type, 0, 4 ) === 'bbp_' ) {
81
+                                            } elseif (substr($type, 0, 4) === 'bbp_') {
82 82
                                                 ?>
83
-                                                <optgroup label="<?php _e( 'BBPress Conditional Tags', 'autoptimize' ); ?>">
83
+                                                <optgroup label="<?php _e('BBPress Conditional Tags', 'autoptimize'); ?>">
84 84
                                                 <?php
85
-                                            } elseif ( substr( $type, 0, 3 ) === 'bp_' ) {
85
+                                            } elseif (substr($type, 0, 3) === 'bp_') {
86 86
                                                 ?>
87
-                                                <optgroup label="<?php _e( 'BuddyPress Conditional Tags', 'autoptimize' ); ?>">
87
+                                                <optgroup label="<?php _e('BuddyPress Conditional Tags', 'autoptimize'); ?>">
88 88
                                                 <?php
89
-                                            } elseif ( substr( $type, 0, 4 ) === 'edd_' ) {
89
+                                            } elseif (substr($type, 0, 4) === 'edd_') {
90 90
                                                 ?>
91
-                                                <optgroup label="<?php _e( 'Easy Digital Downloads Conditional Tags', 'autoptimize' ); ?>">
91
+                                                <optgroup label="<?php _e('Easy Digital Downloads Conditional Tags', 'autoptimize'); ?>">
92 92
                                                 <?php
93
-                                            } elseif ( substr( $type, 0, 4 ) === 'woo_' ) {
93
+                                            } elseif (substr($type, 0, 4) === 'woo_') {
94 94
                                                 ?>
95
-                                                <optgroup label="<?php _e( 'WooCommerce Conditional Tags', 'autoptimize' ); ?>">
95
+                                                <optgroup label="<?php _e('WooCommerce Conditional Tags', 'autoptimize'); ?>">
96 96
                                                 <?php
97 97
                                             }
98 98
                                         }
99 99
 
100 100
                                         // Options.
101
-                                        if ( 'is_' !== $optgrp ) {
101
+                                        if ('is_' !== $optgrp) {
102 102
                                             // Remove prefix from custom post types, templates and some specific conditional tags.
103
-                                            if ( substr( $type, 0, 12 ) === 'custom_post_' ) {
104
-                                                $_type = str_replace( 'custom_post_', '', $type );
105
-                                            } elseif ( substr( $type, 0, 9 ) === 'template_' ) {
106
-                                                $_type = str_replace( 'template_', '', $type );
107
-                                            } elseif ( 'bbp_is_bbpress' == $type ) {
108
-                                                $_type = str_replace( 'bbp_', '', $type );
109
-                                            } elseif ( 'bp_is_buddypress' == $type ) {
110
-                                                $_type = str_replace( 'bp_', '', $type );
111
-                                            } elseif ( substr( $type, 0, 4 ) === 'woo_' ) {
112
-                                                $_type = str_replace( 'woo_', '', $type );
113
-                                            } elseif ( substr( $type, 0, 4 ) === 'edd_' ) {
114
-                                                $_type = str_replace( 'edd_', '', $type );
103
+                                            if (substr($type, 0, 12) === 'custom_post_') {
104
+                                                $_type = str_replace('custom_post_', '', $type);
105
+                                            } elseif (substr($type, 0, 9) === 'template_') {
106
+                                                $_type = str_replace('template_', '', $type);
107
+                                            } elseif ('bbp_is_bbpress' == $type) {
108
+                                                $_type = str_replace('bbp_', '', $type);
109
+                                            } elseif ('bp_is_buddypress' == $type) {
110
+                                                $_type = str_replace('bp_', '', $type);
111
+                                            } elseif (substr($type, 0, 4) === 'woo_') {
112
+                                                $_type = str_replace('woo_', '', $type);
113
+                                            } elseif (substr($type, 0, 4) === 'edd_') {
114
+                                                $_type = str_replace('edd_', '', $type);
115 115
                                             } else {
116 116
                                                 $_type = $type;
117 117
                                             }
118 118
 
119
-                                            echo '<option value="' . $type . '">' . $_type . '</option>';
119
+                                            echo '<option value="'.$type.'">'.$_type.'</option>';
120 120
                                             $prevgrp = $optgrp;
121 121
                                         }
122 122
                                     }
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
                     </tr>
128 128
                     <tr>
129 129
                         <th scope="row">
130
-                            <?php _e( 'Custom Critical CSS', 'autoptimize' ); ?>
130
+                            <?php _e('Custom Critical CSS', 'autoptimize'); ?>
131 131
                         </th>
132 132
                         <td>
133
-                            <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your specific critical CSS here and hit submit to save.', 'autoptimize' ); ?>"></textarea>
133
+                            <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e('Paste your specific critical CSS here and hit submit to save.', 'autoptimize'); ?>"></textarea>
134 134
                             <input type="hidden" id="critcss_addedit_file">
135 135
                             <input type="hidden" id="critcss_addedit_id">
136 136
                         </td>
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
             </div>
140 140
 
141 141
             <!-- Remove dialog -->
142
-            <div id="confirm-rm" title="<?php _e( 'Delete Rule', 'autoptimize' ); ?>" class="hidden">
143
-                <p><?php _e( 'This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p>
142
+            <div id="confirm-rm" title="<?php _e('Delete Rule', 'autoptimize'); ?>" class="hidden">
143
+                <p><?php _e('This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p>
144 144
             </div>
145 145
 
146 146
             <!-- Remove All dialog -->
147
-            <div id="confirm-rm-all" title="<?php _e( 'Delete all Rules and Jobs', 'autoptimize' ); ?>" class="hidden">
148
-                <p><?php _e( 'All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p>
147
+            <div id="confirm-rm-all" title="<?php _e('Delete all Rules and Jobs', 'autoptimize'); ?>" class="hidden">
148
+                <p><?php _e('All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p>
149 149
             </div>
150 150
 
151 151
             <!-- Add/edit default critical CSS dialog -->
152 152
             <div id="default_critcss_wrapper" class="hidden">
153
-                <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize' ); ?>"></textarea>
153
+                <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize'); ?>"></textarea>
154 154
             </div>
155 155
 
156 156
             <!-- Add/edit additional critical CSS dialog -->
157 157
             <div id="additional_critcss_wrapper" class="hidden">
158
-                <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea>
158
+                <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize'); ?>"></textarea>
159 159
             </div>
160 160
 
161 161
             <!-- Wrapper for in screen notices -->
@@ -165,38 +165,38 @@  discard block
 block discarded – undo
165 165
             <!-- BEGIN Rules UI -->
166 166
             <div class="howto">
167 167
                 <div class="title-wrap">
168
-                    <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize' ); ?></h4>
169
-                    <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p>
168
+                    <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize'); ?></h4>
169
+                    <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p>
170 170
                 </div>
171 171
                 <button type="button" class="toggle-btn">
172 172
                     <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
173 173
                 </button>
174 174
                 <div class="howto-wrap hidden">
175
-                <p><?php _e( "TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize' ); ?></p>
175
+                <p><?php _e("TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize'); ?></p>
176 176
                     <ol>
177
-                        <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li>
178
-                        <li><?php _e( 'Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize' ); ?></li>
179
-                        <li><?php _e( 'These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize' ); ?></li>
180
-                        <li><?php _e( 'If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize' ); ?></li>
181
-                        <li><?php _e( 'You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize' ); ?></li>
182
-                        <li><?php _e( 'You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize' ); ?></li>
183
-                        <li><?php _e( "If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize' ); ?></li>
184
-                        <li><?php _e( 'At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize' ); ?></li>
177
+                        <li><?php _e('When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize'); ?></li>
178
+                        <li><?php _e('Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize'); ?></li>
179
+                        <li><?php _e('These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize'); ?></li>
180
+                        <li><?php _e('If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize'); ?></li>
181
+                        <li><?php _e('You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize'); ?></li>
182
+                        <li><?php _e('You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize'); ?></li>
183
+                        <li><?php _e("If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize'); ?></li>
184
+                        <li><?php _e('At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize'); ?></li>
185 185
                     </ol>
186 186
                 </div>
187 187
             </div>
188
-            <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_css_defer_inline', '' ); ?></textarea>
189
-            <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_ccss_additional', '' ); ?></textarea>
188
+            <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option('autoptimize_css_defer_inline', ''); ?></textarea>
189
+            <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option('autoptimize_ccss_additional', ''); ?></textarea>
190 190
             <table class="rules-list" cellspacing="0"><tbody id="rules-list"></tbody></table>
191
-            <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo ( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ); ?>'>
191
+            <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo (json_encode($ao_ccss_rules, JSON_FORCE_OBJECT)); ?>'>
192 192
             <div class="submit rules-btn">
193 193
                 <div class="alignleft">
194
-                    <span id="addCritCssButton" class="button-secondary"><?php _e( 'Add New Rule', 'autoptimize' ); ?></span>
195
-                    <span id="editDefaultButton" class="button-secondary"><?php _e( 'Edit Default Rule CSS', 'autoptimize' ); ?></span>
196
-                    <span id="editAdditionalButton" class="button-secondary"><?php _e( 'Add CSS To All Rules', 'autoptimize' ); ?></span>
194
+                    <span id="addCritCssButton" class="button-secondary"><?php _e('Add New Rule', 'autoptimize'); ?></span>
195
+                    <span id="editDefaultButton" class="button-secondary"><?php _e('Edit Default Rule CSS', 'autoptimize'); ?></span>
196
+                    <span id="editAdditionalButton" class="button-secondary"><?php _e('Add CSS To All Rules', 'autoptimize'); ?></span>
197 197
                 </div>
198 198
                 <div class="alignright">
199
-                    <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e( 'Remove all rules', 'autoptimize' ); ?></span>
199
+                    <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e('Remove all rules', 'autoptimize'); ?></span>
200 200
                 </div>
201 201
             </div>
202 202
             <!-- END Rules UI -->
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_debug.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $ao_options = $wpdb->get_results('
11 11
   SELECT option_name  AS name,
12 12
          option_value AS value
13
-  FROM ' . $wpdb->options . '
13
+  FROM ' . $wpdb->options.'
14 14
   WHERE option_name LIKE "autoptimize_%%"
15 15
   ORDER BY name
16 16
 ', ARRAY_A);
@@ -19,27 +19,27 @@  discard block
 block discarded – undo
19 19
 $ao_trans = $wpdb->get_results('
20 20
   SELECT option_name  AS name,
21 21
          option_value AS value
22
-  FROM ' . $wpdb->options . '
22
+  FROM ' . $wpdb->options.'
23 23
   WHERE option_name LIKE "_transient_autoptimize_%%"
24 24
      OR option_name LIKE "_transient_timeout_autoptimize_%%"
25 25
 ', ARRAY_A);
26 26
 
27 27
 // Render debug panel if there's something to show.
28
-if ( $ao_options || $ao_trans ) {
28
+if ($ao_options || $ao_trans) {
29 29
 ?>
30 30
 <!-- BEGIN: Settings Debug -->
31 31
 <ul>
32 32
     <li class="itemDetail">
33
-        <h2 class="itemTitle"><?php _e( 'Debug Information', 'autoptimize' ); ?></h2>
33
+        <h2 class="itemTitle"><?php _e('Debug Information', 'autoptimize'); ?></h2>
34 34
 
35 35
         <?php
36 36
         // Render options.
37
-        if ( $ao_options ) {
37
+        if ($ao_options) {
38 38
         ?>
39
-            <h4><?php _e( 'Options', 'autoptimize' ); ?>:</h4>
39
+            <h4><?php _e('Options', 'autoptimize'); ?>:</h4>
40 40
             <table class="form-table debug">
41 41
             <?php
42
-            foreach ( $ao_options as $option ) {
42
+            foreach ($ao_options as $option) {
43 43
             ?>
44 44
                 <tr>
45 45
                     <th scope="row">
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
                     </th>
48 48
                     <td>
49 49
                         <?php
50
-                        if ( 'autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name'] ) {
51
-                            $value = print_r( json_decode( $option['value'], true ), true );
52
-                            if ( $value ) {
53
-                                echo "Raw JSON:\n<pre>" . $option['value'] . "</pre>\n\nDecoded JSON:\n<pre>" . $value . '</pre>';
50
+                        if ('autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name']) {
51
+                            $value = print_r(json_decode($option['value'], true), true);
52
+                            if ($value) {
53
+                                echo "Raw JSON:\n<pre>".$option['value']."</pre>\n\nDecoded JSON:\n<pre>".$value.'</pre>';
54 54
                             } else {
55 55
                                 echo 'Empty';
56 56
                             }
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
         }
70 70
         // Render WP-Cron intervals and scheduled events.
71 71
         ?>
72
-        <h4><?php _e( 'WP-Cron Intervals', 'autoptimize' ); ?>:</h4>
73
-        <pre><?php print_r( wp_get_schedules() ); ?></pre>
72
+        <h4><?php _e('WP-Cron Intervals', 'autoptimize'); ?>:</h4>
73
+        <pre><?php print_r(wp_get_schedules()); ?></pre>
74 74
         <hr />
75
-        <h4><?php _e( 'WP-Cron Scheduled Events', 'autoptimize' ); ?>:</h4>
76
-        <pre><?php print_r( _get_cron_array() ); ?></pre>
75
+        <h4><?php _e('WP-Cron Scheduled Events', 'autoptimize'); ?>:</h4>
76
+        <pre><?php print_r(_get_cron_array()); ?></pre>
77 77
     </li>
78 78
 </ul>
79 79
 <!-- END: Settings Debug -->
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,56 +52,56 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rlimit' );
62
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' );
63
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' );
64
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' );
65
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' );
66
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' );
67
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' );
68
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' );
69
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rlimit');
62
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize');
63
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug');
64
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_key');
65
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst');
66
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin');
67
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath');
68
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery');
69
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain');
70 70
 
71 71
         // And add submenu-page.
72
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
72
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
73 73
     }
74 74
 
75
-    public function admin_assets( $hook ) {
75
+    public function admin_assets($hook) {
76 76
         // Return if plugin is not hooked.
77
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
77
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
78 78
             return;
79 79
         }
80 80
 
81 81
         // Stylesheets to add.
82
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
83
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
84
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
82
+        wp_enqueue_style('wp-jquery-ui-dialog');
83
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
84
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
85 85
 
86 86
         // Scripts to add.
87
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
88
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
89
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
90
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
87
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
88
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
89
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
90
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
91 91
     }
92 92
 
93 93
     public function ao_criticalcsssettings_page()
94 94
     {
95 95
         // these are not OO yet, simply require for now.
96
-        require_once( 'critcss-inc/admin_settings_rules.php' );
97
-        require_once( 'critcss-inc/admin_settings_queue.php' );
98
-        require_once( 'critcss-inc/admin_settings_key.php' );
99
-        require_once( 'critcss-inc/admin_settings_adv.php' );
100
-        require_once( 'critcss-inc/admin_settings_explain.php' );
96
+        require_once('critcss-inc/admin_settings_rules.php');
97
+        require_once('critcss-inc/admin_settings_queue.php');
98
+        require_once('critcss-inc/admin_settings_key.php');
99
+        require_once('critcss-inc/admin_settings_adv.php');
100
+        require_once('critcss-inc/admin_settings_explain.php');
101 101
 
102 102
         // fetch all options at once and populate them individually explicitely as globals.
103 103
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
104
-        foreach ( $all_options as $_option => $_value ) {
104
+        foreach ($all_options as $_option => $_value) {
105 105
             global ${$_option};
106 106
             ${$_option} = $_value;
107 107
         }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         <div class="wrap">
110 110
             <div id="autoptimize_main">
111 111
                 <div id="ao_title_and_button">
112
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
112
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
113 113
                 </div>
114 114
 
115 115
                 <?php
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
                 echo autoptimizeConfig::ao_admin_tabs();
118 118
 
119 119
                 // Make sure dir to write ao_ccss exists and is writable.
120
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
121
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
122
-                    $fileresp  = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' );
123
-                    if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
120
+                if (!is_dir(AO_CCSS_DIR)) {
121
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
122
+                    $fileresp  = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>');
123
+                    if ((!$mkdirresp) || (!$fileresp)) {
124 124
                         ?>
125 125
                         <div class="notice-error notice"><p>
126 126
                         <?php
127
-                        _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
127
+                        _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
128 128
                         ?>
129 129
                         </p></div>
130 130
                         <?php
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
                 }
133 133
 
134 134
                 // Check for Autoptimize.
135
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
135
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
136 136
                     ?>
137 137
                     <div class="notice-error notice"><p>
138 138
                     <?php
139
-                    _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' );
139
+                    _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize');
140 140
                     ?>
141 141
                     </p></div>
142 142
                     <?php
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
                 }
145 145
 
146 146
                 // check if WordPress cron is disabled and warn if so.
147
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
147
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
148 148
                     ?>
149 149
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
150 150
                     <?php
151
-                    _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
151
+                    _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
152 152
                     ?>
153 153
                     </p></div>
154 154
                     <?php
@@ -156,24 +156,24 @@  discard block
 block discarded – undo
156 156
 
157 157
                 // warn if it looks as though the queue processing job looks isn't running
158 158
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
159
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
160
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
159
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
160
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
161 161
                     $_jobs_all_new         = true;
162
-                    $_oldest_job_timestamp = microtime( true ); // now.
162
+                    $_oldest_job_timestamp = microtime(true); // now.
163 163
                     $_jobs_too_old         = true;
164 164
 
165 165
                     // go over queue array.
166
-                    if ( empty( $ao_ccss_queue ) ) {
166
+                    if (empty($ao_ccss_queue)) {
167 167
                         // no jobs, then no warning.
168 168
                         $_jobs_all_new = false;
169 169
                     } else {
170
-                        foreach ( $ao_ccss_queue as $job ) {
171
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
170
+                        foreach ($ao_ccss_queue as $job) {
171
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
172 172
                                 // we need to catch the oldest job's timestamp.
173 173
                                 $_oldest_job_timestamp = $job['jctime'];
174 174
                             }
175 175
 
176
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
176
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
177 177
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
178 178
                                 $_jobs_all_new = false;
179 179
                                 break;
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
                     }
183 183
 
184 184
                     // is the oldest job too old (4h)?
185
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
185
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
186 186
                         $_jobs_too_old = false;
187 187
                     }
188 188
 
189
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
189
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
190 190
                         $_warn_cron            = 'on';
191 191
                         $_transient_multiplier = 1; // store for 1 hour.
192 192
                     } else {
@@ -194,33 +194,33 @@  discard block
 block discarded – undo
194 194
                         $_transient_multiplier = 4; // store for 4 hours.
195 195
                     }
196 196
                     // and set transient.
197
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
197
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
198 198
                 }
199 199
 
200
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
200
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
201 201
                     ?>
202 202
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
203 203
                     <?php
204
-                    _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
204
+                    _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
205 205
                     ?>
206 206
                     </p></div>
207 207
                     <?php
208
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
208
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
209 209
                     ?>
210 210
                     <div class="notice-success notice"><p>
211 211
                     <?php
212
-                    _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' );
212
+                    _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize');
213 213
                     ?>
214 214
                     </p></div>
215 215
                     <?php
216 216
                 }
217 217
 
218 218
                 // warn if service is down.
219
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
219
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
220 220
                     ?>
221 221
                     <div class="notice-warning notice"><p>
222 222
                     <?php
223
-                    _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' );
223
+                    _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize');
224 224
                     ?>
225 225
                     </p></div>
226 226
                     <?php
@@ -230,24 +230,24 @@  discard block
 block discarded – undo
230 230
                 ?>
231 231
                 <form id="settings" method="post" action="options.php">
232 232
                     <?php
233
-                    settings_fields( 'ao_ccss_options_group' );
233
+                    settings_fields('ao_ccss_options_group');
234 234
 
235 235
                     // Get API key status.
236
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
236
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
237 237
 
238
-                    if ( $this->is_multisite_network_admin() ) {
238
+                    if ($this->is_multisite_network_admin()) {
239 239
                         ?>
240 240
                         <ul id="key-panel">
241 241
                             <li class="itemDetail">
242 242
                             <?php
243 243
                                 // translators: the placesholder is for a line of code in wp-config.php.
244
-                                echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' );
244
+                                echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>');
245 245
                             ?>
246 246
                             </li>
247 247
                         </ul>
248 248
                         <?php
249 249
                     } else {
250
-                        if ( 'valid' == $key['status'] ) {
250
+                        if ('valid' == $key['status']) {
251 251
                             // If key status is valid, render other panels.
252 252
                             // Render rules section.
253 253
                             ao_ccss_render_rules();
@@ -264,23 +264,23 @@  discard block
 block discarded – undo
264 264
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
265 265
 
266 266
                             // Add hidden fields.
267
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
268
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
269
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
270
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
271
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
272
-                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">';
273
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
274
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
275
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
276
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
277
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
267
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
268
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
269
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
270
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
271
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
272
+                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="'.$ao_ccss_rlimit.'">';
273
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
274
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
275
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
276
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
277
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
278 278
                         }
279 279
                         // Render key panel unconditionally.
280
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
280
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
281 281
                         ?>
282 282
                         <p class="submit left">
283
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
283
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
284 284
                         </p>
285 285
                         <?php
286 286
                     }
@@ -298,31 +298,31 @@  discard block
 block discarded – undo
298 298
                     });
299 299
                 }
300 300
                 </script>
301
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
302
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
303
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
301
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
302
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
303
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
304 304
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
305 305
                 </form>
306 306
                 <div id="importdialog"></div>
307 307
             </div><!-- /#autoptimize_main -->
308 308
         </div><!-- /#wrap -->
309 309
         <?php
310
-        if ( ! $this->is_multisite_network_admin() ) {
310
+        if (!$this->is_multisite_network_admin()) {
311 311
             // Include debug panel if debug mode is enable.
312
-            if ( $ao_ccss_debug ) {
312
+            if ($ao_ccss_debug) {
313 313
             ?>
314 314
                 <div id="debug">
315 315
                     <?php
316 316
                     // Include debug panel.
317
-                    include( 'critcss-inc/admin_settings_debug.php' );
317
+                    include('critcss-inc/admin_settings_debug.php');
318 318
                     ?>
319 319
                 </div><!-- /#debug -->
320 320
             <?php
321 321
             }
322 322
             echo '<script>';
323
-            include( 'critcss-inc/admin_settings_rules.js.php' );
324
-            include( 'critcss-inc/admin_settings_queue.js.php' );
325
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
323
+            include('critcss-inc/admin_settings_rules.js.php');
324
+            include('critcss-inc/admin_settings_queue.js.php');
325
+            include('critcss-inc/admin_settings_impexp.js.php');
326 326
             echo '</script>';
327 327
         }
328 328
     }
@@ -330,19 +330,19 @@  discard block
 block discarded – undo
330 330
     public static function ao_ccss_has_autorules() {
331 331
         static $_has_auto_rules = null;
332 332
 
333
-        if ( null === $_has_auto_rules ) {
333
+        if (null === $_has_auto_rules) {
334 334
             global $ao_ccss_rules;
335 335
             $_has_auto_rules = false;
336
-            if ( ! empty( $ao_ccss_rules ) ) {
337
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
338
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
339
-                        if ( ! empty( $rule['hash'] ) ) {
336
+            if (!empty($ao_ccss_rules)) {
337
+                foreach (array('types', 'paths') as $_typat) {
338
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
339
+                        if (!empty($rule['hash'])) {
340 340
                             // we have at least one AUTO job, so all is fine.
341 341
                             $_has_auto_rules = true;
342 342
                             break;
343 343
                         }
344 344
                     }
345
-                    if ( $_has_auto_rules ) {
345
+                    if ($_has_auto_rules) {
346 346
                         break;
347 347
                     }
348 348
                 }
@@ -355,8 +355,8 @@  discard block
 block discarded – undo
355 355
     public function is_multisite_network_admin() {
356 356
         static $_multisite_network_admin = null;
357 357
 
358
-        if ( null === $_multisite_network_admin ) {
359
-            if ( is_multisite() && is_network_admin() ) {
358
+        if (null === $_multisite_network_admin) {
359
+            if (is_multisite() && is_network_admin()) {
360 360
                 $_multisite_network_admin = true;
361 361
             } else {
362 362
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettingsAjax.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS settings AJAX logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
@@ -21,47 +21,47 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function run() {
23 23
         // add filters.
24
-        add_action( 'wp_ajax_fetch_critcss', array( $this, 'critcss_fetch_callback' ) );
25
-        add_action( 'wp_ajax_save_critcss', array( $this, 'critcss_save_callback' ) );
26
-        add_action( 'wp_ajax_rm_critcss', array( $this, 'critcss_rm_callback' ) );
27
-        add_action( 'wp_ajax_rm_critcss_all', array( $this, 'critcss_rm_all_callback' ) );
28
-        add_action( 'wp_ajax_ao_ccss_export', array( $this, 'ao_ccss_export_callback' ) );
29
-        add_action( 'wp_ajax_ao_ccss_import', array( $this, 'ao_ccss_import_callback' ) );
24
+        add_action('wp_ajax_fetch_critcss', array($this, 'critcss_fetch_callback'));
25
+        add_action('wp_ajax_save_critcss', array($this, 'critcss_save_callback'));
26
+        add_action('wp_ajax_rm_critcss', array($this, 'critcss_rm_callback'));
27
+        add_action('wp_ajax_rm_critcss_all', array($this, 'critcss_rm_all_callback'));
28
+        add_action('wp_ajax_ao_ccss_export', array($this, 'ao_ccss_export_callback'));
29
+        add_action('wp_ajax_ao_ccss_import', array($this, 'ao_ccss_import_callback'));
30 30
     }
31 31
 
32 32
     public function critcss_fetch_callback() {
33 33
         // Ajax handler to obtain a critical CSS file from the filesystem.
34 34
         // Check referer.
35
-        check_ajax_referer( 'fetch_critcss_nonce', 'critcss_fetch_nonce' );
35
+        check_ajax_referer('fetch_critcss_nonce', 'critcss_fetch_nonce');
36 36
 
37 37
         // Initialize error flag.
38 38
         $error = true;
39 39
 
40 40
         // Allow no content for MANUAL rules (as they may not exist just yet).
41
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
41
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
42 42
             $content = '';
43 43
             $error   = false;
44
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
44
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
45 45
             // Or check user permissios and filename.
46 46
             // Set file path and obtain its content.
47
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
48
-            if ( file_exists( $critcssfile ) ) {
49
-                $content = file_get_contents( $critcssfile );
47
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
48
+            if (file_exists($critcssfile)) {
49
+                $content = file_get_contents($critcssfile);
50 50
                 $error   = false;
51 51
             }
52 52
         }
53 53
 
54 54
         // Prepare response.
55
-        if ( $error ) {
55
+        if ($error) {
56 56
             $response['code']   = '500';
57
-            $response['string'] = 'Error reading file ' . $critcssfile . '.';
57
+            $response['string'] = 'Error reading file '.$critcssfile.'.';
58 58
         } else {
59 59
             $response['code']   = '200';
60 60
             $response['string'] = $content;
61 61
         }
62 62
 
63 63
         // Dispatch respose.
64
-        echo json_encode( $response );
64
+        echo json_encode($response);
65 65
 
66 66
         // Close ajax request.
67 67
         wp_die();
@@ -74,22 +74,22 @@  discard block
 block discarded – undo
74 74
 
75 75
         // Ajax handler to write a critical CSS to the filesystem
76 76
         // Check referer.
77
-        check_ajax_referer( 'save_critcss_nonce', 'critcss_save_nonce' );
77
+        check_ajax_referer('save_critcss_nonce', 'critcss_save_nonce');
78 78
 
79 79
         // Allow empty contents for MANUAL rules (as they are fetched later).
80
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
80
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
81 81
             $critcssfile = false;
82 82
             $status      = true;
83
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
83
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
84 84
             // Or check user permissios and filename
85 85
             // Set critical CSS content.
86
-            $critcsscontents = stripslashes( $_POST['critcsscontents'] );
86
+            $critcsscontents = stripslashes($_POST['critcsscontents']);
87 87
 
88 88
             // If there is content and it's valid, write the file.
89
-            if ( $critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents( $critcsscontents ) ) {
89
+            if ($critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents($critcsscontents)) {
90 90
                 // Set file path and status.
91
-                $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
92
-                $status      = file_put_contents( $critcssfile, $critcsscontents, LOCK_EX );
91
+                $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
92
+                $status      = file_put_contents($critcssfile, $critcsscontents, LOCK_EX);
93 93
                 // Or set as error.
94 94
             } else {
95 95
                 $error = true;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
         }
101 101
 
102 102
         // Prepare response.
103
-        if ( ! $status || $error ) {
103
+        if (!$status || $error) {
104 104
             $response['code']   = '500';
105
-            $response['string'] = 'Error saving file ' . $critcssfile . '.';
105
+            $response['string'] = 'Error saving file '.$critcssfile.'.';
106 106
         } else {
107 107
             $response['code'] = '200';
108
-            if ( $critcssfile ) {
109
-                $response['string'] = 'File ' . $critcssfile . ' saved.';
108
+            if ($critcssfile) {
109
+                $response['string'] = 'File '.$critcssfile.' saved.';
110 110
             } else {
111 111
                 $response['string'] = 'Empty content do not need to be saved.';
112 112
             }
113 113
         }
114 114
 
115 115
         // Dispatch respose.
116
-        echo json_encode( $response );
116
+        echo json_encode($response);
117 117
 
118 118
         // Close ajax request.
119 119
         wp_die();
@@ -123,40 +123,40 @@  discard block
 block discarded – undo
123 123
     public function critcss_rm_callback() {
124 124
         // Ajax handler to delete a critical CSS from the filesystem
125 125
         // Check referer.
126
-        check_ajax_referer( 'rm_critcss_nonce', 'critcss_rm_nonce' );
126
+        check_ajax_referer('rm_critcss_nonce', 'critcss_rm_nonce');
127 127
 
128 128
         // Initialize error and status flags.
129 129
         $error  = true;
130 130
         $status = false;
131 131
 
132 132
         // Allow no file for MANUAL rules (as they may not exist just yet).
133
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
133
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
134 134
             $error = false;
135
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
135
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
136 136
             // Or check user permissios and filename
137 137
             // Set file path and delete it.
138
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
139
-            if ( file_exists( $critcssfile ) ) {
140
-                $status = unlink( $critcssfile );
138
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
139
+            if (file_exists($critcssfile)) {
140
+                $status = unlink($critcssfile);
141 141
                 $error  = false;
142 142
             }
143 143
         }
144 144
 
145 145
         // Prepare response.
146
-        if ( $error ) {
146
+        if ($error) {
147 147
             $response['code']   = '500';
148
-            $response['string'] = 'Error removing file ' . $critcssfile . '.';
148
+            $response['string'] = 'Error removing file '.$critcssfile.'.';
149 149
         } else {
150 150
             $response['code'] = '200';
151
-            if ( $status ) {
152
-                $response['string'] = 'File ' . $critcssfile . ' removed.';
151
+            if ($status) {
152
+                $response['string'] = 'File '.$critcssfile.' removed.';
153 153
             } else {
154 154
                 $response['string'] = 'No file to be removed.';
155 155
             }
156 156
         }
157 157
 
158 158
         // Dispatch respose.
159
-        echo json_encode( $response );
159
+        echo json_encode($response);
160 160
 
161 161
         // Close ajax request.
162 162
         wp_die();
@@ -165,28 +165,28 @@  discard block
 block discarded – undo
165 165
     public function critcss_rm_all_callback() {
166 166
         // Ajax handler to delete a critical CSS from the filesystem
167 167
         // Check referer.
168
-        check_ajax_referer( 'rm_critcss_all_nonce', 'critcss_rm_all_nonce' );
168
+        check_ajax_referer('rm_critcss_all_nonce', 'critcss_rm_all_nonce');
169 169
 
170 170
         // Initialize error and status flags.
171 171
         $error  = true;
172 172
         $status = false;
173 173
 
174 174
         // Remove all ccss files on filesystem.
175
-        if ( current_user_can( 'manage_options' ) ) {
176
-            if ( file_exists( AO_CCSS_DIR ) && is_dir( AO_CCSS_DIR ) ) {
177
-                array_map( 'unlink', glob( AO_CCSS_DIR . 'ccss_*.css', GLOB_BRACE ) );
175
+        if (current_user_can('manage_options')) {
176
+            if (file_exists(AO_CCSS_DIR) && is_dir(AO_CCSS_DIR)) {
177
+                array_map('unlink', glob(AO_CCSS_DIR.'ccss_*.css', GLOB_BRACE));
178 178
                 $error  = false;
179 179
                 $status = true;
180 180
             }
181 181
         }
182 182
 
183 183
         // Prepare response.
184
-        if ( $error ) {
184
+        if ($error) {
185 185
             $response['code']   = '500';
186 186
             $response['string'] = 'Error removing all critical CSS files.';
187 187
         } else {
188 188
             $response['code'] = '200';
189
-            if ( $status ) {
189
+            if ($status) {
190 190
                 $response['string'] = 'Critical CSS Files removed.';
191 191
             } else {
192 192
                 $response['string'] = 'No file removed.';
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Dispatch respose.
197
-        echo json_encode( $response );
197
+        echo json_encode($response);
198 198
 
199 199
         // Close ajax request.
200 200
         wp_die();
@@ -203,70 +203,70 @@  discard block
 block discarded – undo
203 203
     public function ao_ccss_export_callback() {
204 204
         // Ajax handler export settings
205 205
         // Check referer.
206
-        check_ajax_referer( 'ao_ccss_export_nonce', 'ao_ccss_export_nonce' );
206
+        check_ajax_referer('ao_ccss_export_nonce', 'ao_ccss_export_nonce');
207 207
 
208
-        if ( ! class_exists( 'ZipArchive' ) ) {
208
+        if (!class_exists('ZipArchive')) {
209 209
             $response['code'] = '500';
210 210
             $response['msg']  = 'PHP ZipArchive not present, cannot create zipfile';
211
-            echo json_encode( $response );
211
+            echo json_encode($response);
212 212
             wp_die();
213 213
         }
214 214
 
215 215
         // Init array, get options and prepare the raw object.
216 216
         $settings               = array();
217
-        $settings['rules']      = get_option( 'autoptimize_ccss_rules' );
218
-        $settings['additional'] = get_option( 'autoptimize_ccss_additional' );
219
-        $settings['viewport']   = get_option( 'autoptimize_ccss_viewport' );
220
-        $settings['finclude']   = get_option( 'autoptimize_ccss_finclude' );
221
-        $settings['rlimit']     = get_option( 'autoptimize_ccss_rlimit' );
222
-        $settings['noptimize']  = get_option( 'autoptimize_ccss_noptimize' );
223
-        $settings['debug']      = get_option( 'autoptimize_ccss_debug' );
224
-        $settings['key']        = get_option( 'autoptimize_ccss_key' );
217
+        $settings['rules']      = get_option('autoptimize_ccss_rules');
218
+        $settings['additional'] = get_option('autoptimize_ccss_additional');
219
+        $settings['viewport']   = get_option('autoptimize_ccss_viewport');
220
+        $settings['finclude']   = get_option('autoptimize_ccss_finclude');
221
+        $settings['rlimit']     = get_option('autoptimize_ccss_rlimit');
222
+        $settings['noptimize']  = get_option('autoptimize_ccss_noptimize');
223
+        $settings['debug']      = get_option('autoptimize_ccss_debug');
224
+        $settings['key']        = get_option('autoptimize_ccss_key');
225 225
 
226 226
         // Initialize error flag.
227 227
         $error = true;
228 228
 
229 229
         // Check user permissions.
230
-        if ( current_user_can( 'manage_options' ) ) {
230
+        if (current_user_can('manage_options')) {
231 231
             // Prepare settings file path and content.
232
-            $exportfile = AO_CCSS_DIR . 'settings.json';
233
-            $contents   = json_encode( $settings );
234
-            $status     = file_put_contents( $exportfile, $contents, LOCK_EX );
232
+            $exportfile = AO_CCSS_DIR.'settings.json';
233
+            $contents   = json_encode($settings);
234
+            $status     = file_put_contents($exportfile, $contents, LOCK_EX);
235 235
             $error      = false;
236 236
         }
237 237
 
238 238
         // Prepare archive.
239
-        $zipfile = AO_CCSS_DIR . date( 'Ymd-H\hi' ) . '_ao_ccss_settings.zip';
240
-        $file    = pathinfo( $zipfile, PATHINFO_BASENAME );
239
+        $zipfile = AO_CCSS_DIR.date('Ymd-H\hi').'_ao_ccss_settings.zip';
240
+        $file    = pathinfo($zipfile, PATHINFO_BASENAME);
241 241
         $zip     = new ZipArchive();
242
-        $ret     = $zip->open( $zipfile, ZipArchive::CREATE );
243
-        if ( true !== $ret ) {
242
+        $ret     = $zip->open($zipfile, ZipArchive::CREATE);
243
+        if (true !== $ret) {
244 244
             $error = true;
245 245
         } else {
246
-            $zip->addFile( AO_CCSS_DIR . 'settings.json', 'settings.json' );
247
-            if ( file_exists( AO_CCSS_DIR . 'queue.json' ) ) {
248
-                $zip->addFile( AO_CCSS_DIR . 'queue.json', 'queue.json' );
246
+            $zip->addFile(AO_CCSS_DIR.'settings.json', 'settings.json');
247
+            if (file_exists(AO_CCSS_DIR.'queue.json')) {
248
+                $zip->addFile(AO_CCSS_DIR.'queue.json', 'queue.json');
249 249
             }
250 250
             $options = array(
251 251
                 'add_path'        => './',
252 252
                 'remove_all_path' => true,
253 253
             );
254
-            $zip->addGlob( AO_CCSS_DIR . '*.css', 0, $options );
254
+            $zip->addGlob(AO_CCSS_DIR.'*.css', 0, $options);
255 255
             $zip->close();
256 256
         }
257 257
 
258 258
         // Prepare response.
259
-        if ( ! $status || $error ) {
259
+        if (!$status || $error) {
260 260
             $response['code'] = '500';
261
-            $response['msg']  = 'Error saving file ' . $file . ', code: ' . $ret;
261
+            $response['msg']  = 'Error saving file '.$file.', code: '.$ret;
262 262
         } else {
263 263
             $response['code'] = '200';
264
-            $response['msg']  = 'File ' . $file . ' saved.';
264
+            $response['msg']  = 'File '.$file.' saved.';
265 265
             $response['file'] = $file;
266 266
         }
267 267
 
268 268
         // Dispatch respose.
269
-        echo json_encode( $response );
269
+        echo json_encode($response);
270 270
 
271 271
         // Close ajax request.
272 272
         wp_die();
@@ -275,44 +275,44 @@  discard block
 block discarded – undo
275 275
     public function ao_ccss_import_callback() {
276 276
         // Ajax handler import settings
277 277
         // Check referer.
278
-        check_ajax_referer( 'ao_ccss_import_nonce', 'ao_ccss_import_nonce' );
278
+        check_ajax_referer('ao_ccss_import_nonce', 'ao_ccss_import_nonce');
279 279
 
280 280
         // Initialize error flag.
281 281
         $error = false;
282 282
 
283 283
         // Process an uploaded file with no errors.
284
-        if ( ! $_FILES['file']['error'] ) {
284
+        if (!$_FILES['file']['error']) {
285 285
             // Save file to the cache directory.
286
-            $zipfile = AO_CCSS_DIR . $_FILES['file']['name'];
287
-            move_uploaded_file( $_FILES['file']['tmp_name'], $zipfile );
286
+            $zipfile = AO_CCSS_DIR.$_FILES['file']['name'];
287
+            move_uploaded_file($_FILES['file']['tmp_name'], $zipfile);
288 288
 
289 289
             // Extract archive.
290 290
             $zip = new ZipArchive;
291
-            if ( $zip->open( $zipfile ) === true ) {
292
-                $zip->extractTo( AO_CCSS_DIR );
291
+            if ($zip->open($zipfile) === true) {
292
+                $zip->extractTo(AO_CCSS_DIR);
293 293
                 $zip->close();
294 294
             } else {
295 295
                 $error = 'extracting';
296 296
             }
297 297
 
298
-            if ( ! $error ) {
298
+            if (!$error) {
299 299
                 // Archive extraction ok, continue settings importing
300 300
                 // Settings file.
301
-                $importfile = AO_CCSS_DIR . 'settings.json';
301
+                $importfile = AO_CCSS_DIR.'settings.json';
302 302
 
303
-                if ( file_exists( $importfile ) ) {
303
+                if (file_exists($importfile)) {
304 304
                     // Get settings and turn them into an object.
305
-                    $settings = json_decode( file_get_contents( $importfile ), true );
305
+                    $settings = json_decode(file_get_contents($importfile), true);
306 306
 
307 307
                     // Update options.
308
-                    update_option( 'autoptimize_ccss_rules', $settings['rules'] );
309
-                    update_option( 'autoptimize_ccss_additional', $settings['additional'] );
310
-                    update_option( 'autoptimize_ccss_viewport', $settings['viewport'] );
311
-                    update_option( 'autoptimize_ccss_finclude', $settings['finclude'] );
312
-                    update_option( 'autoptimize_ccss_rlimit', $settings['rlimit'] );
313
-                    update_option( 'autoptimize_ccss_noptimize', $settings['noptimize'] );
314
-                    update_option( 'autoptimize_ccss_debug', $settings['debug'] );
315
-                    update_option( 'autoptimize_ccss_key', $settings['key'] );
308
+                    update_option('autoptimize_ccss_rules', $settings['rules']);
309
+                    update_option('autoptimize_ccss_additional', $settings['additional']);
310
+                    update_option('autoptimize_ccss_viewport', $settings['viewport']);
311
+                    update_option('autoptimize_ccss_finclude', $settings['finclude']);
312
+                    update_option('autoptimize_ccss_rlimit', $settings['rlimit']);
313
+                    update_option('autoptimize_ccss_noptimize', $settings['noptimize']);
314
+                    update_option('autoptimize_ccss_debug', $settings['debug']);
315
+                    update_option('autoptimize_ccss_key', $settings['key']);
316 316
                 } else {
317 317
                     // Settings file doesn't exist, update error flag.
318 318
                     $error = 'settings file does not exist';
@@ -321,28 +321,28 @@  discard block
 block discarded – undo
321 321
         }
322 322
 
323 323
         // Prepare response.
324
-        if ( $error ) {
324
+        if ($error) {
325 325
             $response['code'] = '500';
326
-            $response['msg']  = 'Error importing settings: ' . $error;
326
+            $response['msg']  = 'Error importing settings: '.$error;
327 327
         } else {
328 328
             $response['code'] = '200';
329 329
             $response['msg']  = 'Settings imported successfully';
330 330
         }
331 331
 
332 332
         // Dispatch respose.
333
-        echo json_encode( $response );
333
+        echo json_encode($response);
334 334
 
335 335
         // Close ajax request.
336 336
         wp_die();
337 337
     }
338 338
 
339
-    public function critcss_check_filename( $filename ) {
339
+    public function critcss_check_filename($filename) {
340 340
         // Try to avoid directory traversal when reading/writing/deleting critical CSS files.
341
-        if ( strpos( $filename, 'ccss_' ) !== 0 ) {
341
+        if (strpos($filename, 'ccss_') !== 0) {
342 342
             return false;
343
-        } elseif ( substr( $filename, -4, 4 ) !== '.css' ) {
343
+        } elseif (substr($filename, -4, 4) !== '.css') {
344 344
             return false;
345
-        } elseif ( sanitize_file_name( $filename ) !== $filename ) {
345
+        } elseif (sanitize_file_name($filename) !== $filename) {
346 346
             // Use WordPress core's sanitize_file_name to see if anything fishy is going on.
347 347
             return false;
348 348
         } else {
Please login to merge, or discard this patch.
classes/autoptimizeUtils.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * General helpers.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @return bool
18 18
      */
19
-    public static function mbstring_available( $override = null )
19
+    public static function mbstring_available($override = null)
20 20
     {
21 21
         static $available = null;
22 22
 
23
-        if ( null === $available ) {
24
-            $available = \extension_loaded( 'mbstring' );
23
+        if (null === $available) {
24
+            $available = \extension_loaded('mbstring');
25 25
         }
26 26
 
27
-        if ( null !== $override ) {
27
+        if (null !== $override) {
28 28
             $available = $override;
29 29
         }
30 30
 
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return int|false
44 44
      */
45
-    public static function strpos( $haystack, $needle, $offset = 0, $encoding = null )
45
+    public static function strpos($haystack, $needle, $offset = 0, $encoding = null)
46 46
     {
47
-        if ( self::mbstring_available() ) {
48
-            return ( null === $encoding ) ? \mb_strpos( $haystack, $needle, $offset ) : \mb_strpos( $haystack, $needle, $offset, $encoding );
47
+        if (self::mbstring_available()) {
48
+            return (null === $encoding) ? \mb_strpos($haystack, $needle, $offset) : \mb_strpos($haystack, $needle, $offset, $encoding);
49 49
         } else {
50
-            return \strpos( $haystack, $needle, $offset );
50
+            return \strpos($haystack, $needle, $offset);
51 51
         }
52 52
     }
53 53
 
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
      * @return int Number of characters or bytes in given $string
63 63
      *             (characters if/when supported, bytes otherwise).
64 64
      */
65
-    public static function strlen( $string, $encoding = null )
65
+    public static function strlen($string, $encoding = null)
66 66
     {
67
-        if ( self::mbstring_available() ) {
68
-            return ( null === $encoding ) ? \mb_strlen( $string ) : \mb_strlen( $string, $encoding );
67
+        if (self::mbstring_available()) {
68
+            return (null === $encoding) ? \mb_strlen($string) : \mb_strlen($string, $encoding);
69 69
         } else {
70
-            return \strlen( $string );
70
+            return \strlen($string);
71 71
         }
72 72
     }
73 73
 
@@ -85,44 +85,44 @@  discard block
 block discarded – undo
85 85
      *
86 86
      * @return string
87 87
      */
88
-    public static function substr_replace( $string, $replacement, $start, $length = null, $encoding = null )
88
+    public static function substr_replace($string, $replacement, $start, $length = null, $encoding = null)
89 89
     {
90
-        if ( self::mbstring_available() ) {
91
-            $strlen = self::strlen( $string, $encoding );
90
+        if (self::mbstring_available()) {
91
+            $strlen = self::strlen($string, $encoding);
92 92
 
93
-            if ( $start < 0 ) {
93
+            if ($start < 0) {
94 94
                 if ( -$start < $strlen ) {
95 95
                     $start = $strlen + $start;
96 96
                 } else {
97 97
                     $start = 0;
98 98
                 }
99
-            } elseif ( $start > $strlen ) {
99
+            } elseif ($start > $strlen) {
100 100
                 $start = $strlen;
101 101
             }
102 102
 
103
-            if ( null === $length || '' === $length ) {
103
+            if (null === $length || '' === $length) {
104 104
                 $start2 = $strlen;
105
-            } elseif ( $length < 0 ) {
105
+            } elseif ($length < 0) {
106 106
                 $start2 = $strlen + $length;
107
-                if ( $start2 < $start ) {
107
+                if ($start2 < $start) {
108 108
                     $start2 = $start;
109 109
                 }
110 110
             } else {
111 111
                 $start2 = $start + $length;
112 112
             }
113 113
 
114
-            if ( null === $encoding ) {
115
-                $leader  = $start ? \mb_substr( $string, 0, $start ) : '';
116
-                $trailer = ( $start2 < $strlen ) ? \mb_substr( $string, $start2, null ) : '';
114
+            if (null === $encoding) {
115
+                $leader  = $start ? \mb_substr($string, 0, $start) : '';
116
+                $trailer = ($start2 < $strlen) ? \mb_substr($string, $start2, null) : '';
117 117
             } else {
118
-                $leader  = $start ? \mb_substr( $string, 0, $start, $encoding ) : '';
119
-                $trailer = ( $start2 < $strlen ) ? \mb_substr( $string, $start2, null, $encoding ) : '';
118
+                $leader  = $start ? \mb_substr($string, 0, $start, $encoding) : '';
119
+                $trailer = ($start2 < $strlen) ? \mb_substr($string, $start2, null, $encoding) : '';
120 120
             }
121 121
 
122 122
             return "{$leader}{$replacement}{$trailer}";
123 123
         }
124 124
 
125
-        return ( null === $length ) ? \substr_replace( $string, $replacement, $start ) : \substr_replace( $string, $replacement, $start, $length );
125
+        return (null === $length) ? \substr_replace($string, $replacement, $start) : \substr_replace($string, $replacement, $start, $length);
126 126
     }
127 127
 
128 128
     /**
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @return bool
134 134
      */
135
-    public static function siteurl_not_root( $override = null )
135
+    public static function siteurl_not_root($override = null)
136 136
     {
137 137
         static $subdir = null;
138 138
 
139
-        if ( null === $subdir ) {
139
+        if (null === $subdir) {
140 140
             $parts  = self::get_ao_wp_site_url_parts();
141
-            $subdir = ( isset( $parts['path'] ) && ( '/' !== $parts['path'] ) );
141
+            $subdir = (isset($parts['path']) && ('/' !== $parts['path']));
142 142
         }
143 143
 
144
-        if ( null !== $override ) {
144
+        if (null !== $override) {
145 145
             $subdir = $override;
146 146
         }
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
     {
159 159
         static $parts = array();
160 160
 
161
-        if ( empty( $parts ) ) {
162
-            $parts = \parse_url( AUTOPTIMIZE_WP_SITE_URL );
161
+        if (empty($parts)) {
162
+            $parts = \parse_url(AUTOPTIMIZE_WP_SITE_URL);
163 163
         }
164 164
 
165 165
         return $parts;
@@ -174,33 +174,33 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @return string
176 176
      */
177
-    public static function tweak_cdn_url_if_needed( $cdn_url, $force_cache_miss = false )
177
+    public static function tweak_cdn_url_if_needed($cdn_url, $force_cache_miss = false)
178 178
     {
179 179
         static $results = array();
180 180
 
181
-        if ( ! isset( $results[ $cdn_url ] ) || $force_cache_miss ) {
181
+        if (!isset($results[$cdn_url]) || $force_cache_miss) {
182 182
 
183 183
             // In order to return unmodified input when there's no need to tweak.
184
-            $results[ $cdn_url ] = $cdn_url;
184
+            $results[$cdn_url] = $cdn_url;
185 185
 
186 186
             // Behind a default true filter for backcompat, and only for sites
187 187
             // in a subfolder/subdirectory, but still easily turned off if
188 188
             // not wanted/needed...
189
-            if ( autoptimizeUtils::siteurl_not_root() ) {
190
-                $check = apply_filters( 'autoptimize_filter_cdn_magic_path_check', true, $cdn_url );
191
-                if ( $check ) {
189
+            if (autoptimizeUtils::siteurl_not_root()) {
190
+                $check = apply_filters('autoptimize_filter_cdn_magic_path_check', true, $cdn_url);
191
+                if ($check) {
192 192
                     $site_url_parts = autoptimizeUtils::get_ao_wp_site_url_parts();
193
-                    $cdn_url_parts  = \parse_url( $cdn_url );
194
-                    $schemeless     = self::is_protocol_relative( $cdn_url );
195
-                    $cdn_url_parts  = self::maybe_replace_cdn_path( $site_url_parts, $cdn_url_parts );
196
-                    if ( false !== $cdn_url_parts ) {
197
-                        $results[ $cdn_url ] = self::assemble_parsed_url( $cdn_url_parts, $schemeless );
193
+                    $cdn_url_parts  = \parse_url($cdn_url);
194
+                    $schemeless     = self::is_protocol_relative($cdn_url);
195
+                    $cdn_url_parts  = self::maybe_replace_cdn_path($site_url_parts, $cdn_url_parts);
196
+                    if (false !== $cdn_url_parts) {
197
+                        $results[$cdn_url] = self::assemble_parsed_url($cdn_url_parts, $schemeless);
198 198
                     }
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203
-        return $results[ $cdn_url ];
203
+        return $results[$cdn_url];
204 204
     }
205 205
 
206 206
     /**
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return array|false
216 216
      */
217
-    public static function maybe_replace_cdn_path( array $site_url_parts, array $cdn_url_parts )
217
+    public static function maybe_replace_cdn_path(array $site_url_parts, array $cdn_url_parts)
218 218
     {
219
-        if ( isset( $site_url_parts['path'] ) && '/' !== $site_url_parts['path'] ) {
220
-            if ( ! isset( $cdn_url_parts['path'] ) || '/' === $cdn_url_parts['path'] ) {
219
+        if (isset($site_url_parts['path']) && '/' !== $site_url_parts['path']) {
220
+            if (!isset($cdn_url_parts['path']) || '/' === $cdn_url_parts['path']) {
221 221
                 $cdn_url_parts['path'] = $site_url_parts['path'];
222 222
                 return $cdn_url_parts;
223 223
             }
@@ -237,20 +237,20 @@  discard block
 block discarded – undo
237 237
      *
238 238
      * @return string
239 239
      */
240
-    public static function assemble_parsed_url( array $parsed_url, $schemeless = false )
240
+    public static function assemble_parsed_url(array $parsed_url, $schemeless = false)
241 241
     {
242
-        $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
243
-        if ( $schemeless ) {
242
+        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
243
+        if ($schemeless) {
244 244
             $scheme = '//';
245 245
         }
246
-        $host     = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
247
-        $port     = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
248
-        $user     = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
249
-        $pass     = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
250
-        $pass     = ( $user || $pass ) ? "$pass@" : '';
251
-        $path     = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
252
-        $query    = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
253
-        $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
246
+        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
247
+        $port     = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
248
+        $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
249
+        $pass     = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
250
+        $pass     = ($user || $pass) ? "$pass@" : '';
251
+        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
252
+        $query    = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
253
+        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
254 254
 
255 255
         return "$scheme$user$pass$host$port$path$query$fragment";
256 256
     }
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
      *
263 263
      * @return bool
264 264
      */
265
-    public static function is_protocol_relative( $url )
265
+    public static function is_protocol_relative($url)
266 266
     {
267 267
         $result = false;
268 268
 
269
-        if ( ! empty( $url ) ) {
270
-            $result = ( 0 === strpos( $url, '//' ) );
269
+        if (!empty($url)) {
270
+            $result = (0 === strpos($url, '//'));
271 271
         }
272 272
 
273 273
         return $result;
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
      *
281 281
      * @return string
282 282
      */
283
-    public static function path_canonicalize( $path )
283
+    public static function path_canonicalize($path)
284 284
     {
285
-        $patterns     = array(
285
+        $patterns = array(
286 286
             '~/{2,}~',
287 287
             '~/(\./)+~',
288 288
             '~([^/\.]+/(?R)*\.{2,}/)~',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             '',
296 296
         );
297 297
 
298
-        return preg_replace( $patterns, $replacements, $path );
298
+        return preg_replace($patterns, $replacements, $path);
299 299
     }
300 300
 
301 301
     /**
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return null|array Service status or null.
309 309
      */
310
-    public static function check_service_availability( $return_result = false )
310
+    public static function check_service_availability($return_result = false)
311 311
     {
312
-        $service_availability_resp = wp_remote_get( 'https://misc.optimizingmatters.com/api/autoptimize_service_availablity.json?from=aomain&ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
313
-        if ( ! is_wp_error( $service_availability_resp ) ) {
314
-            if ( '200' == wp_remote_retrieve_response_code( $service_availability_resp ) ) {
315
-                $availabilities = json_decode( wp_remote_retrieve_body( $service_availability_resp ), true );
316
-                if ( is_array( $availabilities ) ) {
317
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_service_availablity', $availabilities );
318
-                    if ( $return_result ) {
312
+        $service_availability_resp = wp_remote_get('https://misc.optimizingmatters.com/api/autoptimize_service_availablity.json?from=aomain&ver='.AUTOPTIMIZE_PLUGIN_VERSION);
313
+        if (!is_wp_error($service_availability_resp)) {
314
+            if ('200' == wp_remote_retrieve_response_code($service_availability_resp)) {
315
+                $availabilities = json_decode(wp_remote_retrieve_body($service_availability_resp), true);
316
+                if (is_array($availabilities)) {
317
+                    autoptimizeOptionWrapper::update_option('autoptimize_service_availablity', $availabilities);
318
+                    if ($return_result) {
319 319
                         return $availabilities;
320 320
                     }
321 321
                 }
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
      *
332 332
      * @return bool
333 333
      */
334
-    public static function str_is_valid_regex( $string )
334
+    public static function str_is_valid_regex($string)
335 335
     {
336
-        set_error_handler( function() {}, E_WARNING );
337
-        $is_regex = ( false !== preg_match( $string, '' ) );
336
+        set_error_handler(function() {}, E_WARNING);
337
+        $is_regex = (false !== preg_match($string, ''));
338 338
         restore_error_handler();
339 339
 
340 340
         return $is_regex;
@@ -347,17 +347,17 @@  discard block
 block discarded – undo
347 347
      *
348 348
      * @return bool
349 349
      */
350
-    public static function is_plugin_active( $plugin_file )
350
+    public static function is_plugin_active($plugin_file)
351 351
     {
352 352
         static $ipa_exists = null;
353
-        if ( null === $ipa_exists ) {
354
-            if ( ! function_exists( '\is_plugin_active' ) ) {
355
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
353
+        if (null === $ipa_exists) {
354
+            if (!function_exists('\is_plugin_active')) {
355
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
356 356
             }
357
-            $ipa_exists = function_exists( '\is_plugin_active' );
357
+            $ipa_exists = function_exists('\is_plugin_active');
358 358
         }
359 359
 
360
-        return $ipa_exists && \is_plugin_active( $plugin_file );
360
+        return $ipa_exists && \is_plugin_active($plugin_file);
361 361
     }
362 362
 
363 363
     /**
@@ -367,11 +367,11 @@  discard block
 block discarded – undo
367 367
      *
368 368
      * @return string
369 369
      */
370
-    public static function remove_id_from_node( $node ) {
371
-        if ( strpos( $node, 'id=' ) === false || apply_filters( 'autoptimize_filter_utils_keep_ids', false ) ) {
370
+    public static function remove_id_from_node($node) {
371
+        if (strpos($node, 'id=') === false || apply_filters('autoptimize_filter_utils_keep_ids', false)) {
372 372
             return $node;
373 373
         } else {
374
-            return preg_replace( '#(.*) id=[\'|"].*[\'|"] (.*)#Um', '$1 $2', $node );
374
+            return preg_replace('#(.*) id=[\'|"].*[\'|"] (.*)#Um', '$1 $2', $node);
375 375
         }
376 376
     }
377 377
 
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
      *
384 384
      * @return bool
385 385
      */
386
-    public static function str_ends_in( $str, $test )
386
+    public static function str_ends_in($str, $test)
387 387
     {
388 388
         // @codingStandardsIgnoreStart
389 389
         // substr_compare() is bugged on 5.5.11: https://3v4l.org/qGYBH
390 390
         // return ( 0 === substr_compare( $str, $test, -strlen( $test ) ) );
391 391
         // @codingStandardsIgnoreEnd
392 392
 
393
-        $length = strlen( $test );
393
+        $length = strlen($test);
394 394
 
395
-        return ( substr( $str, -$length, $length ) === $test );
395
+        return (substr($str, -$length, $length) === $test);
396 396
     }
397 397
 }
Please login to merge, or discard this patch.
classes/autoptimizeImages.php 1 patch
Spacing   +338 added lines, -338 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 )
396
+    private function can_optimize_image($url)
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 ) {
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) {
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,43 +453,43 @@  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] ) ) {
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])) {
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 filter_optimize_images( $in )
492
+    public function filter_optimize_images($in)
493 493
     {
494 494
         /*
495 495
          * potential future functional improvements:
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
         $to_replace = array();
500 500
 
501 501
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
502
-        if ( $this->should_lazyload() ) {
502
+        if ($this->should_lazyload()) {
503 503
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
504 504
                 'SCRIPT',
505 505
                 '<script',
@@ -509,25 +509,25 @@  discard block
 block discarded – undo
509 509
         }
510 510
 
511 511
         // extract img tags.
512
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
513
-            foreach ( $matches[0] as $tag ) {
512
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
513
+            foreach ($matches[0] as $tag) {
514 514
                 $orig_tag = $tag;
515 515
                 $imgopt_w = '';
516 516
                 $imgopt_h = '';
517 517
 
518 518
                 // first do (data-)srcsets.
519
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
520
-                    foreach ( $allsrcsets as $srcset ) {
519
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
520
+                    foreach ($allsrcsets as $srcset) {
521 521
                         $srcset  = $srcset[2];
522
-                        $srcsets = explode( ',', $srcset );
523
-                        foreach ( $srcsets as $indiv_srcset ) {
524
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
525
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
526
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
522
+                        $srcsets = explode(',', $srcset);
523
+                        foreach ($srcsets as $indiv_srcset) {
524
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
525
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
526
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
527 527
                             }
528
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0] ) ) {
529
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
530
-                                $tag        = str_replace( $indiv_srcset_parts[0], $imgopt_url, $tag );
528
+                            if ($this->can_optimize_image($indiv_srcset_parts[0])) {
529
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
530
+                                $tag        = str_replace($indiv_srcset_parts[0], $imgopt_url, $tag);
531 531
                             }
532 532
                         }
533 533
                     }
@@ -535,124 +535,124 @@  discard block
 block discarded – undo
535 535
 
536 536
                 // proceed with img src.
537 537
                 // get width and height and add to $imgopt_size.
538
-                $_get_size = $this->get_size_from_tag( $tag );
538
+                $_get_size = $this->get_size_from_tag($tag);
539 539
                 $imgopt_w  = $_get_size['width'];
540 540
                 $imgopt_h  = $_get_size['height'];
541 541
 
542 542
                 // then start replacing images src.
543
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
544
-                    foreach ( $urls as $url ) {
543
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
544
+                    foreach ($urls as $url) {
545 545
                         $full_src_orig = $url[0];
546 546
                         $url           = $url[1];
547
-                        if ( $this->can_optimize_image( $url ) ) {
548
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
549
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
550
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
547
+                        if ($this->can_optimize_image($url)) {
548
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
549
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
550
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
551 551
                         }
552 552
                     }
553 553
                 }
554 554
 
555 555
                 // do lazyload stuff.
556
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
556
+                if ($this->should_lazyload($in) && !empty($url)) {
557 557
                     // first do lpiq placeholder logic.
558
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
558
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
559 559
                         // if all img src have been replaced during srcset, we have to extract the
560 560
                         // origin url from the imgopt one to be able to set a lqip placeholder.
561
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
561
+                        $_url = substr($url, strpos($url, '/http') + 1);
562 562
                     } else {
563 563
                         $_url = $url;
564 564
                     }
565 565
 
566
-                    $_url = $this->normalize_img_url( $_url );
566
+                    $_url = $this->normalize_img_url($_url);
567 567
 
568 568
                     $placeholder = '';
569
-                    if ( $this->can_optimize_image( $_url ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
569
+                    if ($this->can_optimize_image($_url) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
570 570
                         $lqip_w = '';
571 571
                         $lqip_h = '';
572
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
573
-                            $lqip_w = ',w_' . $imgopt_w;
572
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
573
+                            $lqip_w = ',w_'.$imgopt_w;
574 574
                         }
575
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
576
-                            $lqip_h = ',h_' . $imgopt_h;
575
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
576
+                            $lqip_h = ',h_'.$imgopt_h;
577 577
                         }
578
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
578
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
579 579
                     }
580 580
                     // then call add_lazyload-function with lpiq placeholder if set.
581
-                    $tag = $this->add_lazyload( $tag, $placeholder );
581
+                    $tag = $this->add_lazyload($tag, $placeholder);
582 582
                 }
583 583
 
584 584
                 // and add tag to array for later replacement.
585
-                if ( $tag !== $orig_tag ) {
586
-                    $to_replace[ $orig_tag ] = $tag;
585
+                if ($tag !== $orig_tag) {
586
+                    $to_replace[$orig_tag] = $tag;
587 587
                 }
588 588
             }
589 589
         }
590 590
 
591 591
         // and replace all.
592
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
592
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
593 593
 
594 594
         // img thumbnails in e.g. woocommerce.
595
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
595
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
596 596
             $out = preg_replace_callback(
597 597
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
598
-                array( $this, 'replace_data_thumbs' ),
598
+                array($this, 'replace_data_thumbs'),
599 599
                 $out
600 600
             );
601 601
         }
602 602
 
603 603
         // background-image in inline style.
604
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
604
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
605 605
             $out = preg_replace_callback(
606 606
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
607
-                array( $this, 'replace_img_callback' ),
607
+                array($this, 'replace_img_callback'),
608 608
                 $out
609 609
             );
610 610
         }
611 611
 
612 612
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
613
-        if ( $this->should_lazyload() ) {
613
+        if ($this->should_lazyload()) {
614 614
             $out = autoptimizeBase::restore_marked_content(
615 615
                 'SCRIPT',
616 616
                 $out
617 617
             );
618 618
 
619
-            $out = $this->process_picture_tag( $out, true, true );
620
-            $out = $this->process_bgimage( $out );
619
+            $out = $this->process_picture_tag($out, true, true);
620
+            $out = $this->process_bgimage($out);
621 621
         } else {
622
-            $out = $this->process_picture_tag( $out, true, false );
622
+            $out = $this->process_picture_tag($out, true, false);
623 623
         }
624 624
 
625 625
         return $out;
626 626
     }
627 627
 
628
-    public function get_size_from_tag( $tag ) {
628
+    public function get_size_from_tag($tag) {
629 629
         // reusable function to extract widht and height from an image tag
630 630
         // enforcing a filterable maximum width and height (default 4999X4999).
631 631
         $width  = '';
632 632
         $height = '';
633 633
 
634
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
635
-            if ( strpos( $_width[2], '%' ) === false ) {
634
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
635
+            if (strpos($_width[2], '%') === false) {
636 636
                 $width = (int) $_width[2];
637 637
             }
638 638
         }
639
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
640
-            if ( strpos( $_height[2], '%' ) === false ) {
639
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
640
+            if (strpos($_height[2], '%') === false) {
641 641
                 $height = (int) $_height[2];
642 642
             }
643 643
         }
644 644
 
645 645
         // check for and enforce (filterable) max sizes.
646
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
647
-        if ( $width > $_max_width ) {
646
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
647
+        if ($width > $_max_width) {
648 648
             $_width = $_max_width;
649
-            $height = $_width / $width * $height;
649
+            $height = $_width/$width*$height;
650 650
             $width  = $_width;
651 651
         }
652
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
653
-        if ( $height > $_max_height ) {
652
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
653
+        if ($height > $_max_height) {
654 654
             $_height = $_max_height;
655
-            $width   = $_height / $height * $width;
655
+            $width   = $_height/$height*$width;
656 656
             $height  = $_height;
657 657
         }
658 658
 
@@ -671,26 +671,26 @@  discard block
 block discarded – undo
671 671
         return $self->should_lazyload();
672 672
     }
673 673
 
674
-    public function should_lazyload( $context = '' ) {
675
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
674
+    public function should_lazyload($context = '') {
675
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
676 676
             $lazyload_return = true;
677 677
         } else {
678 678
             $lazyload_return = false;
679 679
         }
680
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
680
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
681 681
 
682 682
         return $lazyload_return;
683 683
     }
684 684
 
685 685
     public function check_nolazy() {
686
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
686
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
687 687
             return true;
688 688
         } else {
689 689
             return false;
690 690
         }
691 691
     }
692 692
 
693
-    public function filter_lazyload_images( $in )
693
+    public function filter_lazyload_images($in)
694 694
     {
695 695
         // only used is image optimization is NOT active but lazyload is.
696 696
         $to_replace = array();
@@ -704,20 +704,20 @@  discard block
 block discarded – undo
704 704
         );
705 705
 
706 706
         // extract img tags and add lazyload attribs.
707
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
708
-            foreach ( $matches[0] as $tag ) {
709
-                if ( $this->should_lazyload( $out ) ) {
710
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
707
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
708
+            foreach ($matches[0] as $tag) {
709
+                if ($this->should_lazyload($out)) {
710
+                    $to_replace[$tag] = $this->add_lazyload($tag);
711 711
                 }
712 712
             }
713
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
713
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
714 714
         }
715 715
 
716 716
         // and also lazyload picture tag.
717
-        $out = $this->process_picture_tag( $out, false, true );
717
+        $out = $this->process_picture_tag($out, false, true);
718 718
 
719 719
         // and inline style blocks with background-image.
720
-        $out = $this->process_bgimage( $out );
720
+        $out = $this->process_bgimage($out);
721 721
 
722 722
         // restore noscript tags.
723 723
         $out = autoptimizeBase::restore_marked_content(
@@ -728,84 +728,84 @@  discard block
 block discarded – undo
728 728
         return $out;
729 729
     }
730 730
 
731
-    public function add_lazyload( $tag, $placeholder = '' ) {
731
+    public function add_lazyload($tag, $placeholder = '') {
732 732
         // adds actual lazyload-attributes to an image node.
733
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
734
-            $tag = $this->maybe_fix_missing_quotes( $tag );
733
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) {
734
+            $tag = $this->maybe_fix_missing_quotes($tag);
735 735
 
736 736
             // store original tag for use in noscript version.
737
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
737
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
738 738
 
739
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
739
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
740 740
 
741 741
             // insert lazyload class.
742
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
742
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
743 743
 
744
-            if ( ! $placeholder || empty( $placeholder ) ) {
744
+            if (!$placeholder || empty($placeholder)) {
745 745
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
746
-                $_get_size = $this->get_size_from_tag( $tag );
746
+                $_get_size = $this->get_size_from_tag($tag);
747 747
                 $width     = $_get_size['width'];
748 748
                 $height    = $_get_size['height'];
749
-                if ( false === $width || empty( $width ) ) {
749
+                if (false === $width || empty($width)) {
750 750
                     $width = 210; // default width for SVG placeholder.
751 751
                 }
752
-                if ( false === $height || empty( $height ) ) {
753
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
752
+                if (false === $height || empty($height)) {
753
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
754 754
                 }
755 755
 
756 756
                 // insert the actual lazyload stuff.
757 757
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
758
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
758
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
759 759
             }
760 760
 
761
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
762
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
761
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
762
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
763 763
 
764 764
             // move sizes to data-sizes unless filter says no.
765
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
766
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
765
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
766
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
767 767
             }
768 768
 
769 769
             // add the noscript-tag from earlier.
770
-            $tag = $noscript_tag . $tag;
771
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
770
+            $tag = $noscript_tag.$tag;
771
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
772 772
         }
773 773
 
774 774
         return $tag;
775 775
     }
776 776
 
777 777
     public function add_lazyload_js_footer() {
778
-        if ( false === autoptimizeMain::should_buffer() ) {
778
+        if (false === autoptimizeMain::should_buffer()) {
779 779
             return;
780 780
         }
781 781
 
782 782
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
783 783
         $noptimize_flag = '';
784
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
784
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
785 785
             $noptimize_flag = ' data-noptimize="1"';
786 786
         }
787 787
 
788
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
788
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
789 789
         $cdn_url      = $this->get_cdn_url();
790
-        if ( ! empty( $cdn_url ) ) {
791
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
790
+        if (!empty($cdn_url)) {
791
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
792 792
         }
793 793
 
794 794
         $type_js = '';
795
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
795
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
796 796
             $type_js = ' type="text/javascript"';
797 797
         }
798 798
 
799 799
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
800
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<style>.lazyload,.lazyloading{opacity:0;}.lazyloaded{opacity:1;transition:opacity 300ms;}</style><noscript><style>.lazyload{display:none;}</style></noscript>' );
801
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
802
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
800
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<style>.lazyload,.lazyloading{opacity:0;}.lazyloaded{opacity:1;transition:opacity 300ms;}</style><noscript><style>.lazyload{display:none;}</style></noscript>');
801
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
802
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
803 803
 
804 804
         // And add webp detection and loading JS.
805
-        if ( $this->should_webp() ) {
805
+        if ($this->should_webp()) {
806 806
             $_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);";
807 807
             $_webp_load   = "document.addEventListener('lazybeforeunveil',function({target:c}){supportsWebP&&['data-src','data-srcset'].forEach(function(a){attr=c.getAttribute(a),null!==attr&&c.setAttribute(a,attr.replace(/\/client\//,'/client/to_webp,'))})});";
808
-            echo apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_webp_detect . $_webp_load . '</script>' );
808
+            echo apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_webp_detect.$_webp_load.'</script>');
809 809
         }
810 810
     }
811 811
 
@@ -813,10 +813,10 @@  discard block
 block discarded – undo
813 813
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
814 814
         static $cdn_url = null;
815 815
 
816
-        if ( null === $cdn_url ) {
817
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
818
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
819
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
816
+        if (null === $cdn_url) {
817
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
818
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
819
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
820 820
         }
821 821
 
822 822
         return $cdn_url;
@@ -826,47 +826,47 @@  discard block
 block discarded – undo
826 826
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
827 827
         static $exclude_lazyload_array = null;
828 828
 
829
-        if ( null === $exclude_lazyload_array ) {
829
+        if (null === $exclude_lazyload_array) {
830 830
             $options = $this->options;
831 831
 
832 832
             // set default exclusions.
833
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
833
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
834 834
 
835 835
             // add from setting.
836
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
836
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
837 837
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
838
-                if ( ! empty( $exclude_lazyload_option ) ) {
839
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
838
+                if (!empty($exclude_lazyload_option)) {
839
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
840 840
                 }
841 841
             }
842 842
 
843 843
             // and filter for developer-initiated changes.
844
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
844
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
845 845
         }
846 846
 
847 847
         return $exclude_lazyload_array;
848 848
     }
849 849
 
850
-    public function inject_classes_in_tag( $tag, $target_class ) {
851
-        if ( strpos( $tag, 'class=' ) !== false ) {
852
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
850
+    public function inject_classes_in_tag($tag, $target_class) {
851
+        if (strpos($tag, 'class=') !== false) {
852
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
853 853
         } else {
854
-            $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
854
+            $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag);
855 855
         }
856 856
 
857 857
         return $tag;
858 858
     }
859 859
 
860
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
861
-        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';
860
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
861
+        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';
862 862
     }
863 863
 
864 864
     public function should_webp() {
865 865
         static $webp_return = null;
866 866
 
867
-        if ( is_null( $webp_return ) ) {
867
+        if (is_null($webp_return)) {
868 868
             // webp only works if imgopt and lazyload are also active.
869
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
869
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
870 870
                 $webp_return = true;
871 871
             } else {
872 872
                 $webp_return = false;
@@ -876,9 +876,9 @@  discard block
 block discarded – undo
876 876
         return $webp_return;
877 877
     }
878 878
 
879
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
879
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
880 880
         // check if "<picture" is present and if filter allows us to process <picture>.
881
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
881
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
882 882
             return $in;
883 883
         }
884 884
 
@@ -886,37 +886,37 @@  discard block
 block discarded – undo
886 886
         $to_replace_pict = array();
887 887
 
888 888
         // extract and process each picture-node.
889
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
890
-        foreach ( $_pictures as $_picture ) {
891
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
892
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
893
-                foreach ( $_sources as $_source ) {
889
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
890
+        foreach ($_pictures as $_picture) {
891
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
892
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
893
+                foreach ($_sources as $_source) {
894 894
                     $_picture_replacement = $_source[0];
895 895
 
896 896
                     // should we optimize the image?
897
-                    if ( $imgopt && $this->can_optimize_image( $_source[1] ) ) {
898
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
897
+                    if ($imgopt && $this->can_optimize_image($_source[1])) {
898
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
899 899
                     }
900 900
                     // should we lazy-load?
901
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
902
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
901
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
902
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
903 903
                     }
904
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
904
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
905 905
                 }
906 906
             }
907 907
         }
908 908
 
909 909
         // and return the fully procesed $in.
910
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
910
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
911 911
 
912 912
         return $out;
913 913
     }
914 914
 
915
-    public function process_bgimage( $in ) {
916
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
915
+    public function process_bgimage($in) {
916
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
917 917
             $out = preg_replace_callback(
918 918
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
919
-                array( $this, 'lazyload_bgimg_callback' ),
919
+                array($this, 'lazyload_bgimg_callback'),
920 920
                 $in
921 921
             );
922 922
             return $out;
@@ -924,27 +924,27 @@  discard block
 block discarded – undo
924 924
         return $in;
925 925
     }
926 926
 
927
-    public function lazyload_bgimg_callback( $matches ) {
928
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
927
+    public function lazyload_bgimg_callback($matches) {
928
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
929 929
             // get placeholder & lazyload class strings.
930
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
931
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
930
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
931
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
932 932
             // replace background-image URL with SVG placeholder.
933
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
933
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
934 934
             // add data-bg attribute with real background-image URL for lazyload to pick up.
935
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
935
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
936 936
             // add lazyload class to tag.
937
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
937
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
938 938
             return $out;
939 939
         }
940 940
         return $matches[0];
941 941
     }
942 942
 
943
-    public function maybe_fix_missing_quotes( $tag_in ) {
943
+    public function maybe_fix_missing_quotes($tag_in) {
944 944
         // 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.
945
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
946
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
947
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
945
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
946
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
947
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
948 948
             return $tag_out;
949 949
         } else {
950 950
             return $tag_in;
@@ -957,23 +957,23 @@  discard block
 block discarded – undo
957 957
     public function imgopt_admin_menu()
958 958
     {
959 959
         // no acces if multisite and not network admin and no site config allowed.
960
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
960
+        if (autoptimizeConfig::should_show_menu_tabs()) {
961 961
             add_submenu_page(
962 962
                 null,
963 963
                 'autoptimize_imgopt',
964 964
                 'autoptimize_imgopt',
965 965
                 'manage_options',
966 966
                 'autoptimize_imgopt',
967
-                array( $this, 'imgopt_options_page' )
967
+                array($this, 'imgopt_options_page')
968 968
             );
969 969
         }
970
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
970
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
971 971
     }
972 972
 
973
-    public function add_imgopt_tab( $in )
973
+    public function add_imgopt_tab($in)
974 974
     {
975
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
976
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
975
+        if (autoptimizeConfig::should_show_menu_tabs()) {
976
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
977 977
         }
978 978
 
979 979
         return $in;
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
     public function imgopt_options_page()
983 983
     {
984 984
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
985
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
985
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
986 986
             $this->query_img_provider_stats();
987 987
         }
988 988
 
@@ -994,47 +994,47 @@  discard block
 block discarded – undo
994 994
         #ao_settings_form .form-table th {font-weight: normal;}
995 995
         #autoptimize_imgopt_descr{font-size: 120%;}
996 996
     </style>
997
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
997
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
998 998
     <div class="wrap">
999
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
999
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1000 1000
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1001
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1001
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1002 1002
             <div class="notice-warning notice"><p>
1003 1003
             <?php
1004 1004
             // translators: "Autoptimize support forum" will appear in a "a href".
1005
-            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>' );
1005
+            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>');
1006 1006
             ?>
1007 1007
             </p></div>
1008 1008
         <?php } ?>
1009 1009
 
1010
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1010
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1011 1011
             <div class="notice-warning notice"><p>
1012
-            <?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' ); ?>
1012
+            <?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'); ?>
1013 1013
             </p></div>
1014 1014
         <?php } ?>
1015 1015
 
1016
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1016
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1017 1017
             <div class="notice-warning notice"><p>
1018 1018
             <?php
1019 1019
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1020
-            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>' );
1020
+            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>');
1021 1021
             ?>
1022 1022
             </p></div>
1023 1023
         <?php } ?>
1024
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1025
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1026
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1027
-        <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>
1024
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1025
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1026
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1027
+        <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>
1028 1028
         <table class="form-table">
1029 1029
             <tr>
1030
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1030
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1031 1031
                 <td>
1032
-                    <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>
1032
+                    <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>
1033 1033
                     <?php
1034 1034
                     // show shortpixel status.
1035 1035
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1036
-                    if ( $_notice ) {
1037
-                        switch ( $_notice['status'] ) {
1036
+                    if ($_notice) {
1037
+                        switch ($_notice['status']) {
1038 1038
                             case 2:
1039 1039
                                 $_notice_color = 'green';
1040 1040
                                 break;
@@ -1049,29 +1049,29 @@  discard block
 block discarded – undo
1049 1049
                             default:
1050 1050
                                 $_notice_color = 'green';
1051 1051
                         }
1052
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1052
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1053 1053
                     } else {
1054 1054
                         // translators: link points to shortpixel.
1055
-                        $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>' );
1056
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1057
-                            $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' );
1055
+                        $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>');
1056
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1057
+                            $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');
1058 1058
                         } else {
1059 1059
                             // translators: link points to shortpixel.
1060
-                            $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>' );
1060
+                            $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>');
1061 1061
                         }
1062
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1062
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1063 1063
                     }
1064 1064
                     // translators: link points to shortpixel FAQ.
1065
-                    $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>' );
1066
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1065
+                    $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>');
1066
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1067 1067
                     // translators: links points to shortpixel TOS & Privacy Policy.
1068
-                    $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>' );
1069
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1068
+                    $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>');
1069
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1070 1070
                     ?>
1071 1071
                 </td>
1072 1072
             </tr>
1073
-            <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"'; } ?>>
1074
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1073
+            <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"'; } ?>>
1074
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1075 1075
                 <td>
1076 1076
                     <label>
1077 1077
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1079,12 +1079,12 @@  discard block
 block discarded – undo
1079 1079
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1080 1080
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1081 1081
 
1082
-                        foreach ( $_imgopt_array as $key => $value ) {
1083
-                            echo '<option value="' . $key . '"';
1084
-                            if ( $_imgopt_val == $key ) {
1082
+                        foreach ($_imgopt_array as $key => $value) {
1083
+                            echo '<option value="'.$key.'"';
1084
+                            if ($_imgopt_val == $key) {
1085 1085
                                 echo ' selected';
1086 1086
                             }
1087
-                            echo '>' . ucfirst( $value ) . '</option>';
1087
+                            echo '>'.ucfirst($value).'</option>';
1088 1088
                         }
1089 1089
                         echo "\n";
1090 1090
                         ?>
@@ -1093,31 +1093,31 @@  discard block
 block discarded – undo
1093 1093
                     <p>
1094 1094
                         <?php
1095 1095
                             // translators: link points to shortpixel image test page.
1096
-                            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>' ) );
1096
+                            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>'));
1097 1097
                         ?>
1098 1098
                     </p>
1099 1099
                 </td>
1100 1100
             </tr>
1101
-            <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"'; } ?>>
1102
-                <th scope="row"><?php _e( 'Load WebP in supported browsers?', 'autoptimize' ); ?></th>
1101
+            <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"'; } ?>>
1102
+                <th scope="row"><?php _e('Load WebP in supported browsers?', 'autoptimize'); ?></th>
1103 1103
                 <td>
1104
-                    <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>
1104
+                    <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>
1105 1105
                 </td>
1106 1106
             </tr>
1107 1107
             <tr>
1108
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1108
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1109 1109
                 <td>
1110
-                    <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>
1110
+                    <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>
1111 1111
                 </td>
1112 1112
             </tr>
1113
-            <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"'; } ?>>
1114
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1113
+            <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"'; } ?>>
1114
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1115 1115
                 <td>
1116
-                    <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>
1116
+                    <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>
1117 1117
                 </td>
1118 1118
             </tr>
1119 1119
         </table>
1120
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1120
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1121 1121
     </form>
1122 1122
     <script>
1123 1123
         jQuery(document).ready(function() {
@@ -1153,50 +1153,50 @@  discard block
 block discarded – undo
1153 1153
      * Ïmg opt status as used on dashboard.
1154 1154
      */
1155 1155
     public function get_imgopt_status_notice() {
1156
-        if ( $this->imgopt_active() ) {
1156
+        if ($this->imgopt_active()) {
1157 1157
             $_imgopt_notice  = '';
1158
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1158
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1159 1159
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1160
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1160
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1161 1161
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1162 1162
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1163 1163
 
1164
-            if ( is_array( $_stat ) ) {
1165
-                if ( 1 == $_stat['Status'] ) {
1164
+            if (is_array($_stat)) {
1165
+                if (1 == $_stat['Status']) {
1166 1166
                     // translators: "add more credits" will appear in a "a href".
1167
-                    $_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>' );
1167
+                    $_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>');
1168 1168
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1169 1169
                     // translators: "add more credits" will appear in a "a href".
1170
-                    $_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>' );
1170
+                    $_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>');
1171 1171
                     // translators: "associate your domain" will appear in a "a href".
1172
-                    $_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>' );
1172
+                    $_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>');
1173 1173
                 } elseif ( -3 == $_stat['Status'] ) {
1174 1174
                     // translators: "check the documentation here" will appear in a "a href".
1175
-                    $_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>' );
1175
+                    $_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>');
1176 1176
                 } else {
1177 1177
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1178 1178
                     // translators: "log in to check your account" will appear in a "a href".
1179
-                    $_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>' );
1179
+                    $_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>');
1180 1180
                 }
1181 1181
 
1182 1182
                 // add info on freshness + refresh link if status is not 2 (good shape).
1183
-                if ( 2 != $_stat['Status'] ) {
1184
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1183
+                if (2 != $_stat['Status']) {
1184
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1185 1185
                         'page'                => 'autoptimize_imgopt',
1186 1186
                         'refreshImgProvStats' => '1',
1187
-                    ), admin_url( 'options-general.php' ) );
1188
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1189
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1187
+                    ), admin_url('options-general.php'));
1188
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1189
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1190 1190
                     } else {
1191
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1191
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1192 1192
                     }
1193
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1193
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1194 1194
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1195
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1195
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1196 1196
                 }
1197 1197
 
1198 1198
                 // and make the full notice filterable.
1199
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1199
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1200 1200
 
1201 1201
                 return array(
1202 1202
                     'status' => $_stat['Status'],
@@ -1217,14 +1217,14 @@  discard block
 block discarded – undo
1217 1217
      * Get img provider stats (used to display notice).
1218 1218
      */
1219 1219
     public function query_img_provider_stats() {
1220
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1220
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1221 1221
             $url      = '';
1222
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1222
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1223 1223
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1224 1224
 
1225 1225
             // make sure parse_url result makes sense, keeping $url empty if not.
1226
-            if ( $domain && ! empty( $domain ) ) {
1227
-                $url = $endpoint . $domain;
1226
+            if ($domain && !empty($domain)) {
1227
+                $url = $endpoint.$domain;
1228 1228
             }
1229 1229
 
1230 1230
             $url = apply_filters(
@@ -1234,12 +1234,12 @@  discard block
 block discarded – undo
1234 1234
 
1235 1235
             // only do the remote call if $url is not empty to make sure no parse_url
1236 1236
             // weirdness results in useless calls.
1237
-            if ( ! empty( $url ) ) {
1238
-                $response = wp_remote_get( $url );
1239
-                if ( ! is_wp_error( $response ) ) {
1240
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1241
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1242
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1237
+            if (!empty($url)) {
1238
+                $response = wp_remote_get($url);
1239
+                if (!is_wp_error($response)) {
1240
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1241
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1242
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1243 1243
                     }
1244 1244
                 }
1245 1245
             }
@@ -1262,15 +1262,15 @@  discard block
 block discarded – undo
1262 1262
     {
1263 1263
         static $launch_status = null;
1264 1264
 
1265
-        if ( null === $launch_status ) {
1265
+        if (null === $launch_status) {
1266 1266
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1267
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1268
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1267
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1268
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1269 1269
             $launch_status = false;
1270
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1270
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1271 1271
                 $launch_status = true;
1272
-                if ( ! $has_launched ) {
1273
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1272
+                if (!$has_launched) {
1273
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1274 1274
                 }
1275 1275
             }
1276 1276
         }
@@ -1287,16 +1287,16 @@  discard block
 block discarded – undo
1287 1287
     public function get_imgopt_provider_userstatus() {
1288 1288
         static $_provider_userstatus = null;
1289 1289
 
1290
-        if ( is_null( $_provider_userstatus ) ) {
1291
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1292
-            if ( is_array( $_stat ) ) {
1293
-                if ( array_key_exists( 'Status', $_stat ) ) {
1290
+        if (is_null($_provider_userstatus)) {
1291
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1292
+            if (is_array($_stat)) {
1293
+                if (array_key_exists('Status', $_stat)) {
1294 1294
                     $_provider_userstatus['Status'] = $_stat['Status'];
1295 1295
                 } else {
1296 1296
                     // if no stats then we assume all is well.
1297 1297
                     $_provider_userstatus['Status'] = 2;
1298 1298
                 }
1299
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1299
+                if (array_key_exists('timestamp', $_stat)) {
1300 1300
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1301 1301
                 } else {
1302 1302
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeMain.php 1 patch
Spacing   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @param string $version Version.
34 34
      * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks.
35 35
      */
36
-    public function __construct( $version, $filepath )
36
+    public function __construct($version, $filepath)
37 37
     {
38 38
         $this->version  = $version;
39 39
         $this->filepath = $filepath;
@@ -50,102 +50,102 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected function add_hooks()
52 52
     {
53
-        if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) {
54
-            define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' );
53
+        if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) {
54
+            define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded');
55 55
         }
56 56
 
57
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) );
58
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) );
57
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup'));
58
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge'));
59 59
 
60
-        add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) );
61
-        add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) );
62
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ), 15 );
63
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ), 20 );
64
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss' ), 11 );
65
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_notfound_fallback' ), 10 );
60
+        add_action('autoptimize_setup_done', array($this, 'version_upgrades_check'));
61
+        add_action('autoptimize_setup_done', array($this, 'check_cache_and_run'));
62
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'), 15);
63
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'), 20);
64
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_criticalcss'), 11);
65
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_notfound_fallback'), 10);
66 66
 
67
-        add_action( 'init', array( $this, 'load_textdomain' ) );
68
-        add_action( 'admin_init', array( 'PAnD', 'init' ) );
67
+        add_action('init', array($this, 'load_textdomain'));
68
+        add_action('admin_init', array('PAnD', 'init'));
69 69
 
70
-        if ( is_multisite() && is_admin() ) {
70
+        if (is_multisite() && is_admin()) {
71 71
             // Only if multisite and if in admin we want to check if we need to save options on network level.
72
-            add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' );
72
+            add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options');
73 73
         }
74 74
 
75 75
         // register uninstall & deactivation hooks.
76
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
77
-        register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' );
76
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
77
+        register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation');
78 78
     }
79 79
 
80 80
     public function load_textdomain()
81 81
     {
82
-        load_plugin_textdomain( 'autoptimize' );
82
+        load_plugin_textdomain('autoptimize');
83 83
     }
84 84
 
85 85
     public function setup()
86 86
     {
87 87
         // Do we gzip in php when caching or is the webserver doing it?
88
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) );
88
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip'));
89 89
 
90 90
         // These can be overridden by specifying them in wp-config.php or such.
91
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
92
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
91
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
92
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
93 93
         }
94
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
95
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
94
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
95
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
96 96
         }
97
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
98
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
97
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
98
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
99 99
         }
100 100
         // Note: trailing slash is not optional!
101
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
102
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
101
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
102
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
103 103
         }
104 104
 
105
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
105
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
106 106
 
107
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
108
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
109
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
107
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
108
+            if (function_exists('domain_mapping_siteurl')) {
109
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
110 110
             } else {
111
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
111
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
112 112
             }
113 113
         }
114
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
115
-            if ( function_exists( 'get_original_url' ) ) {
116
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
114
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
115
+            if (function_exists('get_original_url')) {
116
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
117 117
             } else {
118
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
118
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
119 119
             }
120 120
         }
121
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
122
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
121
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
122
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
123 123
                 $blog_id = get_current_blog_id();
124
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
124
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
125 125
             } else {
126
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
126
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
127 127
             }
128 128
         }
129
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
130
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
129
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
130
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
131 131
         }
132
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
133
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
132
+        if (!defined('AUTOPTIMIZE_HASH')) {
133
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
134 134
         }
135
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
136
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
135
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
136
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
137 137
         }
138 138
 
139 139
         // Multibyte-capable string replacements are available with a filter.
140 140
         // Also requires 'mbstring' extension.
141
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
142
-        if ( $with_mbstring ) {
143
-            autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) );
141
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
142
+        if ($with_mbstring) {
143
+            autoptimizeUtils::mbstring_available(\extension_loaded('mbstring'));
144 144
         } else {
145
-            autoptimizeUtils::mbstring_available( false );
145
+            autoptimizeUtils::mbstring_available(false);
146 146
         }
147 147
 
148
-        do_action( 'autoptimize_setup_done' );
148
+        do_action('autoptimize_setup_done');
149 149
     }
150 150
 
151 151
     /**
@@ -155,61 +155,61 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function version_upgrades_check()
157 157
     {
158
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
158
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
159 159
     }
160 160
 
161 161
     public function check_cache_and_run()
162 162
     {
163
-        if ( autoptimizeCache::cacheavail() ) {
163
+        if (autoptimizeCache::cacheavail()) {
164 164
             $conf = autoptimizeConfig::instance();
165
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) {
166
-                if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) {
165
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) {
166
+                if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) {
167 167
                     // Hook into WordPress frontend.
168
-                    if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
168
+                    if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
169 169
                         add_action(
170 170
                             'init',
171
-                            array( $this, 'start_buffering' ),
171
+                            array($this, 'start_buffering'),
172 172
                             self::INIT_EARLIER_PRIORITY
173 173
                         );
174 174
                     } else {
175
-                        if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
176
-                            define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
175
+                        if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
176
+                            define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
177 177
                         }
178 178
                         add_action(
179
-                            constant( 'AUTOPTIMIZE_HOOK_INTO' ),
180
-                            array( $this, 'start_buffering' ),
179
+                            constant('AUTOPTIMIZE_HOOK_INTO'),
180
+                            array($this, 'start_buffering'),
181 181
                             self::DEFAULT_HOOK_PRIORITY
182 182
                         );
183 183
                     }
184 184
                 }
185 185
 
186 186
                 // And disable Jetpack's site accelerator if JS or CSS opt. are active.
187
-                if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) {
188
-                    add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
187
+                if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) {
188
+                    add_filter('jetpack_force_disable_site_accelerator', '__return_true');
189 189
                 }
190 190
             }
191 191
         } else {
192
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
192
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
193 193
         }
194 194
     }
195 195
 
196 196
     public function maybe_run_ao_extra()
197 197
     {
198
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
198
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
199 199
             $ao_imgopt = new autoptimizeImages();
200 200
             $ao_imgopt->run();
201 201
             $ao_extra = new autoptimizeExtra();
202 202
             $ao_extra->run();
203 203
 
204 204
             // And show the imgopt notice.
205
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
205
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
206 206
         }
207 207
     }
208 208
 
209 209
     public function maybe_run_partners_tab()
210 210
     {
211 211
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
212
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
212
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
213 213
             new autoptimizePartners();
214 214
         }
215 215
     }
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
     public function maybe_run_criticalcss()
218 218
     {
219 219
         // Loads criticalcss if the power-up is not active and if the filter returns true.
220
-        if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
220
+        if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) {
221 221
             new autoptimizeCriticalCSSBase();
222 222
         }
223 223
     }
224 224
 
225 225
     public function maybe_run_notfound_fallback()
226 226
     {
227
-        if ( autoptimizeCache::do_fallback() ) {
228
-            add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) );
227
+        if (autoptimizeCache::do_fallback()) {
228
+            add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback'));
229 229
         }
230 230
     }
231 231
 
232 232
     public function hook_page_cache_purge()
233 233
     {
234 234
         // hook into a collection of page cache purge actions if filter allows.
235
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
235
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
236 236
             $page_cache_purge_actions = array(
237 237
                 'after_rocket_clean_domain', // exists.
238 238
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
                 'wpo_cache_flush', // wp-optimize.
248 248
                 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper.
249 249
             );
250
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
251
-            foreach ( $page_cache_purge_actions as $purge_action ) {
252
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
250
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
251
+            foreach ($page_cache_purge_actions as $purge_action) {
252
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
253 253
             }
254 254
         }
255 255
     }
@@ -261,38 +261,38 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function start_buffering()
263 263
     {
264
-        if ( $this->should_buffer() ) {
264
+        if ($this->should_buffer()) {
265 265
 
266 266
             // Load speedupper conditionally (true by default).
267
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
267
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
268 268
                 $ao_speedupper = new autoptimizeSpeedupper();
269 269
             }
270 270
 
271 271
             $conf = autoptimizeConfig::instance();
272 272
 
273
-            if ( $conf->get( 'autoptimize_js' ) ) {
274
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
275
-                    define( 'CONCATENATE_SCRIPTS', false );
273
+            if ($conf->get('autoptimize_js')) {
274
+                if (!defined('CONCATENATE_SCRIPTS')) {
275
+                    define('CONCATENATE_SCRIPTS', false);
276 276
                 }
277
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
278
-                    define( 'COMPRESS_SCRIPTS', false );
277
+                if (!defined('COMPRESS_SCRIPTS')) {
278
+                    define('COMPRESS_SCRIPTS', false);
279 279
                 }
280 280
             }
281 281
 
282
-            if ( $conf->get( 'autoptimize_css' ) ) {
283
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
284
-                    define( 'COMPRESS_CSS', false );
282
+            if ($conf->get('autoptimize_css')) {
283
+                if (!defined('COMPRESS_CSS')) {
284
+                    define('COMPRESS_CSS', false);
285 285
                 }
286 286
             }
287 287
 
288
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
289
-                while ( ob_get_level() > 0 ) {
288
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
289
+                while (ob_get_level() > 0) {
290 290
                     ob_end_clean();
291 291
                 }
292 292
             }
293 293
 
294 294
             // Now, start the real thing!
295
-            ob_start( array( $this, 'end_buffering' ) );
295
+            ob_start(array($this, 'end_buffering'));
296 296
         }
297 297
     }
298 298
 
@@ -303,31 +303,31 @@  discard block
 block discarded – undo
303 303
      *                          deciding once per request (for use in tests).
304 304
      * @return bool
305 305
      */
306
-    public static function should_buffer( $doing_tests = false )
306
+    public static function should_buffer($doing_tests = false)
307 307
     {
308 308
         static $do_buffering = null;
309 309
 
310 310
         // Only check once in case we're called multiple times by others but
311 311
         // still allows multiple calls when doing tests.
312
-        if ( null === $do_buffering || $doing_tests ) {
312
+        if (null === $do_buffering || $doing_tests) {
313 313
 
314 314
             $ao_noptimize = false;
315 315
 
316 316
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
317
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
317
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
318 318
                 $ao_noptimize = true;
319 319
             }
320 320
 
321 321
             // Skip checking query strings if they're disabled.
322
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
322
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
323 323
                 // Check for `ao_noptimize` (and other) keys in the query string
324 324
                 // to get non-optimized page for debugging.
325 325
                 $keys = array(
326 326
                     'ao_noptimize',
327 327
                     'ao_noptirocket',
328 328
                 );
329
-                foreach ( $keys as $key ) {
330
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
329
+                foreach ($keys as $key) {
330
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
331 331
                         $ao_noptimize = true;
332 332
                         break;
333 333
                     }
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
             }
336 336
 
337 337
             // If setting says not to optimize logged in user and user is logged in...
338
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
338
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
339 339
                 $ao_noptimize = true;
340 340
             }
341 341
 
342 342
             // If setting says not to optimize cart/checkout.
343
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) {
343
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) {
344 344
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
345
-                foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
346
-                    if ( function_exists( $func ) && $func() ) {
345
+                foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
346
+                    if (function_exists($func) && $func()) {
347 347
                         $ao_noptimize = true;
348 348
                         break;
349 349
                     }
@@ -351,10 +351,10 @@  discard block
 block discarded – undo
351 351
             }
352 352
 
353 353
             // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
354
-            if ( false === $ao_noptimize ) {
355
-                $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
356
-                foreach ( $_qs_pagebuilders as $_pagebuilder ) {
357
-                    if ( array_key_exists( $_pagebuilder, $_GET ) ) {
354
+            if (false === $ao_noptimize) {
355
+                $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor');
356
+                foreach ($_qs_pagebuilders as $_pagebuilder) {
357
+                    if (array_key_exists($_pagebuilder, $_GET)) {
358 358
                         $ao_noptimize = true;
359 359
                         break;
360 360
                     }
@@ -363,16 +363,16 @@  discard block
 block discarded – undo
363 363
 
364 364
             // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
365 365
             // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
366
-            if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
366
+            if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
367 367
                 $ao_noptimize = true;
368 368
             }
369 369
 
370 370
             // And finally allows blocking of autoptimization on your own terms regardless of above decisions.
371
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
371
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
372 372
 
373 373
             // Check for site being previewed in the Customizer (available since WP 4.0).
374 374
             $is_customize_preview = false;
375
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
375
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
376 376
                 $is_customize_preview = is_customize_preview();
377 377
             }
378 378
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
              * while the main query hasn't been ran yet. Thats why we use
384 384
              * AUTOPTIMIZE_INIT_EARLIER in tests.
385 385
              */
386
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview );
386
+            $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview);
387 387
         }
388 388
 
389 389
         return $do_buffering;
@@ -396,25 +396,25 @@  discard block
 block discarded – undo
396 396
      *
397 397
      * @return bool
398 398
      */
399
-    public function is_valid_buffer( $content )
399
+    public function is_valid_buffer($content)
400 400
     {
401 401
         // Defaults to true.
402 402
         $valid = true;
403 403
 
404
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
405
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) );
406
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 );
407
-        $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) );
404
+        $has_no_html_tag    = (false === stripos($content, '<html'));
405
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet'));
406
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0);
407
+        $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->'));
408 408
 
409
-        if ( $has_no_html_tag ) {
409
+        if ($has_no_html_tag) {
410 410
             // Can't be valid amp markup without an html tag preceding it.
411 411
             $is_amp_markup = false;
412 412
         } else {
413
-            $is_amp_markup = self::is_amp_markup( $content );
413
+            $is_amp_markup = self::is_amp_markup($content);
414 414
         }
415 415
 
416 416
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
417
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) {
417
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) {
418 418
             $valid = false;
419 419
         }
420 420
 
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
      *
430 430
      * @return bool
431 431
      */
432
-    public static function is_amp_markup( $content )
432
+    public static function is_amp_markup($content)
433 433
     {
434 434
         // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page.
435
-        if ( function_exists( 'is_amp_endpoint' ) ) {
435
+        if (function_exists('is_amp_endpoint')) {
436 436
             return is_amp_endpoint();
437 437
         }
438 438
 
439
-        $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content );
439
+        $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content);
440 440
 
441 441
         return (bool) $is_amp_markup;
442 442
     }
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
      *
450 450
      * @return string
451 451
      */
452
-    public function end_buffering( $content )
452
+    public function end_buffering($content)
453 453
     {
454 454
         // Bail early without modifying anything if we can't handle the content.
455
-        if ( ! $this->is_valid_buffer( $content ) ) {
455
+        if (!$this->is_valid_buffer($content)) {
456 456
             return $content;
457 457
         }
458 458
 
@@ -460,73 +460,73 @@  discard block
 block discarded – undo
460 460
 
461 461
         // Determine what needs to be ran.
462 462
         $classes = array();
463
-        if ( $conf->get( 'autoptimize_js' ) ) {
463
+        if ($conf->get('autoptimize_js')) {
464 464
             $classes[] = 'autoptimizeScripts';
465 465
         }
466
-        if ( $conf->get( 'autoptimize_css' ) ) {
466
+        if ($conf->get('autoptimize_css')) {
467 467
             $classes[] = 'autoptimizeStyles';
468 468
         }
469
-        if ( $conf->get( 'autoptimize_html' ) ) {
469
+        if ($conf->get('autoptimize_html')) {
470 470
             $classes[] = 'autoptimizeHTML';
471 471
         }
472 472
 
473 473
         $classoptions = array(
474 474
             'autoptimizeScripts' => array(
475
-                'aggregate'       => $conf->get( 'autoptimize_js_aggregate' ),
476
-                'justhead'        => $conf->get( 'autoptimize_js_justhead' ),
477
-                'forcehead'       => $conf->get( 'autoptimize_js_forcehead' ),
478
-                'trycatch'        => $conf->get( 'autoptimize_js_trycatch' ),
479
-                'js_exclude'      => $conf->get( 'autoptimize_js_exclude' ),
480
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
481
-                'include_inline'  => $conf->get( 'autoptimize_js_include_inline' ),
482
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
475
+                'aggregate'       => $conf->get('autoptimize_js_aggregate'),
476
+                'justhead'        => $conf->get('autoptimize_js_justhead'),
477
+                'forcehead'       => $conf->get('autoptimize_js_forcehead'),
478
+                'trycatch'        => $conf->get('autoptimize_js_trycatch'),
479
+                'js_exclude'      => $conf->get('autoptimize_js_exclude'),
480
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
481
+                'include_inline'  => $conf->get('autoptimize_js_include_inline'),
482
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
483 483
             ),
484 484
             'autoptimizeStyles'  => array(
485
-                'aggregate'       => $conf->get( 'autoptimize_css_aggregate' ),
486
-                'justhead'        => $conf->get( 'autoptimize_css_justhead' ),
487
-                'datauris'        => $conf->get( 'autoptimize_css_datauris' ),
488
-                'defer'           => $conf->get( 'autoptimize_css_defer' ),
489
-                'defer_inline'    => $conf->get( 'autoptimize_css_defer_inline' ),
490
-                'inline'          => $conf->get( 'autoptimize_css_inline' ),
491
-                'css_exclude'     => $conf->get( 'autoptimize_css_exclude' ),
492
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
493
-                'include_inline'  => $conf->get( 'autoptimize_css_include_inline' ),
494
-                'nogooglefont'    => $conf->get( 'autoptimize_css_nogooglefont' ),
495
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
485
+                'aggregate'       => $conf->get('autoptimize_css_aggregate'),
486
+                'justhead'        => $conf->get('autoptimize_css_justhead'),
487
+                'datauris'        => $conf->get('autoptimize_css_datauris'),
488
+                'defer'           => $conf->get('autoptimize_css_defer'),
489
+                'defer_inline'    => $conf->get('autoptimize_css_defer_inline'),
490
+                'inline'          => $conf->get('autoptimize_css_inline'),
491
+                'css_exclude'     => $conf->get('autoptimize_css_exclude'),
492
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
493
+                'include_inline'  => $conf->get('autoptimize_css_include_inline'),
494
+                'nogooglefont'    => $conf->get('autoptimize_css_nogooglefont'),
495
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
496 496
             ),
497 497
             'autoptimizeHTML'    => array(
498
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
498
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
499 499
             ),
500 500
         );
501 501
 
502
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
502
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
503 503
 
504 504
         // Run the classes!
505
-        foreach ( $classes as $name ) {
506
-            $instance = new $name( $content );
507
-            if ( $instance->read( $classoptions[ $name ] ) ) {
505
+        foreach ($classes as $name) {
506
+            $instance = new $name($content);
507
+            if ($instance->read($classoptions[$name])) {
508 508
                 $instance->minify();
509 509
                 $instance->cache();
510 510
                 $content = $instance->getcontent();
511 511
             }
512
-            unset( $instance );
512
+            unset($instance);
513 513
         }
514 514
 
515
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
515
+        $content = apply_filters('autoptimize_html_after_minify', $content);
516 516
 
517 517
         return $content;
518 518
     }
519 519
 
520
-    public static function autoptimize_nobuffer_optimize( $html_in ) {
520
+    public static function autoptimize_nobuffer_optimize($html_in) {
521 521
         $html_out = $html_in;
522 522
 
523
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
523
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
524 524
             $ao_speedupper = new autoptimizeSpeedupper();
525 525
         }
526 526
 
527
-        $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
528
-        if ( $self->should_buffer() ) {
529
-            $html_out = $self->end_buffering( $html_in );
527
+        $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
528
+        if ($self->should_buffer()) {
529
+            $html_out = $self->end_buffering($html_in);
530 530
         }
531 531
         return $html_out;
532 532
     }
@@ -587,45 +587,45 @@  discard block
 block discarded – undo
587 587
             'autoptimize_ccss_domain',
588 588
         );
589 589
 
590
-        if ( ! is_multisite() ) {
591
-            foreach ( $delete_options as $del_opt ) {
592
-                delete_option( $del_opt );
590
+        if (!is_multisite()) {
591
+            foreach ($delete_options as $del_opt) {
592
+                delete_option($del_opt);
593 593
             }
594 594
             autoptimizeMain::remove_cronjobs();
595 595
         } else {
596 596
             global $wpdb;
597
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
597
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
598 598
             $original_blog_id = get_current_blog_id();
599
-            foreach ( $blog_ids as $blog_id ) {
600
-                switch_to_blog( $blog_id );
601
-                foreach ( $delete_options as $del_opt ) {
602
-                    delete_option( $del_opt );
599
+            foreach ($blog_ids as $blog_id) {
600
+                switch_to_blog($blog_id);
601
+                foreach ($delete_options as $del_opt) {
602
+                    delete_option($del_opt);
603 603
                 }
604 604
                 autoptimizeMain::remove_cronjobs();
605 605
             }
606
-            switch_to_blog( $original_blog_id );
606
+            switch_to_blog($original_blog_id);
607 607
         }
608 608
 
609 609
         // Remove AO CCSS cached files and directory.
610
-        $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/';
611
-        if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) {
610
+        $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/';
611
+        if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) {
612 612
             // fixme: should check for subdirs when in multisite and remove contents of those as well.
613
-            array_map( 'unlink', glob( AO_CCSS_DIR . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) );
614
-            rmdir( AO_CCSS_DIR );
613
+            array_map('unlink', glob(AO_CCSS_DIR.'*.{css,html,json,log,zip,lock}', GLOB_BRACE));
614
+            rmdir(AO_CCSS_DIR);
615 615
         }
616 616
     }
617 617
 
618 618
     public static function on_deactivation()
619 619
     {
620
-        if ( is_multisite() && is_network_admin() ) {
620
+        if (is_multisite() && is_network_admin()) {
621 621
             global $wpdb;
622
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
622
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
623 623
             $original_blog_id = get_current_blog_id();
624
-            foreach ( $blog_ids as $blog_id ) {
625
-                switch_to_blog( $blog_id );
624
+            foreach ($blog_ids as $blog_id) {
625
+                switch_to_blog($blog_id);
626 626
                 autoptimizeMain::remove_cronjobs();
627 627
             }
628
-            switch_to_blog( $original_blog_id );
628
+            switch_to_blog($original_blog_id);
629 629
         } else {
630 630
             autoptimizeMain::remove_cronjobs();
631 631
         }
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 
635 635
     public static function remove_cronjobs() {
636 636
         // Remove scheduled events.
637
-        foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) {
638
-            if ( wp_get_schedule( $_event ) ) {
639
-                wp_clear_scheduled_hook( $_event );
637
+        foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) {
638
+            if (wp_get_schedule($_event)) {
639
+                wp_clear_scheduled_hook($_event);
640 640
             }
641 641
         }
642 642
     }
@@ -645,35 +645,35 @@  discard block
 block discarded – undo
645 645
     {
646 646
         echo '<div class="error"><p>';
647 647
         // Translators: %s is the cache directory location.
648
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
648
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
649 649
         echo '</p></div>';
650 650
     }
651 651
 
652 652
     public static function notice_installed()
653 653
     {
654 654
         echo '<div class="updated"><p>';
655
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
655
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
656 656
         echo '</p></div>';
657 657
     }
658 658
 
659 659
     public static function notice_updated()
660 660
     {
661 661
         echo '<div class="updated"><p>';
662
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
662
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
663 663
         echo '</p></div>';
664 664
     }
665 665
 
666 666
     public static function notice_plug_imgopt()
667 667
     {
668 668
         // Translators: the URL added points to the Autopmize Extra settings.
669
-        $_ao_imgopt_plug_notice      = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' );
670
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
669
+        $_ao_imgopt_plug_notice      = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>');
670
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
671 671
         $_ao_imgopt_launch_ok        = autoptimizeImages::launch_ok_wrapper();
672 672
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
673 673
         $_ao_imgopt_active           = autoptimizeImages::imgopt_active();
674 674
 
675
-        if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) {
676
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
675
+        if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) {
676
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
677 677
             echo $_ao_imgopt_plug_notice;
678 678
             echo '</p></div>';
679 679
         }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSEnqueue.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 job enqueue logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
19 19
     }
20 20
 
21
-    public static function ao_ccss_enqueue( $hash ) {
21
+    public static function ao_ccss_enqueue($hash) {
22 22
         $self = new self();
23 23
         // Get key status.
24
-        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( false );
24
+        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(false);
25 25
 
26 26
         // Queue is available to anyone...
27 27
         $enqueue = true;
28 28
 
29 29
         // ... which are not the ones below.
30
-        if ( is_user_logged_in() || is_feed() || is_404() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] ) {
30
+        if (is_user_logged_in() || is_feed() || is_404() || (defined('DOING_AJAX') && DOING_AJAX) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status']) {
31 31
             $enqueue = false;
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( "Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log("Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3);
33 33
         }
34 34
 
35
-        if ( $enqueue ) {
35
+        if ($enqueue) {
36 36
             // Continue if queue is available
37 37
             // Attach required arrays/ vars.
38 38
             global $ao_ccss_rules;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             global $ao_ccss_forcepath;
42 42
 
43 43
             // Get request path and page type, and initialize the queue update flag.
44
-            $req_path        = strtok( $_SERVER['REQUEST_URI'], '?' );
44
+            $req_path        = strtok($_SERVER['REQUEST_URI'], '?');
45 45
             $req_type        = $self->ao_ccss_get_type();
46 46
             $job_qualify     = false;
47 47
             $target_rule     = false;
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             $queue_update    = false;
50 50
 
51 51
             // Match for paths in rules.
52
-            foreach ( $ao_ccss_rules['paths'] as $path => $props ) {
52
+            foreach ($ao_ccss_rules['paths'] as $path => $props) {
53 53
 
54 54
                 // Prepare rule target and log.
55
-                $target_rule = 'paths|' . $path;
56
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
55
+                $target_rule = 'paths|'.$path;
56
+                autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
57 57
 
58 58
                 // Path match
59 59
                 // -> exact match needed for AUTO rules
60 60
                 // -> partial match OK for MANUAL rules (which have empty hash and a file with CCSS).
61
-                if ( $path === $req_path || ( false == $props['hash'] && false != $props['file'] && preg_match( '|' . $path . '|', $req_path ) ) ) {
61
+                if ($path === $req_path || (false == $props['hash'] && false != $props['file'] && preg_match('|'.$path.'|', $req_path))) {
62 62
 
63 63
                     // There's a path match in the rule, so job QUALIFIES with a path rule match.
64 64
                     $job_qualify     = true;
65 65
                     $rule_properties = $props;
66
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
66
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
67 67
 
68 68
                     // Stop processing other path rules.
69 69
                     break;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
             }
72 72
 
73 73
             // Match for types in rules if no path rule matches and if we're not enforcing paths.
74
-            if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) {
75
-                foreach ( $ao_ccss_rules['types'] as $type => $props ) {
74
+            if (!$job_qualify && (!$ao_ccss_forcepath || !in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page'))) || !apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false))) {
75
+                foreach ($ao_ccss_rules['types'] as $type => $props) {
76 76
 
77 77
                     // Prepare rule target and log.
78
-                    $target_rule = 'types|' . $type;
79
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying page type <' . $req_type . '> on path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
78
+                    $target_rule = 'types|'.$type;
79
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying page type <'.$req_type.'> on path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
80 80
 
81
-                    if ( $req_type == $type ) {
81
+                    if ($req_type == $type) {
82 82
                         // Type match.
83 83
                         // There's a type match in the rule, so job QUALIFIES with a type rule match.
84 84
                         $job_qualify     = true;
85 85
                         $rule_properties = $props;
86
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Page type <' . $req_type . '> on path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
86
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Page type <'.$req_type.'> on path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
87 87
 
88 88
                         // Stop processing other type rules.
89 89
                         break;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 }
92 92
             }
93 93
 
94
-            if ( $job_qualify && false == $rule_properties['hash'] && false != $rule_properties['file'] ) {
94
+            if ($job_qualify && false == $rule_properties['hash'] && false != $rule_properties['file']) {
95 95
                 // If job qualifies but rule hash is false and file isn't false  (MANUAL rule), job does not qualify despite what previous evaluations says.
96 96
                 $job_qualify = false;
97
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission DISQUALIFIED by MANUAL rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
98
-            } elseif ( ! $job_qualify && empty( $rule_properties ) ) {
97
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission DISQUALIFIED by MANUAL rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
98
+            } elseif (!$job_qualify && empty($rule_properties)) {
99 99
                 // But if job does not qualify and rule properties are set, job qualifies as there is no matching rule for it yet
100 100
                 // Fill-in the new target rule.
101 101
                 $job_qualify = true;
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
                 // Should we switch to path-base AUTO-rules? Conditions:
104 104
                 // 1. forcepath option has to be enabled (off by default)
105 105
                 // 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category).
106
-                if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) {
107
-                    if ( '/' !== $req_path ) {
108
-                        $target_rule = 'paths|' . $req_path;
106
+                if (($ao_ccss_forcepath && in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page')))) || apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false)) {
107
+                    if ('/' !== $req_path) {
108
+                        $target_rule = 'paths|'.$req_path;
109 109
                     } else {
110 110
                         // Exception; we don't want a path-based rule for "/" as that messes things up, hard-switch this to a type-based is_front_page rule.
111
-                        $target_rule = 'types|' . 'is_front_page';
111
+                        $target_rule = 'types|'.'is_front_page';
112 112
                     }
113 113
                 } else {
114
-                    $target_rule = 'types|' . $req_type;
114
+                    $target_rule = 'types|'.$req_type;
115 115
                 }
116
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by MISSING rule for page type <' . $req_type . '> on path <' . $req_path . '>, new rule target is <' . $target_rule . '>', 3 );
116
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by MISSING rule for page type <'.$req_type.'> on path <'.$req_path.'>, new rule target is <'.$target_rule.'>', 3);
117 117
             } else {
118 118
                 // Or just log a job qualified by a matching rule.
119
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by AUTO rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
119
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by AUTO rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
120 120
             }
121 121
 
122 122
             // Submit job.
123
-            if ( $job_qualify ) {
124
-                if ( ! array_key_exists( $req_path, $ao_ccss_queue ) ) {
123
+            if ($job_qualify) {
124
+                if (!array_key_exists($req_path, $ao_ccss_queue)) {
125 125
                     // This is a NEW job
126 126
                     // Merge job into the queue.
127
-                    $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
127
+                    $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
128 128
                         $req_path,
129 129
                         $target_rule,
130 130
                         $req_type,
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
                 } else {
141 141
                     // This is an existing job
142 142
                     // The job is still NEW, most likely this is extra CSS file for the same page that needs a hash.
143
-                    if ( 'NEW' == $ao_ccss_queue[ $req_path ]['jqstat'] ) {
143
+                    if ('NEW' == $ao_ccss_queue[$req_path]['jqstat']) {
144 144
                         // Add hash if it's not already in the job.
145
-                        if ( ! in_array( $hash, $ao_ccss_queue[ $req_path ]['hashes'] ) ) {
145
+                        if (!in_array($hash, $ao_ccss_queue[$req_path]['hashes'])) {
146 146
                             // Push new hash to its array and update flag.
147
-                            $queue_update = array_push( $ao_ccss_queue[ $req_path ]['hashes'], $hash );
147
+                            $queue_update = array_push($ao_ccss_queue[$req_path]['hashes'], $hash);
148 148
 
149 149
                             // Log job update.
150
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Hashes UPDATED on local job id <' . $ao_ccss_queue[ $req_path ]['ljid'] . '>, job status NEW, target rule <' . $ao_ccss_queue[ $req_path ]['rtarget'] . '>, hash added: ' . $hash, 3 );
150
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Hashes UPDATED on local job id <'.$ao_ccss_queue[$req_path]['ljid'].'>, job status NEW, target rule <'.$ao_ccss_queue[$req_path]['rtarget'].'>, hash added: '.$hash, 3);
151 151
 
152 152
                             // Return from here as the hash array is already updated.
153 153
                             return true;
154 154
                         }
155
-                    } elseif ( 'NEW' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[ $req_path ]['jqstat'] ) {
155
+                    } elseif ('NEW' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[$req_path]['jqstat']) {
156 156
                         // Allow requeuing jobs that are not NEW, JOB_QUEUED or JOB_ONGOING
157 157
                         // Merge new job keeping some previous job values.
158
-                        $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
158
+                        $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
159 159
                             $req_path,
160 160
                             $target_rule,
161 161
                             $req_type,
162 162
                             $hash,
163
-                            $ao_ccss_queue[ $req_path ]['file'],
164
-                            $ao_ccss_queue[ $req_path ]['jid'],
165
-                            $ao_ccss_queue[ $req_path ]['jrstat'],
166
-                            $ao_ccss_queue[ $req_path ]['jvstat'],
163
+                            $ao_ccss_queue[$req_path]['file'],
164
+                            $ao_ccss_queue[$req_path]['jid'],
165
+                            $ao_ccss_queue[$req_path]['jrstat'],
166
+                            $ao_ccss_queue[$req_path]['jvstat'],
167 167
                             false
168 168
                         );
169 169
                         // Set update flag.
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
                     }
172 172
                 }
173 173
 
174
-                if ( $queue_update ) {
174
+                if ($queue_update) {
175 175
                     // Persist the job to the queue and return.
176
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
177
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
176
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
177
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
178 178
                     return true;
179 179
                 } else {
180 180
                     // Or just return false if no job was added.
181
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A job for path <' . $req_path . '> already exist with NEW or PENDING status, skipping job creation', 3 );
181
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A job for path <'.$req_path.'> already exist with NEW or PENDING status, skipping job creation', 3);
182 182
                     return false;
183 183
                 }
184 184
             }
@@ -194,25 +194,25 @@  discard block
 block discarded – undo
194 194
         $page_type = false;
195 195
 
196 196
         // Iterates over the array to match a type.
197
-        foreach ( $ao_ccss_types as $type ) {
198
-            if ( is_404() ) {
197
+        foreach ($ao_ccss_types as $type) {
198
+            if (is_404()) {
199 199
                 $page_type = 'is_404';
200 200
                 break;
201
-            } elseif ( strpos( $type, 'custom_post_' ) !== false ) {
201
+            } elseif (strpos($type, 'custom_post_') !== false) {
202 202
                 // Match custom post types.
203
-                if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
203
+                if (get_post_type(get_the_ID()) === substr($type, 12)) {
204 204
                     $page_type = $type;
205 205
                     break;
206 206
                 }
207
-            } elseif ( strpos( $type, 'template_' ) !== false ) {
207
+            } elseif (strpos($type, 'template_') !== false) {
208 208
                 // If templates; don't break, templates become manual-only rules.
209 209
             } else {
210 210
                 // Match all other existing types
211 211
                 // but remove prefix to be able to check if the function exists & returns true.
212
-                $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
213
-                if ( function_exists( $_type ) && call_user_func( $_type ) ) {
212
+                $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
213
+                if (function_exists($_type) && call_user_func($_type)) {
214 214
                     // Make sure we only return is_front_page (and is_home) for one page, not for the "paged frontpage" (/page/2 ..).
215
-                    if ( ( 'is_front_page' !== $_type && 'is_home' !== $_type ) || ! is_paged() ) {
215
+                    if (('is_front_page' !== $_type && 'is_home' !== $_type) || !is_paged()) {
216 216
                         $page_type = $type;
217 217
                         break;
218 218
                     }
@@ -224,44 +224,44 @@  discard block
 block discarded – undo
224 224
         return $page_type;
225 225
     }
226 226
 
227
-    public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
227
+    public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) {
228 228
         // Define a job entry to be created or updated
229 229
         // Define commom job properties.
230 230
         $path            = array();
231 231
         $path['ljid']    = $this->ao_ccss_job_id();
232 232
         $path['rtarget'] = $target;
233 233
         $path['ptype']   = $type;
234
-        $path['hashes']  = array( $hash );
234
+        $path['hashes']  = array($hash);
235 235
         $path['hash']    = $hash;
236 236
         $path['file']    = $file;
237 237
         $path['jid']     = $jid;
238 238
         $path['jqstat']  = 'NEW';
239 239
         $path['jrstat']  = $jrstat;
240 240
         $path['jvstat']  = $jvstat;
241
-        $path['jctime']  = microtime( true );
241
+        $path['jctime']  = microtime(true);
242 242
         $path['jftime']  = null;
243 243
 
244 244
         // Set operation requested.
245
-        if ( $create ) {
245
+        if ($create) {
246 246
             $operation = 'CREATED';
247 247
         } else {
248 248
             $operation = 'UPDATED';
249 249
         }
250 250
 
251 251
         // Log job creation.
252
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 );
252
+        autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3);
253 253
 
254 254
         return $path;
255 255
     }
256 256
 
257
-    public function ao_ccss_job_id( $length = 6 ) {
257
+    public function ao_ccss_job_id($length = 6) {
258 258
         // Generate random strings for the local job ID
259 259
         // Based on https://stackoverflow.com/a/4356295 .
260 260
         $characters        = '0123456789abcdefghijklmnopqrstuvwxyz';
261
-        $characters_length = strlen( $characters );
261
+        $characters_length = strlen($characters);
262 262
         $random_string     = 'j-';
263
-        for ( $i = 0; $i < $length; $i++ ) {
264
-            $random_string .= $characters[ rand( 0, $characters_length - 1 ) ];
263
+        for ($i = 0; $i < $length; $i++) {
264
+            $random_string .= $characters[rand(0, $characters_length - 1)];
265 265
         }
266 266
         return $random_string;
267 267
     }
@@ -269,17 +269,17 @@  discard block
 block discarded – undo
269 269
     public function ao_ccss_ua() {
270 270
         // Check for criticalcss.com user agent.
271 271
         $agent = '';
272
-        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
272
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
273 273
             $agent = $_SERVER['HTTP_USER_AGENT'];
274 274
         }
275 275
 
276 276
         // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not.
277
-        $rtn = strpos( $agent, AO_CCSS_URL );
278
-        if ( 0 === $rtn ) {
277
+        $rtn = strpos($agent, AO_CCSS_URL);
278
+        if (0 === $rtn) {
279 279
             $rtn = true;
280 280
         } else {
281 281
             $rtn = false;
282 282
         }
283
-        return ( $rtn );
283
+        return ($rtn);
284 284
     }
285 285
 }
Please login to merge, or discard this patch.