Completed
Push — master ( 0e3b51...8538b3 )
by frank
01:43
created
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 for one page, not for the "paged pages" (/page/2 ..).
220
-                    if ( ! is_page() || ! is_paged() ) {
220
+                    if (!is_page() || !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/critcss-inc/admin_settings_adv.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     global $ao_ccss_unloadccss;
20 20
 
21 21
     // In case domain is not set yet (done in cron.php).
22
-    if ( empty( $ao_ccss_domain ) ) {
22
+    if (empty($ao_ccss_domain)) {
23 23
         $ao_ccss_domain = get_site_url();
24 24
     }
25 25
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 ?>
29 29
     <ul id="adv-panel">
30 30
         <li class="itemDetail">
31
-            <h2 class="itemTitle fleft"><?php _e( 'Advanced Settings', 'autoptimize' ); ?></h2>
31
+            <h2 class="itemTitle fleft"><?php _e('Advanced Settings', 'autoptimize'); ?></h2>
32 32
             <button type="button" class="toggle-btn">
33 33
                 <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
34 34
             </button>
@@ -36,114 +36,114 @@  discard block
 block discarded – undo
36 36
                 <table id="key" class="form-table">
37 37
                     <tr>
38 38
                         <th scope="row">
39
-                            <?php _e( 'Viewport Size', 'autoptimize' ); ?>
39
+                            <?php _e('Viewport Size', 'autoptimize'); ?>
40 40
                         </th>
41 41
                         <td>
42
-                            <label for="autoptimize_ccss_vw"><?php _e( 'Width', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" />&nbsp;&nbsp;
43
-                            <label for="autoptimize_ccss_vh"><?php _e( 'Height', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" />
42
+                            <label for="autoptimize_ccss_vw"><?php _e('Width', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" />&nbsp;&nbsp;
43
+                            <label for="autoptimize_ccss_vh"><?php _e('Height', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" />
44 44
                             <p class="notes">
45
-                                <?php _e( '<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize' ); ?>
45
+                                <?php _e('<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize'); ?>
46 46
                             </p>
47 47
                         </td>
48 48
                     </tr>
49 49
                     <tr>
50 50
                         <th scope="row">
51
-                            <?php _e( 'Force Include CSS selectors', 'autoptimize' ); ?>
51
+                            <?php _e('Force Include CSS selectors', 'autoptimize'); ?>
52 52
                         </th>
53 53
                         <td>
54
-                            <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e( '.button-special,//#footer', 'autoptimize' ); ?>"><?php echo trim( $ao_ccss_finclude ); ?></textarea>
54
+                            <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e('.button-special,//#footer', 'autoptimize'); ?>"><?php echo trim($ao_ccss_finclude); ?></textarea>
55 55
                             <p class="notes">
56
-                                <?php _e( 'Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize' ); ?>
56
+                                <?php _e('Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize'); ?>
57 57
                             </p>
58 58
                         </td>
59 59
                     </tr>
60 60
                     <tr>
61 61
                         <th scope="row">
62
-                            <?php _e( 'Queue processing time limit', 'autoptimize' ); ?>
62
+                            <?php _e('Queue processing time limit', 'autoptimize'); ?>
63 63
                         </th>
64 64
                         <td>
65 65
                             <input type="number" id="autoptimize_ccss_rtimelimit" name="autoptimize_ccss_rtimelimit" min="0" max="240" placeholder="0" value="<?php echo $ao_ccss_rtimelimit; ?>" />
66 66
                             <p class="notes">
67
-                                <?php _e( 'The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize' ); ?>
67
+                                <?php _e('The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize'); ?>
68 68
                             </p>
69 69
                         </td>
70 70
                     </tr>
71 71
                     <tr>
72 72
                         <th scope="row">
73
-                            <?php _e( 'Fetch Original CSS', 'autoptimize' ); ?>
73
+                            <?php _e('Fetch Original CSS', 'autoptimize'); ?>
74 74
                         </th>
75 75
                         <td>
76
-                            <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked( 1 == $ao_ccss_noptimize ); ?>>
76
+                            <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked(1 == $ao_ccss_noptimize); ?>>
77 77
                             <p class="notes">
78
-                                <?php _e( 'In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize' ); ?>
78
+                                <?php _e('In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize'); ?>
79 79
                             </p>
80 80
                         </td>
81 81
                     </tr>
82 82
                     <tr>
83 83
                         <th scope="row">
84
-                            <?php _e( 'Add CCSS for logged in users?', 'autoptimize' ); ?>
84
+                            <?php _e('Add CCSS for logged in users?', 'autoptimize'); ?>
85 85
                         </th>
86 86
                         <td>
87
-                            <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked( 1 == $ao_ccss_loggedin ); ?>>
87
+                            <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked(1 == $ao_ccss_loggedin); ?>>
88 88
                             <p class="notes">
89
-                                <?php _e( 'Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize' ); ?>
89
+                                <?php _e('Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize'); ?>
90 90
                             </p>
91 91
                         </td>
92 92
                     </tr>
93 93
                     <tr>
94 94
                         <th scope="row">
95
-                            <?php _e( 'Force path-based rules to be generated for pages?', 'autoptimize' ); ?>
95
+                            <?php _e('Force path-based rules to be generated for pages?', 'autoptimize'); ?>
96 96
                         </th>
97 97
                         <td>
98
-                            <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked( 1 == $ao_ccss_forcepath ); ?>>
98
+                            <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked(1 == $ao_ccss_forcepath); ?>>
99 99
                             <p class="notes">
100
-                                <?php _e( 'By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize' ); ?>
100
+                                <?php _e('By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize'); ?>
101 101
                             </p>
102 102
                         </td>
103 103
                     </tr>
104 104
                     <tr>
105 105
                         <th scope="row">
106
-                            <?php _e( 'Defer jQuery and other non-aggregated JS-files?', 'autoptimize' ); ?>
106
+                            <?php _e('Defer jQuery and other non-aggregated JS-files?', 'autoptimize'); ?>
107 107
                         </th>
108 108
                         <td>
109
-                            <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked( 1 == $ao_ccss_deferjquery ); ?>>
109
+                            <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked(1 == $ao_ccss_deferjquery); ?>>
110 110
                             <p class="notes">
111
-                                <?php _e( 'Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize' ); ?>
111
+                                <?php _e('Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize'); ?>
112 112
                             </p>
113 113
                         </td>
114 114
                     </tr>
115 115
                     <tr>
116 116
                         <th scope="row">
117
-                            <?php _e( 'Unload critical CSS after page load?', 'autoptimize' ); ?>
117
+                            <?php _e('Unload critical CSS after page load?', 'autoptimize'); ?>
118 118
                         </th>
119 119
                         <td>
120
-                            <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked( 1 == $ao_ccss_unloadccss ); ?>>
120
+                            <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked(1 == $ao_ccss_unloadccss); ?>>
121 121
                             <p class="notes">
122
-                                <?php _e( 'In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize' ); ?>
122
+                                <?php _e('In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize'); ?>
123 123
                             </p>
124 124
                         </td>
125 125
                     </tr>
126 126
                     <tr>
127 127
                         <th scope="row">
128
-                            <?php _e( 'Bound domain', 'autoptimize' ); ?>
128
+                            <?php _e('Bound domain', 'autoptimize'); ?>
129 129
                         </th>
130 130
                         <td>
131
-                            <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e( 'Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize' ); ?>" value="<?php echo trim( $ao_ccss_domain ); ?>">
131
+                            <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e('Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize'); ?>" value="<?php echo trim($ao_ccss_domain); ?>">
132 132
                             <p class="notes">
133
-                                <?php _e( 'Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize' ); ?>
133
+                                <?php _e('Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize'); ?>
134 134
                             </p>
135 135
                         </td>
136 136
                     </tr>
137 137
                     <tr>
138 138
                         <th scope="row">
139
-                            <?php _e( 'Debug Mode', 'autoptimize' ); ?>
139
+                            <?php _e('Debug Mode', 'autoptimize'); ?>
140 140
                         </th>
141 141
                         <td>
142
-                            <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked( 1 == $ao_ccss_debug ); ?>>
142
+                            <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked(1 == $ao_ccss_debug); ?>>
143 143
                             <p class="notes">
144 144
                                 <?php
145
-                                _e( '<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize' );
146
-                                echo '<code>' . AO_CCSS_LOG . '</code>';
145
+                                _e('<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize');
146
+                                echo '<code>'.AO_CCSS_LOG.'</code>';
147 147
                                 ?>
148 148
                             </p>
149 149
                         </td>
Please login to merge, or discard this patch.
classes/autoptimizeVersionUpdatesHandler.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles version updates and should only be instantiated in autoptimize.php if/when needed.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      */
17 17
     protected $current_major_version = null;
18 18
 
19
-    public function __construct( $current_version )
19
+    public function __construct($current_version)
20 20
     {
21
-        $this->current_major_version = substr( $current_version, 0, 3 );
21
+        $this->current_major_version = substr($current_version, 0, 3);
22 22
     }
23 23
 
24 24
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $major_update = false;
31 31
 
32
-        switch ( $this->current_major_version ) {
32
+        switch ($this->current_major_version) {
33 33
             case '1.6':
34 34
                 $this->upgrade_from_1_6();
35 35
                 $major_update = true;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
                 $major_update = true;
48 48
                 // No break, intentionally, so all upgrades are ran during a single request...
49 49
             case '2.4':
50
-                if ( autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' ) == '2.4.2' ) {
50
+                if (autoptimizeOptionWrapper::get_option('autoptimize_version', 'none') == '2.4.2') {
51 51
                     $this->upgrade_from_2_4_2();
52 52
                 }
53 53
                 $this->upgrade_from_2_4();
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 // No break, intentionally, so all upgrades are ran during a single request...
60 60
         }
61 61
 
62
-        if ( true === $major_update ) {
62
+        if (true === $major_update) {
63 63
             $this->on_major_version_update();
64 64
         }
65 65
     }
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @param string $target Target version to check against (ie., the currently running one).
73 73
      */
74
-    public static function check_installed_and_update( $target )
74
+    public static function check_installed_and_update($target)
75 75
     {
76
-        $db_version = autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' );
77
-        if ( $db_version !== $target ) {
78
-            if ( 'none' === $db_version ) {
79
-                add_action( 'admin_notices', 'autoptimizeMain::notice_installed' );
76
+        $db_version = autoptimizeOptionWrapper::get_option('autoptimize_version', 'none');
77
+        if ($db_version !== $target) {
78
+            if ('none' === $db_version) {
79
+                add_action('admin_notices', 'autoptimizeMain::notice_installed');
80 80
             } else {
81
-                $updater = new self( $db_version );
81
+                $updater = new self($db_version);
82 82
                 $updater->run_needed_major_upgrades();
83 83
             }
84 84
 
85 85
             // Versions differed, upgrades happened if needed, store the new version.
86
-            autoptimizeOptionWrapper::update_option( 'autoptimize_version', $target );
86
+            autoptimizeOptionWrapper::update_option('autoptimize_version', $target);
87 87
         }
88 88
     }
89 89
 
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
     protected function on_major_version_update()
95 95
     {
96 96
         // The transients guard here prevents stale object caches from busting the cache on every request.
97
-        if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) {
98
-            set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS );
97
+        if (false == get_transient('autoptimize_stale_option_buster')) {
98
+            set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS);
99 99
             autoptimizeCache::clearall();
100
-            add_action( 'admin_notices', 'autoptimizeMain::notice_updated' );
100
+            add_action('admin_notices', 'autoptimizeMain::notice_updated');
101 101
         }
102 102
     }
103 103
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     private function upgrade_from_1_6()
108 108
     {
109 109
         // If user was on version 1.6.x, force advanced options to be shown by default.
110
-        autoptimizeOptionWrapper::update_option( 'autoptimize_show_adv', '1' );
110
+        autoptimizeOptionWrapper::update_option('autoptimize_show_adv', '1');
111 111
 
112 112
         // And remove old options.
113 113
         $to_delete_options = array(
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
             'autoptimize_cdn_img_url',
120 120
             'autoptimize_css_yui',
121 121
         );
122
-        foreach ( $to_delete_options as $del_opt ) {
123
-            delete_option( $del_opt );
122
+        foreach ($to_delete_options as $del_opt) {
123
+            delete_option($del_opt);
124 124
         }
125 125
     }
126 126
 
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
      */
132 132
     private function upgrade_from_1_7()
133 133
     {
134
-        if ( ! is_multisite() ) {
135
-            $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' );
136
-            if ( empty( $css_exclude ) ) {
134
+        if (!is_multisite()) {
135
+            $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude');
136
+            if (empty($css_exclude)) {
137 137
                 $css_exclude = 'admin-bar.min.css, dashicons.min.css';
138
-            } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
138
+            } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
139 139
                 $css_exclude .= ', dashicons.min.css';
140 140
             }
141
-            autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude );
141
+            autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude);
142 142
         } else {
143 143
             global $wpdb;
144
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
144
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
145 145
             $original_blog_id = get_current_blog_id();
146
-            foreach ( $blog_ids as $blog_id ) {
147
-                switch_to_blog( $blog_id );
148
-                $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' );
149
-                if ( empty( $css_exclude ) ) {
146
+            foreach ($blog_ids as $blog_id) {
147
+                switch_to_blog($blog_id);
148
+                $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude');
149
+                if (empty($css_exclude)) {
150 150
                     $css_exclude = 'admin-bar.min.css, dashicons.min.css';
151
-                } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
151
+                } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
152 152
                     $css_exclude .= ', dashicons.min.css';
153 153
                 }
154
-                autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude );
154
+                autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude);
155 155
             }
156
-            switch_to_blog( $original_blog_id );
156
+            switch_to_blog($original_blog_id);
157 157
         }
158 158
     }
159 159
 
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private function upgrade_from_1_9()
167 167
     {
168
-        if ( ! is_multisite() ) {
169
-            autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' );
170
-            autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' );
168
+        if (!is_multisite()) {
169
+            autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on');
170
+            autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on');
171 171
         } else {
172 172
             global $wpdb;
173
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
173
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
174 174
             $original_blog_id = get_current_blog_id();
175
-            foreach ( $blog_ids as $blog_id ) {
176
-                switch_to_blog( $blog_id );
177
-                autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' );
178
-                autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' );
175
+            foreach ($blog_ids as $blog_id) {
176
+                switch_to_blog($blog_id);
177
+                autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on');
178
+                autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on');
179 179
             }
180
-            switch_to_blog( $original_blog_id );
180
+            switch_to_blog($original_blog_id);
181 181
         }
182 182
     }
183 183
 
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
      */
189 189
     private function upgrade_from_2_2()
190 190
     {
191
-        if ( ! is_multisite() ) {
191
+        if (!is_multisite()) {
192 192
             $this->do_2_2_settings_update();
193 193
         } else {
194 194
             global $wpdb;
195
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
195
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
196 196
             $original_blog_id = get_current_blog_id();
197
-            foreach ( $blog_ids as $blog_id ) {
198
-                switch_to_blog( $blog_id );
197
+            foreach ($blog_ids as $blog_id) {
198
+                switch_to_blog($blog_id);
199 199
                 $this->do_2_2_settings_update();
200 200
             }
201
-            switch_to_blog( $original_blog_id );
201
+            switch_to_blog($original_blog_id);
202 202
         }
203 203
     }
204 204
 
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
      */
208 208
     private function do_2_2_settings_update()
209 209
     {
210
-        $nogooglefont    = autoptimizeOptionWrapper::get_option( 'autoptimize_css_nogooglefont', '' );
211
-        $ao_extrasetting = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' );
212
-        if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) {
213
-            autoptimizeOptionWrapper::update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() );
210
+        $nogooglefont    = autoptimizeOptionWrapper::get_option('autoptimize_css_nogooglefont', '');
211
+        $ao_extrasetting = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', '');
212
+        if (($nogooglefont) && (empty($ao_extrasetting))) {
213
+            autoptimizeOptionWrapper::update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options());
214 214
         }
215
-        delete_option( 'autoptimize_css_nogooglefont' );
215
+        delete_option('autoptimize_css_nogooglefont');
216 216
     }
217 217
 
218 218
     /**
@@ -224,33 +224,33 @@  discard block
 block discarded – undo
224 224
         $jobs = _get_cron_array();
225 225
 
226 226
         // Remove all ao_cachechecker cron jobs (for now).
227
-        foreach ( $jobs as $when => $job ) {
228
-            $name = key( $job );
227
+        foreach ($jobs as $when => $job) {
228
+            $name = key($job);
229 229
 
230
-            if ( false !== strpos( $name, 'ao_cachechecker' ) ) {
231
-                unset( $jobs[ $when ] );
230
+            if (false !== strpos($name, 'ao_cachechecker')) {
231
+                unset($jobs[$when]);
232 232
             }
233 233
         }
234 234
 
235 235
         // Save the data.
236
-        _set_cron_array( $jobs );
236
+        _set_cron_array($jobs);
237 237
     }
238 238
 
239 239
     /**
240 240
      * Migrate imgopt options from autoptimize_extra_settings to autoptimize_imgopt_settings
241 241
      */
242 242
     private function upgrade_from_2_4() {
243
-        $extra_settings  = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' );
244
-        $imgopt_settings = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
245
-        if ( empty( $imgopt_settings ) && ! empty( $extra_settings ) ) {
243
+        $extra_settings  = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', '');
244
+        $imgopt_settings = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
245
+        if (empty($imgopt_settings) && !empty($extra_settings)) {
246 246
             $imgopt_settings = autoptimizeConfig::get_ao_imgopt_default_options();
247
-            if ( array_key_exists( 'autoptimize_extra_checkbox_field_5', $extra_settings ) ) {
247
+            if (array_key_exists('autoptimize_extra_checkbox_field_5', $extra_settings)) {
248 248
                 $imgopt_settings['autoptimize_imgopt_checkbox_field_1'] = $extra_settings['autoptimize_extra_checkbox_field_5'];
249 249
             }
250
-            if ( array_key_exists( 'autoptimize_extra_select_field_6', $extra_settings ) ) {
250
+            if (array_key_exists('autoptimize_extra_select_field_6', $extra_settings)) {
251 251
                 $imgopt_settings['autoptimize_imgopt_select_field_2'] = $extra_settings['autoptimize_extra_select_field_6'];
252 252
             }
253
-            autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_settings', $imgopt_settings );
253
+            autoptimizeOptionWrapper::update_option('autoptimize_imgopt_settings', $imgopt_settings);
254 254
         }
255 255
     }
256 256
 
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
      * remove CCSS request limit option + update jquery exclusion to include WordPress 5.6 jquery.min.js.
259 259
      */    
260 260
     private function upgrade_from_2_7() {
261
-        delete_option( 'autoptimize_ccss_rlimit' );
262
-        $js_exclusions = get_option( 'autoptimize_js_exclude', '' );
263
-        if ( strpos( $js_exclusions, 'js/jquery/jquery.js' ) !== false && strpos( $js_exclusions, 'js/jquery/jquery.min.js' ) === false ) {
261
+        delete_option('autoptimize_ccss_rlimit');
262
+        $js_exclusions = get_option('autoptimize_js_exclude', '');
263
+        if (strpos($js_exclusions, 'js/jquery/jquery.js') !== false && strpos($js_exclusions, 'js/jquery/jquery.min.js') === false) {
264 264
             $js_exclusions .= ', js/jquery/jquery.min.js';
265
-            update_option( 'autoptimize_js_exclude', $js_exclusions );
265
+            update_option('autoptimize_js_exclude', $js_exclusions);
266 266
         }
267 267
     }
268 268
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSBase.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS base file (initializes all ccss files).
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -19,35 +19,35 @@  discard block
 block discarded – undo
19 19
     public function __construct()
20 20
     {
21 21
         // define constant, but only once.
22
-        if ( ! defined( 'AO_CCSS_DIR' ) ) {
22
+        if (!defined('AO_CCSS_DIR')) {
23 23
             // Define a constant with the directory to store critical CSS in.
24
-            if ( is_multisite() ) {
24
+            if (is_multisite()) {
25 25
                 $blog_id = get_current_blog_id();
26
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' . $blog_id . '/' );
26
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'.$blog_id.'/');
27 27
             } else {
28
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' );
28
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/');
29 29
             }
30 30
         }
31
-        if ( ! defined( 'AO_CCSS_VER' ) ) {
31
+        if (!defined('AO_CCSS_VER')) {
32 32
             // Define plugin version.
33
-            define( 'AO_CCSS_VER', 'AO_' . AUTOPTIMIZE_PLUGIN_VERSION );
33
+            define('AO_CCSS_VER', 'AO_'.AUTOPTIMIZE_PLUGIN_VERSION);
34 34
 
35 35
             // Define constants for criticalcss.com base path and API endpoints.
36 36
             // fixme: AO_CCSS_URL should be read from the autoptimize availability json stored as option.
37
-            define( 'AO_CCSS_URL', 'https://criticalcss.com' );
38
-            define( 'AO_CCSS_API', AO_CCSS_URL . '/api/premium/' );
39
-            define( 'AO_CCSS_SLEEP', 10 );
37
+            define('AO_CCSS_URL', 'https://criticalcss.com');
38
+            define('AO_CCSS_API', AO_CCSS_URL.'/api/premium/');
39
+            define('AO_CCSS_SLEEP', 10);
40 40
         }
41 41
 
42 42
         // Define support files locations, in case they are not already defined.
43
-        if ( ! defined( 'AO_CCSS_LOCK' ) ) {
44
-            define( 'AO_CCSS_LOCK', AO_CCSS_DIR . 'queue.lock' );
43
+        if (!defined('AO_CCSS_LOCK')) {
44
+            define('AO_CCSS_LOCK', AO_CCSS_DIR.'queue.lock');
45 45
         }
46
-        if ( ! defined( 'AO_CCSS_LOG' ) ) {
47
-            define( 'AO_CCSS_LOG', AO_CCSS_DIR . 'queuelog.html' );
46
+        if (!defined('AO_CCSS_LOG')) {
47
+            define('AO_CCSS_LOG', AO_CCSS_DIR.'queuelog.html');
48 48
         }
49
-        if ( ! defined( 'AO_CCSS_DEBUG' ) ) {
50
-            define( 'AO_CCSS_DEBUG', AO_CCSS_DIR . 'queue.json' );
49
+        if (!defined('AO_CCSS_DEBUG')) {
50
+            define('AO_CCSS_DEBUG', AO_CCSS_DIR.'queue.json');
51 51
         }
52 52
 
53 53
         $this->filepath = __FILE__;
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
     {
61 61
         // get all options.
62 62
         $all_options = $this->fetch_options();
63
-        foreach ( $all_options as $option => $value ) {
63
+        foreach ($all_options as $option => $value) {
64 64
             ${$option} = $value;
65 65
         }
66 66
 
67 67
         // make sure the 10 minutes cron schedule is added.
68
-        add_filter( 'cron_schedules', array( $this, 'ao_ccss_interval' ) );
68
+        add_filter('cron_schedules', array($this, 'ao_ccss_interval'));
69 69
 
70 70
         // check if we need to upgrade.
71 71
         $this->check_upgrade();
72 72
 
73 73
         // make sure ao_ccss_queue is scheduled OK if an API key is set.
74
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
75
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
74
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
75
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
76 76
         }
77 77
     }
78 78
 
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
         // Required libs, core is always needed.
81 81
         $criticalcss_core = new autoptimizeCriticalCSSCore();
82 82
 
83
-        if ( defined( 'WP_CLI' ) || defined( 'DOING_CRON' ) || is_admin() ) {
83
+        if (defined('WP_CLI') || defined('DOING_CRON') || is_admin()) {
84 84
             // TODO: also include if overridden somehow to force queue processing to be executed?
85 85
             $criticalcss_cron = new autoptimizeCriticalCSSCron();
86 86
         }
87 87
 
88
-        if ( is_admin() ) {
88
+        if (is_admin()) {
89 89
             $criticalcss_settings = new autoptimizeCriticalCSSSettings();
90 90
         } else {
91 91
             // enqueuing only done when not wp-admin.
@@ -96,51 +96,51 @@  discard block
 block discarded – undo
96 96
     public static function fetch_options() {
97 97
         static $autoptimize_ccss_options = null;
98 98
 
99
-        if ( null === $autoptimize_ccss_options ) {
99
+        if (null === $autoptimize_ccss_options) {
100 100
             // not cached yet, fetching from WordPress options.
101
-            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' );
102
-            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' );
103
-            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option( 'autoptimize_ccss_rules', false );
104
-            $autoptimize_ccss_options['ao_ccss_additional']    = get_option( 'autoptimize_ccss_additional' );
105
-            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option( 'autoptimize_ccss_queue', false );
106
-            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option( 'autoptimize_ccss_viewport', false );
107
-            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option( 'autoptimize_ccss_finclude', false );
108
-            $autoptimize_ccss_options['ao_ccss_rtimelimit']    = get_option( 'autoptimize_ccss_rtimelimit', '30' );
109
-            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option( 'autoptimize_ccss_noptimize', false );
110
-            $autoptimize_ccss_options['ao_ccss_debug']         = get_option( 'autoptimize_ccss_debug', false );
111
-            $autoptimize_ccss_options['ao_ccss_key']           = get_option( 'autoptimize_ccss_key' );
112
-            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option( 'autoptimize_ccss_keyst' );
113
-            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option( 'autoptimize_ccss_loggedin', '1' );
114
-            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option( 'autoptimize_ccss_forcepath', '1' );
115
-            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' );
116
-            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option( 'autoptimize_ccss_deferjquery', false );
117
-            $autoptimize_ccss_options['ao_ccss_domain']        = get_option( 'autoptimize_ccss_domain' );
118
-            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option( 'autoptimize_ccss_unloadccss', false );
119
-
120
-            if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) {
121
-                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] );
122
-            } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) {
101
+            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option('autoptimize_css_defer');
102
+            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline');
103
+            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option('autoptimize_ccss_rules', false);
104
+            $autoptimize_ccss_options['ao_ccss_additional']    = get_option('autoptimize_ccss_additional');
105
+            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option('autoptimize_ccss_queue', false);
106
+            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option('autoptimize_ccss_viewport', false);
107
+            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option('autoptimize_ccss_finclude', false);
108
+            $autoptimize_ccss_options['ao_ccss_rtimelimit']    = get_option('autoptimize_ccss_rtimelimit', '30');
109
+            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option('autoptimize_ccss_noptimize', false);
110
+            $autoptimize_ccss_options['ao_ccss_debug']         = get_option('autoptimize_ccss_debug', false);
111
+            $autoptimize_ccss_options['ao_ccss_key']           = get_option('autoptimize_ccss_key');
112
+            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option('autoptimize_ccss_keyst');
113
+            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option('autoptimize_ccss_loggedin', '1');
114
+            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option('autoptimize_ccss_forcepath', '1');
115
+            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option('autoptimize_service_availablity');
116
+            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option('autoptimize_ccss_deferjquery', false);
117
+            $autoptimize_ccss_options['ao_ccss_domain']        = get_option('autoptimize_ccss_domain');
118
+            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option('autoptimize_ccss_unloadccss', false);
119
+
120
+            if (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') === false && strpos($autoptimize_ccss_options['ao_ccss_domain'], 'uggc') === 0) {
121
+                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13($autoptimize_ccss_options['ao_ccss_domain']);
122
+            } elseif (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') !== false) {
123 123
                 // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain).
124
-                update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) );
124
+                update_option('autoptimize_ccss_domain', str_rot13($autoptimize_ccss_options['ao_ccss_domain']));
125 125
             }
126 126
 
127 127
             // Setup the rules array.
128
-            if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) {
128
+            if (empty($autoptimize_ccss_options['ao_ccss_rules_raw'])) {
129 129
                 $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array();
130 130
                 $autoptimize_ccss_options['ao_ccss_rules']['types'] = array();
131 131
             } else {
132
-                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true );
132
+                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode($autoptimize_ccss_options['ao_ccss_rules_raw'], true);
133 133
             }
134 134
 
135 135
             // Setup the queue array.
136
-            if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) {
136
+            if (empty($autoptimize_ccss_options['ao_ccss_queue_raw'])) {
137 137
                 $autoptimize_ccss_options['ao_ccss_queue'] = array();
138 138
             } else {
139
-                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true );
139
+                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode($autoptimize_ccss_options['ao_ccss_queue_raw'], true);
140 140
             }
141 141
 
142 142
             // Override API key if constant is defined.
143
-            if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
143
+            if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
144 144
                 $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY;
145 145
             }
146 146
         }
@@ -152,49 +152,49 @@  discard block
 block discarded – undo
152 152
         global $ao_ccss_key;
153 153
 
154 154
         // Create the cache directory if it doesn't exist already.
155
-        if ( ! file_exists( AO_CCSS_DIR ) ) {
156
-            mkdir( AO_CCSS_DIR, 0755, true );
155
+        if (!file_exists(AO_CCSS_DIR)) {
156
+            mkdir(AO_CCSS_DIR, 0755, true);
157 157
         }
158 158
 
159 159
         // Create a scheduled event for the queue.
160
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
161
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
160
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
161
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
162 162
         }
163 163
 
164 164
         // Create a scheduled event for log maintenance.
165
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) {
166
-            wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' );
165
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_maintenance')) {
166
+            wp_schedule_event(time(), 'twicedaily', 'ao_ccss_maintenance');
167 167
         }
168 168
     }
169 169
 
170 170
     public function check_upgrade() {
171
-        $db_version = get_option( 'autoptimize_ccss_version', '' );
172
-        if ( AO_CCSS_VER !== $db_version ) {
171
+        $db_version = get_option('autoptimize_ccss_version', '');
172
+        if (AO_CCSS_VER !== $db_version) {
173 173
             // check schedules & re-schedule if needed.
174 174
             $this->on_upgrade();
175 175
             // and update db_version.
176
-            update_option( 'autoptimize_ccss_version', AO_CCSS_VER );
176
+            update_option('autoptimize_ccss_version', AO_CCSS_VER);
177 177
         }
178 178
     }
179 179
 
180
-    public function ao_ccss_interval( $schedules ) {
180
+    public function ao_ccss_interval($schedules) {
181 181
         // Let interval be configurable.
182
-        if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) {
182
+        if (!defined('AO_CCSS_DEBUG_INTERVAL')) {
183 183
             $intsec = 600;
184 184
         } else {
185 185
             $intsec = AO_CCSS_DEBUG_INTERVAL;
186
-            if ( $intsec >= 120 ) {
187
-                $inttxt = $intsec / 60 . ' minutes';
186
+            if ($intsec >= 120) {
187
+                $inttxt = $intsec/60.' minutes';
188 188
             } else {
189
-                $inttxt = $intsec . ' second(s)';
189
+                $inttxt = $intsec.' second(s)';
190 190
             }
191
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 );
191
+            autoptimizeCriticalCSSCore::ao_ccss_log('Using custom WP-Cron interval of '.$inttxt, 3);
192 192
         }
193 193
 
194 194
         // Attach interval to schedule.
195 195
         $schedules['ao_ccss'] = array(
196 196
             'interval' => $intsec,
197
-            'display'  => __( 'Autoptimize CriticalCSS' ),
197
+            'display'  => __('Autoptimize CriticalCSS'),
198 198
         );
199 199
         return $schedules;
200 200
     }
Please login to merge, or discard this patch.
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.
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 ) && is_writable( WP_CONTENT_DIR ) ) {
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) && is_writable(WP_CONTENT_DIR)) {
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/autoptimizeCriticalCSSCron.php 1 patch
Spacing   +254 added lines, -254 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.
@@ -86,45 +86,45 @@  discard block
 block discarded – undo
86 86
             global $ao_ccss_rtimelimit;
87 87
 
88 88
             // Initialize counters.
89
-            if ( $ao_ccss_rtimelimit == 0 ) {
89
+            if ($ao_ccss_rtimelimit == 0) {
90 90
                 // no time limit set, let's go with 1000 seconds.
91 91
                 $ao_ccss_rtimelimit = 1000;
92 92
             }
93 93
             $mt = time() + $ao_ccss_rtimelimit; // maxtime queue processing can run.
94 94
             $jc = 1; // job count number.
95 95
             $jr = 1; // jobs requests number.
96
-            $jt = count( $ao_ccss_queue ); // number of jobs in queue.
96
+            $jt = count($ao_ccss_queue); // number of jobs in queue.
97 97
 
98 98
             // Sort queue by ascending job status (e.g. ERROR, JOB_ONGOING, JOB_QUEUED, NEW...).
99
-            array_multisort( array_column( $ao_ccss_queue, 'jqstat' ), $ao_ccss_queue ); // @codingStandardsIgnoreLine
99
+            array_multisort(array_column($ao_ccss_queue, 'jqstat'), $ao_ccss_queue); // @codingStandardsIgnoreLine
100 100
 
101 101
             // Iterates over the entire queue.
102
-            foreach ( $ao_ccss_queue as $path => $jprops ) {
102
+            foreach ($ao_ccss_queue as $path => $jprops) {
103 103
                 // Prepare flags and target rule.
104 104
                 $update      = false;
105 105
                 $deljob      = false;
106 106
                 $rule_update = false;
107 107
                 $oldccssfile = false;
108
-                $trule       = explode( '|', $jprops['rtarget'] );
108
+                $trule       = explode('|', $jprops['rtarget']);
109 109
 
110 110
                 // Log job count.
111
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Processing job ' . $jc . ' of ' . $jt . ' with id <' . $jprops['ljid'] . '> and status <' . $jprops['jqstat'] . '>', 3 );
111
+                autoptimizeCriticalCSSCore::ao_ccss_log('Processing job '.$jc.' of '.$jt.' with id <'.$jprops['ljid'].'> and status <'.$jprops['jqstat'].'>', 3);
112 112
 
113 113
                 // Process NEW jobs.
114
-                if ( 'NEW' == $jprops['jqstat'] ) {
114
+                if ('NEW' == $jprops['jqstat']) {
115 115
 
116 116
                     // Log the new job.
117
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found NEW job with local ID <' . $jprops['ljid'] . '>, starting its queue processing', 3 );
117
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found NEW job with local ID <'.$jprops['ljid'].'>, starting its queue processing', 3);
118 118
 
119 119
                     // Compare job and rule hashes (if any).
120
-                    $hash = $this->ao_ccss_diff_hashes( $jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget'] );
120
+                    $hash = $this->ao_ccss_diff_hashes($jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget']);
121 121
 
122 122
                     // If job hash is new or different of a previous one.
123
-                    if ( $hash ) {
124
-                        if ( $jr > 2 ) {
123
+                    if ($hash) {
124
+                        if ($jr > 2) {
125 125
                             // we already posted 2 jobs to criticalcss.com, don't post more this run
126 126
                             // but we can keep on processing the queue to keep it tidy.
127
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Holding off on generating request for job with local ID <' . $jprops['ljid'] . '>, maximum number of POSTS reached.', 3 );
127
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Holding off on generating request for job with local ID <'.$jprops['ljid'].'>, maximum number of POSTS reached.', 3);
128 128
                             continue;
129 129
                         }
130 130
 
@@ -132,182 +132,182 @@  discard block
 block discarded – undo
132 132
                         $jprops['hash'] = $hash;
133 133
 
134 134
                         // Dispatch the job generate request and increment request count.
135
-                        $apireq = $this->ao_ccss_api_generate( $path, $queue_debug, $qdobj['htcode'] );
135
+                        $apireq = $this->ao_ccss_api_generate($path, $queue_debug, $qdobj['htcode']);
136 136
                         $jr++;
137 137
 
138 138
                         // NOTE: All the following conditions maps to the ones in admin_settings_queue.js.php.
139
-                        if ( 'JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status'] ) {
139
+                        if ('JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status']) {
140 140
                             // SUCCESS: request has a valid result.
141 141
                             // Update job properties.
142 142
                             $jprops['jid']    = $apireq['job']['id'];
143 143
                             $jprops['jqstat'] = $apireq['job']['status'];
144
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request successful, remote id <' . $jprops['jid'] . '>, status now is <' . $jprops['jqstat'] . '>', 3 );
145
-                        } elseif ( 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
144
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request successful, remote id <'.$jprops['jid'].'>, status now is <'.$jprops['jqstat'].'>', 3);
145
+                        } elseif ('STATUS_JOB_BAD' == $apireq['job']['status']) {
146 146
                             // ERROR: concurrent requests
147 147
                             // Update job properties.
148 148
                             $jprops['jid']    = $apireq['job']['id'];
149 149
                             $jprops['jqstat'] = $apireq['job']['status'];
150
-                            if ( $apireq['job']['error'] ) {
150
+                            if ($apireq['job']['error']) {
151 151
                                 $jprops['jrstat'] = $apireq['job']['error'];
152 152
                             } else {
153 153
                                 $jprops['jrstat'] = 'Baby did a bad bad thing';
154 154
                             }
155 155
                             $jprops['jvstat'] = 'NONE';
156
-                            $jprops['jftime'] = microtime( true );
157
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Concurrent requests when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
158
-                        } elseif ( 'INVALID_JWT_TOKEN' == $apireq['errorCode'] ) {
156
+                            $jprops['jftime'] = microtime(true);
157
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Concurrent requests when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
158
+                        } elseif ('INVALID_JWT_TOKEN' == $apireq['errorCode']) {
159 159
                             // ERROR: key validation
160 160
                             // Update job properties.
161 161
                             $jprops['jqstat'] = $apireq['errorCode'];
162 162
                             $jprops['jrstat'] = $apireq['error'];
163 163
                             $jprops['jvstat'] = 'NONE';
164
-                            $jprops['jftime'] = microtime( true );
165
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'API key validation error when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
166
-                        } elseif ( empty( $apireq ) ) {
164
+                            $jprops['jftime'] = microtime(true);
165
+                            autoptimizeCriticalCSSCore::ao_ccss_log('API key validation error when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
166
+                        } elseif (empty($apireq)) {
167 167
                             // ERROR: no response
168 168
                             // Update job properties.
169 169
                             $jprops['jqstat'] = 'NO_RESPONSE';
170 170
                             $jprops['jrstat'] = 'NONE';
171 171
                             $jprops['jvstat'] = 'NONE';
172
-                            $jprops['jftime'] = microtime( true );
173
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
172
+                            $jprops['jftime'] = microtime(true);
173
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
174 174
                         } else {
175 175
                             // UNKNOWN: unhandled generate exception
176 176
                             // Update job properties.
177 177
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
178 178
                             $jprops['jrstat'] = 'NONE';
179 179
                             $jprops['jvstat'] = 'NONE';
180
-                            $jprops['jftime'] = microtime( true );
181
-                            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 );
182
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
180
+                            $jprops['jftime'] = microtime(true);
181
+                            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);
182
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
183 183
                         }
184 184
                     } else {
185 185
                         // SUCCESS: Job hash is equal to a previous one, so it's done
186 186
                         // Update job status and finish time.
187 187
                         $jprops['jqstat'] = 'JOB_DONE';
188
-                        $jprops['jftime'] = microtime( true );
189
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> requires no further processing, status now is <' . $jprops['jqstat'] . '>', 3 );
188
+                        $jprops['jftime'] = microtime(true);
189
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> requires no further processing, status now is <'.$jprops['jqstat'].'>', 3);
190 190
                     }
191 191
 
192 192
                     // Set queue update flag.
193 193
                     $update = true;
194 194
 
195
-                } elseif ( 'JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat'] ) {
195
+                } elseif ('JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat']) {
196 196
                     // Process QUEUED and ONGOING jobs
197 197
                     // Log the pending job.
198
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found PENDING job with local ID <' . $jprops['ljid'] . '>, continuing its queue processing', 3 );
198
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found PENDING job with local ID <'.$jprops['ljid'].'>, continuing its queue processing', 3);
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
 
203 203
                     // NOTE: All the following condigitons maps to the ones in admin_settings_queue.js.php
204 204
                     // Replace API response values if queue debugging is enabled and some value is set.
205
-                    if ( $queue_debug ) {
206
-                        if ( $qdobj['status'] ) {
205
+                    if ($queue_debug) {
206
+                        if ($qdobj['status']) {
207 207
                             $apireq['status'] = $qdobj['status'];
208 208
                         }
209
-                        if ( $qdobj['resultStatus'] ) {
209
+                        if ($qdobj['resultStatus']) {
210 210
                             $apireq['resultStatus'] = $qdobj['resultStatus'];
211 211
                         }
212
-                        if ( $qdobj['validationStatus'] ) {
212
+                        if ($qdobj['validationStatus']) {
213 213
                             $apireq['validationStatus'] = $qdobj['validationStatus'];
214 214
                         }
215 215
                     }
216 216
 
217
-                    if ( 'JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status'] ) {
217
+                    if ('JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status']) {
218 218
                         // SUCCESS: request has a valid result
219 219
                         // Process a PENDING job
220 220
                         // Update job properties.
221 221
                         $jprops['jqstat'] = $apireq['status'];
222
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '> unchanged', 3 );
223
-                    } elseif ( 'JOB_DONE' == $apireq['status'] ) {
222
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'> unchanged', 3);
223
+                    } elseif ('JOB_DONE' == $apireq['status']) {
224 224
                         // Process a DONE job
225 225
                         // New resultStatus from ccss.com "HTML_404", consider as "GOOD" for now.
226
-                        if ( 'HTML_404' == $apireq['resultStatus'] ) {
226
+                        if ('HTML_404' == $apireq['resultStatus']) {
227 227
                             $apireq['resultStatus'] = 'GOOD';
228 228
                         }
229 229
 
230
-                        if ( 'GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus'] ) {
230
+                        if ('GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus']) {
231 231
                             // SUCCESS: GOOD job with GOOD validation
232 232
                             // Update job properties.
233
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, false );
233
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, false);
234 234
                             $jprops['jqstat'] = $apireq['status'];
235 235
                             $jprops['jrstat'] = $apireq['resultStatus'];
236 236
                             $jprops['jvstat'] = $apireq['validationStatus'];
237
-                            $jprops['jftime'] = microtime( true );
237
+                            $jprops['jftime'] = microtime(true);
238 238
                             $rule_update      = true;
239
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '>, file saved <' . $jprops['file'] . '>', 3 );
240
-                        } elseif ( 'GOOD' == $apireq['resultStatus'] && ( 'WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'] ) ) {
239
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'>, file saved <'.$jprops['file'].'>', 3);
240
+                        } elseif ('GOOD' == $apireq['resultStatus'] && ('WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'])) {
241 241
                             // SUCCESS: GOOD job with WARN or BAD validation
242 242
                             // Update job properties.
243 243
                             $jprops['jqstat'] = $apireq['status'];
244 244
                             $jprops['jrstat'] = $apireq['resultStatus'];
245 245
                             $jprops['jvstat'] = $apireq['validationStatus'];
246
-                            $jprops['jftime'] = microtime( true );
247
-                            if ( apply_filters( 'autoptimize_filter_ccss_save_review_rules', true ) ) {
248
-                                $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, true );
246
+                            $jprops['jftime'] = microtime(true);
247
+                            if (apply_filters('autoptimize_filter_ccss_save_review_rules', true)) {
248
+                                $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, 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 );
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 251
                             } else {
252
-                                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . ', file saved <' . $jprops['file'] . '> but required REVIEW so not saved.', 3 );
252
+                                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].', file saved <'.$jprops['file'].'> but required REVIEW so not saved.', 3);
253 253
                             }
254
-                        } elseif ( 'GOOD' != $apireq['resultStatus'] && ( 'GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'] ) ) {
254
+                        } elseif ('GOOD' != $apireq['resultStatus'] && ('GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'])) {
255 255
                             // ERROR: no GOOD, WARN or BAD results
256 256
                             // Update job properties.
257 257
                             $jprops['jqstat'] = $apireq['status'];
258 258
                             $jprops['jrstat'] = $apireq['resultStatus'];
259 259
                             $jprops['jvstat'] = $apireq['validationStatus'];
260
-                            $jprops['jftime'] = microtime( true );
261
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
260
+                            $jprops['jftime'] = microtime(true);
261
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
262 262
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
263
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
263
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
264 264
                         } else {
265 265
                             // UNKNOWN: unhandled JOB_DONE exception
266 266
                             // Update job properties.
267 267
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
268 268
                             $jprops['jrstat'] = $apireq['resultStatus'];
269 269
                             $jprops['jvstat'] = $apireq['validationStatus'];
270
-                            $jprops['jftime'] = microtime( true );
271
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job is UNKNOWN, status now is <' . $jprops['jqstat'] . '>', 2 );
270
+                            $jprops['jftime'] = microtime(true);
271
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job is UNKNOWN, status now is <'.$jprops['jqstat'].'>', 2);
272 272
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
273
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
273
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
274 274
                         }
275
-                    } elseif ( 'JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
275
+                    } elseif ('JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status']) {
276 276
                         // ERROR: failed job
277 277
                         // Update job properties.
278 278
                         $jprops['jqstat'] = $apireq['job']['status'];
279
-                        if ( $apireq['job']['error'] ) {
279
+                        if ($apireq['job']['error']) {
280 280
                             $jprops['jrstat'] = $apireq['job']['error'];
281 281
                         } else {
282 282
                             $jprops['jrstat'] = 'Baby did a bad bad thing';
283 283
                         }
284 284
                         $jprops['jvstat'] = 'NONE';
285
-                        $jprops['jftime'] = microtime( true );
286
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
287
-                    } elseif ( 'This css no longer exists. Please re-generate it.' == $apireq['error'] ) {
285
+                        $jprops['jftime'] = microtime(true);
286
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
287
+                    } elseif ('This css no longer exists. Please re-generate it.' == $apireq['error']) {
288 288
                         // ERROR: CSS doesn't exist
289 289
                         // Update job properties.
290 290
                         $jprops['jqstat'] = 'NO_CSS';
291 291
                         $jprops['jrstat'] = $apireq['error'];
292 292
                         $jprops['jvstat'] = 'NONE';
293
-                        $jprops['jftime'] = microtime( true );
294
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
295
-                    } elseif ( empty( $apireq ) ) {
293
+                        $jprops['jftime'] = microtime(true);
294
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
295
+                    } elseif (empty($apireq)) {
296 296
                         // ERROR: no response
297 297
                         // Update job properties.
298 298
                         $jprops['jqstat'] = 'NO_RESPONSE';
299 299
                         $jprops['jrstat'] = 'NONE';
300 300
                         $jprops['jvstat'] = 'NONE';
301
-                        $jprops['jftime'] = microtime( true );
302
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
301
+                        $jprops['jftime'] = microtime(true);
302
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
303 303
                     } else {
304 304
                         // UNKNOWN: unhandled results exception
305 305
                         // Update job properties.
306 306
                         $jprops['jqstat'] = 'JOB_UNKNOWN';
307 307
                         $jprops['jrstat'] = 'NONE';
308 308
                         $jprops['jvstat'] = 'NONE';
309
-                        $jprops['jftime'] = microtime( true );
310
-                        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 );
309
+                        $jprops['jftime'] = microtime(true);
310
+                        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);
311 311
                     }
312 312
 
313 313
                     // Set queue update flag.
@@ -315,40 +315,40 @@  discard block
 block discarded – undo
315 315
                 }
316 316
 
317 317
                 // Mark DONE jobs for removal.
318
-                if ( 'JOB_DONE' == $jprops['jqstat'] ) {
318
+                if ('JOB_DONE' == $jprops['jqstat']) {
319 319
                     $update = true;
320 320
                     $deljob = true;
321 321
                 }
322 322
 
323 323
                 // Persist updated queue object.
324
-                if ( $update ) {
325
-                    if ( ! $deljob ) {
324
+                if ($update) {
325
+                    if (!$deljob) {
326 326
                         // Update properties of a NEW or PENDING job...
327
-                        $ao_ccss_queue[ $path ] = $jprops;
327
+                        $ao_ccss_queue[$path] = $jprops;
328 328
                     } else {
329 329
                         // ...or remove the DONE job.
330
-                        unset( $ao_ccss_queue[ $path ] );
331
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> is DONE and was removed from the queue', 3 );
330
+                        unset($ao_ccss_queue[$path]);
331
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> is DONE and was removed from the queue', 3);
332 332
                     }
333 333
 
334 334
                     // Update queue object.
335
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
336
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
337
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue updated by job id <' . $jprops['ljid'] . '>', 3 );
335
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
336
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
337
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue updated by job id <'.$jprops['ljid'].'>', 3);
338 338
 
339 339
                     // Update target rule.
340
-                    if ( $rule_update ) {
341
-                        $this->ao_ccss_rule_update( $jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash'] );
342
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> updated the target rule <' . $jprops['rtarget'] . '>', 3 );
340
+                    if ($rule_update) {
341
+                        $this->ao_ccss_rule_update($jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash']);
342
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> updated the target rule <'.$jprops['rtarget'].'>', 3);
343 343
                     }
344 344
                 } else {
345 345
                     // Or log no queue action.
346
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Nothing to do on this job', 3 );
346
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Nothing to do on this job', 3);
347 347
                 }
348 348
 
349 349
                 // Break the loop if request time limit is (almost exceeded).
350
-                if ( time() > $mt ) {
351
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'The time limit of ' . $ao_ccss_rtimelimit . ' seconds was exceeded, queue control must finish now', 3 );
350
+                if (time() > $mt) {
351
+                    autoptimizeCriticalCSSCore::ao_ccss_log('The time limit of '.$ao_ccss_rtimelimit.' seconds was exceeded, queue control must finish now', 3);
352 352
                     break;
353 353
                 }
354 354
 
@@ -357,46 +357,46 @@  discard block
 block discarded – undo
357 357
             }
358 358
 
359 359
             // Remove the lock file and log the queue end.
360
-            if ( file_exists( AO_CCSS_LOCK ) ) {
361
-                unlink( AO_CCSS_LOCK );
362
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control unlocked', 3 );
360
+            if (file_exists(AO_CCSS_LOCK)) {
361
+                unlink(AO_CCSS_LOCK);
362
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control unlocked', 3);
363 363
             }
364
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control finished', 3 );
364
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control finished', 3);
365 365
 
366 366
             // Log that queue is locked.
367 367
         } else {
368
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue is already running, skipping the attempt to run it again', 3 );
368
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue is already running, skipping the attempt to run it again', 3);
369 369
         }
370 370
     }
371 371
 
372
-    public function ao_ccss_diff_hashes( $ljid, $hash, $hashes, $rule ) {
372
+    public function ao_ccss_diff_hashes($ljid, $hash, $hashes, $rule) {
373 373
         // Compare job hashes
374 374
         // STEP 1: update job hashes.
375
-        if ( 1 == count( $hashes ) ) {
375
+        if (1 == count($hashes)) {
376 376
             // Job with a single hash
377 377
             // Set job hash.
378 378
             $hash = $hashes[0];
379
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with SINGLE hash <' . $hash . '>', 3 );
379
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with SINGLE hash <'.$hash.'>', 3);
380 380
         } else {
381 381
             // Job with multiple hashes
382 382
             // Loop through hashes to concatenate them.
383 383
             $nhash = '';
384
-            foreach ( $hashes as $shash ) {
384
+            foreach ($hashes as $shash) {
385 385
                 $nhash .= $shash;
386 386
             }
387 387
 
388 388
             // Set job hash.
389
-            $hash = md5( $nhash );
390
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with a COMPOSITE hash <' . $hash . '>', 3 );
389
+            $hash = md5($nhash);
390
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with a COMPOSITE hash <'.$hash.'>', 3);
391 391
         }
392 392
 
393 393
         // STEP 2: compare job to existing jobs to prevent double submission for same type+hash.
394 394
         global $ao_ccss_queue;
395 395
 
396
-        foreach ( $ao_ccss_queue as $queue_item ) {
397
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Comparing <' . $rule . $hash . '> with <' . $queue_item['rtarget'] . $queue_item['hash'] . '>', 3 );
398
-            if ( $queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array( $queue_item['jqstat'], array( 'JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE' ) ) ) {
399
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the already pending job <' . $queue_item['ljid'] . '>', 3 );
396
+        foreach ($ao_ccss_queue as $queue_item) {
397
+            autoptimizeCriticalCSSCore::ao_ccss_log('Comparing <'.$rule.$hash.'> with <'.$queue_item['rtarget'].$queue_item['hash'].'>', 3);
398
+            if ($queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array($queue_item['jqstat'], array('JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE'))) {
399
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the already pending job <'.$queue_item['ljid'].'>', 3);
400 400
                 return false;
401 401
             }
402 402
         }
@@ -406,32 +406,32 @@  discard block
 block discarded – undo
406 406
         global $ao_ccss_rules;
407 407
 
408 408
         // Prepare rule variables.
409
-        $trule = explode( '|', $rule );
410
-        $srule = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
409
+        $trule = explode('|', $rule);
410
+        $srule = $ao_ccss_rules[$trule[0]][$trule[1]];
411 411
 
412 412
         // Check if a MANUAL rule exist and return false.
413
-        if ( ! empty( $srule ) && ( 0 == $srule['hash'] && 0 != $srule['file'] ) ) {
414
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the MANUAL rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
413
+        if (!empty($srule) && (0 == $srule['hash'] && 0 != $srule['file'])) {
414
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the MANUAL rule <'.$trule[0].'|'.$trule[1].'>', 3);
415 415
             return false;
416
-        } elseif ( ! empty( $srule ) ) {
416
+        } elseif (!empty($srule)) {
417 417
             // Check if an AUTO rule exist.
418
-            if ( $hash === $srule['hash'] && is_file( AO_CCSS_DIR . $srule['file'] ) && 0 != filesize( AO_CCSS_DIR . $srule['file'] ) ) {
418
+            if ($hash === $srule['hash'] && is_file(AO_CCSS_DIR.$srule['file']) && 0 != filesize(AO_CCSS_DIR.$srule['file'])) {
419 419
                 // Check if job hash matches rule, if the CCSS file exists said file is not empty and return FALSE is so.
420
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
420
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> MATCH the one in rule <'.$trule[0].'|'.$trule[1].'>', 3);
421 421
                 return false;
422 422
             } else {
423 423
                 // Or return the new hash if they differ.
424
-                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 );
424
+                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);
425 425
                 return $hash;
426 426
             }
427 427
         } else {
428 428
             // Or just return the hash if no rule exist yet.
429
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> has no rule yet', 3 );
429
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> has no rule yet', 3);
430 430
             return $hash;
431 431
         }
432 432
     }
433 433
 
434
-    public function ao_ccss_api_generate( $path, $debug, $dcode ) {
434
+    public function ao_ccss_api_generate($path, $debug, $dcode) {
435 435
         // POST jobs to criticalcss.com and return responses
436 436
         // Get key and key status.
437 437
         global $ao_ccss_key;
@@ -443,35 +443,35 @@  discard block
 block discarded – undo
443 443
         global $ao_ccss_noptimize;
444 444
 
445 445
         $site_host = get_site_url();
446
-        $site_path = parse_url( $site_host, PHP_URL_PATH );
446
+        $site_path = parse_url($site_host, PHP_URL_PATH);
447 447
 
448
-        if ( ! empty( $site_path ) ) {
449
-            $site_host = str_replace( $site_path, '', $site_host );
448
+        if (!empty($site_path)) {
449
+            $site_host = str_replace($site_path, '', $site_host);
450 450
         }
451 451
 
452 452
         // Logic to bind to one domain to avoid site clones of sites would
453 453
         // automatically begin spawning requests to criticalcss.com which has
454 454
         // a per domain cost.
455 455
         global $ao_ccss_domain;
456
-        if ( empty( $ao_ccss_domain ) ) {
456
+        if (empty($ao_ccss_domain)) {
457 457
             // first request being done, update option to allow future requests are only allowed if from same domain.
458
-            update_option( 'autoptimize_ccss_domain', str_rot13( $site_host ) );
459
-        } 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 ) ) {
458
+            update_option('autoptimize_ccss_domain', str_rot13($site_host));
459
+        } 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)) {
460 460
             // not the same domain, log as error and return without posting to criticalcss.com.
461
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Request for domain ' . $site_host . ' does not match bound domain ' . $ao_ccss_domain . ' so not proceeding.', 2 );
461
+            autoptimizeCriticalCSSCore::ao_ccss_log('Request for domain '.$site_host.' does not match bound domain '.$ao_ccss_domain.' so not proceeding.', 2);
462 462
             return false;
463 463
         }
464 464
 
465
-        $src_url = $site_host . $path;
465
+        $src_url = $site_host.$path;
466 466
 
467 467
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
468
-        if ( ! empty( $ao_ccss_noptimize ) ) {
468
+        if (!empty($ao_ccss_noptimize)) {
469 469
             $src_url .= '?ao_noptirocket=1';
470
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
470
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
471 471
             $src_url .= '?ao_nolazy=1';
472 472
         }
473 473
 
474
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
474
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
475 475
 
476 476
         // Initialize request body.
477 477
         $body           = array();
@@ -481,88 +481,88 @@  discard block
 block discarded – undo
481 481
 
482 482
         // Prepare and add viewport size to the body if available.
483 483
         $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
484
-        if ( ! empty( $viewport['w'] ) && ! empty( $viewport['h'] ) ) {
484
+        if (!empty($viewport['w']) && !empty($viewport['h'])) {
485 485
             $body['width']  = $viewport['w'];
486 486
             $body['height'] = $viewport['h'];
487 487
         }
488 488
 
489 489
         // Prepare and add forceInclude to the body if available.
490 490
         global $ao_ccss_finclude;
491
-        $finclude = $this->ao_ccss_finclude( $ao_ccss_finclude );
492
-        if ( ! empty( $finclude ) ) {
491
+        $finclude = $this->ao_ccss_finclude($ao_ccss_finclude);
492
+        if (!empty($finclude)) {
493 493
             $body['forceInclude'] = $finclude;
494 494
         }
495 495
 
496 496
         // Add filter to allow the body array to be altered (e.g. to add customPageHeaders).
497
-        $body = apply_filters( 'autoptimize_ccss_cron_api_generate_body', $body );
497
+        $body = apply_filters('autoptimize_ccss_cron_api_generate_body', $body);
498 498
 
499 499
         // Body must be json and log it.
500
-        $body = json_encode( $body );
501
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request body is ' . $body, 3 );
500
+        $body = json_encode($body);
501
+        autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request body is '.$body, 3);
502 502
 
503 503
         // Prepare the request.
504
-        $url  = esc_url_raw( AO_CCSS_API . 'generate?aover=' . AO_CCSS_VER );
504
+        $url  = esc_url_raw(AO_CCSS_API.'generate?aover='.AO_CCSS_VER);
505 505
         $args = array(
506 506
             'headers' => array(
507
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
507
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
508 508
                 'Content-type'  => 'application/json; charset=utf-8',
509
-                'Authorization' => 'JWT ' . $key,
509
+                'Authorization' => 'JWT '.$key,
510 510
                 'Connection'    => 'close',
511 511
             ),
512 512
             'body'    => $body,
513 513
         );
514 514
 
515 515
         // Dispatch the request and store its response code.
516
-        $req  = wp_safe_remote_post( $url, $args );
517
-        $code = wp_remote_retrieve_response_code( $req );
518
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
516
+        $req  = wp_safe_remote_post($url, $args);
517
+        $code = wp_remote_retrieve_response_code($req);
518
+        $body = json_decode(wp_remote_retrieve_body($req), true);
519 519
 
520
-        if ( $debug && $dcode ) {
520
+        if ($debug && $dcode) {
521 521
             // If queue debug is active, change response code.
522 522
             $code = $dcode;
523 523
         }
524 524
 
525
-        if ( 200 == $code ) {
525
+        if (200 == $code) {
526 526
             // Response code is OK.
527 527
             // Workaround criticalcss.com non-RESTful reponses.
528
-            if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) {
528
+            if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status']) {
529 529
                 // Log successful and return encoded request body.
530
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied successfully', 3 );
530
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied successfully', 3);
531 531
 
532 532
                 // This code also means the key is valid, so cache key status for 24h if not already cached.
533
-                if ( ( ! $key_status || 2 != $key_status ) && $key ) {
534
-                    update_option( 'autoptimize_ccss_keyst', 2 );
535
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
533
+                if ((!$key_status || 2 != $key_status) && $key) {
534
+                    update_option('autoptimize_ccss_keyst', 2);
535
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
536 536
                 }
537 537
 
538 538
                 // Return the request body.
539 539
                 return $body;
540 540
             } else {
541 541
                 // Log successful requests with invalid reponses.
542
-                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 );
543
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
542
+                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);
543
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
544 544
                 return $body;
545 545
             }
546 546
         } else {
547 547
             // Response code is anything else.
548 548
             // Log failed request with a valid response code and return body.
549
-            if ( $code ) {
550
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with error code <' . $code . '>, body follows...', 2 );
551
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
549
+            if ($code) {
550
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with error code <'.$code.'>, body follows...', 2);
551
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
552 552
 
553
-                if ( 401 == $code ) {
553
+                if (401 == $code) {
554 554
                     // If request is unauthorized, also clear key status.
555
-                    update_option( 'autoptimize_ccss_keyst', 1 );
556
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
555
+                    update_option('autoptimize_ccss_keyst', 1);
556
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
557 557
                 }
558 558
 
559 559
                 // Return the request body.
560 560
                 return $body;
561 561
             } else {
562 562
                 // Log failed request with no response and return false.
563
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> has no response, this could be a service timeout', 2 );
564
-                if ( is_wp_error( $req ) ) {
565
-                    autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
563
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> has no response, this could be a service timeout', 2);
564
+                if (is_wp_error($req)) {
565
+                    autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
566 566
                 }
567 567
 
568 568
                 return false;
@@ -570,76 +570,76 @@  discard block
 block discarded – undo
570 570
         }
571 571
     }
572 572
 
573
-    public function ao_ccss_api_results( $jobid, $debug, $dcode ) {
573
+    public function ao_ccss_api_results($jobid, $debug, $dcode) {
574 574
         // GET jobs from criticalcss.com and return responses
575 575
         // Get key.
576 576
         global $ao_ccss_key;
577 577
         $key = $ao_ccss_key;
578 578
 
579 579
         // Prepare the request.
580
-        $url  = AO_CCSS_API . 'results?resultId=' . $jobid;
580
+        $url  = AO_CCSS_API.'results?resultId='.$jobid;
581 581
         $args = array(
582 582
             'headers' => array(
583
-                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER,
584
-                'Authorization' => 'JWT ' . $key,
583
+                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v'.AO_CCSS_VER,
584
+                'Authorization' => 'JWT '.$key,
585 585
                 'Connection'    => 'close',
586 586
             ),
587 587
         );
588 588
 
589 589
         // Dispatch the request and store its response code.
590
-        $req  = wp_safe_remote_get( $url, $args );
591
-        $code = wp_remote_retrieve_response_code( $req );
592
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
590
+        $req  = wp_safe_remote_get($url, $args);
591
+        $code = wp_remote_retrieve_response_code($req);
592
+        $body = json_decode(wp_remote_retrieve_body($req), true);
593 593
 
594
-        if ( $debug && $dcode ) {
594
+        if ($debug && $dcode) {
595 595
             // If queue debug is active, change response code.
596 596
             $code = $dcode;
597 597
         }
598 598
 
599
-        if ( 200 == $code ) {
599
+        if (200 == $code) {
600 600
             // Response code is OK.
601
-            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'] ) ) {
601
+            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'])) {
602 602
                 // Workaround criticalcss.com non-RESTful reponses
603 603
                 // Log successful and return encoded request body.
604
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully', 3 );
604
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully', 3);
605 605
                 return $body;
606
-            } elseif ( is_array( $body ) && ( array_key_exists( 'error', $body ) && 'This css no longer exists. Please re-generate it.' == $body['error'] ) ) {
606
+            } elseif (is_array($body) && (array_key_exists('error', $body) && 'This css no longer exists. Please re-generate it.' == $body['error'])) {
607 607
                 // Handle no CSS reply
608 608
                 // Log no CSS error and return encoded request body.
609
-                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 );
609
+                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);
610 610
                 return $body;
611 611
             } else {
612 612
                 // Log failed request and return false.
613
-                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 );
614
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
613
+                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);
614
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
615 615
                 return false;
616 616
             }
617 617
         } else {
618 618
             // Response code is anything else
619 619
             // Log failed request with a valid response code and return body.
620
-            if ( $code ) {
621
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with error code <' . $code . '>, body follows...', 2 );
622
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
623
-                if ( 401 == $code ) {
620
+            if ($code) {
621
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with error code <'.$code.'>, body follows...', 2);
622
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
623
+                if (401 == $code) {
624 624
                     // If request is unauthorized, also clear key status.
625
-                    update_option( 'autoptimize_ccss_keyst', 1 );
626
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
625
+                    update_option('autoptimize_ccss_keyst', 1);
626
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
627 627
                 }
628 628
 
629 629
                 // Return the request body.
630 630
                 return $body;
631 631
             } else {
632 632
                 // Log failed request with no response and return false.
633
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> has no response, this could be a service timeout', 2 );
633
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> has no response, this could be a service timeout', 2);
634 634
                 return false;
635 635
             }
636 636
         }
637 637
     }
638 638
 
639
-    public function ao_ccss_save_file( $ccss, $target, $review ) {
639
+    public function ao_ccss_save_file($ccss, $target, $review) {
640 640
         // Save critical CSS into the filesystem and return its filename
641 641
         // Prepare review mark.
642
-        if ( $review ) {
642
+        if ($review) {
643 643
             $rmark = '_R';
644 644
         } else {
645 645
             $rmark = '';
@@ -649,21 +649,21 @@  discard block
 block discarded – undo
649 649
         $filename = false;
650 650
         $content  = $ccss;
651 651
 
652
-        if ( autoptimizeCriticalCSSCore::ao_ccss_check_contents( $content ) ) {
652
+        if (autoptimizeCriticalCSSCore::ao_ccss_check_contents($content)) {
653 653
             // Sanitize content, set filename and try to save file.
654
-            $file     = AO_CCSS_DIR . 'ccss_' . md5( $ccss . $target[1] ) . $rmark . '.css';
655
-            $status   = file_put_contents( $file, $content, LOCK_EX );
656
-            $filename = pathinfo( $file, PATHINFO_BASENAME );
657
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file for the rule <' . $target[0] . '|' . $target[1] . '> was saved as <' . $filename . '>, size in bytes is <' . $status . '>', 3 );
654
+            $file     = AO_CCSS_DIR.'ccss_'.md5($ccss.$target[1]).$rmark.'.css';
655
+            $status   = file_put_contents($file, $content, LOCK_EX);
656
+            $filename = pathinfo($file, PATHINFO_BASENAME);
657
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file for the rule <'.$target[0].'|'.$target[1].'> was saved as <'.$filename.'>, size in bytes is <'.$status.'>', 3);
658 658
 
659
-            if ( ! $status ) {
659
+            if (!$status) {
660 660
                 // If file has not been saved, reset filename.
661
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file <' . $filename . '> could not be not saved', 2 );
661
+                autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file <'.$filename.'> could not be not saved', 2);
662 662
                 $filename = false;
663 663
                 return $filename;
664 664
             }
665 665
         } else {
666
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not pass content check', 2 );
666
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not pass content check', 2);
667 667
             return $filename;
668 668
         }
669 669
 
@@ -673,15 +673,15 @@  discard block
 block discarded – undo
673 673
         global $ao_ccss_rules;
674 674
 
675 675
         // Prepare rule variables.
676
-        $srule   = $ao_ccss_rules[ $target[0] ][ $target[1] ];
676
+        $srule   = $ao_ccss_rules[$target[0]][$target[1]];
677 677
         $oldfile = $srule['file'];
678 678
 
679
-        if ( $oldfile && $oldfile !== $filename ) {
680
-            $delfile = AO_CCSS_DIR . $oldfile;
681
-            if ( file_exists( $delfile ) ) {
682
-                $unlinkst = unlink( $delfile );
683
-                if ( $unlinkst ) {
684
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A previous critical CSS file <' . $oldfile . '> was removed for the rule <' . $target[0] . '|' . $target[1] . '>', 3 );
679
+        if ($oldfile && $oldfile !== $filename) {
680
+            $delfile = AO_CCSS_DIR.$oldfile;
681
+            if (file_exists($delfile)) {
682
+                $unlinkst = unlink($delfile);
683
+                if ($unlinkst) {
684
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A previous critical CSS file <'.$oldfile.'> was removed for the rule <'.$target[0].'|'.$target[1].'>', 3);
685 685
                 }
686 686
             }
687 687
         }
@@ -690,29 +690,29 @@  discard block
 block discarded – undo
690 690
         return $filename;
691 691
     }
692 692
 
693
-    public function ao_ccss_rule_update( $ljid, $srule, $file, $hash ) {
693
+    public function ao_ccss_rule_update($ljid, $srule, $file, $hash) {
694 694
         // Update or create a rule
695 695
         // Attach required arrays.
696 696
         global $ao_ccss_rules;
697 697
 
698 698
         // Prepare rule variables.
699
-        $trule  = explode( '|', $srule );
700
-        $rule   = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
699
+        $trule  = explode('|', $srule);
700
+        $rule   = $ao_ccss_rules[$trule[0]][$trule[1]];
701 701
         $action = false;
702 702
         $rtype  = '';
703 703
 
704
-        if ( 0 === $rule['hash'] && 0 !== $rule['file'] ) {
704
+        if (0 === $rule['hash'] && 0 !== $rule['file']) {
705 705
             // manual rule, don't ever overwrite.
706 706
             $action = 'NOT UPDATED';
707 707
             $rtype  = 'MANUAL';
708
-        } elseif ( 0 === $rule['hash'] && 0 === $rule['file'] ) {
708
+        } elseif (0 === $rule['hash'] && 0 === $rule['file']) {
709 709
             // If this is an user created AUTO rule with no hash and file yet, update its hash and filename
710 710
             // Set rule hash, file and action flag.
711 711
             $rule['hash'] = $hash;
712 712
             $rule['file'] = $file;
713 713
             $action       = 'UPDATED';
714 714
             $rtype        = 'AUTO';
715
-        } elseif ( 0 !== $rule['hash'] && ctype_alnum( $rule['hash'] ) ) {
715
+        } elseif (0 !== $rule['hash'] && ctype_alnum($rule['hash'])) {
716 716
             // If this is an genuine AUTO rule, update its hash and filename
717 717
             // Set rule hash, file and action flag.
718 718
             $rule['hash'] = $hash;
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         } else {
723 723
             // If rule doesn't exist, create an AUTO rule
724 724
             // AUTO rules were only for types, but will now also work for paths.
725
-            if ( 'types' == $trule[0] || 'paths' == $trule[0] ) {
725
+            if ('types' == $trule[0] || 'paths' == $trule[0]) {
726 726
                 // Set rule hash and file and action flag.
727 727
                 $rule['hash'] = $hash;
728 728
                 $rule['file'] = $file;
@@ -730,47 +730,47 @@  discard block
 block discarded – undo
730 730
                 $rtype        = 'AUTO';
731 731
             } else {
732 732
                 // Log that no rule was created.
733
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Exception, no AUTO rule created', 3 );
733
+                autoptimizeCriticalCSSCore::ao_ccss_log('Exception, no AUTO rule created', 3);
734 734
             }
735 735
         }
736 736
 
737
-        if ( $action ) {
737
+        if ($action) {
738 738
             // If a rule creation/update is required, persist updated rules object.
739
-            $ao_ccss_rules[ $trule[0] ][ $trule[1] ] = $rule;
740
-            $ao_ccss_rules_raw                       = json_encode( $ao_ccss_rules );
741
-            update_option( 'autoptimize_ccss_rules', $ao_ccss_rules_raw );
742
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Target rule <' . $srule . '> of type <' . $rtype . '> was ' . $action . ' for job id <' . $ljid . '>', 3 );
739
+            $ao_ccss_rules[$trule[0]][$trule[1]] = $rule;
740
+            $ao_ccss_rules_raw                       = json_encode($ao_ccss_rules);
741
+            update_option('autoptimize_ccss_rules', $ao_ccss_rules_raw);
742
+            autoptimizeCriticalCSSCore::ao_ccss_log('Target rule <'.$srule.'> of type <'.$rtype.'> was '.$action.' for job id <'.$ljid.'>', 3);
743 743
         } else {
744
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No rule action required', 3 );
744
+            autoptimizeCriticalCSSCore::ao_ccss_log('No rule action required', 3);
745 745
         }
746 746
     }
747 747
 
748
-    function ao_ccss_finclude( $finclude_raw ) {
748
+    function ao_ccss_finclude($finclude_raw) {
749 749
         // Prepare forceInclude object.
750
-        if ( ! empty( $finclude_raw ) ) {
750
+        if (!empty($finclude_raw)) {
751 751
             // If there are any content
752 752
             // Convert raw string into arra and initialize the returning object.
753
-            $fincludes = explode( ',', $finclude_raw );
753
+            $fincludes = explode(',', $finclude_raw);
754 754
             $finclude  = array();
755 755
 
756 756
             // Interacts over every rule.
757 757
             $i = 0;
758
-            foreach ( $fincludes as $include ) {
758
+            foreach ($fincludes as $include) {
759 759
                 // Trim leading and trailing whitespaces.
760
-                $include = trim( $include );
760
+                $include = trim($include);
761 761
 
762
-                if ( substr( $include, 0, 2 ) === '//' ) {
762
+                if (substr($include, 0, 2) === '//') {
763 763
                     // Regex rule
764 764
                     // Format value as required.
765
-                    $include = str_replace( '//', '/', $include );
766
-                    $include = $include . '/i';
765
+                    $include = str_replace('//', '/', $include);
766
+                    $include = $include.'/i';
767 767
 
768 768
                     // Store regex object.
769
-                    $finclude[ $i ]['type']  = 'RegExp';
770
-                    $finclude[ $i ]['value'] = $include;
769
+                    $finclude[$i]['type']  = 'RegExp';
770
+                    $finclude[$i]['value'] = $include;
771 771
                 } else {
772 772
                     // Simple value rule.
773
-                    $finclude[ $i ]['value'] = $include;
773
+                    $finclude[$i]['value'] = $include;
774 774
                 }
775 775
 
776 776
                 $i++;
@@ -787,54 +787,54 @@  discard block
 block discarded – undo
787 787
     public function ao_ccss_cleaning() {
788 788
         // Perform plugin maintenance
789 789
         // Truncate log file >= 1MB .
790
-        if ( file_exists( AO_CCSS_LOG ) ) {
791
-            if ( filesize( AO_CCSS_LOG ) >= 1048576 ) {
792
-                $logfile = fopen( AO_CCSS_LOG, 'w' );
793
-                fclose( $logfile );
790
+        if (file_exists(AO_CCSS_LOG)) {
791
+            if (filesize(AO_CCSS_LOG) >= 1048576) {
792
+                $logfile = fopen(AO_CCSS_LOG, 'w');
793
+                fclose($logfile);
794 794
             }
795 795
         }
796 796
 
797 797
         // Remove lock file.
798
-        if ( file_exists( AO_CCSS_LOCK ) ) {
799
-            unlink( AO_CCSS_LOCK );
798
+        if (file_exists(AO_CCSS_LOCK)) {
799
+            unlink(AO_CCSS_LOCK);
800 800
         }
801 801
 
802 802
         // Make sure queue processing is scheduled, recreate if not.
803
-        if ( ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
804
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
803
+        if (!wp_next_scheduled('ao_ccss_queue')) {
804
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
805 805
         }
806 806
 
807 807
         // Queue cleaning.
808 808
         global $ao_ccss_queue;
809 809
         $queue_purge_threshold = 100;
810
-        $queue_purge_age       = 24 * 60 * 60;
811
-        $queue_length          = count( $ao_ccss_queue );
812
-        $timestamp_yesterday   = microtime( true ) - $queue_purge_age;
810
+        $queue_purge_age       = 24*60*60;
811
+        $queue_length          = count($ao_ccss_queue);
812
+        $timestamp_yesterday   = microtime(true) - $queue_purge_age;
813 813
         $remove_old_new        = false;
814 814
         $queue_altered         = false;
815 815
 
816
-        if ( $queue_length > $queue_purge_threshold ) {
816
+        if ($queue_length > $queue_purge_threshold) {
817 817
             $remove_old_new = true;
818 818
         }
819 819
 
820
-        foreach ( $ao_ccss_queue as $path => $job ) {
821
-            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' ) ) ) {
822
-                unset( $ao_ccss_queue[ $path ] );
820
+        foreach ($ao_ccss_queue as $path => $job) {
821
+            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'))) {
822
+                unset($ao_ccss_queue[$path]);
823 823
                 $queue_altered = true;
824 824
             }
825 825
         }
826 826
 
827 827
         // save queue to options!
828
-        if ( $queue_altered ) {
829
-            $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
830
-            update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
831
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue cleaning done.', 3 );
828
+        if ($queue_altered) {
829
+            $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
830
+            update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
831
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue cleaning done.', 3);
832 832
         }
833 833
 
834 834
         // re-check key if invalid.
835 835
         global $ao_ccss_keyst;
836
-        if ( 1 == $ao_ccss_keyst ) {
837
-            $this->ao_ccss_api_generate( '', '', '' );
836
+        if (1 == $ao_ccss_keyst) {
837
+            $this->ao_ccss_api_generate('', '', '');
838 838
         }
839 839
     }
840 840
 }
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/autoptimizeConfig.php 1 patch
Spacing   +225 added lines, -225 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
     }
@@ -184,32 +184,32 @@  discard block
 block discarded – undo
184 184
 <div class="wrap">
185 185
 
186 186
 <!-- Temporary nudge to disable aoccss power-up. -->
187
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
187
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
188 188
     <div class="notice-info notice"><p>
189
-        <?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' ); ?>
189
+        <?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'); ?>
190 190
     </p></div>
191 191
 <?php } ?>
192 192
 
193 193
 <div id="autoptimize_main">
194
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
194
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
195 195
     <?php echo $this->ao_admin_tabs(); ?>
196 196
 
197
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
198
-<?php settings_fields( 'autoptimize' ); ?>
197
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
198
+<?php settings_fields('autoptimize'); ?>
199 199
 
200 200
 <ul>
201 201
 
202 202
 <?php
203 203
 // Only show enable site configuration in network site option.
204
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
204
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
205 205
 ?>
206 206
     <li class="itemDetail multiSite">
207
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
207
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
208 208
         <table class="form-table">
209 209
             <tr valign="top">
210
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
211
-                <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" ' : ''; ?>/>
212
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
210
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
211
+                <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" ' : ''; ?>/>
212
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
213 213
             </tr>
214 214
         </table>
215 215
     </li>
@@ -218,120 +218,120 @@  discard block
 block discarded – undo
218 218
 <?php } ?>    
219 219
 
220 220
 <li class="itemDetail">
221
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
221
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
222 222
 <table class="form-table">
223 223
 <tr valign="top">
224
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
225
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
224
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
225
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
226 226
 </tr>
227 227
 <tr valign="top" class="js_sub js_aggregate_master">
228
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
229
-<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" ' : ''; ?>/>
230
-<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
228
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
229
+<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" ' : ''; ?>/>
230
+<?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>
231 231
 </tr>
232 232
 <tr valign="top" class="js_sub js_not_aggregate">
233
-<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
234
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
235
-<?php _e( 'When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
233
+<th scope="row"><?php _e('Do not aggregate but defer?', 'autoptimize'); ?></th>
234
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get('autoptimize_js_defer_not_aggregate') ? 'checked="checked" ' : ''; ?>/>
235
+<?php _e('When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize'); ?></label></td>
236 236
 </tr>
237 237
 <tr valign="top" class="js_sub js_aggregate">
238
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
239
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
240
-<?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>
238
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
239
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
240
+<?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>
241 241
 </tr>
242 242
 <tr valign="top" class="js_sub js_aggregate">
243
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
244
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
245
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
243
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
244
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
245
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
246 246
 </tr>
247
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
247
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
248 248
 <tr valign="top" class="js_sub js_aggregate">
249 249
 <th scope="row">
250 250
 <?php
251
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
252
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
251
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
252
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
253 253
 ?>
254 254
 </th>
255
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
256
-<?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>
255
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
256
+<?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>
257 257
 </tr>
258 258
 <?php } ?>
259 259
 <tr valign="top" class="js_sub">
260
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
261
-<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, js/jquery/jquery.min.js' ) ); ?>"/><br />
260
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
261
+<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, js/jquery/jquery.min.js')); ?>"/><br />
262 262
 <?php
263
-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' );
263
+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');
264 264
 ?>
265 265
 </label></td>
266 266
 </tr>
267 267
 <tr valign="top" class="js_sub js_aggregate">
268
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
269
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
270
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
268
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
269
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
270
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
271 271
 </tr>
272 272
 </table>
273 273
 </li>
274 274
 
275 275
 <li class="itemDetail">
276
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
276
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
277 277
 <table class="form-table">
278 278
 <tr valign="top">
279
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
280
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
279
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
280
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
281 281
 </tr>
282 282
 <tr class="css_sub" valign="top">
283
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
284
-<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" ' : ''; ?>/>
285
-<?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>
283
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
284
+<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" ' : ''; ?>/>
285
+<?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>
286 286
 </tr>
287 287
 <tr valign="top" class="css_sub css_aggregate">
288
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
289
-<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" ' : ''; ?>/>
290
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
288
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
289
+<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" ' : ''; ?>/>
290
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
291 291
 </tr>
292 292
 <tr class="css_sub css_aggregate" valign="top">
293
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
294
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
295
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
293
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
294
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
295
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
296 296
 </tr>
297
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
297
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
298 298
 <tr valign="top" class="css_sub css_aggregate">
299 299
 <th scope="row">
300 300
 <?php
301
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
302
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
301
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
302
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
303 303
 ?>
304 304
 </th>
305
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
306
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
305
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
306
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
307 307
 </tr>
308 308
 <?php } ?>
309 309
 <tr valign="top" class="css_sub">
310
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
311
-<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" ' : ''; ?>/>
310
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
311
+<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" ' : ''; ?>/>
312 312
 <?php
313
-_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' );
313
+_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');
314 314
 echo ' ';
315
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
315
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
316 316
 // translators: links "autoptimize critical CSS" tab.
317
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
317
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
318 318
 ?>
319 319
 </label></td>
320 320
 </tr>
321 321
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
322 322
 <th scope="row"></th>
323
-<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>
323
+<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>
324 324
 </tr>
325 325
 <tr valign="top" class="css_sub css_aggregate">
326
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
327
-<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" ' : ''; ?>/>
328
-<?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>
326
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
327
+<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" ' : ''; ?>/>
328
+<?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>
329 329
 </tr>
330 330
 <tr valign="top" class="css_sub">
331
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
332
-<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 />
331
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
332
+<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 />
333 333
 <?php
334
-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' );
334
+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');
335 335
 ?>
336 336
 </label></td>
337 337
 </tr>
@@ -339,55 +339,55 @@  discard block
 block discarded – undo
339 339
 </li>
340 340
 
341 341
 <li class="itemDetail">
342
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
342
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
343 343
 <table class="form-table">
344 344
 <tr valign="top">
345
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
346
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
345
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
346
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
347 347
 </tr>
348 348
 <tr class="html_sub" valign="top">
349
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
350
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
351
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
349
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
350
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
351
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
352 352
 </tr>
353 353
 </table>
354 354
 </li>
355 355
 
356 356
 <li class="itemDetail">
357
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
357
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
358 358
 <table class="form-table">
359 359
 <tr valign="top">
360
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
361
-<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 />
362
-<?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>
360
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
361
+<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 />
362
+<?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>
363 363
 </tr>
364 364
 </table>
365 365
 </li>
366 366
 
367 367
 <li class="itemDetail">
368
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
368
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
369 369
 <table class="form-table" >
370 370
 <tr valign="top" >
371
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
372
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
371
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
372
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
373 373
 </tr>
374 374
 <tr valign="top" >
375
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
376
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
375
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
376
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
377 377
 </tr>
378 378
 <tr valign="top" >
379
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
379
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
380 380
 <td>
381 381
     <?php
382 382
     $ao_stat_arr = autoptimizeCache::stats();
383
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
384
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
383
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
384
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
385 385
         $details       = '';
386
-        if ( $ao_cache_size > 0 ) {
387
-            $details = ', ~' . $ao_cache_size . ' total';
386
+        if ($ao_cache_size > 0) {
387
+            $details = ', ~'.$ao_cache_size.' total';
388 388
         }
389 389
         // translators: Kilobytes + timestamp shown.
390
-        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] ) );
390
+        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]));
391 391
     }
392 392
     ?>
393 393
 </td>
@@ -396,41 +396,41 @@  discard block
 block discarded – undo
396 396
 </li>
397 397
 
398 398
 <li class="itemDetail">
399
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
399
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
400 400
 <table class="form-table">
401 401
     <tr valign="top" >
402
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
403
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
404
-    <?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>
402
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
403
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
404
+    <?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>
405 405
     </tr>
406 406
     <?php
407 407
     $_min_excl_class = '';
408
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
408
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
409 409
         $_min_excl_class = 'hidden';
410 410
     }
411 411
     ?>
412 412
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
413
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
414
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
415
-        <?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>
413
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
414
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
415
+        <?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>
416 416
     </tr>
417 417
     <tr valign="top">
418
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
419
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
420
-        <?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>
418
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
419
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
420
+        <?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>
421 421
     </tr>
422 422
     <tr valign="top">
423
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
424
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
425
-    <?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>
423
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
424
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
425
+    <?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>
426 426
     </tr>
427 427
     <?php
428
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
428
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
429 429
     ?>
430 430
     <tr valign="top" >
431
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
432
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
433
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
431
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
432
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
433
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
434 434
         </td>
435 435
     </tr>
436 436
     <?php } ?>
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 </ul>
441 441
 
442 442
 <p class="submit">
443
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
444
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
443
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
444
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
445 445
 </p>
446 446
 
447 447
 </form>
@@ -450,46 +450,46 @@  discard block
 block discarded – undo
450 450
     <div class="autoptimize_banner hidden">
451 451
     <ul>
452 452
     <?php
453
-    if ( $this->settings_screen_do_remote_http ) {
454
-        $ao_banner = get_transient( 'autoptimize_banner' );
455
-        if ( empty( $ao_banner ) ) {
456
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
457
-            if ( ! is_wp_error( $banner_resp ) ) {
458
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
459
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
460
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
453
+    if ($this->settings_screen_do_remote_http) {
454
+        $ao_banner = get_transient('autoptimize_banner');
455
+        if (empty($ao_banner)) {
456
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
457
+            if (!is_wp_error($banner_resp)) {
458
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
459
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
460
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
461 461
                 }
462 462
             }
463 463
         }
464 464
         echo $ao_banner;
465 465
     }
466 466
     ?>
467
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
468
-        <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>
467
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
468
+        <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>
469 469
     </ul>
470 470
     </div>
471 471
     <div style="margin-left:10px;margin-top:-5px;">
472 472
         <h2>
473
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
473
+            <?php _e('futtta about', 'autoptimize'); ?>
474 474
             <select id="feed_dropdown" >
475
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
476
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
477
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
475
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
476
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
477
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
478 478
             </select>
479 479
         </h2>
480 480
         <div id="futtta_feed">
481 481
             <div id="autoptimizefeed">
482
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
482
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
483 483
             </div>
484 484
             <div id="wordpressfeed">
485
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
485
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
486 486
             </div>
487 487
             <div id="webtechfeed">
488
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
488
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
489 489
             </div>
490 490
         </div>
491 491
     </div>
492
-    <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>
492
+    <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>
493 493
 </div>
494 494
 
495 495
 <script type="text/javascript">
@@ -655,82 +655,82 @@  discard block
 block discarded – undo
655 655
 
656 656
     public function addmenu()
657 657
     {
658
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
658
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
659 659
             // multisite, network admin, ao network activated: add normal settings page at network level.
660
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
661
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
660
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
661
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
662 662
             // 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.
663
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
663
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
664 664
         } else {
665 665
             // 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.
666
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
666
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
667 667
         }
668 668
 
669
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
670
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
669
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
670
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
671 671
     }
672 672
 
673 673
     public function autoptimize_admin_scripts()
674 674
     {
675
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
676
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
675
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
676
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
677 677
     }
678 678
 
679 679
     public function autoptimize_admin_styles()
680 680
     {
681
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
682
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
681
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
682
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
683 683
     }
684 684
 
685 685
     public function registersettings() {
686
-        register_setting( 'autoptimize', 'autoptimize_html' );
687
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
688
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
689
-        register_setting( 'autoptimize', 'autoptimize_js' );
690
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
691
-        register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
692
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
693
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
694
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
695
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
696
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
697
-        register_setting( 'autoptimize', 'autoptimize_css' );
698
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
699
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
700
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
701
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
702
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
703
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
704
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
705
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
706
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
707
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
708
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
709
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
710
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
711
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
712
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
686
+        register_setting('autoptimize', 'autoptimize_html');
687
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
688
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
689
+        register_setting('autoptimize', 'autoptimize_js');
690
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
691
+        register_setting('autoptimize', 'autoptimize_js_defer_not_aggregate');
692
+        register_setting('autoptimize', 'autoptimize_js_exclude');
693
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
694
+        register_setting('autoptimize', 'autoptimize_js_justhead');
695
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
696
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
697
+        register_setting('autoptimize', 'autoptimize_css');
698
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
699
+        register_setting('autoptimize', 'autoptimize_css_exclude');
700
+        register_setting('autoptimize', 'autoptimize_css_justhead');
701
+        register_setting('autoptimize', 'autoptimize_css_datauris');
702
+        register_setting('autoptimize', 'autoptimize_css_defer');
703
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
704
+        register_setting('autoptimize', 'autoptimize_css_inline');
705
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
706
+        register_setting('autoptimize', 'autoptimize_cdn_url');
707
+        register_setting('autoptimize', 'autoptimize_cache_clean');
708
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
709
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
710
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
711
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
712
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
713 713
     }
714 714
 
715
-    public function setmeta( $links, $file = null )
715
+    public function setmeta($links, $file = null)
716 716
     {
717 717
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
718 718
         // Do it only once - saves time.
719 719
         static $plugin;
720
-        if ( empty( $plugin ) ) {
721
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
720
+        if (empty($plugin)) {
721
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
722 722
         }
723 723
 
724
-        if ( null === $file ) {
724
+        if (null === $file) {
725 725
             // 2.7 and lower.
726
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
727
-            array_unshift( $links, $settings_link );
726
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
727
+            array_unshift($links, $settings_link);
728 728
         } else {
729 729
             // 2.8 and higher.
730 730
             // If it's us, add the link.
731
-            if ( $file === $plugin ) {
732
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
733
-                $links   = array_merge( $links, $newlink );
731
+            if ($file === $plugin) {
732
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
733
+                $links   = array_merge($links, $newlink);
734 734
             }
735 735
         }
736 736
 
@@ -807,8 +807,8 @@  discard block
 block discarded – undo
807 807
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
808 808
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
809 809
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
810
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
811
-            'autoptimize_imgopt_text_field_6'     => '',  // optimization exclusions empty.
810
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
811
+            'autoptimize_imgopt_text_field_6'     => '', // optimization exclusions empty.
812 812
             'autoptimize_imgopt_number_field_7'   => '0', // lazy load from nth image (0 = lazyload all).
813 813
         );
814 814
         return $defaults;
@@ -821,58 +821,58 @@  discard block
 block discarded – undo
821 821
      *
822 822
      * @return string
823 823
      */
824
-    public static function get_ao_css_preload_onload( $media = 'all' )
824
+    public static function get_ao_css_preload_onload($media = 'all')
825 825
     {
826
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
826
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
827 827
         return $preload_onload;
828 828
     }
829 829
 
830
-    public function get( $key )
830
+    public function get($key)
831 831
     {
832
-        if ( ! is_array( $this->config ) ) {
832
+        if (!is_array($this->config)) {
833 833
             // Default config.
834 834
             $config = self::get_defaults();
835 835
 
836 836
             // Override with user settings.
837
-            foreach ( array_keys( $config ) as $name ) {
838
-                $conf = autoptimizeOptionWrapper::get_option( $name );
839
-                if ( false !== $conf ) {
837
+            foreach (array_keys($config) as $name) {
838
+                $conf = autoptimizeOptionWrapper::get_option($name);
839
+                if (false !== $conf) {
840 840
                     // It was set before!
841
-                    $config[ $name ] = $conf;
841
+                    $config[$name] = $conf;
842 842
                 }
843 843
             }
844 844
 
845 845
             // Save for next call.
846
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
846
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
847 847
         }
848 848
 
849
-        if ( isset( $this->config[ $key ] ) ) {
850
-            return $this->config[ $key ];
849
+        if (isset($this->config[$key])) {
850
+            return $this->config[$key];
851 851
         }
852 852
 
853 853
         return false;
854 854
     }
855 855
 
856
-    private function get_futtta_feeds( $url ) {
857
-        if ( $this->settings_screen_do_remote_http ) {
858
-            $rss      = fetch_feed( $url );
856
+    private function get_futtta_feeds($url) {
857
+        if ($this->settings_screen_do_remote_http) {
858
+            $rss      = fetch_feed($url);
859 859
             $maxitems = 0;
860 860
 
861
-            if ( ! is_wp_error( $rss ) ) {
862
-                $maxitems  = $rss->get_item_quantity( 7 );
863
-                $rss_items = $rss->get_items( 0, $maxitems );
861
+            if (!is_wp_error($rss)) {
862
+                $maxitems  = $rss->get_item_quantity(7);
863
+                $rss_items = $rss->get_items(0, $maxitems);
864 864
             }
865 865
             ?>
866 866
             <ul>
867
-                <?php if ( 0 == $maxitems ) : ?>
868
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
867
+                <?php if (0 == $maxitems) : ?>
868
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
869 869
                 <?php else : ?>
870
-                    <?php foreach ( $rss_items as $item ) : ?>
870
+                    <?php foreach ($rss_items as $item) : ?>
871 871
                         <li>
872
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
872
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
873 873
                                 <?php // translators: the variable contains a date. ?>
874
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
875
-                                <?php echo esc_html( $item->get_title() ); ?>
874
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
875
+                                <?php echo esc_html($item->get_title()); ?>
876 876
                             </a>
877 877
                         </li>
878 878
                     <?php endforeach; ?>
@@ -885,23 +885,23 @@  discard block
 block discarded – undo
885 885
     static function ao_admin_tabs()
886 886
     {
887 887
         // based on http://wordpress.stackexchange.com/a/58826 .
888
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
888
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
889 889
         $tab_content = '';
890
-        $tabs_count  = count( $tabs );
891
-        if ( $tabs_count > 1 ) {
892
-            if ( isset( $_GET['page'] ) ) {
890
+        $tabs_count  = count($tabs);
891
+        if ($tabs_count > 1) {
892
+            if (isset($_GET['page'])) {
893 893
                 $current_id = $_GET['page'];
894 894
             } else {
895 895
                 $current_id = 'autoptimize';
896 896
             }
897 897
             $tab_content .= '<h2 class="nav-tab-wrapper">';
898
-            foreach ( $tabs as $tab_id => $tab_name ) {
899
-                if ( $current_id == $tab_id ) {
898
+            foreach ($tabs as $tab_id => $tab_name) {
899
+                if ($current_id == $tab_id) {
900 900
                     $class = ' nav-tab-active';
901 901
                 } else {
902 902
                     $class = '';
903 903
                 }
904
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
904
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
905 905
             }
906 906
             $tab_content .= '</h2>';
907 907
         } else {
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
      */
919 919
     public static function is_admin_and_not_ajax()
920 920
     {
921
-        return ( is_admin() && ! self::doing_ajax() );
921
+        return (is_admin() && !self::doing_ajax());
922 922
     }
923 923
 
924 924
     /**
@@ -928,10 +928,10 @@  discard block
 block discarded – undo
928 928
      */
929 929
     protected static function doing_ajax()
930 930
     {
931
-        if ( function_exists( 'wp_doing_ajax' ) ) {
931
+        if (function_exists('wp_doing_ajax')) {
932 932
             return wp_doing_ajax();
933 933
         }
934
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
934
+        return (defined('DOING_AJAX') && DOING_AJAX);
935 935
     }
936 936
 
937 937
     /**
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
      * @return bool
941 941
      */
942 942
     public static function should_show_menu_tabs() {
943
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
943
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
944 944
             return true;
945 945
         } else {
946 946
             return false;
Please login to merge, or discard this patch.