Completed
Push — master ( 8cd4be...fd6893 )
by frank
02:38
created
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['rtimelimit'] = get_option( 'autoptimize_ccss_rtimelimit' );
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['rtimelimit'] = get_option('autoptimize_ccss_rtimelimit');
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_rtimelimit', $settings['rtimelimit'] );
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_rtimelimit', $settings['rtimelimit']);
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.
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.8.1' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.8.1');
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/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,66 +52,66 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rtimelimit' );
62
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' );
63
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' );
64
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' );
65
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' );
66
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' );
67
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' );
68
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' );
69
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' );
70
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rtimelimit');
62
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize');
63
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug');
64
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_key');
65
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst');
66
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin');
67
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath');
68
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery');
69
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain');
70
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss');
71 71
 
72 72
         // And add submenu-page.
73
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
73
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
74 74
     }
75 75
 
76
-    public function admin_assets( $hook ) {
76
+    public function admin_assets($hook) {
77 77
         // Return if plugin is not hooked.
78
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
78
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
79 79
             return;
80 80
         }
81 81
 
82 82
         // Stylesheets to add.
83
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
84
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
85
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
83
+        wp_enqueue_style('wp-jquery-ui-dialog');
84
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
85
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
86 86
 
87 87
         // Scripts to add.
88
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
89
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
90
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
91
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
88
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
89
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
90
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
91
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
92 92
     }
93 93
 
94 94
     public function ao_criticalcsssettings_page()
