Completed
Push — master ( d10a3b...267ab8 )
by frank
01:54
created
classes/autoptimizeCriticalCSSCron.php 1 patch
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * processes the queue, submitting jobs to criticalcss.com and retrieving generated CSS from criticalcss.com and saving rules.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -13,23 +13,23 @@  discard block
 block discarded – undo
13 13
     {
14 14
         // fetch all options at once and populate them individually explicitely as globals.
15 15
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
16
-        foreach ( $all_options as $_option => $_value ) {
16
+        foreach ($all_options as $_option => $_value) {
17 17
             global ${$_option};
18 18
             ${$_option} = $_value;
19 19
         }
20 20
 
21 21
         // Add queue control to a registered event.
22
-        add_action( 'ao_ccss_queue', array( $this, 'ao_ccss_queue_control' ) );
22
+        add_action('ao_ccss_queue', array($this, 'ao_ccss_queue_control'));
23 23
         // Add cleaning job to a registered event.
24
-        add_action( 'ao_ccss_maintenance', array( $this, 'ao_ccss_cleaning' ) );
24
+        add_action('ao_ccss_maintenance', array($this, 'ao_ccss_cleaning'));
25 25
     }
26 26
 
27 27
     public function ao_ccss_queue_control() {
28 28
         // The queue execution backend.
29 29
         global $ao_ccss_key;
30
-        if ( ! isset( $ao_ccss_key ) || empty( $ao_ccss_key ) ) {
30
+        if (!isset($ao_ccss_key) || empty($ao_ccss_key)) {
31 31
             // no key set, not processing the queue!
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No key set, so not processing queue.', 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log('No key set, so not processing queue.', 3);
33 33
             return;
34 34
         }
35 35
 
@@ -50,35 +50,35 @@  discard block
 block discarded – undo
50 50
          *    When properly set, queue will always finish a job with the declared settings above regardless of the real API responses.
51 51
          */
52 52
         $queue_debug = false;
53
-        if ( file_exists( AO_CCSS_DEBUG ) ) {
54
-            $qdobj_raw = file_get_contents( AO_CCSS_DEBUG );
55
-            $qdobj     = json_decode( $qdobj_raw, true );
56
-            if ( $qdobj ) {
57
-                if ( 1 === $qdobj['enable'] ) {
53
+        if (file_exists(AO_CCSS_DEBUG)) {
54
+            $qdobj_raw = file_get_contents(AO_CCSS_DEBUG);
55
+            $qdobj     = json_decode($qdobj_raw, true);
56
+            if ($qdobj) {
57
+                if (1 === $qdobj['enable']) {
58 58
                     $queue_debug = true;
59
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue operating in debug mode with the following settings: <' . $qdobj_raw . '>', 3 );
59
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue operating in debug mode with the following settings: <'.$qdobj_raw.'>', 3);
60 60
                 }
61 61
             }
62 62
         }
63 63
 
64 64
         // Set some default values for $qdobj to avoid function call warnings.
65
-        if ( ! $queue_debug ) {
65
+        if (!$queue_debug) {
66 66
             $qdobj['htcode'] = false;
67 67
         }
68 68
 
69 69
         // Check if queue is already running.
70 70
         $queue_lock = false;
71
-        if ( file_exists( AO_CCSS_LOCK ) ) {
71
+        if (file_exists(AO_CCSS_LOCK)) {
72 72
             $queue_lock = true;
73 73
         }
74 74
 
75 75
         // Proceed with the queue if it's not already running.
76
-        if ( ! $queue_lock ) {
76
+        if (!$queue_lock) {
77 77
 
78 78
             // Log queue start and create the lock file.
79
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control started', 3 );
80
-            if ( touch( AO_CCSS_LOCK ) ) {
81
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control locked', 3 );
79
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control started', 3);
80
+            if (touch(AO_CCSS_LOCK)) {
81
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control locked', 3);
82 82
             }
83 83
 
84 84
             // Attach required variables.
@@ -88,223 +88,223 @@  discard block
 block discarded – undo
88 88
             // Initialize job counters.
89 89
             $jc = 1;
90 90
             $jr = 1;
91
-            $jt = count( $ao_ccss_queue );
91
+            $jt = count($ao_ccss_queue);
92 92
 
93 93
             // Sort queue by ascending job status (e.g. ERROR, JOB_ONGOING, JOB_QUEUED, NEW...).
94
-            array_multisort( array_column( $ao_ccss_queue, 'jqstat' ), $ao_ccss_queue ); // @codingStandardsIgnoreLine
94
+            array_multisort(array_column($ao_ccss_queue, 'jqstat'), $ao_ccss_queue); // @codingStandardsIgnoreLine
95 95
 
96 96
             // Iterates over the entire queue.
97
-            foreach ( $ao_ccss_queue as $path => $jprops ) {
97
+            foreach ($ao_ccss_queue as $path => $jprops) {
98 98
                 // Prepare flags and target rule.
99 99
                 $update      = false;
100 100
                 $deljob      = false;
101 101
                 $rule_update = false;
102 102
                 $oldccssfile = false;
103
-                $trule       = explode( '|', $jprops['rtarget'] );
103
+                $trule       = explode('|', $jprops['rtarget']);
104 104
 
105 105
                 // Log job count.
106
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Processing job ' . $jc . ' of ' . $jt . ' with id <' . $jprops['ljid'] . '> and status <' . $jprops['jqstat'] . '>', 3 );
106
+                autoptimizeCriticalCSSCore::ao_ccss_log('Processing job '.$jc.' of '.$jt.' with id <'.$jprops['ljid'].'> and status <'.$jprops['jqstat'].'>', 3);
107 107
 
108 108
                 // Process NEW jobs.
109
-                if ( 'NEW' == $jprops['jqstat'] ) {
109
+                if ('NEW' == $jprops['jqstat']) {
110 110
 
111 111
                     // Log the new job.
112
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found NEW job with local ID <' . $jprops['ljid'] . '>, starting its queue processing', 3 );
112
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found NEW job with local ID <'.$jprops['ljid'].'>, starting its queue processing', 3);
113 113
 
114 114
                     // Compare job and rule hashes (if any).
115
-                    $hash = $this->ao_ccss_diff_hashes( $jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget'] );
115
+                    $hash = $this->ao_ccss_diff_hashes($jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget']);
116 116
 
117 117
                     // If job hash is new or different of a previous one.
118
-                    if ( $hash ) {
118
+                    if ($hash) {
119 119
                         // Set job hash.
120 120
                         $jprops['hash'] = $hash;
121 121
 
122 122
                         // If this is not the first job, wait 10 seconds before process next job due criticalcss.com API limits.
123
-                        if ( $jr > 1 ) {
124
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 );
125
-                            sleep( AO_CCSS_SLEEP );
123
+                        if ($jr > 1) {
124
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3);
125
+                            sleep(AO_CCSS_SLEEP);
126 126
                         }
127 127
 
128 128
                         // Dispatch the job generate request and increment request count.
129
-                        $apireq = $this->ao_ccss_api_generate( $path, $queue_debug, $qdobj['htcode'] );
129
+                        $apireq = $this->ao_ccss_api_generate($path, $queue_debug, $qdobj['htcode']);
130 130
                         $jr++;
131 131
 
132 132
                         // NOTE: All the following conditions maps to the ones in admin_settings_queue.js.php.
133
-                        if ( 'JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status'] ) {
133
+                        if ('JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status']) {
134 134
                             // SUCCESS: request has a valid result.
135 135
                             // Update job properties.
136 136
                             $jprops['jid']    = $apireq['job']['id'];
137 137
                             $jprops['jqstat'] = $apireq['job']['status'];
138
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request successful, remote id <' . $jprops['jid'] . '>, status now is <' . $jprops['jqstat'] . '>', 3 );
139
-                        } elseif ( 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
138
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request successful, remote id <'.$jprops['jid'].'>, status now is <'.$jprops['jqstat'].'>', 3);
139
+                        } elseif ('STATUS_JOB_BAD' == $apireq['job']['status']) {
140 140
                             // ERROR: concurrent requests
141 141
                             // Update job properties.
142 142
                             $jprops['jid']    = $apireq['job']['id'];
143 143
                             $jprops['jqstat'] = $apireq['job']['status'];
144
-                            if ( $apireq['job']['error'] ) {
144
+                            if ($apireq['job']['error']) {
145 145
                                 $jprops['jrstat'] = $apireq['job']['error'];
146 146
                             } else {
147 147
                                 $jprops['jrstat'] = 'Baby did a bad bad thing';
148 148
                             }
149 149
                             $jprops['jvstat'] = 'NONE';
150
-                            $jprops['jftime'] = microtime( true );
151
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Concurrent requests when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
152
-                        } elseif ( 'INVALID_JWT_TOKEN' == $apireq['errorCode'] ) {
150
+                            $jprops['jftime'] = microtime(true);
151
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Concurrent requests when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
152
+                        } elseif ('INVALID_JWT_TOKEN' == $apireq['errorCode']) {
153 153
                             // ERROR: key validation
154 154
                             // Update job properties.
155 155
                             $jprops['jqstat'] = $apireq['errorCode'];
156 156
                             $jprops['jrstat'] = $apireq['error'];
157 157
                             $jprops['jvstat'] = 'NONE';
158
-                            $jprops['jftime'] = microtime( true );
159
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'API key validation error when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
160
-                        } elseif ( empty( $apireq ) ) {
158
+                            $jprops['jftime'] = microtime(true);
159
+                            autoptimizeCriticalCSSCore::ao_ccss_log('API key validation error when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
160
+                        } elseif (empty($apireq)) {
161 161
                             // ERROR: no response
162 162
                             // Update job properties.
163 163
                             $jprops['jqstat'] = 'NO_RESPONSE';
164 164
                             $jprops['jrstat'] = 'NONE';
165 165
                             $jprops['jvstat'] = 'NONE';
166
-                            $jprops['jftime'] = microtime( true );
167
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
166
+                            $jprops['jftime'] = microtime(true);
167
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
168 168
                         } else {
169 169
                             // UNKNOWN: unhandled generate exception
170 170
                             // Update job properties.
171 171
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
172 172
                             $jprops['jrstat'] = 'NONE';
173 173
                             $jprops['jvstat'] = 'NONE';
174
-                            $jprops['jftime'] = microtime( true );
175
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 );
176
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
174
+                            $jprops['jftime'] = microtime(true);
175
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2);
176
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
177 177
                         }
178 178
                     } else {
179 179
                         // SUCCESS: Job hash is equal to a previous one, so it's done
180 180
                         // Update job status and finish time.
181 181
                         $jprops['jqstat'] = 'JOB_DONE';
182
-                        $jprops['jftime'] = microtime( true );
183
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> requires no further processing, status now is <' . $jprops['jqstat'] . '>', 3 );
182
+                        $jprops['jftime'] = microtime(true);
183
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> requires no further processing, status now is <'.$jprops['jqstat'].'>', 3);
184 184
                     }
185 185
 
186 186
                     // Set queue update flag.
187 187
                     $update = true;
188 188
 
189
-                } elseif ( 'JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat'] ) {
189
+                } elseif ('JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat']) {
190 190
                     // Process QUEUED and ONGOING jobs
191 191
                     // Log the pending job.
192
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found PENDING job with local ID <' . $jprops['ljid'] . '>, continuing its queue processing', 3 );
192
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found PENDING job with local ID <'.$jprops['ljid'].'>, continuing its queue processing', 3);
193 193
 
194 194
                     // If this is not the first job, wait before process next job due criticalcss.com API limits.
195
-                    if ( $jr > 1 ) {
196
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 );
197
-                        sleep( AO_CCSS_SLEEP );
195
+                    if ($jr > 1) {
196
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3);
197
+                        sleep(AO_CCSS_SLEEP);
198 198
                     }
199 199
 
200 200
                     // Dispatch the job result request and increment request count.
201
-                    $apireq = $this->ao_ccss_api_results( $jprops['jid'], $queue_debug, $qdobj['htcode'] );
201
+                    $apireq = $this->ao_ccss_api_results($jprops['jid'], $queue_debug, $qdobj['htcode']);
202 202
                     $jr++;
203 203
 
204 204
                     // NOTE: All the following condigitons maps to the ones in admin_settings_queue.js.php
205 205
                     // Replace API response values if queue debugging is enabled and some value is set.
206
-                    if ( $queue_debug ) {
207
-                        if ( $qdobj['status'] ) {
206
+                    if ($queue_debug) {
207
+                        if ($qdobj['status']) {
208 208
                             $apireq['status'] = $qdobj['status'];
209 209
                         }
210
-                        if ( $qdobj['resultStatus'] ) {
210
+                        if ($qdobj['resultStatus']) {
211 211
                             $apireq['resultStatus'] = $qdobj['resultStatus'];
212 212
                         }
213
-                        if ( $qdobj['validationStatus'] ) {
213
+                        if ($qdobj['validationStatus']) {
214 214
                             $apireq['validationStatus'] = $qdobj['validationStatus'];
215 215
                         }
216 216
                     }
217 217
 
218
-                    if ( 'JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status'] ) {
218
+                    if ('JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status']) {
219 219
                         // SUCCESS: request has a valid result
220 220
                         // Process a PENDING job
221 221
                         // Update job properties.
222 222
                         $jprops['jqstat'] = $apireq['status'];
223
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '> unchanged', 3 );
224
-                    } elseif ( 'JOB_DONE' == $apireq['status'] ) {
223
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'> unchanged', 3);
224
+                    } elseif ('JOB_DONE' == $apireq['status']) {
225 225
                         // Process a DONE job
226 226
                         // New resultStatus from ccss.com "HTML_404", consider as "GOOD" for now.
227
-                        if ( 'HTML_404' == $apireq['resultStatus'] ) {
227
+                        if ('HTML_404' == $apireq['resultStatus']) {
228 228
                             $apireq['resultStatus'] = 'GOOD';
229 229
                         }
230 230
 
231
-                        if ( 'GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus'] ) {
231
+                        if ('GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus']) {
232 232
                             // SUCCESS: GOOD job with GOOD validation
233 233
                             // Update job properties.
234
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, false );
234
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, false);
235 235
                             $jprops['jqstat'] = $apireq['status'];
236 236
                             $jprops['jrstat'] = $apireq['resultStatus'];
237 237
                             $jprops['jvstat'] = $apireq['validationStatus'];
238
-                            $jprops['jftime'] = microtime( true );
238
+                            $jprops['jftime'] = microtime(true);
239 239
                             $rule_update      = true;
240
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '>, file saved <' . $jprops['file'] . '>', 3 );
241
-                        } elseif ( 'GOOD' == $apireq['resultStatus'] && ( 'WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'] ) ) {
240
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'>, file saved <'.$jprops['file'].'>', 3);
241
+                        } elseif ('GOOD' == $apireq['resultStatus'] && ('WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'])) {
242 242
                             // SUCCESS: GOOD job with WARN or BAD validation
243 243
                             // Update job properties.
244
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, true );
244
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, true);
245 245
                             $jprops['jqstat'] = $apireq['status'];
246 246
                             $jprops['jrstat'] = $apireq['resultStatus'];
247 247
                             $jprops['jvstat'] = $apireq['validationStatus'];
248
-                            $jprops['jftime'] = microtime( true );
248
+                            $jprops['jftime'] = microtime(true);
249 249
                             $rule_update      = true;
250
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . ', file saved <' . $jprops['file'] . '> but requires REVIEW', 3 );
251
-                        } elseif ( 'GOOD' != $apireq['resultStatus'] && ( 'GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'] ) ) {
250
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].', file saved <'.$jprops['file'].'> but requires REVIEW', 3);
251
+                        } elseif ('GOOD' != $apireq['resultStatus'] && ('GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'])) {
252 252
                             // ERROR: no GOOD, WARN or BAD results
253 253
                             // Update job properties.
254 254
                             $jprops['jqstat'] = $apireq['status'];
255 255
                             $jprops['jrstat'] = $apireq['resultStatus'];
256 256
                             $jprops['jvstat'] = $apireq['validationStatus'];
257
-                            $jprops['jftime'] = microtime( true );
258
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
257
+                            $jprops['jftime'] = microtime(true);
258
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
259 259
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
260
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
260
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
261 261
                         } else {
262 262
                             // UNKNOWN: unhandled JOB_DONE exception
263 263
                             // Update job properties.
264 264
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
265 265
                             $jprops['jrstat'] = $apireq['resultStatus'];
266 266
                             $jprops['jvstat'] = $apireq['validationStatus'];
267
-                            $jprops['jftime'] = microtime( true );
268
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job is UNKNOWN, status now is <' . $jprops['jqstat'] . '>', 2 );
267
+                            $jprops['jftime'] = microtime(true);
268
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job is UNKNOWN, status now is <'.$jprops['jqstat'].'>', 2);
269 269
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
270
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
270
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
271 271
                         }
272
-                    } elseif ( 'JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
272
+                    } elseif ('JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status']) {
273 273
                         // ERROR: failed job
274 274
                         // Update job properties.
275 275
                         $jprops['jqstat'] = $apireq['job']['status'];
276
-                        if ( $apireq['job']['error'] ) {
276
+                        if ($apireq['job']['error']) {
277 277
                             $jprops['jrstat'] = $apireq['job']['error'];
278 278
                         } else {
279 279
                             $jprops['jrstat'] = 'Baby did a bad bad thing';
280 280
                         }
281 281
                         $jprops['jvstat'] = 'NONE';
282
-                        $jprops['jftime'] = microtime( true );
283
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
284
-                    } elseif ( 'This css no longer exists. Please re-generate it.' == $apireq['error'] ) {
282
+                        $jprops['jftime'] = microtime(true);
283
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
284
+                    } elseif ('This css no longer exists. Please re-generate it.' == $apireq['error']) {
285 285
                         // ERROR: CSS doesn't exist
286 286
                         // Update job properties.
287 287
                         $jprops['jqstat'] = 'NO_CSS';
288 288
                         $jprops['jrstat'] = $apireq['error'];
289 289
                         $jprops['jvstat'] = 'NONE';
290
-                        $jprops['jftime'] = microtime( true );
291
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
292
-                    } elseif ( empty( $apireq ) ) {
290
+                        $jprops['jftime'] = microtime(true);
291
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
292
+                    } elseif (empty($apireq)) {
293 293
                         // ERROR: no response
294 294
                         // Update job properties.
295 295
                         $jprops['jqstat'] = 'NO_RESPONSE';
296 296
                         $jprops['jrstat'] = 'NONE';
297 297
                         $jprops['jvstat'] = 'NONE';
298
-                        $jprops['jftime'] = microtime( true );
299
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
298
+                        $jprops['jftime'] = microtime(true);
299
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
300 300
                     } else {
301 301
                         // UNKNOWN: unhandled results exception
302 302
                         // Update job properties.
303 303
                         $jprops['jqstat'] = 'JOB_UNKNOWN';
304 304
                         $jprops['jrstat'] = 'NONE';
305 305
                         $jprops['jvstat'] = 'NONE';
306
-                        $jprops['jftime'] = microtime( true );
307
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 );
306
+                        $jprops['jftime'] = microtime(true);
307
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2);
308 308
                     }
309 309
 
310 310
                     // Set queue update flag.
@@ -312,40 +312,40 @@  discard block
 block discarded – undo
312 312
                 }
313 313
 
314 314
                 // Mark DONE jobs for removal.