95 95
     {
96 96
         // these are not OO yet, simply require for now.
97
-        require_once( 'critcss-inc/admin_settings_rules.php' );
98
-        require_once( 'critcss-inc/admin_settings_queue.php' );
99
-        require_once( 'critcss-inc/admin_settings_key.php' );
100
-        require_once( 'critcss-inc/admin_settings_adv.php' );
101
-        require_once( 'critcss-inc/admin_settings_explain.php' );
97
+        require_once('critcss-inc/admin_settings_rules.php');
98
+        require_once('critcss-inc/admin_settings_queue.php');
99
+        require_once('critcss-inc/admin_settings_key.php');
100
+        require_once('critcss-inc/admin_settings_adv.php');
101
+        require_once('critcss-inc/admin_settings_explain.php');
102 102
 
103 103
         // fetch all options at once and populate them individually explicitely as globals.
104 104
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
105
-        foreach ( $all_options as $_option => $_value ) {
105
+        foreach ($all_options as $_option => $_value) {
106 106
             global ${$_option};
107 107
             ${$_option} = $_value;
108 108
         }
109 109
         ?>
110
-        <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
110
+        <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
111 111
         <div class="wrap">
112 112
             <div id="autoptimize_main">
113 113
                 <div id="ao_title_and_button">
114
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
114
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
115 115
                 </div>
116 116
 
117 117
                 <?php
@@ -119,39 +119,39 @@  discard block
 block discarded – undo
119 119
                 echo autoptimizeConfig::ao_admin_tabs();
120 120
 
121 121
                 // Make sure dir to write ao_ccss exists and is writable.
122
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
123
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
122
+                if (!is_dir(AO_CCSS_DIR)) {
123
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
124 124
                 } else {
125 125
                     $mkdirresp = true;
126 126
                 }
127 127
 
128 128
                 // Make sure our index.html is there.
129
-                if ( ! is_file( AO_CCSS_DIR . 'index.html' ) ) {
130
-                    $fileresp = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' );
129
+                if (!is_file(AO_CCSS_DIR.'index.html')) {
130
+                    $fileresp = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>');
131 131
                 } else {
132 132
                     $fileresp = true;
133 133
                 }
134 134
 
135 135
                 // Warn if we could not create those files.
136
-                if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
136
+                if ((!$mkdirresp) || (!$fileresp)) {
137 137
                     ?>
138 138
                     <div class="notice-error notice"><p>
139 139
                     <?php
140
-                    _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
140
+                    _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
141 141
                     ?>
142 142
                     </p></div>
143 143
                     <?php
144 144
                 }
145 145
 
146 146
                 // Check for "inline & defer CSS" being active in Autoptimize.
147
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
148
-                    if ( empty( $ao_ccss_keyst ) ) {
147
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
148
+                    if (empty($ao_ccss_keyst)) {
149 149
                         // no keystate so likely in activation-process of CCSS, let's enable "inline & defer CSS" immediately to make things easier!
150
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_css_defer', 'on' );
150
+                        autoptimizeOptionWrapper::update_option('autoptimize_css_defer', 'on');
151 151
                         ?>
152 152
                         <div class="notice-info notice"><p>
153 153
                         <?php
154
-                        _e( "The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize' );
154
+                        _e("The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize');
155 155
                         ?>
156 156
                         </p></div>
157 157
                         <?php
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                         ?>
161 161
                         <div class="notice-warning notice"><p>
162 162
                         <?php
163
-                        _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to ensure critical CSS is used on the front-end.", 'autoptimize' );
163
+                        _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to ensure critical CSS is used on the front-end.", 'autoptimize');
164 164
                         ?>
165 165
                         </p></div>
166 166
                         <?php
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
                 }
169 169
 
170 170
                 // check if WordPress cron is disabled and warn if so.
171
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
171
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
172 172
                     ?>
173 173
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
174 174
                     <?php
175
-                    _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
175
+                    _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
176 176
                     ?>
177 177
                     </p></div>
178 178
                     <?php
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 
181 181
                 // warn if it looks as though the queue processing job looks isn't running
182 182
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
183
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
184
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
183
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
184
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
185 185
                     $_jobs_all_new         = true;
186
-                    $_oldest_job_timestamp = microtime( true ); // now.
186
+                    $_oldest_job_timestamp = microtime(true); // now.
187 187
                     $_jobs_too_old         = true;
188 188
 
189 189
                     // go over queue array.
190
-                    if ( empty( $ao_ccss_queue ) ) {
190
+                    if (empty($ao_ccss_queue)) {
191 191
                         // no jobs, then no warning.
192 192
                         $_jobs_all_new = false;
193 193
                     } else {
194
-                        foreach ( $ao_ccss_queue as $job ) {
195
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
194
+                        foreach ($ao_ccss_queue as $job) {
195
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
196 196
                                 // we need to catch the oldest job's timestamp.
197 197
                                 $_oldest_job_timestamp = $job['jctime'];
198 198
                             }
199 199
 
200
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
200
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
201 201
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
202 202
                                 $_jobs_all_new = false;
203 203
                                 break;
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
                     }
207 207
 
208 208
                     // is the oldest job too old (4h)?
209
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
209
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
210 210
                         $_jobs_too_old = false;
211 211
                     }
212 212
 
213
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
213
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
214 214
                         $_warn_cron            = 'on';
215 215
                         $_transient_multiplier = 1; // store for 1 hour.
216 216
                     } else {
@@ -218,35 +218,35 @@  discard block
 block discarded – undo
218 218
                         $_transient_multiplier = 4; // store for 4 hours.
219 219
                     }
220 220
                     // and set transient.
221
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
221
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
222 222
                 }
223 223
 
224
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
224
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
225 225
                     ?>
226 226
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
227 227
                     <?php
228
-                    _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
228
+                    _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
229 229
                     ?>
230 230
                     </p></div>
231 231
                     <?php
232
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
232
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
233 233
                     ?>
234 234
                     <div class="notice-success notice"><p>
235 235
                     <?php
236
-                    _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' );
236
+                    _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize');
237 237
                     echo ' ';
238
-                    _e( 'In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize' );
238
+                    _e('In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize');
239 239
                     ?>
240 240
                     </p></div>
241 241
                     <?php
242 242
                 }
243 243
 
244 244
                 // warn if service is down.
245
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
245
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
246 246
                     ?>
247 247
                     <div class="notice-warning notice"><p>
248 248
                     <?php
249
-                    _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' );
249
+                    _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize');
250 250
                     ?>
251 251
                     </p></div>
252 252
                     <?php
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
 
255 255
                 // warn if too many rules (based on length of ao_ccss_rules option) as that might cause issues at e.g. wpengine
256 256
                 // see https://wpengine.com/support/database-optimization-best-practices/#Autoloaded_Data
257
-                $_raw_rules_length = strlen( get_option( 'autoptimize_ccss_rules', '') );
258
-                if ( $_raw_rules_length > apply_filters( 'autoptimize_ccss_rules_length_warning', 500000 ) ) {
257
+                $_raw_rules_length = strlen(get_option('autoptimize_ccss_rules', ''));
258
+                if ($_raw_rules_length > apply_filters('autoptimize_ccss_rules_length_warning', 500000)) {
259 259
                     ?>
260 260
                     <div class="notice-warning notice"><p>
261 261
                     <?php
262
-                    _e( 'It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize' );
262
+                    _e('It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize');
263 263
                     ?>
264 264
                     </p></div>
265 265
                     <?php
@@ -269,24 +269,24 @@  discard block
 block discarded – undo
269 269
                 ?>
270 270
                 <form id="settings" method="post" action="options.php">
271 271
                     <?php
272
-                    settings_fields( 'ao_ccss_options_group' );
272
+                    settings_fields('ao_ccss_options_group');
273 273
 
274 274
                     // Get API key status.
275
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
275
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
276 276
 
277
-                    if ( $this->is_multisite_network_admin() ) {
277
+                    if ($this->is_multisite_network_admin()) {
278 278
                         ?>
279 279
                         <ul id="key-panel">
280 280
                             <li class="itemDetail">
281 281
                             <?php
282 282
                                 // translators: the placesholder is for a line of code in wp-config.php.
283
-                                echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' );
283
+                                echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>');
284 284
                             ?>
285 285
                             </li>
286 286
                         </ul>
287 287
                         <?php
288 288
                     } else {
289
-                        if ( 'valid' == $key['status'] ) {
289
+                        if ('valid' == $key['status']) {
290 290
                             // If key status is valid, render other panels.
291 291
                             // Render rules section.
292 292
                             ao_ccss_render_rules();
@@ -303,23 +303,23 @@  discard block
 block discarded – undo
303 303
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
304 304
 
305 305
                             // Add hidden fields.
306
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
307
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
308
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
309
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
310
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
311
-                            echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="' . $ao_ccss_rtimelimit . '">';
312
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
313
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
314
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
315
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
316
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
306
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
307
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
308
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
309
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
310
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
311
+                            echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="'.$ao_ccss_rtimelimit.'">';
312
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
313
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
314
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
315
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
316
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
317 317
                         }
318 318
                         // Render key panel unconditionally.
319
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
319
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
320 320
                         ?>
321 321
                         <p class="submit left">
322
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
322
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
323 323
                         </p>
324 324
                         <?php
325 325
                     }
@@ -337,31 +337,31 @@  discard block
 block discarded – undo
337 337
                     });
338 338
                 }
339 339
                 </script>
340
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
341
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
342
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
340
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
341
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
342
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
343 343
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
344 344
                 </form>
345 345
                 <div id="importdialog"></div>
346 346
             </div><!-- /#autoptimize_main -->
347 347
         </div><!-- /#wrap -->
348 348
         <?php
349
-        if ( ! $this->is_multisite_network_admin() ) {
349
+        if (!$this->is_multisite_network_admin()) {
350 350
             // Include debug panel if debug mode is enable.
351
-            if ( $ao_ccss_debug ) {
351
+            if ($ao_ccss_debug) {
352 352
             ?>
353 353
                 <div id="debug">
354 354
                     <?php
355 355
                     // Include debug panel.
356
-                    include( 'critcss-inc/admin_settings_debug.php' );
356
+                    include('critcss-inc/admin_settings_debug.php');
357 357
                     ?>
358 358
                 </div><!-- /#debug -->
359 359
             <?php
360 360
             }
361 361
             echo '<script>';
362
-            include( 'critcss-inc/admin_settings_rules.js.php' );
363
-            include( 'critcss-inc/admin_settings_queue.js.php' );
364
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
362
+            include('critcss-inc/admin_settings_rules.js.php');
363
+            include('critcss-inc/admin_settings_queue.js.php');
364
+            include('critcss-inc/admin_settings_impexp.js.php');
365 365
             echo '</script>';
366 366
         }
367 367
     }
@@ -369,19 +369,19 @@  discard block
 block discarded – undo
369 369
     public static function ao_ccss_has_autorules() {
370 370
         static $_has_auto_rules = null;
371 371
 
372
-        if ( null === $_has_auto_rules ) {
372
+        if (null === $_has_auto_rules) {
373 373
             global $ao_ccss_rules;
374 374
             $_has_auto_rules = false;
375
-            if ( ! empty( $ao_ccss_rules ) ) {
376
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
377
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
378
-                        if ( ! empty( $rule['hash'] ) ) {
375
+            if (!empty($ao_ccss_rules)) {
376
+                foreach (array('types', 'paths') as $_typat) {
377
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
378
+                        if (!empty($rule['hash'])) {
379 379
                             // we have at least one AUTO job, so all is fine.
380 380
                             $_has_auto_rules = true;
381 381
                             break;
382 382
                         }
383 383
                     }
384
-                    if ( $_has_auto_rules ) {
384
+                    if ($_has_auto_rules) {
385 385
                         break;
386 386
                     }
387 387
                 }
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
     public function is_multisite_network_admin() {
395 395
         static $_multisite_network_admin = null;
396 396
 
397
-        if ( null === $_multisite_network_admin ) {
398
-            if ( is_multisite() && is_network_admin() ) {
397
+        if (null === $_multisite_network_admin) {
398
+            if (is_multisite() && is_network_admin()) {
399 399
                 $_multisite_network_admin = true;
400 400
             } else {
401 401
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.