315
-                if ( 'JOB_DONE' == $jprops['jqstat'] ) {
315
+                if ('JOB_DONE' == $jprops['jqstat']) {
316 316
                     $update = true;
317 317
                     $deljob = true;
318 318
                 }
319 319
 
320 320
                 // Persist updated queue object.
321
-                if ( $update ) {
322
-                    if ( ! $deljob ) {
321
+                if ($update) {
322
+                    if (!$deljob) {
323 323
                         // Update properties of a NEW or PENDING job...
324
-                        $ao_ccss_queue[ $path ] = $jprops;
324
+                        $ao_ccss_queue[$path] = $jprops;
325 325
                     } else {
326 326
                         // ...or remove the DONE job.
327
-                        unset( $ao_ccss_queue[ $path ] );
328
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> is DONE and was removed from the queue', 3 );
327
+                        unset($ao_ccss_queue[$path]);
328
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> is DONE and was removed from the queue', 3);
329 329
                     }
330 330
 
331 331
                     // Update queue object.
332
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
333
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
334
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue updated by job id <' . $jprops['ljid'] . '>', 3 );
332
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
333
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
334
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue updated by job id <'.$jprops['ljid'].'>', 3);
335 335
 
336 336
                     // Update target rule.
337
-                    if ( $rule_update ) {
338
-                        $this->ao_ccss_rule_update( $jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash'] );
339
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> updated the target rule <' . $jprops['rtarget'] . '>', 3 );
337
+                    if ($rule_update) {
338
+                        $this->ao_ccss_rule_update($jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash']);
339
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> updated the target rule <'.$jprops['rtarget'].'>', 3);
340 340
                     }
341 341
                 } else {
342 342
                     // Or log no queue action.
343
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Nothing to do on this job', 3 );
343
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Nothing to do on this job', 3);
344 344
                 }
345 345
 
346 346
                 // Break the loop if request limit is set and was reached.
347
-                if ( $ao_ccss_rlimit && $ao_ccss_rlimit == $jr ) {
348
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'The limit of ' . $ao_ccss_rlimit . ' request(s) to criticalcss.com was reached, queue control must finish now', 3 );
347
+                if ($ao_ccss_rlimit && $ao_ccss_rlimit == $jr) {
348
+                    autoptimizeCriticalCSSCore::ao_ccss_log('The limit of '.$ao_ccss_rlimit.' request(s) to criticalcss.com was reached, queue control must finish now', 3);
349 349
                     break;
350 350
                 }
351 351
 
@@ -354,46 +354,46 @@  discard block
 block discarded – undo
354 354
             }
355 355
 
356 356
             // Remove the lock file and log the queue end.
357
-            if ( file_exists( AO_CCSS_LOCK ) ) {
358
-                unlink( AO_CCSS_LOCK );
359
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control unlocked', 3 );
357
+            if (file_exists(AO_CCSS_LOCK)) {
358
+                unlink(AO_CCSS_LOCK);
359
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control unlocked', 3);
360 360
             }
361
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control finished', 3 );
361
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control finished', 3);
362 362
 
363 363
             // Log that queue is locked.
364 364
         } else {
365
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue is already running, skipping the attempt to run it again', 3 );
365
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue is already running, skipping the attempt to run it again', 3);
366 366
         }
367 367
     }
368 368
 
369
-    public function ao_ccss_diff_hashes( $ljid, $hash, $hashes, $rule ) {
369
+    public function ao_ccss_diff_hashes($ljid, $hash, $hashes, $rule) {
370 370
         // Compare job hashes
371 371
         // STEP 1: update job hashes.
372
-        if ( 1 == count( $hashes ) ) {
372
+        if (1 == count($hashes)) {
373 373
             // Job with a single hash
374 374
             // Set job hash.
375 375
             $hash = $hashes[0];
376
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with SINGLE hash <' . $hash . '>', 3 );
376
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with SINGLE hash <'.$hash.'>', 3);
377 377
         } else {
378 378
             // Job with multiple hashes
379 379
             // Loop through hashes to concatenate them.
380 380
             $nhash = '';
381
-            foreach ( $hashes as $shash ) {
381
+            foreach ($hashes as $shash) {
382 382
                 $nhash .= $shash;
383 383
             }
384 384
 
385 385
             // Set job hash.
386
-            $hash = md5( $nhash );
387
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with a COMPOSITE hash <' . $hash . '>', 3 );
386
+            $hash = md5($nhash);
387
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with a COMPOSITE hash <'.$hash.'>', 3);
388 388
         }
389 389
 
390 390
         // STEP 2: compare job to existing jobs to prevent double submission for same type+hash.
391 391
         global $ao_ccss_queue;
392 392
 
393
-        foreach ( $ao_ccss_queue as $queue_item ) {
394
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Comparing <' . $rule . $hash . '> with <' . $queue_item['rtarget'] . $queue_item['hash'] . '>', 3 );
395
-            if ( $queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array( $queue_item['jqstat'], array( 'JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE' ) ) ) {
396
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the already pending job <' . $queue_item['ljid'] . '>', 3 );
393
+        foreach ($ao_ccss_queue as $queue_item) {
394
+            autoptimizeCriticalCSSCore::ao_ccss_log('Comparing <'.$rule.$hash.'> with <'.$queue_item['rtarget'].$queue_item['hash'].'>', 3);
395
+            if ($queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array($queue_item['jqstat'], array('JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE'))) {
396
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the already pending job <'.$queue_item['ljid'].'>', 3);
397 397
                 return false;
398 398
             }
399 399
         }
@@ -403,32 +403,32 @@  discard block
 block discarded – undo
403 403
         global $ao_ccss_rules;
404 404
 
405 405
         // Prepare rule variables.
406
-        $trule = explode( '|', $rule );
407
-        $srule = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
406
+        $trule = explode('|', $rule);
407
+        $srule = $ao_ccss_rules[$trule[0]][$trule[1]];
408 408
 
409 409
         // Check if a MANUAL rule exist and return false.
410
-        if ( ! empty( $srule ) && ( 0 == $srule['hash'] && 0 != $srule['file'] ) ) {
411
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the MANUAL rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
410
+        if (!empty($srule) && (0 == $srule['hash'] && 0 != $srule['file'])) {
411
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the MANUAL rule <'.$trule[0].'|'.$trule[1].'>', 3);
412 412
             return false;
413
-        } elseif ( ! empty( $srule ) ) {
413
+        } elseif (!empty($srule)) {
414 414
             // Check if an AUTO rule exist.
415
-            if ( $hash === $srule['hash'] && is_file( AO_CCSS_DIR . $srule['file'] ) && 0 != filesize( AO_CCSS_DIR . $srule['file'] ) ) {
415
+            if ($hash === $srule['hash'] && is_file(AO_CCSS_DIR.$srule['file']) && 0 != filesize(AO_CCSS_DIR.$srule['file'])) {
416 416
                 // Check if job hash matches rule, if the CCSS file exists said file is not empty and return FALSE is so.
417
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
417
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> MATCH the one in rule <'.$trule[0].'|'.$trule[1].'>', 3);
418 418
                 return false;
419 419
             } else {
420 420
                 // Or return the new hash if they differ.
421
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> DOES NOT MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '> or rule\'s CCSS file was invalid.', 3 );
421
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> DOES NOT MATCH the one in rule <'.$trule[0].'|'.$trule[1].'> or rule\'s CCSS file was invalid.', 3);
422 422
                 return $hash;
423 423
             }
424 424
         } else {
425 425
             // Or just return the hash if no rule exist yet.
426
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> has no rule yet', 3 );
426
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> has no rule yet', 3);
427 427
             return $hash;
428 428
         }
429 429
     }
430 430
 
431
-    public function ao_ccss_api_generate( $path, $debug, $dcode ) {
431
+    public function ao_ccss_api_generate($path, $debug, $dcode) {
432 432
         // POST jobs to criticalcss.com and return responses
433 433
         // Get key and key status.
434 434
         global $ao_ccss_key;
@@ -440,35 +440,35 @@  discard block
 block discarded – undo
440 440
         global $ao_ccss_noptimize;
441 441
 
442 442
         $site_host = get_site_url();
443
-        $site_path = parse_url( $site_host, PHP_URL_PATH );
443
+        $site_path = parse_url($site_host, PHP_URL_PATH);
444 444
 
445
-        if ( ! empty( $site_path ) ) {
446
-            $site_host = str_replace( $site_path, '', $site_host );
445
+        if (!empty($site_path)) {
446
+            $site_host = str_replace($site_path, '', $site_host);
447 447
         }
448 448
 
449 449
         // Logic to bind to one domain to avoid site clones of sites would
450 450
         // automatically begin spawning requests to criticalcss.com which has
451 451
         // a per domain cost.
452 452
         global $ao_ccss_domain;
453
-        if ( empty( $ao_ccss_domain ) ) {
453
+        if (empty($ao_ccss_domain)) {
454 454
             // first request being done, update option to allow future requests are only allowed if from same domain.
455
-            update_option( 'autoptimize_ccss_domain', str_rot13( $site_host ) );
456
-        } elseif ( trim( $ao_ccss_domain, '\'"' ) !== 'none' && parse_url( $site_host, PHP_URL_HOST ) !== parse_url( $ao_ccss_domain, PHP_URL_HOST ) && apply_filters( 'autoptimize_filter_ccss_bind_domain', true ) ) {
455
+            update_option('autoptimize_ccss_domain', str_rot13($site_host));
456
+        } elseif (trim($ao_ccss_domain, '\'"') !== 'none' && parse_url($site_host, PHP_URL_HOST) !== parse_url($ao_ccss_domain, PHP_URL_HOST) && apply_filters('autoptimize_filter_ccss_bind_domain', true)) {
457 457
             // not the same domain, log as error and return without posting to criticalcss.com.
458
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Request for domain ' . $site_host . ' does not match bound domain ' . $ao_ccss_domain . ' so not proceeding.', 2 );
458
+            autoptimizeCriticalCSSCore::ao_ccss_log('Request for domain '.$site_host.' does not match bound domain '.$ao_ccss_domain.' so not proceeding.', 2);
459 459
             return false;
460 460
         }
461 461
 
462
-        $src_url = $site_host . $path;
462
+        $src_url = $site_host.$path;
463 463
 
464 464
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
465
-        if ( ! empty( $ao_ccss_noptimize ) ) {
465
+        if (!empty($ao_ccss_noptimize)) {
466 466
             $src_url .= '?ao_noptirocket=1';
467
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
467
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
468 468
             $src_url .= '?ao_nolazy=1';
469 469
         }
470 470
 
471
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
471
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
472 472
 
473 473
         // Initialize request body.
474 474
         $body           = array();
@@ -478,88 +478,88 @@  discard block
 block discarded – undo
478 478
 
479 479
         // Prepare and add viewport size to the body if available.
480 480
         $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
481
-        if ( ! empty( $viewport['w'] ) && ! empty( $viewport['h'] ) ) {
481
+        if (!empty($viewport['w']) && !empty($viewport['h'])) {
482 482
             $body['width']  = $viewport['w'];
483 483
             $body['height'] = $viewport['h'];
484 484
         }
485 485
 
486 486
         // Prepare and add forceInclude to the body if available.
487 487
         global $ao_ccss_finclude;
488
-        $finclude = $this->ao_ccss_finclude( $ao_ccss_finclude );
489
-        if ( ! empty( $finclude ) ) {
488
+        $finclude = $this->ao_ccss_finclude($ao_ccss_finclude);
489
+        if (!empty($finclude)) {
490 490
             $body['forceInclude'] = $finclude;
491 491
         }
492 492
 
493 493
         // Add filter to allow the body array to be altered (e.g. to add customPageHeaders).
494
-        $body = apply_filters( 'autoptimize_ccss_cron_api_generate_body', $body );
494
+        $body = apply_filters('autoptimize_ccss_cron_api_generate_body', $body);
495 495
 
496 496
         // Body must be json and log it.
497
-        $body = json_encode( $body );
498
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request body is ' . $body, 3 );
497
+        $body = json_encode($body);
498
+        autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request body is '.$body, 3);
499 499
 
500 500
         // Prepare the request.
501
-        $url  = esc_url_raw( AO_CCSS_API . 'generate?aover=' . AO_CCSS_VER );
501
+        $url  = esc_url_raw(AO_CCSS_API.'generate?aover='.AO_CCSS_VER);
502 502
         $args = array(
503 503
             'headers' => array(
504
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
504
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
505 505
                 'Content-type'  => 'application/json; charset=utf-8',
506
-                'Authorization' => 'JWT ' . $key,
506
+                'Authorization' => 'JWT '.$key,
507 507
                 'Connection'    => 'close',
508 508
             ),
509 509
             'body'    => $body,
510 510
         );
511 511
 
512 512
         // Dispatch the request and store its response code.
513
-        $req  = wp_safe_remote_post( $url, $args );
514
-        $code = wp_remote_retrieve_response_code( $req );
515
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
513
+        $req  = wp_safe_remote_post($url, $args);
514
+        $code = wp_remote_retrieve_response_code($req);
515
+        $body = json_decode(wp_remote_retrieve_body($req), true);
516 516
 
517
-        if ( $debug && $dcode ) {
517
+        if ($debug && $dcode) {
518 518
             // If queue debug is active, change response code.
519 519
             $code = $dcode;
520 520
         }
521 521
 
522
-        if ( 200 == $code ) {
522
+        if (200 == $code) {
523 523
             // Response code is OK.
524 524
             // Workaround criticalcss.com non-RESTful reponses.
525
-            if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) {
525
+            if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status']) {
526 526
                 // Log successful and return encoded request body.
527
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied successfully', 3 );
527
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied successfully', 3);
528 528
 
529 529
                 // This code also means the key is valid, so cache key status for 24h if not already cached.
530
-                if ( ( ! $key_status || 2 != $key_status ) && $key ) {
531
-                    update_option( 'autoptimize_ccss_keyst', 2 );
532
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
530
+                if ((!$key_status || 2 != $key_status) && $key) {
531
+                    update_option('autoptimize_ccss_keyst', 2);
532
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
533 533
                 }
534 534
 
535 535
                 // Return the request body.
536 536
                 return $body;
537 537
             } else {
538 538
                 // Log successful requests with invalid reponses.
539
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 );
540
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
539
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2);
540
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
541 541
                 return $body;
542 542
             }
543 543
         } else {
544 544
             // Response code is anything else.
545 545
             // Log failed request with a valid response code and return body.
546
-            if ( $code ) {
547
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with error code <' . $code . '>, body follows...', 2 );
548
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
546
+            if ($code) {
547
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with error code <'.$code.'>, body follows...', 2);
548
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
549 549
 
550
-                if ( 401 == $code ) {
550
+                if (401 == $code) {
551 551
                     // If request is unauthorized, also clear key status.
552
-                    update_option( 'autoptimize_ccss_keyst', 1 );
553
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
552
+                    update_option('autoptimize_ccss_keyst', 1);
553
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
554 554
                 }
555 555
 
556 556
                 // Return the request body.
557 557
                 return $body;
558 558
             } else {
559 559
                 // Log failed request with no response and return false.
560
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> has no response, this could be a service timeout', 2 );
561
-                if ( is_wp_error( $req ) ) {
562
-                    autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
560
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> has no response, this could be a service timeout', 2);
561
+                if (is_wp_error($req)) {
562
+                    autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
563 563
                 }
564 564
 
565 565
                 return false;
@@ -567,76 +567,76 @@  discard block
 block discarded – undo
567 567
         }
568 568
     }
569 569
 
570
-    public function ao_ccss_api_results( $jobid, $debug, $dcode ) {
570
+    public function ao_ccss_api_results($jobid, $debug, $dcode) {
571 571
         // GET jobs from criticalcss.com and return responses
572 572
         // Get key.
573 573
         global $ao_ccss_key;
574 574
         $key = $ao_ccss_key;
575 575
 
576 576
         // Prepare the request.
577
-        $url  = AO_CCSS_API . 'results?resultId=' . $jobid;
577
+        $url  = AO_CCSS_API.'results?resultId='.$jobid;
578 578
         $args = array(
579 579
             'headers' => array(
580
-                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER,
581
-                'Authorization' => 'JWT ' . $key,
580
+                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v'.AO_CCSS_VER,
581
+                'Authorization' => 'JWT '.$key,
582 582
                 'Connection'    => 'close',
583 583
             ),
584 584
         );
585 585
 
586 586
         // Dispatch the request and store its response code.
587
-        $req  = wp_safe_remote_get( $url, $args );
588
-        $code = wp_remote_retrieve_response_code( $req );
589
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
587
+        $req  = wp_safe_remote_get($url, $args);
588
+        $code = wp_remote_retrieve_response_code($req);
589
+        $body = json_decode(wp_remote_retrieve_body($req), true);
590 590
 
591
-        if ( $debug && $dcode ) {
591
+        if ($debug && $dcode) {
592 592
             // If queue debug is active, change response code.
593 593
             $code = $dcode;
594 594
         }
595 595
 
596
-        if ( 200 == $code ) {
596
+        if (200 == $code) {
597 597
             // Response code is OK.
598
-            if ( is_array( $body ) && ( array_key_exists( 'status', $body ) || array_key_exists( 'job', $body ) ) && ( 'JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) ) {
598
+            if (is_array($body) && (array_key_exists('status', $body) || array_key_exists('job', $body)) && ('JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'])) {
599 599
                 // Workaround criticalcss.com non-RESTful reponses
600 600
                 // Log successful and return encoded request body.
601
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully', 3 );
601
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully', 3);
602 602
                 return $body;
603
-            } elseif ( is_array( $body ) && ( array_key_exists( 'error', $body ) && 'This css no longer exists. Please re-generate it.' == $body['error'] ) ) {
603
+            } elseif (is_array($body) && (array_key_exists('error', $body) && 'This css no longer exists. Please re-generate it.' == $body['error'])) {
604 604
                 // Handle no CSS reply
605 605
                 // Log no CSS error and return encoded request body.
606
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully but the CSS for it does not exist anymore', 3 );
606
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully but the CSS for it does not exist anymore', 3);
607 607
                 return $body;
608 608
             } else {
609 609
                 // Log failed request and return false.
610
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 );
611
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
610
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2);
611
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
612 612
                 return false;
613 613
             }
614 614
         } else {
615 615
             // Response code is anything else
616 616
             // Log failed request with a valid response code and return body.
617
-            if ( $code ) {
618
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with error code <' . $code . '>, body follows...', 2 );
619
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
620
-                if ( 401 == $code ) {
617
+            if ($code) {
618
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with error code <'.$code.'>, body follows...', 2);
619
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
620
+                if (401 == $code) {
621 621
                     // If request is unauthorized, also clear key status.
622
-                    update_option( 'autoptimize_ccss_keyst', 1 );
623
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
622
+                    update_option('autoptimize_ccss_keyst', 1);
623
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
624 624
                 }
625 625
 
626 626
                 // Return the request body.
627 627
                 return $body;
628 628
             } else {
629 629
                 // Log failed request with no response and return false.
630
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> has no response, this could be a service timeout', 2 );
630
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> has no response, this could be a service timeout', 2);
631 631
                 return false;
632 632
             }
633 633
         }
634 634
     }
635 635
 
636
-    public function ao_ccss_save_file( $ccss, $target, $review ) {
636
+    public function ao_ccss_save_file($ccss, $target, $review) {
637 637
         // Save critical CSS into the filesystem and return its filename
638 638
         // Prepare review mark.
639
-        if ( $review ) {
639
+        if ($review) {
640 640
             $rmark = '_R';
641 641
         } else {
642 642
             $rmark = '';
@@ -646,21 +646,21 @@  discard block
 block discarded – undo
646 646
         $filename = false;
647 647
         $content  = $ccss;
648 648
 
649
-        if ( autoptimizeCriticalCSSCore::ao_ccss_check_contents( $content ) ) {
649
+        if (autoptimizeCriticalCSSCore::ao_ccss_check_contents($content)) {
650 650
             // Sanitize content, set filename and try to save file.
651
-            $file     = AO_CCSS_DIR . 'ccss_' . md5( $ccss . $target[1] ) . $rmark . '.css';
652
-            $status   = file_put_contents( $file, $content, LOCK_EX );
653
-            $filename = pathinfo( $file, PATHINFO_BASENAME );
654
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file for the rule <' . $target[0] . '|' . $target[1] . '> was saved as <' . $filename . '>, size in bytes is <' . $status . '>', 3 );
651
+            $file     = AO_CCSS_DIR.'ccss_'.md5($ccss.$target[1]).$rmark.'.css';
652
+            $status   = file_put_contents($file, $content, LOCK_EX);
653
+            $filename = pathinfo($file, PATHINFO_BASENAME);
654
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file for the rule <'.$target[0].'|'.$target[1].'> was saved as <'.$filename.'>, size in bytes is <'.$status.'>', 3);
655 655
 
656
-            if ( ! $status ) {
656
+            if (!$status) {
657 657
                 // If file has not been saved, reset filename.
658
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file <' . $filename . '> could not be not saved', 2 );
658
+                autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file <'.$filename.'> could not be not saved', 2);
659 659
                 $filename = false;
660 660
                 return $filename;
661 661
             }
662 662
         } else {
663
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not pass content check', 2 );
663
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not pass content check', 2);
664 664
             return $filename;
665 665
         }
666 666
 
@@ -670,15 +670,15 @@  discard block
 block discarded – undo
670 670
         global $ao_ccss_rules;
671 671
 
672 672
         // Prepare rule variables.
673
-        $srule   = $ao_ccss_rules[ $target[0] ][ $target[1] ];
673
+        $srule   = $ao_ccss_rules[$target[0]][$target[1]];
674 674
         $oldfile = $srule['file'];
675 675
 
676
-        if ( $oldfile && $oldfile !== $filename ) {
677
-            $delfile = AO_CCSS_DIR . $oldfile;
678
-            if ( file_exists( $delfile ) ) {
679
-                $unlinkst = unlink( $delfile );
680
-                if ( $unlinkst ) {
681
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A previous critical CSS file <' . $oldfile . '> was removed for the rule <' . $target[0] . '|' . $target[1] . '>', 3 );
676
+        if ($oldfile && $oldfile !== $filename) {
677
+            $delfile = AO_CCSS_DIR.$oldfile;
678
+            if (file_exists($delfile)) {
679
+                $unlinkst = unlink($delfile);
680
+                if ($unlinkst) {
681
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A previous critical CSS file <'.$oldfile.'> was removed for the rule <'.$target[0].'|'.$target[1].'>', 3);
682 682
                 }
683 683
             }
684 684
         }
@@ -687,29 +687,29 @@  discard block
 block discarded – undo
687 687
         return $filename;
688 688
     }
689 689
 
690
-    public function ao_ccss_rule_update( $ljid, $srule, $file, $hash ) {
690
+    public function ao_ccss_rule_update($ljid, $srule, $file, $hash) {
691 691
         // Update or create a rule
692 692
         // Attach required arrays.
693 693
         global $ao_ccss_rules;
694 694
 
695 695
         // Prepare rule variables.
696
-        $trule  = explode( '|', $srule );
697
-        $rule   = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
696
+        $trule  = explode('|', $srule);
697
+        $rule   = $ao_ccss_rules[$trule[0]][$trule[1]];
698 698
         $action = false;
699 699
         $rtype  = '';
700 700
 
701
-        if ( 0 === $rule['hash'] && 0 !== $rule['file'] ) {
701
+        if (0 === $rule['hash'] && 0 !== $rule['file']) {
702 702
             // manual rule, don't ever overwrite.
703 703
             $action = 'NOT UPDATED';
704 704
             $rtype  = 'MANUAL';
705
-        } elseif ( 0 === $rule['hash'] && 0 === $rule['file'] ) {
705
+        } elseif (0 === $rule['hash'] && 0 === $rule['file']) {
706 706
             // If this is an user created AUTO rule with no hash and file yet, update its hash and filename
707 707
             // Set rule hash, file and action flag.
708 708
             $rule['hash'] = $hash;
709 709
             $rule['file'] = $file;
710 710
             $action       = 'UPDATED';
711 711
             $rtype        = 'AUTO';
712
-        } elseif ( 0 !== $rule['hash'] && ctype_alnum( $rule['hash'] ) ) {
712
+        } elseif (0 !== $rule['hash'] && ctype_alnum($rule['hash'])) {
713 713
             // If this is an genuine AUTO rule, update its hash and filename
714 714
             // Set rule hash, file and action flag.
715 715
             $rule['hash'] = $hash;
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
         } else {
720 720
             // If rule doesn't exist, create an AUTO rule
721 721
             // AUTO rules were only for types, but will now also work for paths.
722
-            if ( 'types' == $trule[0] || 'paths' == $trule[0] ) {
722
+            if ('types' == $trule[0] || 'paths' == $trule[0]) {
723 723
                 // Set rule hash and file and action flag.
724 724
                 $rule['hash'] = $hash;
725 725
                 $rule['file'] = $file;
@@ -727,47 +727,47 @@  discard block
 block discarded – undo
727 727
                 $rtype        = 'AUTO';
728 728
             } else {
729 729
                 // Log that no rule was created.
730
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Exception, no AUTO rule created', 3 );
730
+                autoptimizeCriticalCSSCore::ao_ccss_log('Exception, no AUTO rule created', 3);
731 731
             }
732 732
         }
733 733
 
734
-        if ( $action ) {
734
+        if ($action) {
735 735
             // If a rule creation/update is required, persist updated rules object.
736
-            $ao_ccss_rules[ $trule[0] ][ $trule[1] ] = $rule;
737
-            $ao_ccss_rules_raw                       = json_encode( $ao_ccss_rules );
738
-            update_option( 'autoptimize_ccss_rules', $ao_ccss_rules_raw );
739
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Target rule <' . $srule . '> of type <' . $rtype . '> was ' . $action . ' for job id <' . $ljid . '>', 3 );
736
+            $ao_ccss_rules[$trule[0]][$trule[1]] = $rule;
737
+            $ao_ccss_rules_raw                       = json_encode($ao_ccss_rules);
738
+            update_option('autoptimize_ccss_rules', $ao_ccss_rules_raw);
739
+            autoptimizeCriticalCSSCore::ao_ccss_log('Target rule <'.$srule.'> of type <'.$rtype.'> was '.$action.' for job id <'.$ljid.'>', 3);
740 740
         } else {
741
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No rule action required', 3 );
741
+            autoptimizeCriticalCSSCore::ao_ccss_log('No rule action required', 3);
742 742
         }
743 743
     }
744 744
 
745
-    function ao_ccss_finclude( $finclude_raw ) {
745
+    function ao_ccss_finclude($finclude_raw) {
746 746
         // Prepare forceInclude object.
747
-        if ( ! empty( $finclude_raw ) ) {
747
+        if (!empty($finclude_raw)) {
748 748
             // If there are any content
749 749
             // Convert raw string into arra and initialize the returning object.
750
-            $fincludes = explode( ',', $finclude_raw );
750
+            $fincludes = explode(',', $finclude_raw);
751 751
             $finclude  = array();
752 752
 
753 753
             // Interacts over every rule.
754 754
             $i = 0;
755
-            foreach ( $fincludes as $include ) {
755
+            foreach ($fincludes as $include) {
756 756
                 // Trim leading and trailing whitespaces.
757
-                $include = trim( $include );
757
+                $include = trim($include);
758 758
 
759
-                if ( substr( $include, 0, 2 ) === '//' ) {
759
+                if (substr($include, 0, 2) === '//') {
760 760
                     // Regex rule
761 761
                     // Format value as required.
762
-                    $include = str_replace( '//', '/', $include );
763
-                    $include = $include . '/i';
762
+                    $include = str_replace('//', '/', $include);
763
+                    $include = $include.'/i';
764 764
 
765 765
                     // Store regex object.
766
-                    $finclude[ $i ]['type']  = 'RegExp';
767
-                    $finclude[ $i ]['value'] = $include;
766
+                    $finclude[$i]['type']  = 'RegExp';
767
+                    $finclude[$i]['value'] = $include;
768 768
                 } else {
769 769
                     // Simple value rule.
770
-                    $finclude[ $i ]['value'] = $include;
770
+                    $finclude[$i]['value'] = $include;
771 771
                 }
772 772
 
773 773
                 $i++;
@@ -784,54 +784,54 @@  discard block
 block discarded – undo
784 784
     public function ao_ccss_cleaning() {
785 785
         // Perform plugin maintenance
786 786
         // Truncate log file >= 1MB .
787
-        if ( file_exists( AO_CCSS_LOG ) ) {
788
-            if ( filesize( AO_CCSS_LOG ) >= 1048576 ) {
789
-                $logfile = fopen( AO_CCSS_LOG, 'w' );
790
-                fclose( $logfile );
787
+        if (file_exists(AO_CCSS_LOG)) {
788
+            if (filesize(AO_CCSS_LOG) >= 1048576) {
789
+                $logfile = fopen(AO_CCSS_LOG, 'w');
790
+                fclose($logfile);
791 791
             }
792 792
         }
793 793
 
794 794
         // Remove lock file.
795
-        if ( file_exists( AO_CCSS_LOCK ) ) {
796
-            unlink( AO_CCSS_LOCK );
795
+        if (file_exists(AO_CCSS_LOCK)) {
796
+            unlink(AO_CCSS_LOCK);
797 797
         }
798 798
 
799 799
         // Make sure queue processing is scheduled, recreate if not.
800
-        if ( ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
801
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
800
+        if (!wp_next_scheduled('ao_ccss_queue')) {
801
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
802 802
         }
803 803
 
804 804
         // Queue cleaning.
805 805
         global $ao_ccss_queue;
806 806
         $queue_purge_threshold = 100;
807
-        $queue_purge_age       = 24 * 60 * 60;
808
-        $queue_length          = count( $ao_ccss_queue );
809
-        $timestamp_yesterday   = microtime( true ) - $queue_purge_age;
807
+        $queue_purge_age       = 24*60*60;
808
+        $queue_length          = count($ao_ccss_queue);
809
+        $timestamp_yesterday   = microtime(true) - $queue_purge_age;
810 810
         $remove_old_new        = false;
811 811
         $queue_altered         = false;
812 812
 
813
-        if ( $queue_length > $queue_purge_threshold ) {
813
+        if ($queue_length > $queue_purge_threshold) {
814 814
             $remove_old_new = true;
815 815
         }
816 816
 
817
-        foreach ( $ao_ccss_queue as $path => $job ) {
818
-            if ( ( $remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday ) || in_array( $job['jqstat'], array( 'JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE' ) ) ) {
819
-                unset( $ao_ccss_queue[ $path ] );
817
+        foreach ($ao_ccss_queue as $path => $job) {
818
+            if (($remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday) || in_array($job['jqstat'], array('JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE'))) {
819
+                unset($ao_ccss_queue[$path]);
820 820
                 $queue_altered = true;
821 821
             }
822 822
         }
823 823
 
824 824
         // save queue to options!
825
-        if ( $queue_altered ) {
826
-            $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
827
-            update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
828
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue cleaning done.', 3 );
825
+        if ($queue_altered) {
826
+            $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
827
+            update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
828
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue cleaning done.', 3);
829 829
         }
830 830
 
831 831
         // re-check key if invalid.
832 832
         global $ao_ccss_keyst;
833
-        if ( 1 == $ao_ccss_keyst ) {
834
-            $this->ao_ccss_api_generate( '', '', '' );
833
+        if (1 == $ao_ccss_keyst) {
834
+            $this->ao_ccss_api_generate('', '', '');
835 835
         }
836 836
     }
837 837
 }
Please login to merge, or discard this patch.
classes/external/php/minify-html.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     {
74 74
         $this->_html = str_replace("\r\n", "\n", trim($html));
75 75
         if (isset($options['xhtml'])) {
76
-            $this->_isXhtml = (bool)$options['xhtml'];
76
+            $this->_isXhtml = (bool) $options['xhtml'];
77 77
         }
78 78
         if (isset($options['cssMinifier'])) {
79 79
             $this->_cssMinifier = $options['cssMinifier'];
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
99 99
         }
100 100
 
101
-        $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
101
+        $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']);
102 102
         $this->_placeholders = array();
103 103
 
104 104
         // replace SCRIPTs (and minify) with placeholders
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             ,$this->_html);
115 115
 
116 116
         // remove HTML comments (not containing IE conditional comments).
117
-        if  ($this->_keepComments == false) {
117
+        if ($this->_keepComments == false) {
118 118
             $this->_html = preg_replace_callback(
119 119
                 '/<!--([\\s\\S]*?)-->/'
120 120
                 ,array($this, '_commentCB')
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
160 160
 
161 161
         // reverse order while preserving keys to ensure the last replacement is done first, etc ...
162
-        $this->_placeholders = array_reverse( $this->_placeholders, true );
162
+        $this->_placeholders = array_reverse($this->_placeholders, true);
163 163
 
164 164
         // fill placeholders
165 165
         $this->_html = str_replace(
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
     protected function _reservePlace($content)
181 181
     {
182
-        $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
182
+        $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%';
183 183
         $this->_placeholders[$placeholder] = $content;
184 184
         return $placeholder;
185 185
     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 
194 194
     protected function _outsideTagCB($m)
195 195
     {
196
-        return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
196
+        return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<';
197 197
     }
198 198
 
199 199
     protected function _removePreCB($m)
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     protected function _removeCdata($str)
266 266
     {
267 267
         return (false !== strpos($str, '<![CDATA['))
268
-            ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
268
+            ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str)
269 269
             : $str;
270 270
     }
271 271
 
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSEnqueue.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS job enqueue logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
19 19
     }
20 20
 
21
-    public static function ao_ccss_enqueue( $hash ) {
21
+    public static function ao_ccss_enqueue($hash) {
22 22
         $self = new self();
23 23
         // Get key status.
24
-        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( false );
24
+        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(false);
25 25
 
26 26
         // Queue is available to anyone...
27 27
         $enqueue = true;
28 28
 
29 29
         // ... which are not the ones below.
30
-        if ( is_user_logged_in() || is_feed() || is_404() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters( 'autoptimize_filter_ccss_enqueue_should_enqueue', true ) ) {
30
+        if (is_user_logged_in() || is_feed() || is_404() || (defined('DOING_AJAX') && DOING_AJAX) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters('autoptimize_filter_ccss_enqueue_should_enqueue', true)) {
31 31
             $enqueue = false;
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( "Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log("Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3);
33 33
         }
34 34
 
35
-        if ( $enqueue ) {
35
+        if ($enqueue) {
36 36
             // Continue if queue is available
37 37
             // Attach required arrays/ vars.
38 38
             global $ao_ccss_rules;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             global $ao_ccss_forcepath;
42 42
 
43 43
             // Get request path and page type, and initialize the queue update flag.
44
-            $req_path        = strtok( $_SERVER['REQUEST_URI'], '?' );
44
+            $req_path        = strtok($_SERVER['REQUEST_URI'], '?');
45 45
             $req_type        = $self->ao_ccss_get_type();
46 46
             $job_qualify     = false;
47 47
             $target_rule     = false;
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             $queue_update    = false;
50 50
 
51 51
             // Match for paths in rules.
52
-            foreach ( $ao_ccss_rules['paths'] as $path => $props ) {
52
+            foreach ($ao_ccss_rules['paths'] as $path => $props) {
53 53
 
54 54
                 // Prepare rule target and log.
55
-                $target_rule = 'paths|' . $path;
56
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
55
+                $target_rule = 'paths|'.$path;
56
+                autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
57 57
 
58 58
                 // Path match
59 59
                 // -> exact match needed for AUTO rules
60 60
                 // -> partial match OK for MANUAL rules (which have empty hash and a file with CCSS).
61
-                if ( $path === $req_path || ( false == $props['hash'] && false != $props['file'] && preg_match( '|' . $path . '|', $req_path ) ) ) {
61
+                if ($path === $req_path || (false == $props['hash'] && false != $props['file'] && preg_match('|'.$path.'|', $req_path))) {
62 62
 
63 63
                     // There's a path match in the rule, so job QUALIFIES with a path rule match.
64 64
                     $job_qualify     = true;
65 65
                     $rule_properties = $props;
66
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
66
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
67 67
 
68 68
                     // Stop processing other path rules.
69 69
                     break;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
             }
72 72
 
73 73
             // Match for types in rules if no path rule matches and if we're not enforcing paths.
74
-            if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) {
75
-                foreach ( $ao_ccss_rules['types'] as $type => $props ) {
74
+            if (!$job_qualify && (!$ao_ccss_forcepath || !in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page'))) || !apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false))) {
75
+                foreach ($ao_ccss_rules['types'] as $type => $props) {
76 76
 
77 77
                     // Prepare rule target and log.
78
-                    $target_rule = 'types|' . $type;
79
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying page type <' . $req_type . '> on path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
78
+                    $target_rule = 'types|'.$type;
79
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying page type <'.$req_type.'> on path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
80 80
 
81
-                    if ( $req_type == $type ) {
81
+                    if ($req_type == $type) {
82 82
                         // Type match.
83 83
                         // There's a type match in the rule, so job QUALIFIES with a type rule match.
84 84
                         $job_qualify     = true;
85 85
                         $rule_properties = $props;
86
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Page type <' . $req_type . '> on path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
86
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Page type <'.$req_type.'> on path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
87 87
 
88 88
                         // Stop processing other type rules.
89 89
                         break;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 }
92 92
             }
93 93
 
94
-            if ( $job_qualify && ( ( false == $rule_properties['hash'] && false != $rule_properties['file'] ) || strpos( $req_type, 'template_' ) !== false ) ) {
94
+            if ($job_qualify && ((false == $rule_properties['hash'] && false != $rule_properties['file']) || strpos($req_type, 'template_') !== false)) {
95 95
                 // If job qualifies but rule hash is false and file isn't false (MANUAL rule) or if template, job does not qualify despite what previous evaluations says.
96 96
                 $job_qualify = false;
97
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission DISQUALIFIED by MANUAL rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
98
-            } elseif ( ! $job_qualify && empty( $rule_properties ) ) {
97
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission DISQUALIFIED by MANUAL rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
98
+            } elseif (!$job_qualify && empty($rule_properties)) {
99 99
                 // But if job does not qualify and rule properties are set, job qualifies as there is no matching rule for it yet
100 100
                 // Fill-in the new target rule.
101 101
                 $job_qualify = true;
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
                 // Should we switch to path-base AUTO-rules? Conditions:
104 104
                 // 1. forcepath option has to be enabled (off by default)
105 105
                 // 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category).
106
-                if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) {
107
-                    if ( '/' !== $req_path ) {
108
-                        $target_rule = 'paths|' . $req_path;
106
+                if (($ao_ccss_forcepath && in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page')))) || apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false)) {
107
+                    if ('/' !== $req_path) {
108
+                        $target_rule = 'paths|'.$req_path;
109 109
                     } else {
110 110
                         // Exception; we don't want a path-based rule for "/" as that messes things up, hard-switch this to a type-based is_front_page rule.
111
-                        $target_rule = 'types|' . 'is_front_page';
111
+                        $target_rule = 'types|'.'is_front_page';
112 112
                     }
113 113
                 } else {
114
-                    $target_rule = 'types|' . $req_type;
114
+                    $target_rule = 'types|'.$req_type;
115 115
                 }
116
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by MISSING rule for page type <' . $req_type . '> on path <' . $req_path . '>, new rule target is <' . $target_rule . '>', 3 );
116
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by MISSING rule for page type <'.$req_type.'> on path <'.$req_path.'>, new rule target is <'.$target_rule.'>', 3);
117 117
             } else {
118 118
                 // Or just log a job qualified by a matching rule.
119
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by AUTO rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
119
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by AUTO rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
120 120
             }
121 121
 
122 122
             // Submit job.
123
-            if ( $job_qualify ) {
124
-                if ( ! array_key_exists( $req_path, $ao_ccss_queue ) ) {
123
+            if ($job_qualify) {
124
+                if (!array_key_exists($req_path, $ao_ccss_queue)) {
125 125
                     // This is a NEW job
126 126
                     // Merge job into the queue.
127
-                    $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
127
+                    $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
128 128
                         $req_path,
129 129
                         $target_rule,
130 130
                         $req_type,
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
                 } else {
141 141
                     // This is an existing job
142 142
                     // The job is still NEW, most likely this is extra CSS file for the same page that needs a hash.
143
-                    if ( 'NEW' == $ao_ccss_queue[ $req_path ]['jqstat'] ) {
143
+                    if ('NEW' == $ao_ccss_queue[$req_path]['jqstat']) {
144 144
                         // Add hash if it's not already in the job.
145
-                        if ( ! in_array( $hash, $ao_ccss_queue[ $req_path ]['hashes'] ) ) {
145
+                        if (!in_array($hash, $ao_ccss_queue[$req_path]['hashes'])) {
146 146
                             // Push new hash to its array and update flag.
147
-                            $queue_update = array_push( $ao_ccss_queue[ $req_path ]['hashes'], $hash );
147
+                            $queue_update = array_push($ao_ccss_queue[$req_path]['hashes'], $hash);
148 148
 
149 149
                             // Log job update.
150
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Hashes UPDATED on local job id <' . $ao_ccss_queue[ $req_path ]['ljid'] . '>, job status NEW, target rule <' . $ao_ccss_queue[ $req_path ]['rtarget'] . '>, hash added: ' . $hash, 3 );
150
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Hashes UPDATED on local job id <'.$ao_ccss_queue[$req_path]['ljid'].'>, job status NEW, target rule <'.$ao_ccss_queue[$req_path]['rtarget'].'>, hash added: '.$hash, 3);
151 151
 
152 152
                             // Return from here as the hash array is already updated.
153 153
                             return true;
154 154
                         }
155
-                    } elseif ( 'NEW' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[ $req_path ]['jqstat'] ) {
155
+                    } elseif ('NEW' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[$req_path]['jqstat']) {
156 156
                         // Allow requeuing jobs that are not NEW, JOB_QUEUED or JOB_ONGOING
157 157
                         // Merge new job keeping some previous job values.
158
-                        $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
158
+                        $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
159 159
                             $req_path,
160 160
                             $target_rule,
161 161
                             $req_type,
162 162
                             $hash,
163
-                            $ao_ccss_queue[ $req_path ]['file'],
164
-                            $ao_ccss_queue[ $req_path ]['jid'],
165
-                            $ao_ccss_queue[ $req_path ]['jrstat'],
166
-                            $ao_ccss_queue[ $req_path ]['jvstat'],
163
+                            $ao_ccss_queue[$req_path]['file'],
164
+                            $ao_ccss_queue[$req_path]['jid'],
165
+                            $ao_ccss_queue[$req_path]['jrstat'],
166
+                            $ao_ccss_queue[$req_path]['jvstat'],
167 167
                             false
168 168
                         );
169 169
                         // Set update flag.
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
                     }
172 172
                 }
173 173
 
174
-                if ( $queue_update ) {
174
+                if ($queue_update) {
175 175
                     // Persist the job to the queue and return.
176
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
177
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
176
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
177
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
178 178
                     return true;
179 179
                 } else {
180 180
                     // Or just return false if no job was added.
181
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A job for path <' . $req_path . '> already exist with NEW or PENDING status, skipping job creation', 3 );
181
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A job for path <'.$req_path.'> already exist with NEW or PENDING status, skipping job creation', 3);
182 182
                     return false;
183 183
                 }
184 184
             }
@@ -195,29 +195,29 @@  discard block
 block discarded – undo
195 195
         $page_type = false;
196 196
 
197 197
         // Iterates over the array to match a type.
198
-        foreach ( $ao_ccss_types as $type ) {
199
-            if ( is_404() ) {
198
+        foreach ($ao_ccss_types as $type) {
199
+            if (is_404()) {
200 200
                 $page_type = 'is_404';
201 201
                 break;
202
-            } elseif ( strpos( $type, 'custom_post_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
202
+            } elseif (strpos($type, 'custom_post_') !== false && (!$ao_ccss_forcepath || !is_page())) {
203 203
                 // Match custom post types and not page or page not forced to path-based.
204
-                if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
204
+                if (get_post_type(get_the_ID()) === substr($type, 12)) {
205 205
                     $page_type = $type;
206 206
                     break;
207 207
                 }
208
-            } elseif ( strpos( $type, 'template_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
208
+            } elseif (strpos($type, 'template_') !== false && (!$ao_ccss_forcepath || !is_page())) {
209 209
                 // Match templates if not page or if page is not forced to path-based.
210
-                if ( is_page_template( substr( $type, 9 ) ) ) {
210
+                if (is_page_template(substr($type, 9))) {
211 211
                     $page_type = $type;
212 212
                     break;
213 213
                 }
214 214
             } else {
215 215
                 // Match all other existing types
216 216
                 // but remove prefix to be able to check if the function exists & returns true.
217
-                $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
218
-                if ( function_exists( $_type ) && call_user_func( $_type ) ) {
217
+                $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
218
+                if (function_exists($_type) && call_user_func($_type)) {
219 219
                     // Make sure we only return is_front_page (and is_home) for one page, not for the "paged frontpage" (/page/2 ..).
220
-                    if ( ( 'is_front_page' !== $_type && 'is_home' !== $_type ) || ! is_paged() ) {
220
+                    if (('is_front_page' !== $_type && 'is_home' !== $_type) || !is_paged()) {
221 221
                         $page_type = $type;
222 222
                         break;
223 223
                     }
@@ -229,44 +229,44 @@  discard block
 block discarded – undo
229 229
         return $page_type;
230 230
     }
231 231
 
232
-    public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
232
+    public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) {
233 233
         // Define a job entry to be created or updated
234 234
         // Define commom job properties.
235 235
         $path            = array();
236 236
         $path['ljid']    = $this->ao_ccss_job_id();
237 237
         $path['rtarget'] = $target;
238 238
         $path['ptype']   = $type;
239
-        $path['hashes']  = array( $hash );
239
+        $path['hashes']  = array($hash);
240 240
         $path['hash']    = $hash;
241 241
         $path['file']    = $file;
242 242
         $path['jid']     = $jid;
243 243
         $path['jqstat']  = 'NEW';
244 244
         $path['jrstat']  = $jrstat;
245 245
         $path['jvstat']  = $jvstat;
246
-        $path['jctime']  = microtime( true );
246
+        $path['jctime']  = microtime(true);
247 247
         $path['jftime']  = null;
248 248
 
249 249
         // Set operation requested.
250
-        if ( $create ) {
250
+        if ($create) {
251 251
             $operation = 'CREATED';
252 252
         } else {
253 253
             $operation = 'UPDATED';
254 254
         }
255 255
 
256 256
         // Log job creation.
257
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 );
257
+        autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3);
258 258
 
259 259
         return $path;
260 260
     }
261 261
 
262
-    public function ao_ccss_job_id( $length = 6 ) {
262
+    public function ao_ccss_job_id($length = 6) {
263 263
         // Generate random strings for the local job ID
264 264
         // Based on https://stackoverflow.com/a/4356295 .
265 265
         $characters        = '0123456789abcdefghijklmnopqrstuvwxyz';
266
-        $characters_length = strlen( $characters );
266
+        $characters_length = strlen($characters);
267 267
         $random_string     = 'j-';
268
-        for ( $i = 0; $i < $length; $i++ ) {
269
-            $random_string .= $characters[ rand( 0, $characters_length - 1 ) ];
268
+        for ($i = 0; $i < $length; $i++) {
269
+            $random_string .= $characters[rand(0, $characters_length - 1)];
270 270
         }
271 271
         return $random_string;
272 272
     }
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
     public function ao_ccss_ua() {
275 275
         // Check for criticalcss.com user agent.
276 276
         $agent = '';
277
-        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
277
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
278 278
             $agent = $_SERVER['HTTP_USER_AGENT'];
279 279
         }
280 280
 
281 281
         // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not.
282
-        $rtn = strpos( $agent, AO_CCSS_URL );
283
-        if ( 0 === $rtn ) {
282
+        $rtn = strpos($agent, AO_CCSS_URL);
283
+        if (0 === $rtn) {
284 284
             $rtn = true;
285 285
         } else {
286 286
             $rtn = false;
287 287
         }
288
-        return ( $rtn );
288
+        return ($rtn);
289 289
     }
290 290
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSCore.php 1 patch
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * gets called by AO core, checks the rules and if a matching rule is found returns the associated CCSS.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     {
14 14
         // fetch all options at once and populate them individually explicitely as globals.
15 15
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
16
-        foreach ( $all_options as $_option => $_value ) {
16
+        foreach ($all_options as $_option => $_value) {
17 17
             global ${$_option};
18 18
             ${$_option} = $_value;
19 19
         }
@@ -28,28 +28,28 @@  discard block
 block discarded – undo
28 28
         global $ao_ccss_unloadccss;
29 29
 
30 30
         // add all filters to do CCSS if key present.
31
-        if ( $ao_css_defer && isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) ) {
31
+        if ($ao_css_defer && isset($ao_ccss_key) && !empty($ao_ccss_key)) {
32 32
             // Set AO behavior: disable minification to avoid double minifying and caching.
33
-            add_filter( 'autoptimize_filter_css_critcss_minify', '__return_false' );
34
-            add_filter( 'autoptimize_filter_css_defer_inline', array( $this, 'ao_ccss_frontend' ), 10, 1 );
33
+            add_filter('autoptimize_filter_css_critcss_minify', '__return_false');
34
+            add_filter('autoptimize_filter_css_defer_inline', array($this, 'ao_ccss_frontend'), 10, 1);
35 35
 
36 36
             // Add the action to enqueue jobs for CriticalCSS cron.
37
-            add_action( 'autoptimize_action_css_hash', array( 'autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue' ), 10, 1 );
37
+            add_action('autoptimize_action_css_hash', array('autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue'), 10, 1);
38 38
 
39 39
             // conditionally add the filter to defer jquery and others.
40
-            if ( $ao_ccss_deferjquery ) {
41
-                add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_defer_jquery' ), 11, 1 );
40
+            if ($ao_ccss_deferjquery) {
41
+                add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_defer_jquery'), 11, 1);
42 42
             }
43 43
 
44 44
             // conditionally add filter to unload the CCSS.
45
-            if ( $ao_ccss_unloadccss ) {
46
-                add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_unloadccss' ), 12, 1 );
45
+            if ($ao_ccss_unloadccss) {
46
+                add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_unloadccss'), 12, 1);
47 47
             }
48 48
 
49 49
             // Order paths by length, as longest ones have greater priority in the rules.
50
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
51
-                $keys = array_map( 'strlen', array_keys( $ao_ccss_rules['paths'] ) );
52
-                array_multisort( $keys, SORT_DESC, $ao_ccss_rules['paths'] );
50
+            if (!empty($ao_ccss_rules['paths'])) {
51
+                $keys = array_map('strlen', array_keys($ao_ccss_rules['paths']));
52
+                array_multisort($keys, SORT_DESC, $ao_ccss_rules['paths']);
53 53
             }
54 54
 
55 55
             // Add an array with default WordPress's conditional tags
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
             $ao_ccss_types = $this->get_ao_ccss_core_types();
59 59
 
60 60
             // Extend conditional tags on plugin initalization.
61
-            add_action( apply_filters( 'autoptimize_filter_ccss_extend_types_hook', 'init' ), array( $this, 'ao_ccss_extend_types' ) );
61
+            add_action(apply_filters('autoptimize_filter_ccss_extend_types_hook', 'init'), array($this, 'ao_ccss_extend_types'));
62 62
 
63 63
             // When autoptimize cache is cleared, also clear transient cache for page templates.
64
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCriticalCSSCore', 'ao_ccss_clear_page_tpl_cache' ), 10, 0 );
64
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCriticalCSSCore', 'ao_ccss_clear_page_tpl_cache'), 10, 0);
65 65
         }
66 66
     }
67 67
 
68
-    public function ao_ccss_frontend( $inlined ) {
68
+    public function ao_ccss_frontend($inlined) {
69 69
         // Apply CriticalCSS to frontend pages
70 70
         // Attach types and settings arrays.
71 71
         global $ao_ccss_types;
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
         $no_ccss = '';
78 78
 
79 79
         // Only if keystatus is OK and option to add CCSS for logged on users is on or user is not logged in.
80
-        if ( ( $ao_ccss_keyst && 2 == $ao_ccss_keyst ) && ( $ao_ccss_loggedin || ! is_user_logged_in() ) ) {
80
+        if (($ao_ccss_keyst && 2 == $ao_ccss_keyst) && ($ao_ccss_loggedin || !is_user_logged_in())) {
81 81
             // Check for a valid CriticalCSS based on path to return its contents.
82
-            $req_path = strtok( $_SERVER['REQUEST_URI'], '?' );
83
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
84
-                foreach ( $ao_ccss_rules['paths'] as $path => $rule ) {
82
+            $req_path = strtok($_SERVER['REQUEST_URI'], '?');
83
+            if (!empty($ao_ccss_rules['paths'])) {
84
+                foreach ($ao_ccss_rules['paths'] as $path => $rule) {
85 85
                     // explicit match OR partial match if MANUAL rule.
86
-                    if ( $req_path == $path || urldecode( $req_path ) == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) {
87
-                        if ( file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
88
-                            $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
89
-                            if ( 'none' != $_ccss_contents ) {
90
-                                if ( $ao_ccss_debug ) {
91
-                                    $_ccss_contents = '/* PATH: ' . $path . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
86
+                    if ($req_path == $path || urldecode($req_path) == $path || (false == $rule['hash'] && false != $rule['file'] && strpos($req_path, str_replace(site_url(), '', $path)) !== false)) {
87
+                        if (file_exists(AO_CCSS_DIR.$rule['file'])) {
88
+                            $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
89
+                            if ('none' != $_ccss_contents) {
90
+                                if ($ao_ccss_debug) {
91
+                                    $_ccss_contents = '/* PATH: '.$path.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
92 92
                                 }
93
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
93
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
94 94
                             } else {
95 95
                                 $no_ccss = 'none';
96 96
                             }
@@ -100,55 +100,55 @@  discard block
 block discarded – undo
100 100
             }
101 101
 
102 102
             // Check for a valid CriticalCSS based on conditional tags to return its contents.
103
-            if ( ! empty( $ao_ccss_rules['types'] ) && 'none' !== $no_ccss ) {
103
+            if (!empty($ao_ccss_rules['types']) && 'none' !== $no_ccss) {
104 104
                 // order types-rules by the order of the original $ao_ccss_types array so as not to depend on the order in which rules were added.
105
-                $ao_ccss_rules['types'] = array_replace( array_intersect_key( array_flip( $ao_ccss_types ), $ao_ccss_rules['types'] ), $ao_ccss_rules['types'] );
105
+                $ao_ccss_rules['types'] = array_replace(array_intersect_key(array_flip($ao_ccss_types), $ao_ccss_rules['types']), $ao_ccss_rules['types']);
106 106
                 $is_front_page          = is_front_page();
107 107
 
108
-                foreach ( $ao_ccss_rules['types'] as $type => $rule ) {
109
-                    if ( in_array( $type, $ao_ccss_types ) && file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
110
-                        $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
111
-                        if ( $is_front_page && 'is_front_page' == $type ) {
112
-                            if ( 'none' != $_ccss_contents ) {
113
-                                if ( $ao_ccss_debug ) {
114
-                                    $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
108
+                foreach ($ao_ccss_rules['types'] as $type => $rule) {
109
+                    if (in_array($type, $ao_ccss_types) && file_exists(AO_CCSS_DIR.$rule['file'])) {
110
+                        $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
111
+                        if ($is_front_page && 'is_front_page' == $type) {
112
+                            if ('none' != $_ccss_contents) {
113
+                                if ($ao_ccss_debug) {
114
+                                    $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
115 115
                                 }
116
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
116
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
117 117
                             } else {
118 118
                                 $no_ccss = 'none';
119 119
                             }
120
-                        } elseif ( strpos( $type, 'custom_post_' ) === 0 && ! $is_front_page ) {
121
-                            if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
122
-                                if ( 'none' != $_ccss_contents ) {
123
-                                    if ( $ao_ccss_debug ) {
124
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
120
+                        } elseif (strpos($type, 'custom_post_') === 0 && !$is_front_page) {
121
+                            if (get_post_type(get_the_ID()) === substr($type, 12)) {
122
+                                if ('none' != $_ccss_contents) {
123
+                                    if ($ao_ccss_debug) {
124
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
125 125
                                     }
126
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
126
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
127 127
                                 } else {
128 128
                                     $no_ccss = 'none';
129 129
                                 }
130 130
                             }
131
-                        } elseif ( 0 === strpos( $type, 'template_' ) && ! $is_front_page ) {
132
-                            if ( is_page_template( substr( $type, 9 ) ) ) {
133
-                                if ( 'none' != $_ccss_contents ) {
134
-                                    if ( $ao_ccss_debug ) {
135
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
131
+                        } elseif (0 === strpos($type, 'template_') && !$is_front_page) {
132
+                            if (is_page_template(substr($type, 9))) {
133
+                                if ('none' != $_ccss_contents) {
134
+                                    if ($ao_ccss_debug) {
135
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
136 136
                                     }
137
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
137
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
138 138
                                 } else {
139 139
                                     $no_ccss = 'none';
140 140
                                 }
141 141
                             }
142
-                        } elseif ( ! $is_front_page ) {
142
+                        } elseif (!$is_front_page) {
143 143
                             // all "normal" conditional tags, core + woo + buddypress + edd + bbpress
144 144
                             // but we have to remove the prefix for the non-core ones for them to function.
145
-                            $type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
146
-                            if ( function_exists( $type ) && call_user_func( $type ) ) {
147
-                                if ( 'none' != $_ccss_contents ) {
148
-                                    if ( $ao_ccss_debug ) {
149
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
145
+                            $type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
146
+                            if (function_exists($type) && call_user_func($type)) {
147
+                                if ('none' != $_ccss_contents) {
148
+                                    if ($ao_ccss_debug) {
149
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
150 150
                                     }
151
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
151
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
152 152
                                 } else {
153 153
                                     $no_ccss = 'none';
154 154
                                 }
@@ -161,45 +161,45 @@  discard block
 block discarded – undo
161 161
 
162 162
         // Finally, inline the default CriticalCSS if any or else the entire CSS for the page
163 163
         // This also applies to logged in users if the option to add CCSS for logged in users has been disabled.
164
-        if ( ! empty( $inlined ) && 'none' !== $no_ccss ) {
165
-            return apply_filters( 'autoptimize_filter_ccss_core_ccss', $inlined . $ao_ccss_additional );
164
+        if (!empty($inlined) && 'none' !== $no_ccss) {
165
+            return apply_filters('autoptimize_filter_ccss_core_ccss', $inlined.$ao_ccss_additional);
166 166
         } else {
167
-            add_filter( 'autoptimize_filter_css_inline', '__return_true' );
167
+            add_filter('autoptimize_filter_css_inline', '__return_true');
168 168
             return;
169 169
         }
170 170
     }
171 171
 
172
-    public function ao_ccss_defer_jquery( $in ) {
172
+    public function ao_ccss_defer_jquery($in) {
173 173
         global $ao_ccss_loggedin;
174 174
         // defer all linked and inline JS.
175
-        if ( ( ! is_user_logged_in() || $ao_ccss_loggedin ) && preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) {
176
-            foreach ( $matches as $match ) {
177
-                if ( str_replace( apply_filters( 'autoptimize_filter_ccss_core_defer_exclude', array( 'data-noptimize="1"', 'data-cfasync="false"', 'data-pagespeed-no-defer' ) ), '', $match[0] ) !== $match[0] ) {
175
+        if ((!is_user_logged_in() || $ao_ccss_loggedin) && preg_match_all('#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER)) {
176
+            foreach ($matches as $match) {
177
+                if (str_replace(apply_filters('autoptimize_filter_ccss_core_defer_exclude', array('data-noptimize="1"', 'data-cfasync="false"', 'data-pagespeed-no-defer')), '', $match[0]) !== $match[0]) {
178 178
                     // do not touch JS with noptimize/ cfasync/ pagespeed-no-defer flags.
179 179
                     continue;
180
-                } elseif ( '' !== $match[1] && ( ! preg_match( '/<script.* type\s?=.*>/', $match[0] ) || preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0] ) ) ) {
180
+                } elseif ('' !== $match[1] && (!preg_match('/<script.* type\s?=.*>/', $match[0]) || preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0]))) {
181 181
                     // base64-encode and defer all inline JS.
182
-                    $base64_js = '<script defer src="data:text/javascript;base64,' . base64_encode( $match[1] ) . '"></script>';
183
-                    $in        = str_replace( $match[0], $base64_js, $in );
184
-                } elseif ( str_replace( array( ' defer', ' async' ), '', $match[0] ) === $match[0] ) {
182
+                    $base64_js = '<script defer src="data:text/javascript;base64,'.base64_encode($match[1]).'"></script>';
183
+                    $in        = str_replace($match[0], $base64_js, $in);
184
+                } elseif (str_replace(array(' defer', ' async'), '', $match[0]) === $match[0]) {
185 185
                     // and defer linked JS unless already deferred or asynced.
186
-                    $new_match = str_replace( '<script ', '<script defer ', $match[0] );
187
-                    $in        = str_replace( $match[0], $new_match, $in );
186
+                    $new_match = str_replace('<script ', '<script defer ', $match[0]);
187
+                    $in        = str_replace($match[0], $new_match, $in);
188 188
                 }
189 189
             }
190 190
         }
191 191
         return $in;
192 192
     }
193 193
 
194
-    public function ao_ccss_unloadccss( $html_in ) {
194
+    public function ao_ccss_unloadccss($html_in) {
195 195
         // set media attrib of inline CCSS to none at onLoad to avoid it impacting full CSS (rarely needed).
196
-        $_unloadccss_js = apply_filters( 'autoptimize_filter_ccss_core_unloadccss_js', '<script>window.addEventListener("load", function(event) {document.getElementById("aoatfcss").media="none";})</script>' );
196
+        $_unloadccss_js = apply_filters('autoptimize_filter_ccss_core_unloadccss_js', '<script>window.addEventListener("load", function(event) {document.getElementById("aoatfcss").media="none";})</script>');
197 197
 
198
-        if ( false !== strpos( $html_in, $_unloadccss_js . '</body>' ) ) {
198
+        if (false !== strpos($html_in, $_unloadccss_js.'</body>')) {
199 199
             return $html_in;
200 200
         }
201 201
 
202
-        return str_replace( '</body>', $_unloadccss_js . '</body>', $html_in );
202
+        return str_replace('</body>', $_unloadccss_js.'</body>', $html_in);
203 203
     }
204 204
 
205 205
     public function ao_ccss_extend_types() {
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
         global $ao_ccss_types;
209 209
 
210 210
         // in some cases $ao_ccss_types is empty and/or not an array, this should work around that problem.
211
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
211
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
212 212
             $ao_ccss_types = get_ao_ccss_core_types();
213
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Empty types array in extend, refetching array with core conditionals.', 3 );
213
+            autoptimizeCriticalCSSCore::ao_ccss_log('Empty types array in extend, refetching array with core conditionals.', 3);
214 214
         }
215 215
 
216 216
         // Custom Post Types.
@@ -222,23 +222,23 @@  discard block
 block discarded – undo
222 222
             'names',
223 223
             'and'
224 224
         );
225
-        foreach ( $cpts as $cpt ) {
226
-            array_unshift( $ao_ccss_types, 'custom_post_' . $cpt );
225
+        foreach ($cpts as $cpt) {
226
+            array_unshift($ao_ccss_types, 'custom_post_'.$cpt);
227 227
         }
228 228
 
229 229
         // Templates.
230 230
         // Transient cache to avoid frequent disk reads.
231
-        $templates = get_transient( 'autoptimize_ccss_page_templates' );
232
-        if ( ! $templates ) {
231
+        $templates = get_transient('autoptimize_ccss_page_templates');
232
+        if (!$templates) {
233 233
             $templates = wp_get_theme()->get_page_templates();
234
-            set_transient( 'autoptimize_ccss_page_templates', $templates, HOUR_IN_SECONDS );
234
+            set_transient('autoptimize_ccss_page_templates', $templates, HOUR_IN_SECONDS);
235 235
         }
236
-        foreach ( $templates as $tplfile => $tplname ) {
237
-            array_unshift( $ao_ccss_types, 'template_' . $tplfile );
236
+        foreach ($templates as $tplfile => $tplname) {
237
+            array_unshift($ao_ccss_types, 'template_'.$tplfile);
238 238
         }
239 239
 
240 240
         // bbPress tags.
241
-        if ( function_exists( 'is_bbpress' ) ) {
241
+        if (function_exists('is_bbpress')) {
242 242
             $ao_ccss_types = array_merge(
243 243
                 array(
244 244
                     'bbp_is_bbpress',
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         }
271 271
 
272 272
         // BuddyPress tags.
273
-        if ( function_exists( 'is_buddypress' ) ) {
273
+        if (function_exists('is_buddypress')) {
274 274
             $ao_ccss_types = array_merge(
275 275
                 array(
276 276
                     'bp_is_activation_page',
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
         }
313 313
 
314 314
         // Easy Digital Downloads (EDD) tags.
315
-        if ( function_exists( 'edd_is_checkout' ) ) {
315
+        if (function_exists('edd_is_checkout')) {
316 316
             $ao_ccss_types = array_merge(
317 317
                 array(
318 318
                     'edd_is_checkout',
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         }
325 325
 
326 326
         // WooCommerce tags.
327
-        if ( class_exists( 'WooCommerce' ) ) {
327
+        if (class_exists('WooCommerce')) {
328 328
             $ao_ccss_types = array_merge(
329 329
                 array(
330 330
                     'woo_is_account_page',
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
     public function get_ao_ccss_core_types() {
345 345
         global $ao_ccss_types;
346
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
346
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
347 347
             return array(
348 348
                 'is_404',
349 349
                 'is_archive',
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         }
365 365
     }
366 366
 
367
-    public static function ao_ccss_key_status( $render ) {
367
+    public static function ao_ccss_key_status($render) {
368 368
         // Provide key status
369 369
         // Get key and key status.
370 370
         global $ao_ccss_key;
@@ -377,55 +377,55 @@  discard block
 block discarded – undo
377 377
         $key_return = array();
378 378
         $status     = false;
379 379
 
380
-        if ( $key && 2 == $key_status ) {
380
+        if ($key && 2 == $key_status) {
381 381
             // Key exists and its status is valid.
382 382
             // Set valid key status.
383 383
             $status     = 'valid';
384
-            $status_msg = __( 'Valid' );
384
+            $status_msg = __('Valid');
385 385
             $color      = '#46b450'; // Green.
386 386
             $message    = null;
387
-        } elseif ( $key && 1 == $key_status ) {
387
+        } elseif ($key && 1 == $key_status) {
388 388
             // Key exists but its validation has failed.
389 389
             // Set invalid key status.
390 390
             $status     = 'invalid';
391
-            $status_msg = __( 'Invalid' );
391
+            $status_msg = __('Invalid');
392 392
             $color      = '#dc3232'; // Red.
393
-            $message    = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
394
-        } elseif ( $key && ! $key_status ) {
393
+            $message    = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
394
+        } elseif ($key && !$key_status) {
395 395
             // Key exists but it has no valid status yet
396 396
             // Perform key validation.
397
-            $key_check = $self->ao_ccss_key_validation( $key );
397
+            $key_check = $self->ao_ccss_key_validation($key);
398 398
 
399 399
             // Key is valid, set valid status.
400
-            if ( $key_check ) {
400
+            if ($key_check) {
401 401
                 $status     = 'valid';
402
-                $status_msg = __( 'Valid' );
402
+                $status_msg = __('Valid');
403 403
                 $color      = '#46b450'; // Green.
404 404
                 $message    = null;
405 405
             } else {
406 406
                 // Key is invalid, set invalid status.
407 407
                 $status     = 'invalid';
408
-                $status_msg = __( 'Invalid' );
408
+                $status_msg = __('Invalid');
409 409
                 $color      = '#dc3232'; // Red.
410
-                if ( get_option( 'autoptimize_ccss_keyst' ) == 1 ) {
411
-                    $message = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
410
+                if (get_option('autoptimize_ccss_keyst') == 1) {
411
+                    $message = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
412 412
                 } else {
413
-                    $message = __( 'Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize' );
413
+                    $message = __('Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize');
414 414
                 }
415 415
             }
416 416
         } else {
417 417
             // No key nor status
418 418
             // Set no key status.
419 419
             $status     = 'nokey';
420
-            $status_msg = __( 'None' );
420
+            $status_msg = __('None');
421 421
             $color      = '#ffb900'; // Yellow.
422
-            $message    = __( 'Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize' );
422
+            $message    = __('Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize');
423 423
         }
424 424
 
425 425
         // Fill returned values.
426 426
         $key_return['status'] = $status;
427 427
         // Provide rendering information if required.
428
-        if ( $render ) {
428
+        if ($render) {
429 429
             $key_return['stmsg'] = $status_msg;
430 430
             $key_return['color'] = $color;
431 431
             $key_return['msg']   = $message;
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         return $key_return;
436 436
     }
437 437
 
438
-    public function ao_ccss_key_validation( $key ) {
438
+    public function ao_ccss_key_validation($key) {
439 439
         global $ao_ccss_noptimize;
440 440
 
441 441
         // POST a dummy job to criticalcss.com to check for key validation
@@ -443,26 +443,26 @@  discard block
 block discarded – undo
443 443
         $src_url = get_home_url();
444 444
 
445 445
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
446
-        if ( ! empty( $ao_ccss_noptimize ) ) {
446
+        if (!empty($ao_ccss_noptimize)) {
447 447
             $src_url .= '?ao_noptirocket=1';
448
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
448
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
449 449
             $src_url .= '?ao_nolazy=1';
450 450
         }
451 451
 
452
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
452
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
453 453
 
454 454
         // Prepare the request.
455
-        $url  = esc_url_raw( AO_CCSS_API . 'generate' );
455
+        $url  = esc_url_raw(AO_CCSS_API.'generate');
456 456
         $args = array(
457 457
             'headers' => array(
458
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
458
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
459 459
                 'Content-type'  => 'application/json; charset=utf-8',
460
-                'Authorization' => 'JWT ' . $key,
460
+                'Authorization' => 'JWT '.$key,
461 461
                 'Connection'    => 'close',
462 462
             ),
463 463
             // Body must be JSON.
464 464
             'body'    => json_encode(
465
-                apply_filters( 'autoptimize_ccss_cron_api_generate_body',
465
+                apply_filters('autoptimize_ccss_cron_api_generate_body',
466 466
                     array(
467 467
                         'url'    => $src_url,
468 468
                         'aff'    => 1,
@@ -473,23 +473,23 @@  discard block
 block discarded – undo
473 473
         );
474 474
 
475 475
         // Dispatch the request and store its response code.
476
-        $req  = wp_safe_remote_post( $url, $args );
477
-        $code = wp_remote_retrieve_response_code( $req );
478
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
476
+        $req  = wp_safe_remote_post($url, $args);
477
+        $code = wp_remote_retrieve_response_code($req);
478
+        $body = json_decode(wp_remote_retrieve_body($req), true);
479 479
 
480
-        if ( 200 == $code ) {
480
+        if (200 == $code) {
481 481
             // Response is OK.
482 482
             // Set key status as valid and log key check.
483
-            update_option( 'autoptimize_ccss_keyst', 2 );
484
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
483
+            update_option('autoptimize_ccss_keyst', 2);
484
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
485 485
 
486 486
             // extract job-id from $body and put it in the queue as a P job
487 487
             // but only if no jobs and no rules!
488 488
             global $ao_ccss_queue;
489 489
             global $ao_ccss_rules;
490 490
 
491
-            if ( 0 == count( $ao_ccss_queue ) && 0 == count( $ao_ccss_rules['types'] ) && 0 == count( $ao_ccss_rules['paths'] ) ) {
492
-                if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] ) {
491
+            if (0 == count($ao_ccss_queue) && 0 == count($ao_ccss_rules['types']) && 0 == count($ao_ccss_rules['paths'])) {
492
+                if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status']) {
493 493
                     $jprops['ljid']     = 'firstrun';
494 494
                     $jprops['rtarget']  = 'types|is_front_page';
495 495
                     $jprops['ptype']    = 'is_front_page';
@@ -500,30 +500,30 @@  discard block
 block discarded – undo
500 500
                     $jprops['jqstat']   = $body['job']['status'];
501 501
                     $jprops['jrstat']   = null;
502 502
                     $jprops['jvstat']   = null;
503
-                    $jprops['jctime']   = microtime( true );
503
+                    $jprops['jctime']   = microtime(true);
504 504
                     $jprops['jftime']   = null;
505 505
                     $ao_ccss_queue['/'] = $jprops;
506
-                    $ao_ccss_queue_raw  = json_encode( $ao_ccss_queue );
507
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
508
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Created P job for is_front_page based on API key check response.', 3 );
506
+                    $ao_ccss_queue_raw  = json_encode($ao_ccss_queue);
507
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
508
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Created P job for is_front_page based on API key check response.', 3);
509 509
                 }
510 510
             }
511 511
             return true;
512
-        } elseif ( 401 == $code ) {
512
+        } elseif (401 == $code) {
513 513
             // Response is unauthorized
514 514
             // Set key status as invalid and log key check.
515
-            update_option( 'autoptimize_ccss_keyst', 1 );
516
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
515
+            update_option('autoptimize_ccss_keyst', 1);
516
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
517 517
             return false;
518 518
         } else {
519 519
             // Response unkown
520 520
             // Log key check attempt.
521
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2 );
522
-            if ( ! empty( $body ) ) {
523
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
521
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2);
522
+            if (!empty($body)) {
523
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
524 524
             }
525
-            if ( is_wp_error( $req ) ) {
526
-                autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
525
+            if (is_wp_error($req)) {
526
+                autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
527 527
             }
528 528
             return false;
529 529
         }
@@ -538,14 +538,14 @@  discard block
 block discarded – undo
538 538
         $viewport = array();
539 539
 
540 540
         // Viewport Width.
541
-        if ( ! empty( $ao_ccss_viewport['w'] ) ) {
541
+        if (!empty($ao_ccss_viewport['w'])) {
542 542
             $viewport['w'] = $ao_ccss_viewport['w'];
543 543
         } else {
544 544
             $viewport['w'] = '';
545 545
         }
546 546
 
547 547
         // Viewport Height.
548
-        if ( ! empty( $ao_ccss_viewport['h'] ) ) {
548
+        if (!empty($ao_ccss_viewport['h'])) {
549 549
             $viewport['h'] = $ao_ccss_viewport['h'];
550 550
         } else {
551 551
             $viewport['h'] = '';
@@ -554,23 +554,23 @@  discard block
 block discarded – undo
554 554
         return $viewport;
555 555
     }
556 556
 
557
-    public static function ao_ccss_check_contents( $ccss ) {
557
+    public static function ao_ccss_check_contents($ccss) {
558 558
         // Perform basic exploit avoidance and CSS validation.
559
-        if ( ! empty( $ccss ) ) {
559
+        if (!empty($ccss)) {
560 560
             // Try to avoid code injection.
561
-            $blocklist = array( '#!/', 'function(', '<script', '<?php' );
562
-            foreach ( $blocklist as $blocklisted ) {
563
-                if ( strpos( $ccss, $blocklisted ) !== false ) {
564
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received contained blocklisted content.', 2 );
561
+            $blocklist = array('#!/', 'function(', '<script', '<?php');
562
+            foreach ($blocklist as $blocklisted) {
563
+                if (strpos($ccss, $blocklisted) !== false) {
564
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received contained blocklisted content.', 2);
565 565
                     return false;
566 566
                 }
567 567
             }
568 568
 
569 569
             // Check for most basics CSS structures.
570
-            $needlist = array( '{', '}', ':' );
571
-            foreach ( $needlist as $needed ) {
572
-                if ( false === strpos( $ccss, $needed ) && 'none' !== $ccss ) {
573
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not seem to contain real CSS.', 2 );
570
+            $needlist = array('{', '}', ':');
571
+            foreach ($needlist as $needed) {
572
+                if (false === strpos($ccss, $needed) && 'none' !== $ccss) {
573
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not seem to contain real CSS.', 2);
574 574
                     return false;
575 575
                 }
576 576
             }
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
         return true;
581 581
     }
582 582
 
583
-    public static function ao_ccss_log( $msg, $lvl ) {
583
+    public static function ao_ccss_log($msg, $lvl) {
584 584
         // Commom logging facility
585 585
         // Attach debug option.
586 586
         global $ao_ccss_debug;
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
         // 3: DD (for debug)
592 592
         // Default: UU (for unkown).
593 593
         $level = false;
594
-        switch ( $lvl ) {
594
+        switch ($lvl) {
595 595
             case 1:
596 596
                 $level = 'II';
597 597
                 break;
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
                 break;
601 601
             case 3:
602 602
                 // Output debug messages only if debug mode is enabled.
603
-                if ( $ao_ccss_debug ) {
603
+                if ($ao_ccss_debug) {
604 604
                     $level = 'DD';
605 605
                 }
606 606
                 break;
@@ -609,19 +609,19 @@  discard block
 block discarded – undo
609 609
         }
610 610
 
611 611
         // Prepare and write a log message if there's a valid level.
612
-        if ( $level ) {
612
+        if ($level) {
613 613
 
614 614
             // Prepare message.
615
-            $message = date( 'c' ) . ' - [' . $level . '] ' . htmlentities( $msg ) . '<br>';
615
+            $message = date('c').' - ['.$level.'] '.htmlentities($msg).'<br>';
616 616
 
617 617
             // Write message to log file.
618
-            error_log( $message, 3, AO_CCSS_LOG );
618
+            error_log($message, 3, AO_CCSS_LOG);
619 619
         }
620 620
     }
621 621
 
622 622
     public static function ao_ccss_clear_page_tpl_cache() {
623 623
         // Clears transient cache for page templates.
624
-        delete_transient( 'autoptimize_ccss_page_templates' );
624
+        delete_transient('autoptimize_ccss_page_templates');
625 625
     }
626 626
 
627 627
 }
Please login to merge, or discard this patch.
config/autoptimize_404_handler.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,24 +20,24 @@
 block discarded – undo
20 20
  * to files that don't exist in AO's cache.
21 21
  */
22 22
 
23
-$original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
23
+$original_request = strtok($_SERVER['REQUEST_URI'], '?');
24 24
 
25
-if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
26
-    $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
25
+if (strpos($original_request, 'uucss/uucss-') !== false) {
26
+    $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
27 27
 }
28 28
 
29
-$fallback_target  = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
29
+$fallback_target  = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
30 30
 $ao_cache_dir     = '<!--ao-cache-dir-->';
31
-$js_or_css        = pathinfo( $original_request, PATHINFO_EXTENSION );
32
-$fallback_path    = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
31
+$js_or_css        = pathinfo($original_request, PATHINFO_EXTENSION);
32
+$fallback_path    = $ao_cache_dir.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
33 33
 
34
-if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
34
+if ($original_request !== $fallback_target && file_exists($fallback_path)) {
35 35
     // error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' );
36
-    header( 'HTTP/1.1 301 Moved Permanently' );
37
-    header( 'Location: ' . $fallback_target );
36
+    header('HTTP/1.1 301 Moved Permanently');
37
+    header('Location: '.$fallback_target);
38 38
 } else {
39 39
     // error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' );
40
-    header( 'HTTP/1.1 410 Gone' );
40
+    header('HTTP/1.1 410 Gone');
41 41
 }
42 42
 
43 43
 exit();
Please login to merge, or discard this patch.
autoptimize.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,66 +17,66 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 
20
-if ( ! defined( 'ABSPATH' ) ) {
20
+if (!defined('ABSPATH')) {
21 21
     exit;
22 22
 }
23 23
 
24
-define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.7.8' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.7.8');
25 25
 
26 26
 // plugin_dir_path() returns the trailing slash!
27
-define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
28
-define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ );
27
+define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__));
28
+define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__);
29 29
 
30 30
 // Bail early if attempting to run on non-supported php versions.
31
-if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
31
+if (version_compare(PHP_VERSION, '5.6', '<')) {
32 32
     function autoptimize_incompatible_admin_notice() {
33
-        echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>';
34
-        if ( isset( $_GET['activate'] ) ) {
35
-            unset( $_GET['activate'] );
33
+        echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>';
34
+        if (isset($_GET['activate'])) {
35
+            unset($_GET['activate']);
36 36
         }
37 37
     }
38 38
     function autoptimize_deactivate_self() {
39
-        deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) );
39
+        deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE));
40 40
     }
41
-    add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' );
42
-    add_action( 'admin_init', 'autoptimize_deactivate_self' );
41
+    add_action('admin_notices', 'autoptimize_incompatible_admin_notice');
42
+    add_action('admin_init', 'autoptimize_deactivate_self');
43 43
     return;
44 44
 }
45 45
 
46
-function autoptimize_autoload( $class_name ) {
47
-    if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) {
48
-        $file     = strtolower( $class_name );
49
-        $file     = str_replace( '_', '-', $file );
50
-        $path     = dirname( __FILE__ ) . '/classes/external/php/';
51
-        $filepath = $path . $file . '.php';
52
-    } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) {
53
-        $file     = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name );
54
-        $path     = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/';
55
-        $filepath = $path . $file . '.php';
56
-    } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) {
46
+function autoptimize_autoload($class_name) {
47
+    if (in_array($class_name, array('Minify_HTML', 'JSMin'))) {
48
+        $file     = strtolower($class_name);
49
+        $file     = str_replace('_', '-', $file);
50
+        $path     = dirname(__FILE__).'/classes/external/php/';
51
+        $filepath = $path.$file.'.php';
52
+    } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) {
53
+        $file     = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name);
54
+        $path     = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/';
55
+        $filepath = $path.$file.'.php';
56
+    } elseif ('autoptimize' === substr($class_name, 0, 11)) {
57 57
         // One of our "old" classes.
58 58
         $file     = $class_name;
59
-        $path     = dirname( __FILE__ ) . '/classes/';
60
-        $filepath = $path . $file . '.php';
61
-    } elseif ( 'PAnD' === $class_name ) {
59
+        $path     = dirname(__FILE__).'/classes/';
60
+        $filepath = $path.$file.'.php';
61
+    } elseif ('PAnD' === $class_name) {
62 62
         $file     = 'persist-admin-notices-dismissal';
63
-        $path     = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/';
64
-        $filepath = $path . $file . '.php';
63
+        $path     = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/';
64
+        $filepath = $path.$file.'.php';
65 65
     }
66 66
 
67 67
     // If we didn't match one of our rules, bail!
68
-    if ( ! isset( $filepath ) ) {
68
+    if (!isset($filepath)) {
69 69
         return;
70 70
     }
71 71
 
72 72
     require $filepath;
73 73
 }
74 74
 
75
-spl_autoload_register( 'autoptimize_autoload' );
75
+spl_autoload_register('autoptimize_autoload');
76 76
 
77 77
 // Load WP CLI command(s) on demand.
78
-if ( defined( 'WP_CLI' ) && WP_CLI ) {
79
-    require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php';
78
+if (defined('WP_CLI') && WP_CLI) {
79
+    require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php';
80 80
 }
81 81
 
82 82
 /**
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 function autoptimize() {
88 88
     static $plugin = null;
89 89
 
90
-    if ( null === $plugin ) {
91
-        $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
90
+    if (null === $plugin) {
91
+        $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
92 92
     }
93 93
 
94 94
     return $plugin;
Please login to merge, or discard this patch.
classes/autoptimizeConfig.php 1 patch
Spacing   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Main configuration logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
      */
36 36
     private function __construct()
37 37
     {
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
             // Add the admin page and settings.
40
-            if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41
-                add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
40
+            if (autoptimizeOptionWrapper::is_ao_active_for_network()) {
41
+                add_action('network_admin_menu', array($this, 'addmenu'));
42 42
             }
43 43
 
44
-            add_action( 'admin_menu', array( $this, 'addmenu' ) );
45
-            add_action( 'admin_init', array( $this, 'registersettings' ) );
46
-            add_action( 'admin_init', array( 'PAnD', 'init' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46
+            add_action('admin_init', array('PAnD', 'init'));
47 47
 
48 48
             // Set meta info.
49
-            if ( function_exists( 'plugin_row_meta' ) ) {
49
+            if (function_exists('plugin_row_meta')) {
50 50
                 // 2.8 and higher.
51
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52
-            } elseif ( function_exists( 'post_class' ) ) {
51
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
52
+            } elseif (function_exists('post_class')) {
53 53
                 // 2.7 and lower.
54
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
54
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
55
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
56 56
             }
57 57
 
58 58
             // Clean cache?
59
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
59
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
60 60
                 autoptimizeCache::clearall();
61
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
61
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
62 62
             }
63 63
 
64
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
64
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
65 65
         }
66 66
 
67 67
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     static public function instance()
78 78
     {
79 79
         // Only one instance.
80
-        if ( null === self::$instance ) {
80
+        if (null === self::$instance) {
81 81
             self::$instance = new autoptimizeConfig();
82 82
         }
83 83
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     public function show_network_message() {
88 88
         ?>
89 89
         <div class="wrap">
90
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
90
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
91 91
             <?php echo $this->ao_admin_tabs(); ?>
92
-            <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
92
+            <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p>
93 93
         </div>
94 94
         <?php
95 95
     }
@@ -182,32 +182,32 @@  discard block
 block discarded – undo
182 182
 <div class="wrap">
183 183
 
184 184
 <!-- Temporary nudge to disable aoccss power-up. -->
185
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
185
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
186 186
     <div class="notice-info notice"><p>
187
-        <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
187
+        <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?>
188 188
     </p></div>
189 189
 <?php } ?>
190 190
 
191 191
 <div id="autoptimize_main">
192
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
192
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
193 193
     <?php echo $this->ao_admin_tabs(); ?>
194 194
 
195
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
196
-<?php settings_fields( 'autoptimize' ); ?>
195
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
196
+<?php settings_fields('autoptimize'); ?>
197 197
 
198 198
 <ul>
199 199
 
200 200
 <?php
201 201
 // Only show enable site configuration in network site option.
202
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
202
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
203 203
 ?>
204 204
     <li class="itemDetail multiSite">
205
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
205
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
206 206
         <table class="form-table">
207 207
             <tr valign="top">
208
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
209
-                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
210
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
208
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
209
+                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/>
210
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
211 211
             </tr>
212 212
         </table>
213 213
     </li>
@@ -216,115 +216,115 @@  discard block
 block discarded – undo
216 216
 <?php } ?>    
217 217
 
218 218
 <li class="itemDetail">
219
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
219
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
220 220
 <table class="form-table">
221 221
 <tr valign="top">
222
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
223
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
222
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
223
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
224 224
 </tr>
225 225
 <tr valign="top" class="js_sub">
226
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
227
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
228
-<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
226
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
227
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/>
228
+<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
229 229
 </tr>
230 230
 <tr valign="top" class="js_sub js_aggregate">
231
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
232
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
233
-<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td>
231
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
232
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
233
+<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td>
234 234
 </tr>
235 235
 <tr valign="top" class="js_sub js_aggregate">
236
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
237
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
238
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
236
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
237
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
238
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
239 239
 </tr>
240
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
240
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
241 241
 <tr valign="top" class="js_sub js_aggregate">
242 242
 <th scope="row">
243 243
 <?php
244
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
245
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
244
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
245
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
246 246
 ?>
247 247
 </th>
248
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
249
-<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td>
248
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
249
+<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td>
250 250
 </tr>
251 251
 <?php } ?>
252 252
 <tr valign="top" class="js_sub">
253
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
254
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ) ); ?>"/><br />
253
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
254
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js')); ?>"/><br />
255 255
 <?php
256
-echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
256
+echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
257 257
 ?>
258 258
 </label></td>
259 259
 </tr>
260 260
 <tr valign="top" class="js_sub js_aggregate">
261
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
262
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
263
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
261
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
262
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
263
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
264 264
 </tr>
265 265
 </table>
266 266
 </li>
267 267
 
268 268
 <li class="itemDetail">
269
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
269
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
270 270
 <table class="form-table">
271 271
 <tr valign="top">
272
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
273
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
272
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
273
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
274 274
 </tr>
275 275
 <tr class="css_sub" valign="top">
276
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
277
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
278
-<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
276
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
277
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/>
278
+<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
279 279
 </tr>
280 280
 <tr valign="top" class="css_sub css_aggregate">
281
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
282
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
283
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
281
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
282
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/>
283
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
284 284
 </tr>
285 285
 <tr class="css_sub css_aggregate" valign="top">
286
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
287
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
288
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
286
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
287
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
288
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
289 289
 </tr>
290
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
290
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
291 291
 <tr valign="top" class="css_sub css_aggregate">
292 292
 <th scope="row">
293 293
 <?php
294
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
295
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
294
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
295
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
296 296
 ?>
297 297
 </th>
298
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
299
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
298
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
299
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
300 300
 </tr>
301 301
 <?php } ?>
302 302
 <tr valign="top" class="css_sub">
303
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
304
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
303
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
304
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/>
305 305
 <?php
306
-_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' );
306
+_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize');
307 307
 echo ' ';
308
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
308
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
309 309
 // translators: links "autoptimize critical CSS" tab.
310
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
310
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
311 311
 ?>
312 312
 </label></td>
313 313
 </tr>
314 314
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
315 315
 <th scope="row"></th>
316
-<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td>
316
+<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
317 317
 </tr>
318 318
 <tr valign="top" class="css_sub css_aggregate">
319
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
320
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
321
-<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
319
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
320
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/>
321
+<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td>
322 322
 </tr>
323 323
 <tr valign="top" class="css_sub">
324
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
325
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
324
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
325
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br />
326 326
 <?php
327
-echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
327
+echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
328 328
 ?>
329 329
 </label></td>
330 330
 </tr>
@@ -332,55 +332,55 @@  discard block
 block discarded – undo
332 332
 </li>
333 333
 
334 334
 <li class="itemDetail">
335
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
335
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
336 336
 <table class="form-table">
337 337
 <tr valign="top">
338
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
339
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
338
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
339
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
340 340
 </tr>
341 341
 <tr class="html_sub" valign="top">
342
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
343
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
344
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
342
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
343
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
344
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
345 345
 </tr>
346 346
 </table>
347 347
 </li>
348 348
 
349 349
 <li class="itemDetail">
350
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
350
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
351 351
 <table class="form-table">
352 352
 <tr valign="top">
353
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
354
-<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
355
-<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td>
353
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
354
+<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br />
355
+<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td>
356 356
 </tr>
357 357
 </table>
358 358
 </li>
359 359
 
360 360
 <li class="itemDetail">
361
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
361
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
362 362
 <table class="form-table" >
363 363
 <tr valign="top" >
364
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
365
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
364
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
365
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
366 366
 </tr>
367 367
 <tr valign="top" >
368
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
369
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
368
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
369
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
370 370
 </tr>
371 371
 <tr valign="top" >
372
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
372
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
373 373
 <td>
374 374
     <?php
375 375
     $ao_stat_arr = autoptimizeCache::stats();
376
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
377
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
376
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
377
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
378 378
         $details       = '';
379
-        if ( $ao_cache_size > 0 ) {
380
-            $details = ', ~' . $ao_cache_size . ' total';
379
+        if ($ao_cache_size > 0) {
380
+            $details = ', ~'.$ao_cache_size.' total';
381 381
         }
382 382
         // translators: Kilobytes + timestamp shown.
383
-        printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
383
+        printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2]));
384 384
     }
385 385
     ?>
386 386
 </td>
@@ -389,41 +389,41 @@  discard block
 block discarded – undo
389 389
 </li>
390 390
 
391 391
 <li class="itemDetail">
392
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
392
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
393 393
 <table class="form-table">
394 394
     <tr valign="top" >
395
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
396
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
397
-    <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td>
395
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
396
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
397
+    <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td>
398 398
     </tr>
399 399
     <?php
400 400
     $_min_excl_class = '';
401
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
401
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
402 402
         $_min_excl_class = 'hidden';
403 403
     }
404 404
     ?>
405 405
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
406
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
407
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
408
-        <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td>
406
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
407
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
408
+        <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td>
409 409
     </tr>
410 410
     <tr valign="top">
411
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
412
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
413
-        <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
411
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
412
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
413
+        <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td>
414 414
     </tr>
415 415
     <tr valign="top">
416
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
417
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
418
-    <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
416
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
417
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
418
+    <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td>
419 419
     </tr>
420 420
     <?php
421
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
421
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
422 422
     ?>
423 423
     <tr valign="top" >
424
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
425
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
426
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
424
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
425
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
426
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
427 427
         </td>
428 428
     </tr>
429 429
     <?php } ?>
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
 </ul>
434 434
 
435 435
 <p class="submit">
436
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
437
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
436
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
437
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
438 438
 </p>
439 439
 
440 440
 </form>
@@ -443,46 +443,46 @@  discard block
 block discarded – undo
443 443
     <div class="autoptimize_banner hidden">
444 444
     <ul>
445 445
     <?php
446
-    if ( $this->settings_screen_do_remote_http ) {
447
-        $ao_banner = get_transient( 'autoptimize_banner' );
448
-        if ( empty( $ao_banner ) ) {
449
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
450
-            if ( ! is_wp_error( $banner_resp ) ) {
451
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
452
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
453
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
446
+    if ($this->settings_screen_do_remote_http) {
447
+        $ao_banner = get_transient('autoptimize_banner');
448
+        if (empty($ao_banner)) {
449
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
450
+            if (!is_wp_error($banner_resp)) {
451
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
452
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
453
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
454 454
                 }
455 455
             }
456 456
         }
457 457
         echo $ao_banner;
458 458
     }
459 459
     ?>
460
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
461
-        <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
460
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
461
+        <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li>
462 462
     </ul>
463 463
     </div>
464 464
     <div style="margin-left:10px;margin-top:-5px;">
465 465
         <h2>
466
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
466
+            <?php _e('futtta about', 'autoptimize'); ?>
467 467
             <select id="feed_dropdown" >
468
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
469
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
470
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
468
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
469
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
470
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
471 471
             </select>
472 472
         </h2>
473 473
         <div id="futtta_feed">
474 474
             <div id="autoptimizefeed">
475
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
475
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
476 476
             </div>
477 477
             <div id="wordpressfeed">
478
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
478
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
479 479
             </div>
480 480
             <div id="webtechfeed">
481
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
481
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
482 482
             </div>
483 483
         </div>
484 484
     </div>
485
-    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
485
+    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div>
486 486
 </div>
487 487
 
488 488
 <script type="text/javascript">
@@ -631,81 +631,81 @@  discard block
 block discarded – undo
631 631
 
632 632
     public function addmenu()
633 633
     {
634
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
634
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
635 635
             // multisite, network admin, ao network activated: add normal settings page at network level.
636
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
637
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
636
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
637
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
638 638
             // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options.
639
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
639
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
640 640
         } else {
641 641
             // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on.
642
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
642
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
643 643
         }
644 644
 
645
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
646
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
645
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
646
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
647 647
     }
648 648
 
649 649
     public function autoptimize_admin_scripts()
650 650
     {
651
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
652
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
651
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
652
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
653 653
     }
654 654
 
655 655
     public function autoptimize_admin_styles()
656 656
     {
657
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
658
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
657
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
658
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
659 659
     }
660 660
 
661 661
     public function registersettings() {
662
-        register_setting( 'autoptimize', 'autoptimize_html' );
663
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
664
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
665
-        register_setting( 'autoptimize', 'autoptimize_js' );
666
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
667
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
668
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
669
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
670
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
671
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
672
-        register_setting( 'autoptimize', 'autoptimize_css' );
673
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
674
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
675
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
676
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
677
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
678
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
679
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
680
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
681
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
682
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
683
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
684
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
685
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
686
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
687
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
662
+        register_setting('autoptimize', 'autoptimize_html');
663
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
664
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
665
+        register_setting('autoptimize', 'autoptimize_js');
666
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
667
+        register_setting('autoptimize', 'autoptimize_js_exclude');
668
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
669
+        register_setting('autoptimize', 'autoptimize_js_justhead');
670
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
671
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
672
+        register_setting('autoptimize', 'autoptimize_css');
673
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
674
+        register_setting('autoptimize', 'autoptimize_css_exclude');
675
+        register_setting('autoptimize', 'autoptimize_css_justhead');
676
+        register_setting('autoptimize', 'autoptimize_css_datauris');
677
+        register_setting('autoptimize', 'autoptimize_css_defer');
678
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
679
+        register_setting('autoptimize', 'autoptimize_css_inline');
680
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
681
+        register_setting('autoptimize', 'autoptimize_cdn_url');
682
+        register_setting('autoptimize', 'autoptimize_cache_clean');
683
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
684
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
685
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
686
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
687
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
688 688
     }
689 689
 
690
-    public function setmeta( $links, $file = null )
690
+    public function setmeta($links, $file = null)
691 691
     {
692 692
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
693 693
         // Do it only once - saves time.
694 694
         static $plugin;
695
-        if ( empty( $plugin ) ) {
696
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
695
+        if (empty($plugin)) {
696
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
697 697
         }
698 698
 
699
-        if ( null === $file ) {
699
+        if (null === $file) {
700 700
             // 2.7 and lower.
701
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
702
-            array_unshift( $links, $settings_link );
701
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
702
+            array_unshift($links, $settings_link);
703 703
         } else {
704 704
             // 2.8 and higher.
705 705
             // If it's us, add the link.
706
-            if ( $file === $plugin ) {
707
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
708
-                $links   = array_merge( $links, $newlink );
706
+            if ($file === $plugin) {
707
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
708
+                $links   = array_merge($links, $newlink);
709 709
             }
710 710
         }
711 711
 
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
782 782
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
783 783
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
784
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
784
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
785 785
         );
786 786
         return $defaults;
787 787
     }
@@ -793,58 +793,58 @@  discard block
 block discarded – undo
793 793
      *
794 794
      * @return string
795 795
      */
796
-    public static function get_ao_css_preload_onload( $media = 'all' )
796
+    public static function get_ao_css_preload_onload($media = 'all')
797 797
     {
798
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
798
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
799 799
         return $preload_onload;
800 800
     }
801 801
 
802
-    public function get( $key )
802
+    public function get($key)
803 803
     {
804
-        if ( ! is_array( $this->config ) ) {
804
+        if (!is_array($this->config)) {
805 805
             // Default config.
806 806
             $config = self::get_defaults();
807 807
 
808 808
             // Override with user settings.
809
-            foreach ( array_keys( $config ) as $name ) {
810
-                $conf = autoptimizeOptionWrapper::get_option( $name );
811
-                if ( false !== $conf ) {
809
+            foreach (array_keys($config) as $name) {
810
+                $conf = autoptimizeOptionWrapper::get_option($name);
811
+                if (false !== $conf) {
812 812
                     // It was set before!
813
-                    $config[ $name ] = $conf;
813
+                    $config[$name] = $conf;
814 814
                 }
815 815
             }
816 816
 
817 817
             // Save for next call.
818
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
818
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
819 819
         }
820 820
 
821
-        if ( isset( $this->config[ $key ] ) ) {
822
-            return $this->config[ $key ];
821
+        if (isset($this->config[$key])) {
822
+            return $this->config[$key];
823 823
         }
824 824
 
825 825
         return false;
826 826
     }
827 827
 
828
-    private function get_futtta_feeds( $url ) {
829
-        if ( $this->settings_screen_do_remote_http ) {
830
-            $rss      = fetch_feed( $url );
828
+    private function get_futtta_feeds($url) {
829
+        if ($this->settings_screen_do_remote_http) {
830
+            $rss      = fetch_feed($url);
831 831
             $maxitems = 0;
832 832
 
833
-            if ( ! is_wp_error( $rss ) ) {
834
-                $maxitems  = $rss->get_item_quantity( 7 );
835
-                $rss_items = $rss->get_items( 0, $maxitems );
833
+            if (!is_wp_error($rss)) {
834
+                $maxitems  = $rss->get_item_quantity(7);
835
+                $rss_items = $rss->get_items(0, $maxitems);
836 836
             }
837 837
             ?>
838 838
             <ul>
839
-                <?php if ( 0 == $maxitems ) : ?>
840
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
839
+                <?php if (0 == $maxitems) : ?>
840
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
841 841
                 <?php else : ?>
842
-                    <?php foreach ( $rss_items as $item ) : ?>
842
+                    <?php foreach ($rss_items as $item) : ?>
843 843
                         <li>
844
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
844
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
845 845
                                 <?php // translators: the variable contains a date. ?>
846
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
847
-                                <?php echo esc_html( $item->get_title() ); ?>
846
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
847
+                                <?php echo esc_html($item->get_title()); ?>
848 848
                             </a>
849 849
                         </li>
850 850
                     <?php endforeach; ?>
@@ -857,23 +857,23 @@  discard block
 block discarded – undo
857 857
     static function ao_admin_tabs()
858 858
     {
859 859
         // based on http://wordpress.stackexchange.com/a/58826 .
860
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
860
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
861 861
         $tab_content = '';
862
-        $tabs_count  = count( $tabs );
863
-        if ( $tabs_count > 1 ) {
864
-            if ( isset( $_GET['page'] ) ) {
862
+        $tabs_count  = count($tabs);
863
+        if ($tabs_count > 1) {
864
+            if (isset($_GET['page'])) {
865 865
                 $current_id = $_GET['page'];
866 866
             } else {
867 867
                 $current_id = 'autoptimize';
868 868
             }
869 869
             $tab_content .= '<h2 class="nav-tab-wrapper">';
870
-            foreach ( $tabs as $tab_id => $tab_name ) {
871
-                if ( $current_id == $tab_id ) {
870
+            foreach ($tabs as $tab_id => $tab_name) {
871
+                if ($current_id == $tab_id) {
872 872
                     $class = ' nav-tab-active';
873 873
                 } else {
874 874
                     $class = '';
875 875
                 }
876
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
876
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
877 877
             }
878 878
             $tab_content .= '</h2>';
879 879
         } else {
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public static function is_admin_and_not_ajax()
892 892
     {
893
-        return ( is_admin() && ! self::doing_ajax() );
893
+        return (is_admin() && !self::doing_ajax());
894 894
     }
895 895
 
896 896
     /**
@@ -900,10 +900,10 @@  discard block
 block discarded – undo
900 900
      */
901 901
     protected static function doing_ajax()
902 902
     {
903
-        if ( function_exists( 'wp_doing_ajax' ) ) {
903
+        if (function_exists('wp_doing_ajax')) {
904 904
             return wp_doing_ajax();
905 905
         }
906
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
906
+        return (defined('DOING_AJAX') && DOING_AJAX);
907 907
     }
908 908
 
909 909
     /**
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
      * @return bool
913 913
      */
914 914
     public static function should_show_menu_tabs() {
915
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
915
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
916 916
             return true;
917 917
         } else {
918 918
             return false;
Please login to merge, or discard this patch.
classes/autoptimizeCache.php 1 patch
Spacing   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles disk-cache-related operations.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
      * @param string $md5 Hash.
39 39
      * @param string $ext Extension.
40 40
      */
41
-    public function __construct( $md5, $ext = 'php' )
41
+    public function __construct($md5, $ext = 'php')
42 42
     {
43 43
         $_min_ext = '';
44
-        if ( apply_filters( 'autoptimize_filter_cache_url_add_min_ext', false ) ) {
44
+        if (apply_filters('autoptimize_filter_cache_url_add_min_ext', false)) {
45 45
             $_min_ext = '.min';
46 46
         }
47 47
 
48 48
         $this->cachedir = AUTOPTIMIZE_CACHE_DIR;
49 49
         $this->nogzip   = AUTOPTIMIZE_CACHE_NOGZIP;
50
-        if ( ! $this->nogzip ) {
51
-            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.php';
50
+        if (!$this->nogzip) {
51
+            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.php';
52 52
         } else {
53
-            if ( in_array( $ext, array( 'js', 'css' ) ) ) {
54
-                $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
53
+            if (in_array($ext, array('js', 'css'))) {
54
+                $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
55 55
             } else {
56
-                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
56
+                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
57 57
             }
58 58
         }
59 59
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function check()
67 67
     {
68
-        return file_exists( $this->cachedir . $this->filename );
68
+        return file_exists($this->cachedir.$this->filename);
69 69
     }
70 70
 
71 71
     /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function retrieve()
77 77
     {
78
-        if ( $this->check() ) {
79
-            if ( false == $this->nogzip ) {
80
-                return file_get_contents( $this->cachedir . $this->filename . '.none' );
78
+        if ($this->check()) {
79
+            if (false == $this->nogzip) {
80
+                return file_get_contents($this->cachedir.$this->filename.'.none');
81 81
             } else {
82
-                return file_get_contents( $this->cachedir . $this->filename );
82
+                return file_get_contents($this->cachedir.$this->filename);
83 83
             }
84 84
         }
85 85
         return false;
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return void
95 95
      */
96
-    public function cache( $data, $mime )
96
+    public function cache($data, $mime)
97 97
     {
98 98
         // readonly FS explicitly OK'ed by developer, so just pretend all is OK.
99
-        if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
99
+        if (defined('AUTOPTIMIZE_CACHE_READONLY')) {
100 100
             return true;
101 101
         }
102 102
 
@@ -104,44 +104,44 @@  discard block
 block discarded – undo
104 104
         //
105 105
         // to be activated for users that experience these ugly errors;
106 106
         // PHP Warning: file_put_contents failed to open stream: No such file or directory.
107
-        if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) {
107
+        if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) {
108 108
             $this->check_and_create_dirs();
109 109
         }
110 110
 
111
-        if ( false === $this->nogzip ) {
111
+        if (false === $this->nogzip) {
112 112
             // We handle gzipping ourselves.
113 113
             $file    = 'default.php';
114
-            $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file );
115
-            $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode );
114
+            $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file);
115
+            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode);
116 116
 
117
-            file_put_contents( $this->cachedir . $this->filename, $phpcode );
118
-            file_put_contents( $this->cachedir . $this->filename . '.none', $data );
117
+            file_put_contents($this->cachedir.$this->filename, $phpcode);
118
+            file_put_contents($this->cachedir.$this->filename.'.none', $data);
119 119
         } else {
120 120
             // Write code to cache without doing anything else.
121
-            file_put_contents( $this->cachedir . $this->filename, $data );
121
+            file_put_contents($this->cachedir.$this->filename, $data);
122 122
 
123 123
             // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single.
124
-            if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) {
125
-                $_extension     = pathinfo( $this->filename, PATHINFO_EXTENSION );
126
-                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension;
127
-                if ( ( 'css' === $_extension || 'js' === $_extension ) && ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) {
128
-                    file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data );
124
+            if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) {
125
+                $_extension     = pathinfo($this->filename, PATHINFO_EXTENSION);
126
+                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension;
127
+                if (('css' === $_extension || 'js' === $_extension) && !file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) {
128
+                    file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data);
129 129
                 }
130 130
             }
131 131
 
132
-            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) {
132
+            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) {
133 133
                 // Create an additional cached gzip file.
134
-                file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) );
134
+                file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP));
135 135
                 // If PHP Brotli extension is installed, create an additional cached Brotli file.
136
-                if ( function_exists( 'brotli_compress' ) ) {
137
-                    file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) );
136
+                if (function_exists('brotli_compress')) {
137
+                    file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC));
138 138
                 }
139 139
             }
140 140
         }
141 141
 
142 142
         // Provide 3rd party action hook for every cache file that is created.
143 143
         // This hook can for example be used to inject a copy of the created cache file to a other domain.
144
-        do_action( 'autoptimize_action_cache_file_created', $this->cachedir . $this->filename );
144
+        do_action('autoptimize_action_cache_file_created', $this->cachedir.$this->filename);
145 145
     }
146 146
 
147 147
     /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         // The original idea here was to provide 3rd party code a hook so that
157 157
         // it can "listen" to all the complete autoptimized-urls that the page
158 158
         // will emit... Or something to that effect I think?
159
-        apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename );
159
+        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename);
160 160
 
161 161
         return $this->filename;
162 162
     }
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
      * @param string $file Filename.
170 170
      * @return bool
171 171
      */
172
-    protected static function is_valid_cache_file( $dir, $file )
172
+    protected static function is_valid_cache_file($dir, $file)
173 173
     {
174
-        if ( '.' !== $file && '..' !== $file &&
175
-            false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) &&
176
-            is_file( $dir . $file ) ) {
174
+        if ('.' !== $file && '..' !== $file &&
175
+            false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) &&
176
+            is_file($dir.$file)) {
177 177
 
178 178
             // It's a valid file!
179 179
             return true;
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
     protected static function clear_cache_classic()
192 192
     {
193 193
         $contents = self::get_cache_contents();
194
-        foreach ( $contents as $name => $files ) {
195
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
196
-            foreach ( $files as $file ) {
197
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
198
-                    @unlink( $dir . $file ); // @codingStandardsIgnoreLine
194
+        foreach ($contents as $name => $files) {
195
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
196
+            foreach ($files as $file) {
197
+                if (self::is_valid_cache_file($dir, $file)) {
198
+                    @unlink($dir.$file); // @codingStandardsIgnoreLine
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203
-        @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine
203
+        @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine
204 204
     }
205 205
 
206 206
     /**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return bool
213 213
      */
214
-    protected static function rmdir( $pathname )
214
+    protected static function rmdir($pathname)
215 215
     {
216
-        $files = self::get_dir_contents( $pathname );
217
-        foreach ( $files as $file ) {
218
-            $path = $pathname . '/' . $file;
219
-            if ( is_dir( $path ) ) {
220
-                self::rmdir( $path );
216
+        $files = self::get_dir_contents($pathname);
217
+        foreach ($files as $file) {
218
+            $path = $pathname.'/'.$file;
219
+            if (is_dir($path)) {
220
+                self::rmdir($path);
221 221
             } else {
222
-                unlink( $path );
222
+                unlink($path);
223 223
             }
224 224
         }
225 225
 
226
-        return rmdir( $pathname );
226
+        return rmdir($pathname);
227 227
     }
228 228
 
229 229
     /**
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
         $new_name = self::get_unique_name();
245 245
 
246 246
         // Makes sure the new pathname is on the same level...
247
-        $new_pathname = dirname( $dir ) . '/' . $new_name;
248
-        $renamed      = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine
247
+        $new_pathname = dirname($dir).'/'.$new_name;
248
+        $renamed      = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine
249 249
 
250 250
         // When renamed, re-create the default cache directory back so it's
251 251
         // available again...
252
-        if ( $renamed ) {
252
+        if ($renamed) {
253 253
             $ok = self::cacheavail();
254 254
         }
255 255
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public static function advanced_cache_clear_enabled()
265 265
     {
266
-        return apply_filters( 'autoptimize_filter_cache_clear_advanced', false );
266
+        return apply_filters('autoptimize_filter_cache_clear_advanced', false);
267 267
     }
268 268
 
269 269
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     protected static function get_unique_name()
275 275
     {
276 276
         $prefix   = self::get_advanced_cache_clear_prefix();
277
-        $new_name = uniqid( $prefix, true );
277
+        $new_name = uniqid($prefix, true);
278 278
 
279 279
         return $new_name;
280 280
     }
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
     protected static function get_advanced_cache_clear_prefix()
288 288
     {
289 289
         $pathname = self::get_pathname_base();
290
-        $basename = basename( $pathname );
291
-        $prefix   = $basename . '-artifact-';
290
+        $basename = basename($pathname);
291
+        $prefix   = $basename.'-artifact-';
292 292
 
293 293
         return $prefix;
294 294
     }
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
      *
302 302
      * @return array
303 303
      */
304
-    protected static function get_dir_contents( $pathname )
304
+    protected static function get_dir_contents($pathname)
305 305
     {
306
-        return array_slice( scandir( $pathname ), 2 );
306
+        return array_slice(scandir($pathname), 2);
307 307
     }
308 308
 
309 309
     /**
@@ -316,24 +316,24 @@  discard block
 block discarded – undo
316 316
     public static function delete_advanced_cache_clear_artifacts()
317 317
     {
318 318
         // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active.
319
-        if ( ! self::advanced_cache_clear_enabled() ) {
319
+        if (!self::advanced_cache_clear_enabled()) {
320 320
             return false;
321 321
         }
322 322
 
323 323
         $dir    = self::get_pathname_base();
324 324
         $prefix = self::get_advanced_cache_clear_prefix();
325
-        $parent = dirname( $dir );
325
+        $parent = dirname($dir);
326 326
         $ok     = false;
327 327
 
328 328
         // Returns the list of files without '.' and '..' elements.
329
-        $files = self::get_dir_contents( $parent );
330
-        if ( is_array( $files ) && ! empty( $files ) ) {
331
-            foreach ( $files as $file ) {
332
-                $path     = $parent . '/' . $file;
333
-                $prefixed = ( false !== strpos( $path, $prefix ) );
329
+        $files = self::get_dir_contents($parent);
330
+        if (is_array($files) && !empty($files)) {
331
+            foreach ($files as $file) {
332
+                $path     = $parent.'/'.$file;
333
+                $prefixed = (false !== strpos($path, $prefix));
334 334
                 // Removing only our own (prefixed) directories...
335
-                if ( is_dir( $path ) && $prefixed ) {
336
-                    $ok = self::rmdir( $path );
335
+                if (is_dir($path) && $prefixed) {
336
+                    $ok = self::rmdir($path);
337 337
                 }
338 338
             }
339 339
         }
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
     {
354 354
         $pathname = self::get_pathname_base();
355 355
 
356
-        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
356
+        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
357 357
             $blog_id   = get_current_blog_id();
358
-            $pathname .= $blog_id . '/';
358
+            $pathname .= $blog_id.'/';
359 359
         }
360 360
 
361 361
         return $pathname;
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     protected static function get_pathname_base()
370 370
     {
371
-        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
371
+        $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR;
372 372
 
373 373
         return $pathname;
374 374
     }
@@ -380,46 +380,46 @@  discard block
 block discarded – undo
380 380
      *
381 381
      * @return bool
382 382
      */
383
-    public static function clearall( $propagate = true )
383
+    public static function clearall($propagate = true)
384 384
     {
385
-        if ( ! self::cacheavail() ) {
385
+        if (!self::cacheavail()) {
386 386
             return false;
387 387
         }
388 388
 
389 389
         // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
390
-        if ( self::advanced_cache_clear_enabled() ) {
390
+        if (self::advanced_cache_clear_enabled()) {
391 391
             self::clear_cache_via_rename();
392 392
         } else {
393 393
             self::clear_cache_classic();
394 394
         }
395 395
 
396 396
         // Remove 404 handler if required.
397
-        if ( self::do_fallback() ) {
398
-            $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php';
399
-            @unlink( $_fallback_php ); // @codingStandardsIgnoreLine
397
+        if (self::do_fallback()) {
398
+            $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php';
399
+            @unlink($_fallback_php); // @codingStandardsIgnoreLine
400 400
         }
401 401
 
402 402
         // Remove the transient so it gets regenerated...
403
-        delete_transient( 'autoptimize_stats' );
403
+        delete_transient('autoptimize_stats');
404 404
 
405 405
         // Cache was just purged, clear page cache and allow others to hook into our purging...
406
-        if ( true === $propagate ) {
407
-            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) {
406
+        if (true === $propagate) {
407
+            if (!function_exists('autoptimize_do_cachepurged_action')) {
408 408
                 function autoptimize_do_cachepurged_action() {
409
-                    do_action( 'autoptimize_action_cachepurged' );
409
+                    do_action('autoptimize_action_cachepurged');
410 410
                 }
411 411
             }
412
-            add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 );
413
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 );
412
+            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11);
413
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0);
414 414
         }
415 415
 
416 416
         // Warm cache (part of speedupper)!
417
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) {
418
-            set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 );
419
-            $url   = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 );
420
-            $url   = apply_filters( 'autoptimize_filter_cache_warmer_url', $url );
421
-            $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine
422
-            unset( $cache );
417
+        if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) {
418
+            set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10);
419
+            $url   = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000);
420
+            $url   = apply_filters('autoptimize_filter_cache_warmer_url', $url);
421
+            $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine
422
+            unset($cache);
423 423
         }
424 424
 
425 425
         return true;
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      */
435 435
     public static function clearall_actionless()
436 436
     {
437
-        return self::clearall( false );
437
+        return self::clearall(false);
438 438
     }
439 439
 
440 440
     /**
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
     {
447 447
         $contents = array();
448 448
 
449
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
450
-            $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir );
449
+        foreach (array('', 'js', 'css') as $dir) {
450
+            $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir);
451 451
         }
452 452
 
453 453
         return $contents;
@@ -460,21 +460,21 @@  discard block
 block discarded – undo
460 460
      */
461 461
     public static function stats()
462 462
     {
463
-        $stats = get_transient( 'autoptimize_stats' );
463
+        $stats = get_transient('autoptimize_stats');
464 464
 
465 465
         // If no transient, do the actual scan!
466
-        if ( ! is_array( $stats ) ) {
467
-            if ( ! self::cacheavail() ) {
466
+        if (!is_array($stats)) {
467
+            if (!self::cacheavail()) {
468 468
                 return 0;
469 469
             }
470 470
             $stats = self::stats_scan();
471 471
             $count = $stats[0];
472
-            if ( $count > 100 ) {
472
+            if ($count > 100) {
473 473
                 // Store results in transient.
474 474
                 set_transient(
475 475
                     'autoptimize_stats',
476 476
                     $stats,
477
-                    apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS )
477
+                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS)
478 478
                 );
479 479
             }
480 480
         }
@@ -497,30 +497,30 @@  discard block
 block discarded – undo
497 497
         $size  = 0;
498 498
 
499 499
         // Scan everything in our cache directories.
500
-        foreach ( self::get_cache_contents() as $name => $files ) {
501
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
502
-            foreach ( $files as $file ) {
503
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
504
-                    if ( AUTOPTIMIZE_CACHE_NOGZIP &&
500
+        foreach (self::get_cache_contents() as $name => $files) {
501
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
502
+            foreach ($files as $file) {
503
+                if (self::is_valid_cache_file($dir, $file)) {
504
+                    if (AUTOPTIMIZE_CACHE_NOGZIP &&
505 505
                         (
506
-                            false !== strpos( $file, '.js' ) ||
507
-                            false !== strpos( $file, '.css' ) ||
508
-                            false !== strpos( $file, '.img' ) ||
509
-                            false !== strpos( $file, '.txt' )
506
+                            false !== strpos($file, '.js') ||
507
+                            false !== strpos($file, '.css') ||
508
+                            false !== strpos($file, '.img') ||
509
+                            false !== strpos($file, '.txt')
510 510
                         )
511 511
                     ) {
512 512
                         // Web server is gzipping, we count .js|.css|.img|.txt files.
513 513
                         $count++;
514
-                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) {
514
+                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) {
515 515
                         // We are gzipping ourselves via php, counting only .none files.
516 516
                         $count++;
517 517
                     }
518
-                    $size += filesize( $dir . $file );
518
+                    $size += filesize($dir.$file);
519 519
                 }
520 520
             }
521 521
         }
522 522
 
523
-        $stats = array( $count, $size, time() );
523
+        $stats = array($count, $size, time());
524 524
 
525 525
         return $stats;
526 526
     }
@@ -535,26 +535,26 @@  discard block
 block discarded – undo
535 535
     public static function cacheavail()
536 536
     {
537 537
         // readonly FS explicitly OK'ed by dev, let's assume the cache dirs are there!
538
-        if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
538
+        if (defined('AUTOPTIMIZE_CACHE_READONLY')) {
539 539
             return true;
540 540
         }
541 541
 
542
-        if ( false === autoptimizeCache::check_and_create_dirs() ) {
542
+        if (false === autoptimizeCache::check_and_create_dirs()) {
543 543
             return false;
544 544
         }
545 545
 
546 546
         // Using .htaccess inside our cache folder to overrule wp-super-cache.
547
-        $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
548
-        if ( ! is_file( $htaccess ) ) {
547
+        $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess';
548
+        if (!is_file($htaccess)) {
549 549
             /**
550 550
              * Create `wp-content/AO_htaccess_tmpl` file with
551 551
              * whatever htaccess rules you might need
552 552
              * if you want to override default AO htaccess
553 553
              */
554
-            $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl';
555
-            if ( is_file( $htaccess_tmpl ) ) {
556
-                $content = file_get_contents( $htaccess_tmpl );
557
-            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) {
554
+            $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl';
555
+            if (is_file($htaccess_tmpl)) {
556
+                $content = file_get_contents($htaccess_tmpl);
557
+            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) {
558 558
                 $content = '<IfModule mod_expires.c>
559 559
         ExpiresActive On
560 560
         ExpiresByType text/css A30672000
@@ -608,13 +608,13 @@  discard block
 block discarded – undo
608 608
 </IfModule>';
609 609
             }
610 610
 
611
-            if ( self::do_fallback() === true ) {
612
-                $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
611
+            if (self::do_fallback() === true) {
612
+                $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php';
613 613
             }
614
-            @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
614
+            @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine
615 615
         }
616 616
 
617
-        if ( self::do_fallback() ) {
617
+        if (self::do_fallback()) {
618 618
             self::check_fallback_php();
619 619
         }
620 620
 
@@ -629,17 +629,17 @@  discard block
 block discarded – undo
629 629
      */
630 630
     public static function check_fallback_php() {
631 631
         $_fallback_filename = 'autoptimize_404_handler.php';
632
-        $_fallback_php      = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename;
632
+        $_fallback_php      = trailingslashit(WP_CONTENT_DIR).$_fallback_filename;
633 633
         $_fallback_status   = true;
634 634
 
635
-        if ( ! file_exists( $_fallback_php ) ) {
636
-            $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
637
-            $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
638
-            $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
639
-            if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
640
-                $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
635
+        if (!file_exists($_fallback_php)) {
636
+            $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename);
637
+            $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents);
638
+            $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents);
639
+            if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) {
640
+                $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents);
641 641
             }
642
-            $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
642
+            $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents);
643 643
         }
644 644
 
645 645
         return $_fallback_status;
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
     public static function do_fallback() {
657 657
         static $_do_fallback = null;
658 658
 
659
-        if ( null === $_do_fallback ) {
660
-            $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) );
659
+        if (null === $_do_fallback) {
660
+            $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1'));
661 661
         }
662 662
 
663 663
         return $_do_fallback;
@@ -669,31 +669,31 @@  discard block
 block discarded – undo
669 669
      * and 410'ing ("Gone") if fallback not available.
670 670
      */
671 671
     public static function wordpress_notfound_fallback() {
672
-        $original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
673
-        if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) {
672
+        $original_request = strtok($_SERVER['REQUEST_URI'], '?');
673
+        if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) {
674 674
             // make sure this is not considered a 404.
675 675
             global $wp_query;
676 676
             $wp_query->is_404 = false;
677 677
 
678 678
             // set fallback path.
679
-            $js_or_css     = pathinfo( $original_request, PATHINFO_EXTENSION );
680
-            $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
679
+            $js_or_css     = pathinfo($original_request, PATHINFO_EXTENSION);
680
+            $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
681 681
 
682 682
             // prepare for Shakeeb's Unused CSS files to be 404-handled as well.
683
-            if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
684
-                $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
683
+            if (strpos($original_request, 'uucss/uucss-') !== false) {
684
+                $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
685 685
             }
686 686
 
687 687
             // set fallback URL.
688
-            $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
688
+            $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
689 689
 
690 690
             // redirect to fallback if possible.
691
-            if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
691
+            if ($original_request !== $fallback_target && file_exists($fallback_path)) {
692 692
                 // redirect to fallback.
693
-                wp_redirect( $fallback_target, 302 );
693
+                wp_redirect($fallback_target, 302);
694 694
             } else {
695 695
                 // return HTTP 410 (gone) reponse.
696
-                status_header( 410 );
696
+                status_header(410);
697 697
             }
698 698
         }
699 699
     }
@@ -705,13 +705,13 @@  discard block
 block discarded – undo
705 705
      * @return bool
706 706
      */
707 707
     public static function check_and_create_dirs() {
708
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
708
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
709 709
             // We didn't set a cache.
710 710
             return false;
711 711
         }
712 712
 
713
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
714
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
713
+        foreach (array('', 'js', 'css') as $dir) {
714
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
715 715
                 return false;
716 716
             }
717 717
         }
@@ -726,25 +726,25 @@  discard block
 block discarded – undo
726 726
      *
727 727
      * @return bool
728 728
      */
729
-    protected static function check_cache_dir( $dir )
729
+    protected static function check_cache_dir($dir)
730 730
     {
731 731
         // Try creating the dir if it doesn't exist.
732
-        if ( ! file_exists( $dir ) ) {
733
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
734
-            if ( ! file_exists( $dir ) ) {
732
+        if (!file_exists($dir)) {
733
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
734
+            if (!file_exists($dir)) {
735 735
                 return false;
736 736
             }
737 737
         }
738 738
 
739 739
         // If we still cannot write, bail.
740
-        if ( ! is_writable( $dir ) ) {
740
+        if (!is_writable($dir)) {
741 741
             return false;
742 742
         }
743 743
 
744 744
         // Create an index.html in there to avoid prying eyes!
745
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
746
-        if ( ! is_file( $idx_file ) ) {
747
-            @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine
745
+        $idx_file = rtrim($dir, '/\\').'/index.html';
746
+        if (!is_file($idx_file)) {
747
+            @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine
748 748
         }
749 749
 
750 750
         return true;
@@ -758,54 +758,54 @@  discard block
 block discarded – undo
758 758
     // @codingStandardsIgnoreStart
759 759
     public static function flushPageCache()
760 760
     {
761
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
762
-            if ( is_multisite() ) {
761
+        if (function_exists('wp_cache_clear_cache')) {
762
+            if (is_multisite()) {
763 763
                 $blog_id = get_current_blog_id();
764
-                wp_cache_clear_cache( $blog_id );
764
+                wp_cache_clear_cache($blog_id);
765 765
             } else {
766 766
                 wp_cache_clear_cache();
767 767
             }
768
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
769
-            do_action( 'cachify_flush_cache' );
770
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
768
+        } elseif (has_action('cachify_flush_cache')) {
769
+            do_action('cachify_flush_cache');
770
+        } elseif (function_exists('w3tc_pgcache_flush')) {
771 771
             w3tc_pgcache_flush();
772
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
772
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
773 773
             wp_fast_cache_bulk_delete_all();
774
-        } elseif ( function_exists( 'rapidcache_clear_cache' ) ) {
774
+        } elseif (function_exists('rapidcache_clear_cache')) {
775 775
             rapidcache_clear_cache();
776
-        } elseif ( class_exists( 'Swift_Performance_Cache' ) ) {
776
+        } elseif (class_exists('Swift_Performance_Cache')) {
777 777
             Swift_Performance_Cache::clear_all_cache();
778
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
778
+        } elseif (class_exists('WpFastestCache')) {
779 779
             $wpfc = new WpFastestCache();
780 780
             $wpfc->deleteCache();
781
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
781
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
782 782
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
783
-        } elseif ( class_exists( 'zencache' ) ) {
783
+        } elseif (class_exists('zencache')) {
784 784
             zencache::clear();
785
-        } elseif ( class_exists( 'comet_cache' ) ) {
785
+        } elseif (class_exists('comet_cache')) {
786 786
             comet_cache::clear();
787
-        } elseif ( class_exists( 'WpeCommon' ) ) {
787
+        } elseif (class_exists('WpeCommon')) {
788 788
             // WPEngine cache purge/flush methods to call by default
789 789
             $wpe_methods = array(
790 790
                 'purge_varnish_cache',
791 791
             );
792 792
 
793 793
             // More agressive clear/flush/purge behind a filter
794
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
795
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
794
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
795
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
796 796
             }
797 797
 
798 798
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
799
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
799
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
800 800
 
801
-            foreach ( $wpe_methods as $wpe_method ) {
802
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
801
+            foreach ($wpe_methods as $wpe_method) {
802
+                if (method_exists('WpeCommon', $wpe_method)) {
803 803
                     WpeCommon::$wpe_method();
804 804
                 }
805 805
             }
806
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
806
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
807 807
             sg_cachepress_purge_cache();
808
-        } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
808
+        } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) {
809 809
             $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
810 810
             $_kinsta_response        = wp_remote_get(
811 811
                 $_kinsta_clear_cache_url,
@@ -814,18 +814,18 @@  discard block
 block discarded – undo
814 814
                     'timeout' => 5,
815 815
                     )
816 816
             );
817
-        } elseif ( defined('NGINX_HELPER_BASENAME') ) {
818
-            do_action( 'rt_nginx_helper_purge_all' );
819
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
817
+        } elseif (defined('NGINX_HELPER_BASENAME')) {
818
+            do_action('rt_nginx_helper_purge_all');
819
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
820 820
             // fallback for WP-Super-Cache
821 821
             global $cache_path;
822
-            if ( is_multisite() ) {
822
+            if (is_multisite()) {
823 823
                 $blog_id = get_current_blog_id();
824
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
825
-                prune_super_cache( $cache_path . 'blogs/', true );
824
+                prune_super_cache(get_supercache_dir($blog_id), true);
825
+                prune_super_cache($cache_path.'blogs/', true);
826 826
             } else {
827
-                prune_super_cache( $cache_path . 'supercache/', true );
828
-                prune_super_cache( $cache_path, true );
827
+                prune_super_cache($cache_path.'supercache/', true);
828
+                prune_super_cache($cache_path, true);
829 829
             }
830 830
         }
831 831
     }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettingsAjax.php 1 patch
Spacing   +109 added lines, -109 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,30 +275,30 @@  discard block
 block discarded – undo
275 275
     public function ao_ccss_import_callback() {
276 276
         // Ajax handler import settings
277 277
         // Check referer.
278
-        check_ajax_referer( 'ao_ccss_import_nonce', 'ao_ccss_import_nonce' );
278
+        check_ajax_referer('ao_ccss_import_nonce', 'ao_ccss_import_nonce');
279 279
 
280 280
         // Initialize error flag.
281 281
         $error = false;
282 282
 
283 283
         // Process an uploaded file with no errors.
284
-        if ( current_user_can( 'manage_options' ) && ! $_FILES['file']['error'] && $_FILES['file']['size'] < 500001 && strpos( $_FILES['file']['name'], '.zip' ) === strlen( $_FILES['file']['name'] ) - 4 ) {
284
+        if (current_user_can('manage_options') && !$_FILES['file']['error'] && $_FILES['file']['size'] < 500001 && strpos($_FILES['file']['name'], '.zip') === strlen($_FILES['file']['name']) - 4) {
285 285
             // create tmp dir with hard guess name in AO_CCSS_DIR.
286
-            $_secret_dir     = wp_hash( uniqid( md5( AUTOPTIMIZE_CACHE_URL ), true ) );
287
-            $_import_tmp_dir = trailingslashit( AO_CCSS_DIR . $_secret_dir );
288
-            mkdir( $_import_tmp_dir );
286
+            $_secret_dir     = wp_hash(uniqid(md5(AUTOPTIMIZE_CACHE_URL), true));
287
+            $_import_tmp_dir = trailingslashit(AO_CCSS_DIR.$_secret_dir);
288
+            mkdir($_import_tmp_dir);
289 289
 
290 290
             // Save file to that tmp directory but give it our own name to prevent directory traversal risks when using original name.
291
-            $zipfile = $_import_tmp_dir . uniqid( 'import_settings-', true ) . '.zip';
292
-            move_uploaded_file( $_FILES['file']['tmp_name'], $zipfile );
291
+            $zipfile = $_import_tmp_dir.uniqid('import_settings-', true).'.zip';
292
+            move_uploaded_file($_FILES['file']['tmp_name'], $zipfile);
293 293
 
294 294
             // Extract archive in the tmp directory.
295 295
             $zip = new ZipArchive;
296
-            if ( $zip->open( $zipfile ) === true ) {
296
+            if ($zip->open($zipfile) === true) {
297 297
                 // loop through all files in the zipfile.
298 298
                 for ($i = 0; $i < $zip->numFiles; $i++) {
299 299
                     // but only extract known good files.
300
-                    if ( preg_match('/^settings\.json$|^ccss_[a-z0-9]{32}\.css$/', $zip->getNameIndex( $i ) ) > 0 ) {
301
-                        $zip->extractTo( AO_CCSS_DIR, $zip->getNameIndex( $i ) );
300
+                    if (preg_match('/^settings\.json$|^ccss_[a-z0-9]{32}\.css$/', $zip->getNameIndex($i)) > 0) {
301
+                        $zip->extractTo(AO_CCSS_DIR, $zip->getNameIndex($i));
302 302
                     }
303 303
                 }
304 304
                 $zip->close();
@@ -307,26 +307,26 @@  discard block
 block discarded – undo
307 307
             }
308 308
             
309 309
             // and remove temp. dir with all contents (the import-zipfile).
310
-            $this->rrmdir( $_import_tmp_dir );
310
+            $this->rrmdir($_import_tmp_dir);
311 311
 
312
-            if ( ! $error ) {
312
+            if (!$error) {
313 313
                 // Archive extraction ok, continue importing settings from AO_CCSS_DIR.
314 314
                 // Settings file.
315
-                $importfile = AO_CCSS_DIR . 'settings.json';
315
+                $importfile = AO_CCSS_DIR.'settings.json';
316 316
 
317
-                if ( file_exists( $importfile ) ) {
317
+                if (file_exists($importfile)) {
318 318
                     // Get settings and turn them into an object.
319
-                    $settings = json_decode( file_get_contents( $importfile ), true );
319
+                    $settings = json_decode(file_get_contents($importfile), true);
320 320
 
321 321
                     // Update options.
322
-                    update_option( 'autoptimize_ccss_rules', $settings['rules'] );
323
-                    update_option( 'autoptimize_ccss_additional', $settings['additional'] );
324
-                    update_option( 'autoptimize_ccss_viewport', $settings['viewport'] );
325
-                    update_option( 'autoptimize_ccss_finclude', $settings['finclude'] );
326
-                    update_option( 'autoptimize_ccss_rlimit', $settings['rlimit'] );
327
-                    update_option( 'autoptimize_ccss_noptimize', $settings['noptimize'] );
328
-                    update_option( 'autoptimize_ccss_debug', $settings['debug'] );
329
-                    update_option( 'autoptimize_ccss_key', $settings['key'] );
322
+                    update_option('autoptimize_ccss_rules', $settings['rules']);
323
+                    update_option('autoptimize_ccss_additional', $settings['additional']);
324
+                    update_option('autoptimize_ccss_viewport', $settings['viewport']);
325
+                    update_option('autoptimize_ccss_finclude', $settings['finclude']);
326
+                    update_option('autoptimize_ccss_rlimit', $settings['rlimit']);
327
+                    update_option('autoptimize_ccss_noptimize', $settings['noptimize']);
328
+                    update_option('autoptimize_ccss_debug', $settings['debug']);
329
+                    update_option('autoptimize_ccss_key', $settings['key']);
330 330
                 } else {
331 331
                     // Settings file doesn't exist, update error flag.
332 332
                     $error = 'settings file does not exist';
@@ -337,28 +337,28 @@  discard block
 block discarded – undo
337 337
         }
338 338
 
339 339
         // Prepare response.
340
-        if ( $error ) {
340
+        if ($error) {
341 341
             $response['code'] = '500';
342
-            $response['msg']  = 'Error importing settings: ' . $error;
342
+            $response['msg']  = 'Error importing settings: '.$error;
343 343
         } else {
344 344
             $response['code'] = '200';
345 345
             $response['msg']  = 'Settings imported successfully';
346 346
         }
347 347
 
348 348
         // Dispatch respose.
349
-        echo json_encode( $response );
349
+        echo json_encode($response);
350 350
 
351 351
         // Close ajax request.
352 352
         wp_die();
353 353
     }
354 354
 
355
-    public function critcss_check_filename( $filename ) {
355
+    public function critcss_check_filename($filename) {
356 356
         // Try to avoid directory traversal when reading/writing/deleting critical CSS files.
357
-        if ( strpos( $filename, 'ccss_' ) !== 0 ) {
357
+        if (strpos($filename, 'ccss_') !== 0) {
358 358
             return false;
359
-        } elseif ( substr( $filename, -4, 4 ) !== '.css' ) {
359
+        } elseif (substr($filename, -4, 4) !== '.css') {
360 360
             return false;
361
-        } elseif ( sanitize_file_name( $filename ) !== $filename ) {
361
+        } elseif (sanitize_file_name($filename) !== $filename) {
362 362
             // Use WordPress core's sanitize_file_name to see if anything fishy is going on.
363 363
             return false;
364 364
         } else {
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
         }
367 367
     }
368 368
     
369
-    public function rrmdir( $path ) {
369
+    public function rrmdir($path) {
370 370
         // recursively remove a directory as found on
371 371
         // https://andy-carter.com/blog/recursively-remove-a-directory-in-php.
372
-        $files = glob($path . '/*');
373
-        foreach ( $files as $file ) {
374
-            is_dir( $file ) ? $this->rrmdir( $file ) : unlink( $file );
372
+        $files = glob($path.'/*');
373
+        foreach ($files as $file) {
374
+            is_dir($file) ? $this->rrmdir($file) : unlink($file);
375 375
         }
376
-        rmdir( $path );
376
+        rmdir($path);
377 377
 
378 378
         return;
379 379
     }
Please login to merge, or discard this patch.