Completed
Push — master ( 964b0c...cd5cb6 )
by frank
01:40
created
classes/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,66 +52,66 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rlimit' );
62
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' );
63
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' );
64
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' );
65
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' );
66
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' );
67
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' );
68
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' );
69
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' );
70
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rlimit');
62
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize');
63
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug');
64
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_key');
65
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst');
66
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin');
67
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath');
68
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery');
69
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain');
70
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss');
71 71
 
72 72
         // And add submenu-page.
73
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
73
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
74 74
     }
75 75
 
76
-    public function admin_assets( $hook ) {
76
+    public function admin_assets($hook) {
77 77
         // Return if plugin is not hooked.
78
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
78
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
79 79
             return;
80 80
         }
81 81
 
82 82
         // Stylesheets to add.
83
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
84
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
85
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
83
+        wp_enqueue_style('wp-jquery-ui-dialog');
84
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
85
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
86 86
 
87 87
         // Scripts to add.
88
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
89
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
90
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
91
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
88
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
89
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
90
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
91
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
92 92
     }
93 93
 
94 94
     public function ao_criticalcsssettings_page()
95 95
     {
96 96
         // these are not OO yet, simply require for now.
97
-        require_once( 'critcss-inc/admin_settings_rules.php' );
98
-        require_once( 'critcss-inc/admin_settings_queue.php' );
99
-        require_once( 'critcss-inc/admin_settings_key.php' );
100
-        require_once( 'critcss-inc/admin_settings_adv.php' );
101
-        require_once( 'critcss-inc/admin_settings_explain.php' );
97
+        require_once('critcss-inc/admin_settings_rules.php');
98
+        require_once('critcss-inc/admin_settings_queue.php');
99
+        require_once('critcss-inc/admin_settings_key.php');
100
+        require_once('critcss-inc/admin_settings_adv.php');
101
+        require_once('critcss-inc/admin_settings_explain.php');
102 102
 
103 103
         // fetch all options at once and populate them individually explicitely as globals.
104 104
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
105
-        foreach ( $all_options as $_option => $_value ) {
105
+        foreach ($all_options as $_option => $_value) {
106 106
             global ${$_option};
107 107
             ${$_option} = $_value;
108 108
         }
109 109
         ?>
110
-        <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
110
+        <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
111 111
         <div class="wrap">
112 112
             <div id="autoptimize_main">
113 113
                 <div id="ao_title_and_button">
114
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
114
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
115 115
                 </div>
116 116
 
117 117
                 <?php
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
                 echo autoptimizeConfig::ao_admin_tabs();
120 120
 
121 121
                 // Make sure dir to write ao_ccss exists and is writable.
122
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
123
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
124
-                    $fileresp  = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' );
125
-                    if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
122
+                if (!is_dir(AO_CCSS_DIR)) {
123
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
124
+                    $fileresp  = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>');
125
+                    if ((!$mkdirresp) || (!$fileresp)) {
126 126
                         ?>
127 127
                         <div class="notice-error notice"><p>
128 128
                         <?php
129
-                        _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
129
+                        _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
130 130
                         ?>
131 131
                         </p></div>
132 132
                         <?php
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
                 }
135 135
 
136 136
                 // Check for Autoptimize.
137
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
137
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
138 138
                     ?>
139 139
                     <div class="notice-error notice"><p>
140 140
                     <?php
141
-                    _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' );
141
+                    _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize');
142 142
                     ?>
143 143
                     </p></div>
144 144
                     <?php
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
                 }
147 147
 
148 148
                 // check if WordPress cron is disabled and warn if so.
149
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
149
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
150 150
                     ?>
151 151
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
152 152
                     <?php
153
-                    _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
153
+                    _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
154 154
                     ?>
155 155
                     </p></div>
156 156
                     <?php
@@ -158,24 +158,24 @@  discard block
 block discarded – undo
158 158
 
159 159
                 // warn if it looks as though the queue processing job looks isn't running
160 160
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
161
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
162
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
161
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
162
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
163 163
                     $_jobs_all_new         = true;
164
-                    $_oldest_job_timestamp = microtime( true ); // now.
164
+                    $_oldest_job_timestamp = microtime(true); // now.
165 165
                     $_jobs_too_old         = true;
166 166
 
167 167
                     // go over queue array.
168
-                    if ( empty( $ao_ccss_queue ) ) {
168
+                    if (empty($ao_ccss_queue)) {
169 169
                         // no jobs, then no warning.
170 170
                         $_jobs_all_new = false;
171 171
                     } else {
172
-                        foreach ( $ao_ccss_queue as $job ) {
173
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
172
+                        foreach ($ao_ccss_queue as $job) {
173
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
174 174
                                 // we need to catch the oldest job's timestamp.
175 175
                                 $_oldest_job_timestamp = $job['jctime'];
176 176
                             }
177 177
 
178
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
178
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
179 179
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
180 180
                                 $_jobs_all_new = false;
181 181
                                 break;
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
                     }
185 185
 
186 186
                     // is the oldest job too old (4h)?
187
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
187
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
188 188
                         $_jobs_too_old = false;
189 189
                     }
190 190
 
191
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
191
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
192 192
                         $_warn_cron            = 'on';
193 193
                         $_transient_multiplier = 1; // store for 1 hour.
194 194
                     } else {
@@ -196,33 +196,33 @@  discard block
 block discarded – undo
196 196
                         $_transient_multiplier = 4; // store for 4 hours.
197 197
                     }
198 198
                     // and set transient.
199
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
199
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
200 200
                 }
201 201
 
202
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
202
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
203 203
                     ?>
204 204
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
205 205
                     <?php
206
-                    _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
206
+                    _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
207 207
                     ?>
208 208
                     </p></div>
209 209
                     <?php
210
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
210
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
211 211
                     ?>
212 212
                     <div class="notice-success notice"><p>
213 213
                     <?php
214
-                    _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' );
214
+                    _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize');
215 215
                     ?>
216 216
                     </p></div>
217 217
                     <?php
218 218
                 }
219 219
 
220 220
                 // warn if service is down.
221
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
221
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
222 222
                     ?>
223 223
                     <div class="notice-warning notice"><p>
224 224
                     <?php
225
-                    _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' );
225
+                    _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize');
226 226
                     ?>
227 227
                     </p></div>
228 228
                     <?php
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
                 ?>
233 233
                 <form id="settings" method="post" action="options.php">
234 234
                     <?php
235
-                    settings_fields( 'ao_ccss_options_group' );
235
+                    settings_fields('ao_ccss_options_group');
236 236
 
237 237
                     // Get API key status.
238
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
238
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
239 239
 
240
-                    if ( $this->is_multisite_network_admin() ) {
240
+                    if ($this->is_multisite_network_admin()) {
241 241
                         ?>
242 242
                         <ul id="key-panel">
243 243
                             <li class="itemDetail">
244 244
                             <?php
245 245
                                 // translators: the placesholder is for a line of code in wp-config.php.
246
-                                echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' );
246
+                                echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>');
247 247
                             ?>
248 248
                             </li>
249 249
                         </ul>
250 250
                         <?php
251 251
                     } else {
252
-                        if ( 'valid' == $key['status'] ) {
252
+                        if ('valid' == $key['status']) {
253 253
                             // If key status is valid, render other panels.
254 254
                             // Render rules section.
255 255
                             ao_ccss_render_rules();
@@ -266,23 +266,23 @@  discard block
 block discarded – undo
266 266
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
267 267
 
268 268
                             // Add hidden fields.
269
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
270
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
271
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
272
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
273
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
274
-                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">';
275
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
276
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
277
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
278
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
279
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
269
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
270
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
271
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
272
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
273
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
274
+                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="'.$ao_ccss_rlimit.'">';
275
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
276
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
277
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
278
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
279
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
280 280
                         }
281 281
                         // Render key panel unconditionally.
282
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
282
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
283 283
                         ?>
284 284
                         <p class="submit left">
285
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
285
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
286 286
                         </p>
287 287
                         <?php
288 288
                     }
@@ -300,31 +300,31 @@  discard block
 block discarded – undo
300 300
                     });
301 301
                 }
302 302
                 </script>
303
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
304
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
305
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
303
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
304
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
305
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
306 306
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
307 307
                 </form>
308 308
                 <div id="importdialog"></div>
309 309
             </div><!-- /#autoptimize_main -->
310 310
         </div><!-- /#wrap -->
311 311
         <?php
312
-        if ( ! $this->is_multisite_network_admin() ) {
312
+        if (!$this->is_multisite_network_admin()) {
313 313
             // Include debug panel if debug mode is enable.
314
-            if ( $ao_ccss_debug ) {
314
+            if ($ao_ccss_debug) {
315 315
             ?>
316 316
                 <div id="debug">
317 317
                     <?php
318 318
                     // Include debug panel.
319
-                    include( 'critcss-inc/admin_settings_debug.php' );
319
+                    include('critcss-inc/admin_settings_debug.php');
320 320
                     ?>
321 321
                 </div><!-- /#debug -->
322 322
             <?php
323 323
             }
324 324
             echo '<script>';
325
-            include( 'critcss-inc/admin_settings_rules.js.php' );
326
-            include( 'critcss-inc/admin_settings_queue.js.php' );
327
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
325
+            include('critcss-inc/admin_settings_rules.js.php');
326
+            include('critcss-inc/admin_settings_queue.js.php');
327
+            include('critcss-inc/admin_settings_impexp.js.php');
328 328
             echo '</script>';
329 329
         }
330 330
     }
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
     public static function ao_ccss_has_autorules() {
333 333
         static $_has_auto_rules = null;
334 334
 
335
-        if ( null === $_has_auto_rules ) {
335
+        if (null === $_has_auto_rules) {
336 336
             global $ao_ccss_rules;
337 337
             $_has_auto_rules = false;
338
-            if ( ! empty( $ao_ccss_rules ) ) {
339
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
340
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
341
-                        if ( ! empty( $rule['hash'] ) ) {
338
+            if (!empty($ao_ccss_rules)) {
339
+                foreach (array('types', 'paths') as $_typat) {
340
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
341
+                        if (!empty($rule['hash'])) {
342 342
                             // we have at least one AUTO job, so all is fine.
343 343
                             $_has_auto_rules = true;
344 344
                             break;
345 345
                         }
346 346
                     }
347
-                    if ( $_has_auto_rules ) {
347
+                    if ($_has_auto_rules) {
348 348
                         break;
349 349
                     }
350 350
                 }
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
     public function is_multisite_network_admin() {
358 358
         static $_multisite_network_admin = null;
359 359
 
360
-        if ( null === $_multisite_network_admin ) {
361
-            if ( is_multisite() && is_network_admin() ) {
360
+        if (null === $_multisite_network_admin) {
361
+            if (is_multisite() && is_network_admin()) {
362 362
                 $_multisite_network_admin = true;
363 363
             } else {
364 364
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSBase.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS base file (initializes all ccss files).
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -19,35 +19,35 @@  discard block
 block discarded – undo
19 19
     public function __construct()
20 20
     {
21 21
         // define constant, but only once.
22
-        if ( ! defined( 'AO_CCSS_DIR' ) ) {
22
+        if (!defined('AO_CCSS_DIR')) {
23 23
             // Define a constant with the directory to store critical CSS in.
24
-            if ( is_multisite() ) {
24
+            if (is_multisite()) {
25 25
                 $blog_id = get_current_blog_id();
26
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' . $blog_id . '/' );
26
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'.$blog_id.'/');
27 27
             } else {
28
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' );
28
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/');
29 29
             }
30 30
         }
31
-        if ( ! defined( 'AO_CCSS_VER' ) ) {
31
+        if (!defined('AO_CCSS_VER')) {
32 32
             // Define plugin version.
33
-            define( 'AO_CCSS_VER', 'AO_' . AUTOPTIMIZE_PLUGIN_VERSION );
33
+            define('AO_CCSS_VER', 'AO_'.AUTOPTIMIZE_PLUGIN_VERSION);
34 34
 
35 35
             // Define constants for criticalcss.com base path and API endpoints.
36 36
             // fixme: AO_CCSS_URL should be read from the autoptimize availability json stored as option.
37
-            define( 'AO_CCSS_URL', 'https://criticalcss.com' );
38
-            define( 'AO_CCSS_API', AO_CCSS_URL . '/api/premium/' );
39
-            define( 'AO_CCSS_SLEEP', 10 );
37
+            define('AO_CCSS_URL', 'https://criticalcss.com');
38
+            define('AO_CCSS_API', AO_CCSS_URL.'/api/premium/');
39
+            define('AO_CCSS_SLEEP', 10);
40 40
         }
41 41
 
42 42
         // Define support files locations, in case they are not already defined.
43
-        if ( ! defined( 'AO_CCSS_LOCK' ) ) {
44
-            define( 'AO_CCSS_LOCK', AO_CCSS_DIR . 'queue.lock' );
43
+        if (!defined('AO_CCSS_LOCK')) {
44
+            define('AO_CCSS_LOCK', AO_CCSS_DIR.'queue.lock');
45 45
         }
46
-        if ( ! defined( 'AO_CCSS_LOG' ) ) {
47
-            define( 'AO_CCSS_LOG', AO_CCSS_DIR . 'queuelog.html' );
46
+        if (!defined('AO_CCSS_LOG')) {
47
+            define('AO_CCSS_LOG', AO_CCSS_DIR.'queuelog.html');
48 48
         }
49
-        if ( ! defined( 'AO_CCSS_DEBUG' ) ) {
50
-            define( 'AO_CCSS_DEBUG', AO_CCSS_DIR . 'queue.json' );
49
+        if (!defined('AO_CCSS_DEBUG')) {
50
+            define('AO_CCSS_DEBUG', AO_CCSS_DIR.'queue.json');
51 51
         }
52 52
 
53 53
         $this->filepath = __FILE__;
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
     {
61 61
         // get all options.
62 62
         $all_options = $this->fetch_options();
63
-        foreach ( $all_options as $option => $value ) {
63
+        foreach ($all_options as $option => $value) {
64 64
             ${$option} = $value;
65 65
         }
66 66
 
67 67
         // make sure the 10 minutes cron schedule is added.
68
-        add_filter( 'cron_schedules', array( $this, 'ao_ccss_interval' ) );
68
+        add_filter('cron_schedules', array($this, 'ao_ccss_interval'));
69 69
 
70 70
         // check if we need to upgrade.
71 71
         $this->check_upgrade();
72 72
 
73 73
         // make sure ao_ccss_queue is scheduled OK if an API key is set.
74
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
75
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
74
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
75
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
76 76
         }
77 77
     }
78 78
 
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
         // Required libs, core is always needed.
81 81
         $criticalcss_core = new autoptimizeCriticalCSSCore();
82 82
 
83
-        if ( defined( 'DOING_CRON' ) || is_admin() ) {
83
+        if (defined('DOING_CRON') || is_admin()) {
84 84
             // TODO: also include if overridden somehow to force queue processing to be executed?
85 85
             $criticalcss_cron = new autoptimizeCriticalCSSCron();
86 86
         }
87 87
 
88
-        if ( is_admin() ) {
88
+        if (is_admin()) {
89 89
             $criticalcss_settings = new autoptimizeCriticalCSSSettings();
90 90
         } else {
91 91
             // enqueuing only done when not wp-admin.
@@ -96,51 +96,51 @@  discard block
 block discarded – undo
96 96
     public static function fetch_options() {
97 97
         static $autoptimize_ccss_options = null;
98 98
 
99
-        if ( null === $autoptimize_ccss_options ) {
99
+        if (null === $autoptimize_ccss_options) {
100 100
             // not cached yet, fetching from WordPress options.
101
-            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' );
102
-            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' );
103
-            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option( 'autoptimize_ccss_rules', false );
104
-            $autoptimize_ccss_options['ao_ccss_additional']    = get_option( 'autoptimize_ccss_additional' );
105
-            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option( 'autoptimize_ccss_queue', false );
106
-            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option( 'autoptimize_ccss_viewport', false );
107
-            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option( 'autoptimize_ccss_finclude', false );
108
-            $autoptimize_ccss_options['ao_ccss_rlimit']        = get_option( 'autoptimize_ccss_rlimit', '5' );
109
-            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option( 'autoptimize_ccss_noptimize', false );
110
-            $autoptimize_ccss_options['ao_ccss_debug']         = get_option( 'autoptimize_ccss_debug', false );
111
-            $autoptimize_ccss_options['ao_ccss_key']           = get_option( 'autoptimize_ccss_key' );
112
-            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option( 'autoptimize_ccss_keyst' );
113
-            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option( 'autoptimize_ccss_loggedin', '1' );
114
-            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option( 'autoptimize_ccss_forcepath', '1' );
115
-            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' );
116
-            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option( 'autoptimize_ccss_deferjquery', false );
117
-            $autoptimize_ccss_options['ao_ccss_domain']        = get_option( 'autoptimize_ccss_domain' );
118
-            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option( 'autoptimize_ccss_unloadccss', false );
119
-
120
-            if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) {
121
-                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] );
122
-            } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) {
101
+            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option('autoptimize_css_defer');
102
+            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline');
103
+            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option('autoptimize_ccss_rules', false);
104
+            $autoptimize_ccss_options['ao_ccss_additional']    = get_option('autoptimize_ccss_additional');
105
+            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option('autoptimize_ccss_queue', false);
106
+            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option('autoptimize_ccss_viewport', false);
107
+            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option('autoptimize_ccss_finclude', false);
108
+            $autoptimize_ccss_options['ao_ccss_rlimit']        = get_option('autoptimize_ccss_rlimit', '5');
109
+            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option('autoptimize_ccss_noptimize', false);
110
+            $autoptimize_ccss_options['ao_ccss_debug']         = get_option('autoptimize_ccss_debug', false);
111
+            $autoptimize_ccss_options['ao_ccss_key']           = get_option('autoptimize_ccss_key');
112
+            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option('autoptimize_ccss_keyst');
113
+            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option('autoptimize_ccss_loggedin', '1');
114
+            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option('autoptimize_ccss_forcepath', '1');
115
+            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option('autoptimize_service_availablity');
116
+            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option('autoptimize_ccss_deferjquery', false);
117
+            $autoptimize_ccss_options['ao_ccss_domain']        = get_option('autoptimize_ccss_domain');
118
+            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option('autoptimize_ccss_unloadccss', false);
119
+
120
+            if (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') === false && strpos($autoptimize_ccss_options['ao_ccss_domain'], 'uggc') === 0) {
121
+                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13($autoptimize_ccss_options['ao_ccss_domain']);
122
+            } elseif (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') !== false) {
123 123
                 // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain).
124
-                update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) );
124
+                update_option('autoptimize_ccss_domain', str_rot13($autoptimize_ccss_options['ao_ccss_domain']));
125 125
             }
126 126
 
127 127
             // Setup the rules array.
128
-            if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) {
128
+            if (empty($autoptimize_ccss_options['ao_ccss_rules_raw'])) {
129 129
                 $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array();
130 130
                 $autoptimize_ccss_options['ao_ccss_rules']['types'] = array();
131 131
             } else {
132
-                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true );
132
+                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode($autoptimize_ccss_options['ao_ccss_rules_raw'], true);
133 133
             }
134 134
 
135 135
             // Setup the queue array.
136
-            if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) {
136
+            if (empty($autoptimize_ccss_options['ao_ccss_queue_raw'])) {
137 137
                 $autoptimize_ccss_options['ao_ccss_queue'] = array();
138 138
             } else {
139
-                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true );
139
+                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode($autoptimize_ccss_options['ao_ccss_queue_raw'], true);
140 140
             }
141 141
 
142 142
             // Override API key if constant is defined.
143
-            if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
143
+            if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
144 144
                 $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY;
145 145
             }
146 146
         }
@@ -152,49 +152,49 @@  discard block
 block discarded – undo
152 152
         global $ao_ccss_key;
153 153
 
154 154
         // Create the cache directory if it doesn't exist already.
155
-        if ( ! file_exists( AO_CCSS_DIR ) ) {
156
-            mkdir( AO_CCSS_DIR, 0755, true );
155
+        if (!file_exists(AO_CCSS_DIR)) {
156
+            mkdir(AO_CCSS_DIR, 0755, true);
157 157
         }
158 158
 
159 159
         // Create a scheduled event for the queue.
160
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
161
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
160
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
161
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
162 162
         }
163 163
 
164 164
         // Create a scheduled event for log maintenance.
165
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) {
166
-            wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' );
165
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_maintenance')) {
166
+            wp_schedule_event(time(), 'twicedaily', 'ao_ccss_maintenance');
167 167
         }
168 168
     }
169 169
 
170 170
     public function check_upgrade() {
171
-        $db_version = get_option( 'autoptimize_ccss_version', '' );
172
-        if ( AO_CCSS_VER !== $db_version ) {
171
+        $db_version = get_option('autoptimize_ccss_version', '');
172
+        if (AO_CCSS_VER !== $db_version) {
173 173
             // check schedules & re-schedule if needed.
174 174
             $this->on_upgrade();
175 175
             // and update db_version.
176
-            update_option( 'autoptimize_ccss_version', AO_CCSS_VER );
176
+            update_option('autoptimize_ccss_version', AO_CCSS_VER);
177 177
         }
178 178
     }
179 179
 
180
-    public function ao_ccss_interval( $schedules ) {
180
+    public function ao_ccss_interval($schedules) {
181 181
         // Let interval be configurable.
182
-        if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) {
182
+        if (!defined('AO_CCSS_DEBUG_INTERVAL')) {
183 183
             $intsec = 600;
184 184
         } else {
185 185
             $intsec = AO_CCSS_DEBUG_INTERVAL;
186
-            if ( $intsec >= 120 ) {
187
-                $inttxt = $intsec / 60 . ' minutes';
186
+            if ($intsec >= 120) {
187
+                $inttxt = $intsec/60.' minutes';
188 188
             } else {
189
-                $inttxt = $intsec . ' second(s)';
189
+                $inttxt = $intsec.' second(s)';
190 190
             }
191
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 );
191
+            autoptimizeCriticalCSSCore::ao_ccss_log('Using custom WP-Cron interval of '.$inttxt, 3);
192 192
         }
193 193
 
194 194
         // Attach interval to schedule.
195 195
         $schedules['ao_ccss'] = array(
196 196
             'interval' => $intsec,
197
-            'display'  => __( 'Autoptimize CriticalCSS' ),
197
+            'display'  => __('Autoptimize CriticalCSS'),
198 198
         );
199 199
         return $schedules;
200 200
     }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSCron.php 1 patch
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * processes the queue, submitting jobs to criticalcss.com and retrieving generated CSS from criticalcss.com and saving rules.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -13,23 +13,23 @@  discard block
 block discarded – undo
13 13
     {
14 14
         // fetch all options at once and populate them individually explicitely as globals.
15 15
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
16
-        foreach ( $all_options as $_option => $_value ) {
16
+        foreach ($all_options as $_option => $_value) {
17 17
             global ${$_option};
18 18
             ${$_option} = $_value;
19 19
         }
20 20
 
21 21
         // Add queue control to a registered event.
22
-        add_action( 'ao_ccss_queue', array( $this, 'ao_ccss_queue_control' ) );
22
+        add_action('ao_ccss_queue', array($this, 'ao_ccss_queue_control'));
23 23
         // Add cleaning job to a registered event.
24
-        add_action( 'ao_ccss_maintenance', array( $this, 'ao_ccss_cleaning' ) );
24
+        add_action('ao_ccss_maintenance', array($this, 'ao_ccss_cleaning'));
25 25
     }
26 26
 
27 27
     public function ao_ccss_queue_control() {
28 28
         // The queue execution backend.
29 29
         global $ao_ccss_key;
30
-        if ( ! isset( $ao_ccss_key ) || empty( $ao_ccss_key ) ) {
30
+        if (!isset($ao_ccss_key) || empty($ao_ccss_key)) {
31 31
             // no key set, not processing the queue!
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No key set, so not processing queue.', 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log('No key set, so not processing queue.', 3);
33 33
             return;
34 34
         }
35 35
 
@@ -50,35 +50,35 @@  discard block
 block discarded – undo
50 50
          *    When properly set, queue will always finish a job with the declared settings above regardless of the real API responses.
51 51
          */
52 52
         $queue_debug = false;
53
-        if ( file_exists( AO_CCSS_DEBUG ) ) {
54
-            $qdobj_raw = file_get_contents( AO_CCSS_DEBUG );
55
-            $qdobj     = json_decode( $qdobj_raw, true );
56
-            if ( $qdobj ) {
57
-                if ( 1 === $qdobj['enable'] ) {
53
+        if (file_exists(AO_CCSS_DEBUG)) {
54
+            $qdobj_raw = file_get_contents(AO_CCSS_DEBUG);
55
+            $qdobj     = json_decode($qdobj_raw, true);
56
+            if ($qdobj) {
57
+                if (1 === $qdobj['enable']) {
58 58
                     $queue_debug = true;
59
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue operating in debug mode with the following settings: <' . $qdobj_raw . '>', 3 );
59
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue operating in debug mode with the following settings: <'.$qdobj_raw.'>', 3);
60 60
                 }
61 61
             }
62 62
         }
63 63
 
64 64
         // Set some default values for $qdobj to avoid function call warnings.
65
-        if ( ! $queue_debug ) {
65
+        if (!$queue_debug) {
66 66
             $qdobj['htcode'] = false;
67 67
         }
68 68
 
69 69
         // Check if queue is already running.
70 70
         $queue_lock = false;
71
-        if ( file_exists( AO_CCSS_LOCK ) ) {
71
+        if (file_exists(AO_CCSS_LOCK)) {
72 72
             $queue_lock = true;
73 73
         }
74 74
 
75 75
         // Proceed with the queue if it's not already running.
76
-        if ( ! $queue_lock ) {
76
+        if (!$queue_lock) {
77 77
 
78 78
             // Log queue start and create the lock file.
79
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control started', 3 );
80
-            if ( touch( AO_CCSS_LOCK ) ) {
81
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control locked', 3 );
79
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control started', 3);
80
+            if (touch(AO_CCSS_LOCK)) {
81
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control locked', 3);
82 82
             }
83 83
 
84 84
             // Attach required variables.
@@ -88,223 +88,223 @@  discard block
 block discarded – undo
88 88
             // Initialize job counters.
89 89
             $jc = 1;
90 90
             $jr = 1;
91
-            $jt = count( $ao_ccss_queue );
91
+            $jt = count($ao_ccss_queue);
92 92
 
93 93
             // Sort queue by ascending job status (e.g. ERROR, JOB_ONGOING, JOB_QUEUED, NEW...).
94
-            array_multisort( array_column( $ao_ccss_queue, 'jqstat' ), $ao_ccss_queue ); // @codingStandardsIgnoreLine
94
+            array_multisort(array_column($ao_ccss_queue, 'jqstat'), $ao_ccss_queue); // @codingStandardsIgnoreLine
95 95
 
96 96
             // Iterates over the entire queue.
97
-            foreach ( $ao_ccss_queue as $path => $jprops ) {
97
+            foreach ($ao_ccss_queue as $path => $jprops) {
98 98
                 // Prepare flags and target rule.
99 99
                 $update      = false;
100 100
                 $deljob      = false;
101 101
                 $rule_update = false;
102 102
                 $oldccssfile = false;
103
-                $trule       = explode( '|', $jprops['rtarget'] );
103
+                $trule       = explode('|', $jprops['rtarget']);
104 104
 
105 105
                 // Log job count.
106
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Processing job ' . $jc . ' of ' . $jt . ' with id <' . $jprops['ljid'] . '> and status <' . $jprops['jqstat'] . '>', 3 );
106
+                autoptimizeCriticalCSSCore::ao_ccss_log('Processing job '.$jc.' of '.$jt.' with id <'.$jprops['ljid'].'> and status <'.$jprops['jqstat'].'>', 3);
107 107
 
108 108
                 // Process NEW jobs.
109
-                if ( 'NEW' == $jprops['jqstat'] ) {
109
+                if ('NEW' == $jprops['jqstat']) {
110 110
 
111 111
                     // Log the new job.
112
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found NEW job with local ID <' . $jprops['ljid'] . '>, starting its queue processing', 3 );
112
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found NEW job with local ID <'.$jprops['ljid'].'>, starting its queue processing', 3);
113 113
 
114 114
                     // Compare job and rule hashes (if any).
115
-                    $hash = $this->ao_ccss_diff_hashes( $jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget'] );
115
+                    $hash = $this->ao_ccss_diff_hashes($jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget']);
116 116
 
117 117
                     // If job hash is new or different of a previous one.
118
-                    if ( $hash ) {
118
+                    if ($hash) {
119 119
                         // Set job hash.
120 120
                         $jprops['hash'] = $hash;
121 121
 
122 122
                         // If this is not the first job, wait 10 seconds before process next job due criticalcss.com API limits.
123
-                        if ( $jr > 1 ) {
124
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 );
125
-                            sleep( AO_CCSS_SLEEP );
123
+                        if ($jr > 1) {
124
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3);
125
+                            sleep(AO_CCSS_SLEEP);
126 126
                         }
127 127
 
128 128
                         // Dispatch the job generate request and increment request count.
129
-                        $apireq = $this->ao_ccss_api_generate( $path, $queue_debug, $qdobj['htcode'] );
129
+                        $apireq = $this->ao_ccss_api_generate($path, $queue_debug, $qdobj['htcode']);
130 130
                         $jr++;
131 131
 
132 132
                         // NOTE: All the following conditions maps to the ones in admin_settings_queue.js.php.
133
-                        if ( 'JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status'] ) {
133
+                        if ('JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status']) {
134 134
                             // SUCCESS: request has a valid result.
135 135
                             // Update job properties.
136 136
                             $jprops['jid']    = $apireq['job']['id'];
137 137
                             $jprops['jqstat'] = $apireq['job']['status'];
138
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request successful, remote id <' . $jprops['jid'] . '>, status now is <' . $jprops['jqstat'] . '>', 3 );
139
-                        } elseif ( 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
138
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request successful, remote id <'.$jprops['jid'].'>, status now is <'.$jprops['jqstat'].'>', 3);
139
+                        } elseif ('STATUS_JOB_BAD' == $apireq['job']['status']) {
140 140
                             // ERROR: concurrent requests
141 141
                             // Update job properties.
142 142
                             $jprops['jid']    = $apireq['job']['id'];
143 143
                             $jprops['jqstat'] = $apireq['job']['status'];
144
-                            if ( $apireq['job']['error'] ) {
144
+                            if ($apireq['job']['error']) {
145 145
                                 $jprops['jrstat'] = $apireq['job']['error'];
146 146
                             } else {
147 147
                                 $jprops['jrstat'] = 'Baby did a bad bad thing';
148 148
                             }
149 149
                             $jprops['jvstat'] = 'NONE';
150
-                            $jprops['jftime'] = microtime( true );
151
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Concurrent requests when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
152
-                        } elseif ( 'INVALID_JWT_TOKEN' == $apireq['errorCode'] ) {
150
+                            $jprops['jftime'] = microtime(true);
151
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Concurrent requests when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
152
+                        } elseif ('INVALID_JWT_TOKEN' == $apireq['errorCode']) {
153 153
                             // ERROR: key validation
154 154
                             // Update job properties.
155 155
                             $jprops['jqstat'] = $apireq['errorCode'];
156 156
                             $jprops['jrstat'] = $apireq['error'];
157 157
                             $jprops['jvstat'] = 'NONE';
158
-                            $jprops['jftime'] = microtime( true );
159
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'API key validation error when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
160
-                        } elseif ( empty( $apireq ) ) {
158
+                            $jprops['jftime'] = microtime(true);
159
+                            autoptimizeCriticalCSSCore::ao_ccss_log('API key validation error when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
160
+                        } elseif (empty($apireq)) {
161 161
                             // ERROR: no response
162 162
                             // Update job properties.
163 163
                             $jprops['jqstat'] = 'NO_RESPONSE';
164 164
                             $jprops['jrstat'] = 'NONE';
165 165
                             $jprops['jvstat'] = 'NONE';
166
-                            $jprops['jftime'] = microtime( true );
167
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
166
+                            $jprops['jftime'] = microtime(true);
167
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
168 168
                         } else {
169 169
                             // UNKNOWN: unhandled generate exception
170 170
                             // Update job properties.
171 171
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
172 172
                             $jprops['jrstat'] = 'NONE';
173 173
                             $jprops['jvstat'] = 'NONE';
174
-                            $jprops['jftime'] = microtime( true );
175
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 );
176
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
174
+                            $jprops['jftime'] = microtime(true);
175
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2);
176
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
177 177
                         }
178 178
                     } else {
179 179
                         // SUCCESS: Job hash is equal to a previous one, so it's done
180 180
                         // Update job status and finish time.
181 181
                         $jprops['jqstat'] = 'JOB_DONE';
182
-                        $jprops['jftime'] = microtime( true );
183
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> requires no further processing, status now is <' . $jprops['jqstat'] . '>', 3 );
182
+                        $jprops['jftime'] = microtime(true);
183
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> requires no further processing, status now is <'.$jprops['jqstat'].'>', 3);
184 184
                     }
185 185
 
186 186
                     // Set queue update flag.
187 187
                     $update = true;
188 188
 
189
-                } elseif ( 'JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat'] ) {
189
+                } elseif ('JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat']) {
190 190
                     // Process QUEUED and ONGOING jobs
191 191
                     // Log the pending job.
192
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found PENDING job with local ID <' . $jprops['ljid'] . '>, continuing its queue processing', 3 );
192
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found PENDING job with local ID <'.$jprops['ljid'].'>, continuing its queue processing', 3);
193 193
 
194 194
                     // If this is not the first job, wait before process next job due criticalcss.com API limits.
195
-                    if ( $jr > 1 ) {
196
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 );
197
-                        sleep( AO_CCSS_SLEEP );
195
+                    if ($jr > 1) {
196
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3);
197
+                        sleep(AO_CCSS_SLEEP);
198 198
                     }
199 199
 
200 200
                     // Dispatch the job result request and increment request count.
201
-                    $apireq = $this->ao_ccss_api_results( $jprops['jid'], $queue_debug, $qdobj['htcode'] );
201
+                    $apireq = $this->ao_ccss_api_results($jprops['jid'], $queue_debug, $qdobj['htcode']);
202 202
                     $jr++;
203 203
 
204 204
                     // NOTE: All the following condigitons maps to the ones in admin_settings_queue.js.php
205 205
                     // Replace API response values if queue debugging is enabled and some value is set.
206
-                    if ( $queue_debug ) {
207
-                        if ( $qdobj['status'] ) {
206
+                    if ($queue_debug) {
207
+                        if ($qdobj['status']) {
208 208
                             $apireq['status'] = $qdobj['status'];
209 209
                         }
210
-                        if ( $qdobj['resultStatus'] ) {
210
+                        if ($qdobj['resultStatus']) {
211 211
                             $apireq['resultStatus'] = $qdobj['resultStatus'];
212 212
                         }
213
-                        if ( $qdobj['validationStatus'] ) {
213
+                        if ($qdobj['validationStatus']) {
214 214
                             $apireq['validationStatus'] = $qdobj['validationStatus'];
215 215
                         }
216 216
                     }
217 217
 
218
-                    if ( 'JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status'] ) {
218
+                    if ('JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status']) {
219 219
                         // SUCCESS: request has a valid result
220 220
                         // Process a PENDING job
221 221
                         // Update job properties.
222 222
                         $jprops['jqstat'] = $apireq['status'];
223
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '> unchanged', 3 );
224
-                    } elseif ( 'JOB_DONE' == $apireq['status'] ) {
223
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'> unchanged', 3);
224
+                    } elseif ('JOB_DONE' == $apireq['status']) {
225 225
                         // Process a DONE job
226 226
                         // New resultStatus from ccss.com "HTML_404", consider as "GOOD" for now.
227
-                        if ( 'HTML_404' == $apireq['resultStatus'] ) {
227
+                        if ('HTML_404' == $apireq['resultStatus']) {
228 228
                             $apireq['resultStatus'] = 'GOOD';
229 229
                         }
230 230
 
231
-                        if ( 'GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus'] ) {
231
+                        if ('GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus']) {
232 232
                             // SUCCESS: GOOD job with GOOD validation
233 233
                             // Update job properties.
234
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, false );
234
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, false);
235 235
                             $jprops['jqstat'] = $apireq['status'];
236 236
                             $jprops['jrstat'] = $apireq['resultStatus'];
237 237
                             $jprops['jvstat'] = $apireq['validationStatus'];
238
-                            $jprops['jftime'] = microtime( true );
238
+                            $jprops['jftime'] = microtime(true);
239 239
                             $rule_update      = true;
240
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '>, file saved <' . $jprops['file'] . '>', 3 );
241
-                        } elseif ( 'GOOD' == $apireq['resultStatus'] && ( 'WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'] ) ) {
240
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'>, file saved <'.$jprops['file'].'>', 3);
241
+                        } elseif ('GOOD' == $apireq['resultStatus'] && ('WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'])) {
242 242
                             // SUCCESS: GOOD job with WARN or BAD validation
243 243
                             // Update job properties.
244
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, true );
244
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, true);
245 245
                             $jprops['jqstat'] = $apireq['status'];
246 246
                             $jprops['jrstat'] = $apireq['resultStatus'];
247 247
                             $jprops['jvstat'] = $apireq['validationStatus'];
248
-                            $jprops['jftime'] = microtime( true );
248
+                            $jprops['jftime'] = microtime(true);
249 249
                             $rule_update      = true;
250
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . ', file saved <' . $jprops['file'] . '> but requires REVIEW', 3 );
251
-                        } elseif ( 'GOOD' != $apireq['resultStatus'] && ( 'GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'] ) ) {
250
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].', file saved <'.$jprops['file'].'> but requires REVIEW', 3);
251
+                        } elseif ('GOOD' != $apireq['resultStatus'] && ('GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'])) {
252 252
                             // ERROR: no GOOD, WARN or BAD results
253 253
                             // Update job properties.
254 254
                             $jprops['jqstat'] = $apireq['status'];
255 255
                             $jprops['jrstat'] = $apireq['resultStatus'];
256 256
                             $jprops['jvstat'] = $apireq['validationStatus'];
257
-                            $jprops['jftime'] = microtime( true );
258
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
257
+                            $jprops['jftime'] = microtime(true);
258
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
259 259
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
260
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
260
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
261 261
                         } else {
262 262
                             // UNKNOWN: unhandled JOB_DONE exception
263 263
                             // Update job properties.
264 264
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
265 265
                             $jprops['jrstat'] = $apireq['resultStatus'];
266 266
                             $jprops['jvstat'] = $apireq['validationStatus'];
267
-                            $jprops['jftime'] = microtime( true );
268
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job is UNKNOWN, status now is <' . $jprops['jqstat'] . '>', 2 );
267
+                            $jprops['jftime'] = microtime(true);
268
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job is UNKNOWN, status now is <'.$jprops['jqstat'].'>', 2);
269 269
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
270
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
270
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
271 271
                         }
272
-                    } elseif ( 'JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
272
+                    } elseif ('JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status']) {
273 273
                         // ERROR: failed job
274 274
                         // Update job properties.
275 275
                         $jprops['jqstat'] = $apireq['job']['status'];
276
-                        if ( $apireq['job']['error'] ) {
276
+                        if ($apireq['job']['error']) {
277 277
                             $jprops['jrstat'] = $apireq['job']['error'];
278 278
                         } else {
279 279
                             $jprops['jrstat'] = 'Baby did a bad bad thing';
280 280
                         }
281 281
                         $jprops['jvstat'] = 'NONE';
282
-                        $jprops['jftime'] = microtime( true );
283
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
284
-                    } elseif ( 'This css no longer exists. Please re-generate it.' == $apireq['error'] ) {
282
+                        $jprops['jftime'] = microtime(true);
283
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
284
+                    } elseif ('This css no longer exists. Please re-generate it.' == $apireq['error']) {
285 285
                         // ERROR: CSS doesn't exist
286 286
                         // Update job properties.
287 287
                         $jprops['jqstat'] = 'NO_CSS';
288 288
                         $jprops['jrstat'] = $apireq['error'];
289 289
                         $jprops['jvstat'] = 'NONE';
290
-                        $jprops['jftime'] = microtime( true );
291
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
292
-                    } elseif ( empty( $apireq ) ) {
290
+                        $jprops['jftime'] = microtime(true);
291
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
292
+                    } elseif (empty($apireq)) {
293 293
                         // ERROR: no response
294 294
                         // Update job properties.
295 295
                         $jprops['jqstat'] = 'NO_RESPONSE';
296 296
                         $jprops['jrstat'] = 'NONE';
297 297
                         $jprops['jvstat'] = 'NONE';
298
-                        $jprops['jftime'] = microtime( true );
299
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
298
+                        $jprops['jftime'] = microtime(true);
299
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
300 300
                     } else {
301 301
                         // UNKNOWN: unhandled results exception
302 302
                         // Update job properties.
303 303
                         $jprops['jqstat'] = 'JOB_UNKNOWN';
304 304
                         $jprops['jrstat'] = 'NONE';
305 305
                         $jprops['jvstat'] = 'NONE';
306
-                        $jprops['jftime'] = microtime( true );
307
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 );
306
+                        $jprops['jftime'] = microtime(true);
307
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2);
308 308
                     }
309 309
 
310 310
                     // Set queue update flag.
@@ -312,40 +312,40 @@  discard block
 block discarded – undo
312 312
                 }
313 313
 
314 314
                 // Mark DONE jobs for removal.
315
-                if ( 'JOB_DONE' == $jprops['jqstat'] ) {
315
+                if ('JOB_DONE' == $jprops['jqstat']) {
316 316
                     $update = true;
317 317
                     $deljob = true;
318 318
                 }
319 319
 
320 320
                 // Persist updated queue object.
321
-                if ( $update ) {
322
-                    if ( ! $deljob ) {
321
+                if ($update) {
322
+                    if (!$deljob) {
323 323
                         // Update properties of a NEW or PENDING job...
324
-                        $ao_ccss_queue[ $path ] = $jprops;
324
+                        $ao_ccss_queue[$path] = $jprops;
325 325
                     } else {
326 326
                         // ...or remove the DONE job.
327
-                        unset( $ao_ccss_queue[ $path ] );
328
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> is DONE and was removed from the queue', 3 );
327
+                        unset($ao_ccss_queue[$path]);
328
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> is DONE and was removed from the queue', 3);
329 329
                     }
330 330
 
331 331
                     // Update queue object.
332
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
333
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
334
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue updated by job id <' . $jprops['ljid'] . '>', 3 );
332
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
333
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
334
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue updated by job id <'.$jprops['ljid'].'>', 3);
335 335
 
336 336
                     // Update target rule.
337
-                    if ( $rule_update ) {
338
-                        $this->ao_ccss_rule_update( $jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash'] );
339
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> updated the target rule <' . $jprops['rtarget'] . '>', 3 );
337
+                    if ($rule_update) {
338
+                        $this->ao_ccss_rule_update($jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash']);
339
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> updated the target rule <'.$jprops['rtarget'].'>', 3);
340 340
                     }
341 341
                 } else {
342 342
                     // Or log no queue action.
343
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Nothing to do on this job', 3 );
343
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Nothing to do on this job', 3);
344 344
                 }
345 345
 
346 346
                 // Break the loop if request limit is set and was reached.
347
-                if ( $ao_ccss_rlimit && $ao_ccss_rlimit == $jr ) {
348
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'The limit of ' . $ao_ccss_rlimit . ' request(s) to criticalcss.com was reached, queue control must finish now', 3 );
347
+                if ($ao_ccss_rlimit && $ao_ccss_rlimit == $jr) {
348
+                    autoptimizeCriticalCSSCore::ao_ccss_log('The limit of '.$ao_ccss_rlimit.' request(s) to criticalcss.com was reached, queue control must finish now', 3);
349 349
                     break;
350 350
                 }
351 351
 
@@ -354,46 +354,46 @@  discard block
 block discarded – undo
354 354
             }
355 355
 
356 356
             // Remove the lock file and log the queue end.
357
-            if ( file_exists( AO_CCSS_LOCK ) ) {
358
-                unlink( AO_CCSS_LOCK );
359
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control unlocked', 3 );
357
+            if (file_exists(AO_CCSS_LOCK)) {
358
+                unlink(AO_CCSS_LOCK);
359
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control unlocked', 3);
360 360
             }
361
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control finished', 3 );
361
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control finished', 3);
362 362
 
363 363
             // Log that queue is locked.
364 364
         } else {
365
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue is already running, skipping the attempt to run it again', 3 );
365
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue is already running, skipping the attempt to run it again', 3);
366 366
         }
367 367
     }
368 368
 
369
-    public function ao_ccss_diff_hashes( $ljid, $hash, $hashes, $rule ) {
369
+    public function ao_ccss_diff_hashes($ljid, $hash, $hashes, $rule) {
370 370
         // Compare job hashes
371 371
         // STEP 1: update job hashes.
372
-        if ( 1 == count( $hashes ) ) {
372
+        if (1 == count($hashes)) {
373 373
             // Job with a single hash
374 374
             // Set job hash.
375 375
             $hash = $hashes[0];
376
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with SINGLE hash <' . $hash . '>', 3 );
376
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with SINGLE hash <'.$hash.'>', 3);
377 377
         } else {
378 378
             // Job with multiple hashes
379 379
             // Loop through hashes to concatenate them.
380 380
             $nhash = '';
381
-            foreach ( $hashes as $shash ) {
381
+            foreach ($hashes as $shash) {
382 382
                 $nhash .= $shash;
383 383
             }
384 384
 
385 385
             // Set job hash.
386
-            $hash = md5( $nhash );
387
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with a COMPOSITE hash <' . $hash . '>', 3 );
386
+            $hash = md5($nhash);
387
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with a COMPOSITE hash <'.$hash.'>', 3);
388 388
         }
389 389
 
390 390
         // STEP 2: compare job to existing jobs to prevent double submission for same type+hash.
391 391
         global $ao_ccss_queue;
392 392
 
393
-        foreach ( $ao_ccss_queue as $queue_item ) {
394
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Comparing <' . $rule . $hash . '> with <' . $queue_item['rtarget'] . $queue_item['hash'] . '>', 3 );
395
-            if ( $queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array( $queue_item['jqstat'], array( 'JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE' ) ) ) {
396
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the already pending job <' . $queue_item['ljid'] . '>', 3 );
393
+        foreach ($ao_ccss_queue as $queue_item) {
394
+            autoptimizeCriticalCSSCore::ao_ccss_log('Comparing <'.$rule.$hash.'> with <'.$queue_item['rtarget'].$queue_item['hash'].'>', 3);
395
+            if ($queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array($queue_item['jqstat'], array('JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE'))) {
396
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the already pending job <'.$queue_item['ljid'].'>', 3);
397 397
                 return false;
398 398
             }
399 399
         }
@@ -403,32 +403,32 @@  discard block
 block discarded – undo
403 403
         global $ao_ccss_rules;
404 404
 
405 405
         // Prepare rule variables.
406
-        $trule = explode( '|', $rule );
407
-        $srule = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
406
+        $trule = explode('|', $rule);
407
+        $srule = $ao_ccss_rules[$trule[0]][$trule[1]];
408 408
 
409 409
         // Check if a MANUAL rule exist and return false.
410
-        if ( ! empty( $srule ) && ( 0 == $srule['hash'] && 0 != $srule['file'] ) ) {
411
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the MANUAL rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
410
+        if (!empty($srule) && (0 == $srule['hash'] && 0 != $srule['file'])) {
411
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the MANUAL rule <'.$trule[0].'|'.$trule[1].'>', 3);
412 412
             return false;
413
-        } elseif ( ! empty( $srule ) ) {
413
+        } elseif (!empty($srule)) {
414 414
             // Check if an AUTO rule exist.
415
-            if ( $hash === $srule['hash'] && is_file( AO_CCSS_DIR . $srule['file'] ) && 0 != filesize( AO_CCSS_DIR . $srule['file'] ) ) {
415
+            if ($hash === $srule['hash'] && is_file(AO_CCSS_DIR.$srule['file']) && 0 != filesize(AO_CCSS_DIR.$srule['file'])) {
416 416
                 // Check if job hash matches rule, if the CCSS file exists said file is not empty and return FALSE is so.
417
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
417
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> MATCH the one in rule <'.$trule[0].'|'.$trule[1].'>', 3);
418 418
                 return false;
419 419
             } else {
420 420
                 // Or return the new hash if they differ.
421
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> DOES NOT MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '> or rule\'s CCSS file was invalid.', 3 );
421
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> DOES NOT MATCH the one in rule <'.$trule[0].'|'.$trule[1].'> or rule\'s CCSS file was invalid.', 3);
422 422
                 return $hash;
423 423
             }
424 424
         } else {
425 425
             // Or just return the hash if no rule exist yet.
426
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> has no rule yet', 3 );
426
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> has no rule yet', 3);
427 427
             return $hash;
428 428
         }
429 429
     }
430 430
 
431
-    public function ao_ccss_api_generate( $path, $debug, $dcode ) {
431
+    public function ao_ccss_api_generate($path, $debug, $dcode) {
432 432
         // POST jobs to criticalcss.com and return responses
433 433
         // Get key and key status.
434 434
         global $ao_ccss_key;
@@ -440,35 +440,35 @@  discard block
 block discarded – undo
440 440
         global $ao_ccss_noptimize;
441 441
 
442 442
         $site_host = get_site_url();
443
-        $site_path = parse_url( $site_host, PHP_URL_PATH );
443
+        $site_path = parse_url($site_host, PHP_URL_PATH);
444 444
 
445
-        if ( ! empty( $site_path ) ) {
446
-            $site_host = str_replace( $site_path, '', $site_host );
445
+        if (!empty($site_path)) {
446
+            $site_host = str_replace($site_path, '', $site_host);
447 447
         }
448 448
 
449 449
         // Logic to bind to one domain to avoid site clones of sites would
450 450
         // automatically begin spawning requests to criticalcss.com which has
451 451
         // a per domain cost.
452 452
         global $ao_ccss_domain;
453
-        if ( empty( $ao_ccss_domain ) ) {
453
+        if (empty($ao_ccss_domain)) {
454 454
             // first request being done, update option to allow future requests are only allowed if from same domain.
455
-            update_option( 'autoptimize_ccss_domain', str_rot13( $site_host ) );
456
-        } elseif ( trim( $ao_ccss_domain, '\'"' ) !== 'none' && parse_url( $site_host, PHP_URL_HOST ) !== parse_url( $ao_ccss_domain, PHP_URL_HOST ) && apply_filters( 'autoptimize_filter_ccss_bind_domain', true ) ) {
455
+            update_option('autoptimize_ccss_domain', str_rot13($site_host));
456
+        } elseif (trim($ao_ccss_domain, '\'"') !== 'none' && parse_url($site_host, PHP_URL_HOST) !== parse_url($ao_ccss_domain, PHP_URL_HOST) && apply_filters('autoptimize_filter_ccss_bind_domain', true)) {
457 457
             // not the same domain, log as error and return without posting to criticalcss.com.
458
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Request for domain ' . $site_host . ' does not match bound domain ' . $ao_ccss_domain . ' so not proceeding.', 2 );
458
+            autoptimizeCriticalCSSCore::ao_ccss_log('Request for domain '.$site_host.' does not match bound domain '.$ao_ccss_domain.' so not proceeding.', 2);
459 459
             return false;
460 460
         }
461 461
 
462
-        $src_url = $site_host . $path;
462
+        $src_url = $site_host.$path;
463 463
 
464 464
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
465
-        if ( ! empty( $ao_ccss_noptimize ) ) {
465
+        if (!empty($ao_ccss_noptimize)) {
466 466
             $src_url .= '?ao_noptirocket=1';
467
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
467
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
468 468
             $src_url .= '?ao_nolazy=1';
469 469
         }
470 470
 
471
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
471
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
472 472
 
473 473
         // Initialize request body.
474 474
         $body           = array();
@@ -478,88 +478,88 @@  discard block
 block discarded – undo
478 478
 
479 479
         // Prepare and add viewport size to the body if available.
480 480
         $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
481
-        if ( ! empty( $viewport['w'] ) && ! empty( $viewport['h'] ) ) {
481
+        if (!empty($viewport['w']) && !empty($viewport['h'])) {
482 482
             $body['width']  = $viewport['w'];
483 483
             $body['height'] = $viewport['h'];
484 484
         }
485 485
 
486 486
         // Prepare and add forceInclude to the body if available.
487 487
         global $ao_ccss_finclude;
488
-        $finclude = $this->ao_ccss_finclude( $ao_ccss_finclude );
489
-        if ( ! empty( $finclude ) ) {
488
+        $finclude = $this->ao_ccss_finclude($ao_ccss_finclude);
489
+        if (!empty($finclude)) {
490 490
             $body['forceInclude'] = $finclude;
491 491
         }
492 492
 
493 493
         // Add filter to allow the body array to be altered (e.g. to add customPageHeaders).
494
-        $body = apply_filters( 'autoptimize_ccss_cron_api_generate_body', $body );
494
+        $body = apply_filters('autoptimize_ccss_cron_api_generate_body', $body);
495 495
 
496 496
         // Body must be json and log it.
497
-        $body = json_encode( $body );
498
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request body is ' . $body, 3 );
497
+        $body = json_encode($body);
498
+        autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request body is '.$body, 3);
499 499
 
500 500
         // Prepare the request.
501
-        $url  = esc_url_raw( AO_CCSS_API . 'generate?aover=' . AO_CCSS_VER );
501
+        $url  = esc_url_raw(AO_CCSS_API.'generate?aover='.AO_CCSS_VER);
502 502
         $args = array(
503 503
             'headers' => array(
504
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
504
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
505 505
                 'Content-type'  => 'application/json; charset=utf-8',
506
-                'Authorization' => 'JWT ' . $key,
506
+                'Authorization' => 'JWT '.$key,
507 507
                 'Connection'    => 'close',
508 508
             ),
509 509
             'body'    => $body,
510 510
         );
511 511
 
512 512
         // Dispatch the request and store its response code.
513
-        $req  = wp_safe_remote_post( $url, $args );
514
-        $code = wp_remote_retrieve_response_code( $req );
515
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
513
+        $req  = wp_safe_remote_post($url, $args);
514
+        $code = wp_remote_retrieve_response_code($req);
515
+        $body = json_decode(wp_remote_retrieve_body($req), true);
516 516
 
517
-        if ( $debug && $dcode ) {
517
+        if ($debug && $dcode) {
518 518
             // If queue debug is active, change response code.
519 519
             $code = $dcode;
520 520
         }
521 521
 
522
-        if ( 200 == $code ) {
522
+        if (200 == $code) {
523 523
             // Response code is OK.
524 524
             // Workaround criticalcss.com non-RESTful reponses.
525
-            if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) {
525
+            if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status']) {
526 526
                 // Log successful and return encoded request body.
527
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied successfully', 3 );
527
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied successfully', 3);
528 528
 
529 529
                 // This code also means the key is valid, so cache key status for 24h if not already cached.
530
-                if ( ( ! $key_status || 2 != $key_status ) && $key ) {
531
-                    update_option( 'autoptimize_ccss_keyst', 2 );
532
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
530
+                if ((!$key_status || 2 != $key_status) && $key) {
531
+                    update_option('autoptimize_ccss_keyst', 2);
532
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
533 533
                 }
534 534
 
535 535
                 // Return the request body.
536 536
                 return $body;
537 537
             } else {
538 538
                 // Log successful requests with invalid reponses.
539
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 );
540
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
539
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2);
540
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
541 541
                 return $body;
542 542
             }
543 543
         } else {
544 544
             // Response code is anything else.
545 545
             // Log failed request with a valid response code and return body.
546
-            if ( $code ) {
547
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with error code <' . $code . '>, body follows...', 2 );
548
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
546
+            if ($code) {
547
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with error code <'.$code.'>, body follows...', 2);
548
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
549 549
 
550
-                if ( 401 == $code ) {
550
+                if (401 == $code) {
551 551
                     // If request is unauthorized, also clear key status.
552
-                    update_option( 'autoptimize_ccss_keyst', 1 );
553
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
552
+                    update_option('autoptimize_ccss_keyst', 1);
553
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
554 554
                 }
555 555
 
556 556
                 // Return the request body.
557 557
                 return $body;
558 558
             } else {
559 559
                 // Log failed request with no response and return false.
560
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> has no response, this could be a service timeout', 2 );
561
-                if ( is_wp_error( $req ) ) {
562
-                    autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
560
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> has no response, this could be a service timeout', 2);
561
+                if (is_wp_error($req)) {
562
+                    autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
563 563
                 }
564 564
 
565 565
                 return false;
@@ -567,76 +567,76 @@  discard block
 block discarded – undo
567 567
         }
568 568
     }
569 569
 
570
-    public function ao_ccss_api_results( $jobid, $debug, $dcode ) {
570
+    public function ao_ccss_api_results($jobid, $debug, $dcode) {
571 571
         // GET jobs from criticalcss.com and return responses
572 572
         // Get key.
573 573
         global $ao_ccss_key;
574 574
         $key = $ao_ccss_key;
575 575
 
576 576
         // Prepare the request.
577
-        $url  = AO_CCSS_API . 'results?resultId=' . $jobid;
577
+        $url  = AO_CCSS_API.'results?resultId='.$jobid;
578 578
         $args = array(
579 579
             'headers' => array(
580
-                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER,
581
-                'Authorization' => 'JWT ' . $key,
580
+                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v'.AO_CCSS_VER,
581
+                'Authorization' => 'JWT '.$key,
582 582
                 'Connection'    => 'close',
583 583
             ),
584 584
         );
585 585
 
586 586
         // Dispatch the request and store its response code.
587
-        $req  = wp_safe_remote_get( $url, $args );
588
-        $code = wp_remote_retrieve_response_code( $req );
589
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
587
+        $req  = wp_safe_remote_get($url, $args);
588
+        $code = wp_remote_retrieve_response_code($req);
589
+        $body = json_decode(wp_remote_retrieve_body($req), true);
590 590
 
591
-        if ( $debug && $dcode ) {
591
+        if ($debug && $dcode) {
592 592
             // If queue debug is active, change response code.
593 593
             $code = $dcode;
594 594
         }
595 595
 
596
-        if ( 200 == $code ) {
596
+        if (200 == $code) {
597 597
             // Response code is OK.
598
-            if ( is_array( $body ) && ( array_key_exists( 'status', $body ) || array_key_exists( 'job', $body ) ) && ( 'JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) ) {
598
+            if (is_array($body) && (array_key_exists('status', $body) || array_key_exists('job', $body)) && ('JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'])) {
599 599
                 // Workaround criticalcss.com non-RESTful reponses
600 600
                 // Log successful and return encoded request body.
601
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully', 3 );
601
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully', 3);
602 602
                 return $body;
603
-            } elseif ( is_array( $body ) && ( array_key_exists( 'error', $body ) && 'This css no longer exists. Please re-generate it.' == $body['error'] ) ) {
603
+            } elseif (is_array($body) && (array_key_exists('error', $body) && 'This css no longer exists. Please re-generate it.' == $body['error'])) {
604 604
                 // Handle no CSS reply
605 605
                 // Log no CSS error and return encoded request body.
606
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully but the CSS for it does not exist anymore', 3 );
606
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully but the CSS for it does not exist anymore', 3);
607 607
                 return $body;
608 608
             } else {
609 609
                 // Log failed request and return false.
610
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 );
611
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
610
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2);
611
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
612 612
                 return false;
613 613
             }
614 614
         } else {
615 615
             // Response code is anything else
616 616
             // Log failed request with a valid response code and return body.
617
-            if ( $code ) {
618
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with error code <' . $code . '>, body follows...', 2 );
619
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
620
-                if ( 401 == $code ) {
617
+            if ($code) {
618
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with error code <'.$code.'>, body follows...', 2);
619
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
620
+                if (401 == $code) {
621 621
                     // If request is unauthorized, also clear key status.
622
-                    update_option( 'autoptimize_ccss_keyst', 1 );
623
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
622
+                    update_option('autoptimize_ccss_keyst', 1);
623
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
624 624
                 }
625 625
 
626 626
                 // Return the request body.
627 627
                 return $body;
628 628
             } else {
629 629
                 // Log failed request with no response and return false.
630
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> has no response, this could be a service timeout', 2 );
630
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> has no response, this could be a service timeout', 2);
631 631
                 return false;
632 632
             }
633 633
         }
634 634
     }
635 635
 
636
-    public function ao_ccss_save_file( $ccss, $target, $review ) {
636
+    public function ao_ccss_save_file($ccss, $target, $review) {
637 637
         // Save critical CSS into the filesystem and return its filename
638 638
         // Prepare review mark.
639
-        if ( $review ) {
639
+        if ($review) {
640 640
             $rmark = '_R';
641 641
         } else {
642 642
             $rmark = '';
@@ -646,21 +646,21 @@  discard block
 block discarded – undo
646 646
         $filename = false;
647 647
         $content  = $ccss;
648 648
 
649
-        if ( autoptimizeCriticalCSSCore::ao_ccss_check_contents( $content ) ) {
649
+        if (autoptimizeCriticalCSSCore::ao_ccss_check_contents($content)) {
650 650
             // Sanitize content, set filename and try to save file.
651
-            $file     = AO_CCSS_DIR . 'ccss_' . md5( $ccss . $target[1] ) . $rmark . '.css';
652
-            $status   = file_put_contents( $file, $content, LOCK_EX );
653
-            $filename = pathinfo( $file, PATHINFO_BASENAME );
654
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file for the rule <' . $target[0] . '|' . $target[1] . '> was saved as <' . $filename . '>, size in bytes is <' . $status . '>', 3 );
651
+            $file     = AO_CCSS_DIR.'ccss_'.md5($ccss.$target[1]).$rmark.'.css';
652
+            $status   = file_put_contents($file, $content, LOCK_EX);
653
+            $filename = pathinfo($file, PATHINFO_BASENAME);
654
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file for the rule <'.$target[0].'|'.$target[1].'> was saved as <'.$filename.'>, size in bytes is <'.$status.'>', 3);
655 655
 
656
-            if ( ! $status ) {
656
+            if (!$status) {
657 657
                 // If file has not been saved, reset filename.
658
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file <' . $filename . '> could not be not saved', 2 );
658
+                autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file <'.$filename.'> could not be not saved', 2);
659 659
                 $filename = false;
660 660
                 return $filename;
661 661
             }
662 662
         } else {
663
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not pass content check', 2 );
663
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not pass content check', 2);
664 664
             return $filename;
665 665
         }
666 666
 
@@ -670,15 +670,15 @@  discard block
 block discarded – undo
670 670
         global $ao_ccss_rules;
671 671
 
672 672
         // Prepare rule variables.
673
-        $srule   = $ao_ccss_rules[ $target[0] ][ $target[1] ];
673
+        $srule   = $ao_ccss_rules[$target[0]][$target[1]];
674 674
         $oldfile = $srule['file'];
675 675
 
676
-        if ( $oldfile && $oldfile !== $filename ) {
677
-            $delfile = AO_CCSS_DIR . $oldfile;
678
-            if ( file_exists( $delfile ) ) {
679
-                $unlinkst = unlink( $delfile );
680
-                if ( $unlinkst ) {
681
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A previous critical CSS file <' . $oldfile . '> was removed for the rule <' . $target[0] . '|' . $target[1] . '>', 3 );
676
+        if ($oldfile && $oldfile !== $filename) {
677
+            $delfile = AO_CCSS_DIR.$oldfile;
678
+            if (file_exists($delfile)) {
679
+                $unlinkst = unlink($delfile);
680
+                if ($unlinkst) {
681
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A previous critical CSS file <'.$oldfile.'> was removed for the rule <'.$target[0].'|'.$target[1].'>', 3);
682 682
                 }
683 683
             }
684 684
         }
@@ -687,29 +687,29 @@  discard block
 block discarded – undo
687 687
         return $filename;
688 688
     }
689 689
 
690
-    public function ao_ccss_rule_update( $ljid, $srule, $file, $hash ) {
690
+    public function ao_ccss_rule_update($ljid, $srule, $file, $hash) {
691 691
         // Update or create a rule
692 692
         // Attach required arrays.
693 693
         global $ao_ccss_rules;
694 694
 
695 695
         // Prepare rule variables.
696
-        $trule  = explode( '|', $srule );
697
-        $rule   = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
696
+        $trule  = explode('|', $srule);
697
+        $rule   = $ao_ccss_rules[$trule[0]][$trule[1]];
698 698
         $action = false;
699 699
         $rtype  = '';
700 700
 
701
-        if ( 0 === $rule['hash'] && 0 !== $rule['file'] ) {
701
+        if (0 === $rule['hash'] && 0 !== $rule['file']) {
702 702
             // manual rule, don't ever overwrite.
703 703
             $action = 'NOT UPDATED';
704 704
             $rtype  = 'MANUAL';
705
-        } elseif ( 0 === $rule['hash'] && 0 === $rule['file'] ) {
705
+        } elseif (0 === $rule['hash'] && 0 === $rule['file']) {
706 706
             // If this is an user created AUTO rule with no hash and file yet, update its hash and filename
707 707
             // Set rule hash, file and action flag.
708 708
             $rule['hash'] = $hash;
709 709
             $rule['file'] = $file;
710 710
             $action       = 'UPDATED';
711 711
             $rtype        = 'AUTO';
712
-        } elseif ( 0 !== $rule['hash'] && ctype_alnum( $rule['hash'] ) ) {
712
+        } elseif (0 !== $rule['hash'] && ctype_alnum($rule['hash'])) {
713 713
             // If this is an genuine AUTO rule, update its hash and filename
714 714
             // Set rule hash, file and action flag.
715 715
             $rule['hash'] = $hash;
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
         } else {
720 720
             // If rule doesn't exist, create an AUTO rule
721 721
             // AUTO rules were only for types, but will now also work for paths.
722
-            if ( 'types' == $trule[0] || 'paths' == $trule[0] ) {
722
+            if ('types' == $trule[0] || 'paths' == $trule[0]) {
723 723
                 // Set rule hash and file and action flag.
724 724
                 $rule['hash'] = $hash;
725 725
                 $rule['file'] = $file;
@@ -727,47 +727,47 @@  discard block
 block discarded – undo
727 727
                 $rtype        = 'AUTO';
728 728
             } else {
729 729
                 // Log that no rule was created.
730
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Exception, no AUTO rule created', 3 );
730
+                autoptimizeCriticalCSSCore::ao_ccss_log('Exception, no AUTO rule created', 3);
731 731
             }
732 732
         }
733 733
 
734
-        if ( $action ) {
734
+        if ($action) {
735 735
             // If a rule creation/update is required, persist updated rules object.
736
-            $ao_ccss_rules[ $trule[0] ][ $trule[1] ] = $rule;
737
-            $ao_ccss_rules_raw                       = json_encode( $ao_ccss_rules );
738
-            update_option( 'autoptimize_ccss_rules', $ao_ccss_rules_raw );
739
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Target rule <' . $srule . '> of type <' . $rtype . '> was ' . $action . ' for job id <' . $ljid . '>', 3 );
736
+            $ao_ccss_rules[$trule[0]][$trule[1]] = $rule;
737
+            $ao_ccss_rules_raw                       = json_encode($ao_ccss_rules);
738
+            update_option('autoptimize_ccss_rules', $ao_ccss_rules_raw);
739
+            autoptimizeCriticalCSSCore::ao_ccss_log('Target rule <'.$srule.'> of type <'.$rtype.'> was '.$action.' for job id <'.$ljid.'>', 3);
740 740
         } else {
741
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No rule action required', 3 );
741
+            autoptimizeCriticalCSSCore::ao_ccss_log('No rule action required', 3);
742 742
         }
743 743
     }
744 744
 
745
-    function ao_ccss_finclude( $finclude_raw ) {
745
+    function ao_ccss_finclude($finclude_raw) {
746 746
         // Prepare forceInclude object.
747
-        if ( ! empty( $finclude_raw ) ) {
747
+        if (!empty($finclude_raw)) {
748 748
             // If there are any content
749 749
             // Convert raw string into arra and initialize the returning object.
750
-            $fincludes = explode( ',', $finclude_raw );
750
+            $fincludes = explode(',', $finclude_raw);
751 751
             $finclude  = array();
752 752
 
753 753
             // Interacts over every rule.
754 754
             $i = 0;
755
-            foreach ( $fincludes as $include ) {
755
+            foreach ($fincludes as $include) {
756 756
                 // Trim leading and trailing whitespaces.
757
-                $include = trim( $include );
757
+                $include = trim($include);
758 758
 
759
-                if ( substr( $include, 0, 2 ) === '//' ) {
759
+                if (substr($include, 0, 2) === '//') {
760 760
                     // Regex rule
761 761
                     // Format value as required.
762
-                    $include = str_replace( '//', '/', $include );
763
-                    $include = $include . '/i';
762
+                    $include = str_replace('//', '/', $include);
763
+                    $include = $include.'/i';
764 764
 
765 765
                     // Store regex object.
766
-                    $finclude[ $i ]['type']  = 'RegExp';
767
-                    $finclude[ $i ]['value'] = $include;
766
+                    $finclude[$i]['type']  = 'RegExp';
767
+                    $finclude[$i]['value'] = $include;
768 768
                 } else {
769 769
                     // Simple value rule.
770
-                    $finclude[ $i ]['value'] = $include;
770
+                    $finclude[$i]['value'] = $include;
771 771
                 }
772 772
 
773 773
                 $i++;
@@ -784,54 +784,54 @@  discard block
 block discarded – undo
784 784
     public function ao_ccss_cleaning() {
785 785
         // Perform plugin maintenance
786 786
         // Truncate log file >= 1MB .
787
-        if ( file_exists( AO_CCSS_LOG ) ) {
788
-            if ( filesize( AO_CCSS_LOG ) >= 1048576 ) {
789
-                $logfile = fopen( AO_CCSS_LOG, 'w' );
790
-                fclose( $logfile );
787
+        if (file_exists(AO_CCSS_LOG)) {
788
+            if (filesize(AO_CCSS_LOG) >= 1048576) {
789
+                $logfile = fopen(AO_CCSS_LOG, 'w');
790
+                fclose($logfile);
791 791
             }
792 792
         }
793 793
 
794 794
         // Remove lock file.
795
-        if ( file_exists( AO_CCSS_LOCK ) ) {
796
-            unlink( AO_CCSS_LOCK );
795
+        if (file_exists(AO_CCSS_LOCK)) {
796
+            unlink(AO_CCSS_LOCK);
797 797
         }
798 798
 
799 799
         // Make sure queue processing is scheduled, recreate if not.
800
-        if ( ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
801
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
800
+        if (!wp_next_scheduled('ao_ccss_queue')) {
801
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
802 802
         }
803 803
 
804 804
         // Queue cleaning.
805 805
         global $ao_ccss_queue;
806 806
         $queue_purge_threshold = 100;
807
-        $queue_purge_age       = 24 * 60 * 60;
808
-        $queue_length          = count( $ao_ccss_queue );
809
-        $timestamp_yesterday   = microtime( true ) - $queue_purge_age;
807
+        $queue_purge_age       = 24*60*60;
808
+        $queue_length          = count($ao_ccss_queue);
809
+        $timestamp_yesterday   = microtime(true) - $queue_purge_age;
810 810
         $remove_old_new        = false;
811 811
         $queue_altered         = false;
812 812
 
813
-        if ( $queue_length > $queue_purge_threshold ) {
813
+        if ($queue_length > $queue_purge_threshold) {
814 814
             $remove_old_new = true;
815 815
         }
816 816
 
817
-        foreach ( $ao_ccss_queue as $path => $job ) {
818
-            if ( ( $remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday ) || in_array( $job['jqstat'], array( 'JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE' ) ) ) {
819
-                unset( $ao_ccss_queue[ $path ] );
817
+        foreach ($ao_ccss_queue as $path => $job) {
818
+            if (($remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday) || in_array($job['jqstat'], array('JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE'))) {
819
+                unset($ao_ccss_queue[$path]);
820 820
                 $queue_altered = true;
821 821
             }
822 822
         }
823 823
 
824 824
         // save queue to options!
825
-        if ( $queue_altered ) {
826
-            $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
827
-            update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
828
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue cleaning done.', 3 );
825
+        if ($queue_altered) {
826
+            $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
827
+            update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
828
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue cleaning done.', 3);
829 829
         }
830 830
 
831 831
         // re-check key if invalid.
832 832
         global $ao_ccss_keyst;
833
-        if ( 1 == $ao_ccss_keyst ) {
834
-            $this->ao_ccss_api_generate( '', '', '' );
833
+        if (1 == $ao_ccss_keyst) {
834
+            $this->ao_ccss_api_generate('', '', '');
835 835
         }
836 836
     }
837 837
 }
Please login to merge, or discard this patch.
autoptimize.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,66 +17,66 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 
20
-if ( ! defined( 'ABSPATH' ) ) {
20
+if (!defined('ABSPATH')) {
21 21
     exit;
22 22
 }
23 23
 
24
-define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.7.7' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.7.7');
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/autoptimizeImages.php 1 patch
Spacing   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles optimizing images.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
      */
24 24
     protected static $instance = null;
25 25
 
26
-    public function __construct( array $options = array() )
26
+    public function __construct(array $options = array())
27 27
     {
28 28
         // If options are not provided, fetch them.
29
-        if ( empty( $options ) ) {
29
+        if (empty($options)) {
30 30
             $options = $this->fetch_options();
31 31
         }
32 32
 
33
-        $this->set_options( $options );
33
+        $this->set_options($options);
34 34
     }
35 35
 
36
-    public function set_options( array $options )
36
+    public function set_options(array $options)
37 37
     {
38 38
         $this->options = $options;
39 39
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 
43 43
     public static function fetch_options()
44 44
     {
45
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
46
-        if ( empty( $value ) ) {
45
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
46
+        if (empty($value)) {
47 47
             // Fallback to returning defaults when no stored option exists yet.
48 48
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
49 49
         }
50 50
 
51 51
         // get service availability and add it to the options-array.
52
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
52
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
53 53
 
54
-        if ( empty( $value['availabilities'] ) ) {
55
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
54
+        if (empty($value['availabilities'])) {
55
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
56 56
         }
57 57
 
58 58
         return $value;
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         // and does not use/ request the availablity data (which could slow things down).
66 66
         static $imgopt_active = null;
67 67
 
68
-        if ( null === $imgopt_active ) {
69
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
70
-            if ( ! empty( $opts ) && is_array( $opts ) && array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $opts ) && ! empty( $opts['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $opts['autoptimize_imgopt_checkbox_field_1'] ) {
68
+        if (null === $imgopt_active) {
69
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
70
+            if (!empty($opts) && is_array($opts) && array_key_exists('autoptimize_imgopt_checkbox_field_1', $opts) && !empty($opts['autoptimize_imgopt_checkbox_field_1']) && '1' === $opts['autoptimize_imgopt_checkbox_field_1']) {
71 71
                 $imgopt_active = true;
72 72
             } else {
73 73
                 $imgopt_active = false;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public static function instance()
89 89
     {
90
-        if ( null === self::$instance ) {
90
+        if (null === self::$instance) {
91 91
             self::$instance = new self();
92 92
         }
93 93
 
@@ -96,34 +96,34 @@  discard block
 block discarded – undo
96 96
 
97 97
     public function run()
98 98
     {
99
-        if ( is_admin() ) {
100
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
101
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
99
+        if (is_admin()) {
100
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
101
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
102 102
             } else {
103
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
103
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
104 104
             }
105
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
105
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
106 106
         } else {
107
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
107
+            add_action('wp', array($this, 'run_on_frontend'));
108 108
         }
109 109
     }
110 110
 
111 111
     public function run_on_frontend() {
112
-        if ( ! $this->should_run() ) {
113
-            if ( $this->should_lazyload() ) {
112
+        if (!$this->should_run()) {
113
+            if ($this->should_lazyload()) {
114 114
                 add_filter(
115 115
                     'wp_lazy_loading_enabled',
116 116
                     '__return_false'
117 117
                 );
118 118
                 add_filter(
119 119
                     'autoptimize_html_after_minify',
120
-                    array( $this, 'filter_lazyload_images' ),
120
+                    array($this, 'filter_lazyload_images'),
121 121
                     10,
122 122
                     1
123 123
                 );
124 124
                 add_action(
125 125
                     'wp_footer',
126
-                    array( $this, 'add_lazyload_js_footer' ),
126
+                    array($this, 'add_lazyload_js_footer'),
127 127
                     10,
128 128
                     0
129 129
                 );
@@ -133,43 +133,43 @@  discard block
 block discarded – undo
133 133
 
134 134
         $active = false;
135 135
 
136
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
136
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
137 137
             add_filter(
138 138
                 'autoptimize_html_after_minify',
139
-                array( $this, 'filter_optimize_images' ),
139
+                array($this, 'filter_optimize_images'),
140 140
                 10,
141 141
                 1
142 142
             );
143 143
             $active = true;
144 144
         }
145 145
 
146
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
146
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
147 147
             add_filter(
148 148
                 'autoptimize_filter_base_replace_cdn',
149
-                array( $this, 'filter_optimize_css_images' ),
149
+                array($this, 'filter_optimize_css_images'),
150 150
                 10,
151 151
                 1
152 152
             );
153 153
             $active = true;
154 154
         }
155 155
 
156
-        if ( $active ) {
156
+        if ($active) {
157 157
             add_filter(
158 158
                 'autoptimize_extra_filter_tobepreconn',
159
-                array( $this, 'filter_preconnect_imgopt_url' ),
159
+                array($this, 'filter_preconnect_imgopt_url'),
160 160
                 10,
161 161
                 1
162 162
             );
163 163
         }
164 164
 
165
-        if ( $this->should_lazyload() ) {
165
+        if ($this->should_lazyload()) {
166 166
             add_filter(
167 167
                 'wp_lazy_loading_enabled',
168 168
                 '__return_false'
169 169
             );
170 170
             add_action(
171 171
                 'wp_footer',
172
-                array( $this, 'add_lazyload_js_footer' ),
172
+                array($this, 'add_lazyload_js_footer'),
173 173
                 10,
174 174
                 0
175 175
             );
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
     protected function should_run()
185 185
     {
186 186
         $opts              = $this->options;
187
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
188
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
187
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
188
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
189 189
 
190 190
         $do_cdn      = true;
191 191
         $_userstatus = $this->get_imgopt_provider_userstatus();
192
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
192
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
193 193
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
194 194
             $do_cdn = false;
195 195
         }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $this->imgopt_active()
199 199
             && $do_cdn
200 200
             && $service_not_down
201
-            && ( $not_launch_status || $this->launch_ok() )
201
+            && ($not_launch_status || $this->launch_ok())
202 202
         ) {
203 203
             return true;
204 204
         }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     {
210 210
         static $imgopt_host = null;
211 211
 
212
-        if ( null === $imgopt_host ) {
212
+        if (null === $imgopt_host) {
213 213
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
214 214
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
215
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
216
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
215
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
216
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
217 217
             }
218
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
218
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
219 219
         }
220 220
 
221 221
         return $imgopt_host;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
     public static function get_service_url_suffix()
232 232
     {
233
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
233
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
234 234
 
235 235
         return $suffix;
236 236
     }
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
     {
240 240
         static $quality = null;
241 241
 
242
-        if ( null === $quality ) {
242
+        if (null === $quality) {
243 243
             $q_array = $this->get_img_quality_array();
244 244
             $setting = $this->get_img_quality_setting();
245 245
             $quality = apply_filters(
246 246
                 'autoptimize_filter_imgopt_quality',
247
-                'q_' . $q_array[ $setting ]
247
+                'q_'.$q_array[$setting]
248 248
             );
249 249
         }
250 250
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     {
256 256
         static $map = null;
257 257
 
258
-        if ( null === $map ) {
258
+        if (null === $map) {
259 259
             $map = array(
260 260
                 '1' => 'lossy',
261 261
                 '2' => 'glossy',
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
     {
275 275
         static $q = null;
276 276
 
277
-        if ( null === $q ) {
278
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
277
+        if (null === $q) {
278
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
279 279
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
280 280
             }
281 281
 
282
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
282
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
283 283
                 // default image opt. value is 2 ("glossy").
284 284
                 $q = '2';
285 285
             } else {
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
         return $q;
291 291
     }
292 292
 
293
-    public function filter_preconnect_imgopt_url( array $in )
293
+    public function filter_preconnect_imgopt_url(array $in)
294 294
     {
295
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
296
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
295
+        $url_parts = parse_url($this->get_imgopt_base_url());
296
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
297 297
 
298 298
         return $in;
299 299
     }
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
      *
307 307
      * @return string
308 308
      */
309
-    private function normalize_img_url( $in )
309
+    private function normalize_img_url($in)
310 310
     {
311 311
         // Only parse the site url once.
312 312
         static $parsed_site_url = null;
313
-        if ( null === $parsed_site_url ) {
314
-            $parsed_site_url = parse_url( site_url() );
313
+        if (null === $parsed_site_url) {
314
+            $parsed_site_url = parse_url(site_url());
315 315
         }
316 316
 
317 317
         // get CDN domain once.
318 318
         static $cdn_domain = null;
319
-        if ( is_null( $cdn_domain ) ) {
319
+        if (is_null($cdn_domain)) {
320 320
             $cdn_url = $this->get_cdn_url();
321
-            if ( ! empty( $cdn_url ) ) {
322
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
321
+            if (!empty($cdn_url)) {
322
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
323 323
             } else {
324 324
                 $cdn_domain = '';
325 325
             }
@@ -335,44 +335,44 @@  discard block
 block discarded – undo
335 335
          * identical string operations).
336 336
          */
337 337
         static $cache = null;
338
-        if ( null === $cache ) {
338
+        if (null === $cache) {
339 339
             $cache = array();
340 340
         }
341 341
 
342 342
         // Do the work on cache miss only.
343
-        if ( ! isset( $cache[ $in ] ) ) {
343
+        if (!isset($cache[$in])) {
344 344
             // Default to (the trimmed version of) what was given to us.
345
-            $result = trim( $in );
345
+            $result = trim($in);
346 346
 
347 347
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
348
-            if ( strpos( $result, '&quot;' ) !== false ) {
349
-                $result = str_replace( '&quot;', '', $result );
348
+            if (strpos($result, '&quot;') !== false) {
349
+                $result = str_replace('&quot;', '', $result);
350 350
             }
351 351
 
352
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
353
-                $result = $parsed_site_url['scheme'] . ':' . $result;
354
-            } elseif ( 0 === strpos( $result, '/' ) ) {
352
+            if (autoptimizeUtils::is_protocol_relative($result)) {
353
+                $result = $parsed_site_url['scheme'].':'.$result;
354
+            } elseif (0 === strpos($result, '/')) {
355 355
                 // Root-relative...
356
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
357
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
358
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
356
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
357
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
358
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
359 359
             }
360 360
 
361
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
361
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
362 362
 
363 363
             // Store in cache.
364
-            $cache[ $in ] = $result;
364
+            $cache[$in] = $result;
365 365
         }
366 366
 
367
-        return $cache[ $in ];
367
+        return $cache[$in];
368 368
     }
369 369
 
370
-    public function filter_optimize_css_images( $in )
370
+    public function filter_optimize_css_images($in)
371 371
     {
372
-        $in = $this->normalize_img_url( $in );
372
+        $in = $this->normalize_img_url($in);
373 373
 
374
-        if ( $this->can_optimize_image( $in ) ) {
375
-            return $this->build_imgopt_url( $in, '', '' );
374
+        if ($this->can_optimize_image($in)) {
375
+            return $this->build_imgopt_url($in, '', '');
376 376
         } else {
377 377
             return $in;
378 378
         }
@@ -382,50 +382,50 @@  discard block
 block discarded – undo
382 382
     {
383 383
         static $imgopt_base_url = null;
384 384
 
385
-        if ( null === $imgopt_base_url ) {
385
+        if (null === $imgopt_base_url) {
386 386
             $imgopt_host     = $this->get_imgopt_host();
387 387
             $quality         = $this->get_img_quality_string();
388
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
389
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
390
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
388
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
389
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
390
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
391 391
         }
392 392
 
393 393
         return $imgopt_base_url;
394 394
     }
395 395
 
396
-    private function can_optimize_image( $url, $tag = '' )
396
+    private function can_optimize_image($url, $tag = '')
397 397
     {
398 398
         static $cdn_url      = null;
399 399
         static $nopti_images = null;
400 400
 
401
-        if ( null === $cdn_url ) {
401
+        if (null === $cdn_url) {
402 402
             $cdn_url = apply_filters(
403 403
                 'autoptimize_filter_base_cdnurl',
404
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
404
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
405 405
             );
406 406
         }
407 407
 
408
-        if ( null === $nopti_images ) {
409
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' );
408
+        if (null === $nopti_images) {
409
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', '');
410 410
         }
411 411
 
412 412
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
413
-        $url        = $this->normalize_img_url( $url );
414
-        $url_parsed = parse_url( $url );
413
+        $url        = $this->normalize_img_url($url);
414
+        $url_parsed = parse_url($url);
415 415
 
416
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
416
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
417 417
             return false;
418
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
418
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
419 419
             return false;
420
-        } elseif ( strpos( $url, '.php' ) !== false ) {
420
+        } elseif (strpos($url, '.php') !== false) {
421 421
             return false;
422
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
422
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp'), '', $url_parsed['path']) === $url_parsed['path']) {
423 423
             // fixme: better check against end of string.
424 424
             return false;
425
-        } elseif ( ! empty( $nopti_images ) ) {
426
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
427
-            foreach ( $nopti_images_array as $nopti_image ) {
428
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
425
+        } elseif (!empty($nopti_images)) {
426
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
427
+            foreach ($nopti_images_array as $nopti_image) {
428
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
429 429
                     return false;
430 430
                 }
431 431
             }
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
         return true;
434 434
     }
435 435
 
436
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
436
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
437 437
     {
438 438
         // sanitize width and height.
439
-        if ( strpos( $width, '%' ) !== false ) {
439
+        if (strpos($width, '%') !== false) {
440 440
             $width = 0;
441 441
         }
442
-        if ( strpos( $height, '%' ) !== false ) {
442
+        if (strpos($height, '%') !== false) {
443 443
             $height = 0;
444 444
         }
445 445
         $width  = (int) $width;
@@ -453,56 +453,56 @@  discard block
 block discarded – undo
453 453
         );
454 454
 
455 455
         // If filter modified the url, return that.
456
-        if ( $filtered_url !== $orig_url ) {
456
+        if ($filtered_url !== $orig_url) {
457 457
             return $filtered_url;
458 458
         }
459 459
 
460
-        $orig_url        = $this->normalize_img_url( $orig_url );
460
+        $orig_url        = $this->normalize_img_url($orig_url);
461 461
         $imgopt_base_url = $this->get_imgopt_base_url();
462 462
         $imgopt_size     = '';
463 463
 
464
-        if ( $width && 0 !== $width ) {
465
-            $imgopt_size = ',w_' . $width;
464
+        if ($width && 0 !== $width) {
465
+            $imgopt_size = ',w_'.$width;
466 466
         }
467 467
 
468
-        if ( $height && 0 !== $height ) {
469
-            $imgopt_size .= ',h_' . $height;
468
+        if ($height && 0 !== $height) {
469
+            $imgopt_size .= ',h_'.$height;
470 470
         }
471 471
 
472
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
472
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
473 473
 
474 474
         return $url;
475 475
     }
476 476
 
477
-    public function replace_data_thumbs( $matches )
477
+    public function replace_data_thumbs($matches)
478 478
     {
479
-        return $this->replace_img_callback( $matches, 150, 150 );
479
+        return $this->replace_img_callback($matches, 150, 150);
480 480
     }
481 481
 
482
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
482
+    public function replace_img_callback($matches, $width = 0, $height = 0)
483 483
     {
484
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
485
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
486
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
484
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
485
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
486
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
487 487
         } else {
488 488
             return $matches[0];
489 489
         }
490 490
     }
491 491
 
492
-    public function replace_icon_callback( $matches )
492
+    public function replace_icon_callback($matches)
493 493
     {
494
-        if ( array_key_exists( '2', $matches ) ) {
495
-            $sizes  = explode( 'x', $matches[2] );
494
+        if (array_key_exists('2', $matches)) {
495
+            $sizes  = explode('x', $matches[2]);
496 496
             $width  = $sizes[0];
497 497
             $height = $sizes[1];
498 498
         } else {
499 499
             $width  = 180;
500 500
             $height = 180;
501 501
         }
502
-        return $this->replace_img_callback( $matches, $width, $height );
502
+        return $this->replace_img_callback($matches, $width, $height);
503 503
     }
504 504
 
505
-    public function filter_optimize_images( $in )
505
+    public function filter_optimize_images($in)
506 506
     {
507 507
         /*
508 508
          * potential future functional improvements:
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         $to_replace = array();
513 513
 
514 514
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
515
-        if ( $this->should_lazyload() ) {
515
+        if ($this->should_lazyload()) {
516 516
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
517 517
                 'SCRIPT',
518 518
                 '<script',
@@ -522,25 +522,25 @@  discard block
 block discarded – undo
522 522
         }
523 523
 
524 524
         // extract img tags.
525
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
526
-            foreach ( $matches[0] as $tag ) {
525
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
526
+            foreach ($matches[0] as $tag) {
527 527
                 $orig_tag = $tag;
528 528
                 $imgopt_w = '';
529 529
                 $imgopt_h = '';
530 530
 
531 531
                 // first do (data-)srcsets.
532
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
533
-                    foreach ( $allsrcsets as $srcset ) {
532
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
533
+                    foreach ($allsrcsets as $srcset) {
534 534
                         $srcset  = $srcset[2];
535
-                        $srcsets = explode( ',', $srcset );
536
-                        foreach ( $srcsets as $indiv_srcset ) {
537
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
538
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
539
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
535
+                        $srcsets = explode(',', $srcset);
536
+                        foreach ($srcsets as $indiv_srcset) {
537
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
538
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
539
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
540 540
                             }
541
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag ) ) {
542
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
543
-                                $tag        = str_replace( $indiv_srcset_parts[0], $imgopt_url, $tag );
541
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag)) {
542
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
543
+                                $tag        = str_replace($indiv_srcset_parts[0], $imgopt_url, $tag);
544 544
                             }
545 545
                         }
546 546
                     }
@@ -548,133 +548,133 @@  discard block
 block discarded – undo
548 548
 
549 549
                 // proceed with img src.
550 550
                 // get width and height and add to $imgopt_size.
551
-                $_get_size = $this->get_size_from_tag( $tag );
551
+                $_get_size = $this->get_size_from_tag($tag);
552 552
                 $imgopt_w  = $_get_size['width'];
553 553
                 $imgopt_h  = $_get_size['height'];
554 554
 
555 555
                 // then start replacing images src.
556
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
557
-                    foreach ( $urls as $url ) {
556
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
557
+                    foreach ($urls as $url) {
558 558
                         $full_src_orig = $url[0];
559 559
                         $url           = $url[1];
560
-                        if ( $this->can_optimize_image( $url, $full_src_orig ) ) {
561
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
562
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
563
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
560
+                        if ($this->can_optimize_image($url, $full_src_orig)) {
561
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
562
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
563
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
564 564
                         }
565 565
                     }
566 566
                 }
567 567
 
568 568
                 // do lazyload stuff.
569
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
569
+                if ($this->should_lazyload($in) && !empty($url)) {
570 570
                     // first do lpiq placeholder logic.
571
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
571
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
572 572
                         // if all img src have been replaced during srcset, we have to extract the
573 573
                         // origin url from the imgopt one to be able to set a lqip placeholder.
574
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
574
+                        $_url = substr($url, strpos($url, '/http') + 1);
575 575
                     } else {
576 576
                         $_url = $url;
577 577
                     }
578 578
 
579
-                    $_url = $this->normalize_img_url( $_url );
579
+                    $_url = $this->normalize_img_url($_url);
580 580
 
581 581
                     $placeholder = '';
582
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
582
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
583 583
                         $lqip_w = '';
584 584
                         $lqip_h = '';
585
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
586
-                            $lqip_w = ',w_' . $imgopt_w;
585
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
586
+                            $lqip_w = ',w_'.$imgopt_w;
587 587
                         }
588
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
589
-                            $lqip_h = ',h_' . $imgopt_h;
588
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
589
+                            $lqip_h = ',h_'.$imgopt_h;
590 590
                         }
591
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
591
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
592 592
                     }
593 593
                     // then call add_lazyload-function with lpiq placeholder if set.
594
-                    $tag = $this->add_lazyload( $tag, $placeholder );
594
+                    $tag = $this->add_lazyload($tag, $placeholder);
595 595
                 }
596 596
 
597 597
                 // and add tag to array for later replacement.
598
-                if ( $tag !== $orig_tag ) {
599
-                    $to_replace[ $orig_tag ] = $tag;
598
+                if ($tag !== $orig_tag) {
599
+                    $to_replace[$orig_tag] = $tag;
600 600
                 }
601 601
             }
602 602
         }
603 603
 
604 604
         // and replace all.
605
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
605
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
606 606
 
607 607
         // img thumbnails in e.g. woocommerce.
608
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
608
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
609 609
             $out = preg_replace_callback(
610 610
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
611
-                array( $this, 'replace_data_thumbs' ),
611
+                array($this, 'replace_data_thumbs'),
612 612
                 $out
613 613
             );
614 614
         }
615 615
 
616 616
         // background-image in inline style.
617
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
617
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
618 618
             $out = preg_replace_callback(
619 619
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
620
-                array( $this, 'replace_img_callback' ),
620
+                array($this, 'replace_img_callback'),
621 621
                 $out
622 622
             );
623 623
         }
624 624
 
625 625
         // act on icon links.
626
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
626
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
627 627
             $out = preg_replace_callback(
628 628
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
629
-                array( $this, 'replace_icon_callback' ),
629
+                array($this, 'replace_icon_callback'),
630 630
                 $out
631 631
             );
632 632
         }
633 633
 
634 634
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
635
-        if ( $this->should_lazyload() ) {
635
+        if ($this->should_lazyload()) {
636 636
             $out = autoptimizeBase::restore_marked_content(
637 637
                 'SCRIPT',
638 638
                 $out
639 639
             );
640 640
 
641
-            $out = $this->process_picture_tag( $out, true, true );
642
-            $out = $this->process_bgimage( $out );
641
+            $out = $this->process_picture_tag($out, true, true);
642
+            $out = $this->process_bgimage($out);
643 643
         } else {
644
-            $out = $this->process_picture_tag( $out, true, false );
644
+            $out = $this->process_picture_tag($out, true, false);
645 645
         }
646 646
 
647 647
         return $out;
648 648
     }
649 649
 
650
-    public function get_size_from_tag( $tag ) {
650
+    public function get_size_from_tag($tag) {
651 651
         // reusable function to extract widht and height from an image tag
652 652
         // enforcing a filterable maximum width and height (default 4999X4999).
653 653
         $width  = '';
654 654
         $height = '';
655 655
 
656
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
657
-            if ( strpos( $_width[2], '%' ) === false ) {
656
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
657
+            if (strpos($_width[2], '%') === false) {
658 658
                 $width = (int) $_width[2];
659 659
             }
660 660
         }
661
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
662
-            if ( strpos( $_height[2], '%' ) === false ) {
661
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
662
+            if (strpos($_height[2], '%') === false) {
663 663
                 $height = (int) $_height[2];
664 664
             }
665 665
         }
666 666
 
667 667
         // check for and enforce (filterable) max sizes.
668
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
669
-        if ( $width > $_max_width ) {
668
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
669
+        if ($width > $_max_width) {
670 670
             $_width = $_max_width;
671
-            $height = $_width / $width * $height;
671
+            $height = $_width/$width*$height;
672 672
             $width  = $_width;
673 673
         }
674
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
675
-        if ( $height > $_max_height ) {
674
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
675
+        if ($height > $_max_height) {
676 676
             $_height = $_max_height;
677
-            $width   = $_height / $height * $width;
677
+            $width   = $_height/$height*$width;
678 678
             $height  = $_height;
679 679
         }
680 680
 
@@ -693,26 +693,26 @@  discard block
 block discarded – undo
693 693
         return $self->should_lazyload();
694 694
     }
695 695
 
696
-    public function should_lazyload( $context = '' ) {
697
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
696
+    public function should_lazyload($context = '') {
697
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
698 698
             $lazyload_return = true;
699 699
         } else {
700 700
             $lazyload_return = false;
701 701
         }
702
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
702
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
703 703
 
704 704
         return $lazyload_return;
705 705
     }
706 706
 
707 707
     public function check_nolazy() {
708
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
708
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
709 709
             return true;
710 710
         } else {
711 711
             return false;
712 712
         }
713 713
     }
714 714
 
715
-    public function filter_lazyload_images( $in )
715
+    public function filter_lazyload_images($in)
716 716
     {
717 717
         // only used is image optimization is NOT active but lazyload is.
718 718
         $to_replace = array();
@@ -726,20 +726,20 @@  discard block
 block discarded – undo
726 726
         );
727 727
 
728 728
         // extract img tags and add lazyload attribs.
729
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
730
-            foreach ( $matches[0] as $tag ) {
731
-                if ( $this->should_lazyload( $out ) ) {
732
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
729
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
730
+            foreach ($matches[0] as $tag) {
731
+                if ($this->should_lazyload($out)) {
732
+                    $to_replace[$tag] = $this->add_lazyload($tag);
733 733
                 }
734 734
             }
735
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
735
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
736 736
         }
737 737
 
738 738
         // and also lazyload picture tag.
739
-        $out = $this->process_picture_tag( $out, false, true );
739
+        $out = $this->process_picture_tag($out, false, true);
740 740
 
741 741
         // and inline style blocks with background-image.
742
-        $out = $this->process_bgimage( $out );
742
+        $out = $this->process_bgimage($out);
743 743
 
744 744
         // restore noscript tags.
745 745
         $out = autoptimizeBase::restore_marked_content(
@@ -750,85 +750,85 @@  discard block
 block discarded – undo
750 750
         return $out;
751 751
     }
752 752
 
753
-    public function add_lazyload( $tag, $placeholder = '' ) {
753
+    public function add_lazyload($tag, $placeholder = '') {
754 754
         // adds actual lazyload-attributes to an image node.
755
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
756
-            $tag = $this->maybe_fix_missing_quotes( $tag );
755
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) {
756
+            $tag = $this->maybe_fix_missing_quotes($tag);
757 757
 
758 758
             // store original tag for use in noscript version.
759
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
759
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
760 760
 
761
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
761
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
762 762
 
763 763
             // insert lazyload class.
764
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
764
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
765 765
 
766
-            if ( ! $placeholder || empty( $placeholder ) ) {
766
+            if (!$placeholder || empty($placeholder)) {
767 767
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
768
-                $_get_size = $this->get_size_from_tag( $tag );
768
+                $_get_size = $this->get_size_from_tag($tag);
769 769
                 $width     = $_get_size['width'];
770 770
                 $height    = $_get_size['height'];
771
-                if ( false === $width || empty( $width ) ) {
771
+                if (false === $width || empty($width)) {
772 772
                     $width = 210; // default width for SVG placeholder.
773 773
                 }
774
-                if ( false === $height || empty( $height ) ) {
775
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
774
+                if (false === $height || empty($height)) {
775
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
776 776
                 }
777 777
 
778 778
                 // insert the actual lazyload stuff.
779 779
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
780
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
780
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
781 781
             }
782 782
 
783
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
784
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
783
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
784
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
785 785
 
786 786
             // move sizes to data-sizes unless filter says no.
787
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
788
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
787
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
788
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
789 789
             }
790 790
 
791 791
             // add the noscript-tag from earlier.
792
-            $tag = $noscript_tag . $tag;
793
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
792
+            $tag = $noscript_tag.$tag;
793
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
794 794
         }
795 795
 
796 796
         return $tag;
797 797
     }
798 798
 
799 799
     public function add_lazyload_js_footer() {
800
-        if ( false === autoptimizeMain::should_buffer() ) {
800
+        if (false === autoptimizeMain::should_buffer()) {
801 801
             return;
802 802
         }
803 803
 
804 804
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
805 805
         $noptimize_flag = '';
806
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
806
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
807 807
             $noptimize_flag = ' data-noptimize="1"';
808 808
         }
809 809
 
810
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
810
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
811 811
         $cdn_url      = $this->get_cdn_url();
812
-        if ( ! empty( $cdn_url ) ) {
813
-            $cdn_url      = rtrim( $cdn_url, '/' );
814
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
812
+        if (!empty($cdn_url)) {
813
+            $cdn_url      = rtrim($cdn_url, '/');
814
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
815 815
         }
816 816
 
817 817
         $type_js = '';
818
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
818
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
819 819
             $type_js = ' type="text/javascript"';
820 820
         }
821 821
 
822 822
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
823
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
824
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
825
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
823
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
824
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
825
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
826 826
 
827 827
         // And add webp detection and loading JS.
828
-        if ( $this->should_webp() ) {
828
+        if ($this->should_webp()) {
829 829
             $_webp_detect = "function c_webp(A){var n=new Image;n.onload=function(){var e=0<n.width&&0<n.height;A(e)},n.onerror=function(){A(!1)},n.src='data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA=='}function s_webp(e){window.supportsWebP=e}c_webp(s_webp);";
830 830
             $_webp_load   = "document.addEventListener('lazybeforeunveil',function({target:b}){window.supportsWebP&&['data-src','data-srcset'].forEach(function(c){attr=b.getAttribute(c),null!==attr&&-1==attr.indexOf('/client/to_webp')&&b.setAttribute(c,attr.replace(/\/client\//,'/client/to_webp,'))})});";
831
-            echo apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_webp_detect . $_webp_load . '</script>' );
831
+            echo apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_webp_detect.$_webp_load.'</script>');
832 832
         }
833 833
     }
834 834
 
@@ -836,10 +836,10 @@  discard block
 block discarded – undo
836 836
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
837 837
         static $cdn_url = null;
838 838
 
839
-        if ( null === $cdn_url ) {
840
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
841
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
842
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
839
+        if (null === $cdn_url) {
840
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
841
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
842
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
843 843
         }
844 844
 
845 845
         return $cdn_url;
@@ -849,47 +849,47 @@  discard block
 block discarded – undo
849 849
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
850 850
         static $exclude_lazyload_array = null;
851 851
 
852
-        if ( null === $exclude_lazyload_array ) {
852
+        if (null === $exclude_lazyload_array) {
853 853
             $options = $this->options;
854 854
 
855 855
             // set default exclusions.
856
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
856
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
857 857
 
858 858
             // add from setting.
859
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
859
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
860 860
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
861
-                if ( ! empty( $exclude_lazyload_option ) ) {
862
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
861
+                if (!empty($exclude_lazyload_option)) {
862
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
863 863
                 }
864 864
             }
865 865
 
866 866
             // and filter for developer-initiated changes.
867
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
867
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
868 868
         }
869 869
 
870 870
         return $exclude_lazyload_array;
871 871
     }
872 872
 
873
-    public function inject_classes_in_tag( $tag, $target_class ) {
874
-        if ( strpos( $tag, 'class=' ) !== false ) {
875
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
873
+    public function inject_classes_in_tag($tag, $target_class) {
874
+        if (strpos($tag, 'class=') !== false) {
875
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
876 876
         } else {
877
-            $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
877
+            $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag);
878 878
         }
879 879
 
880 880
         return $tag;
881 881
     }
882 882
 
883
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
884
-        return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20' . $imgopt_w . '%20' . $imgopt_h . '%22%3E%3C/svg%3E';
883
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
884
+        return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20'.$imgopt_w.'%20'.$imgopt_h.'%22%3E%3C/svg%3E';
885 885
     }
886 886
 
887 887
     public function should_webp() {
888 888
         static $webp_return = null;
889 889
 
890
-        if ( is_null( $webp_return ) ) {
890
+        if (is_null($webp_return)) {
891 891
             // webp only works if imgopt and lazyload are also active.
892
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
892
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
893 893
                 $webp_return = true;
894 894
             } else {
895 895
                 $webp_return = false;
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
         return $webp_return;
900 900
     }
901 901
 
902
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
902
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
903 903
         // check if "<picture" is present and if filter allows us to process <picture>.
904
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
904
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
905 905
             return $in;
906 906
         }
907 907
 
@@ -909,37 +909,37 @@  discard block
 block discarded – undo
909 909
         $to_replace_pict = array();
910 910
 
911 911
         // extract and process each picture-node.
912
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
913
-        foreach ( $_pictures as $_picture ) {
914
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
915
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
916
-                foreach ( $_sources as $_source ) {
912
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
913
+        foreach ($_pictures as $_picture) {
914
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
915
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
916
+                foreach ($_sources as $_source) {
917 917
                     $_picture_replacement = $_source[0];
918 918
 
919 919
                     // should we optimize the image?
920
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
921
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
920
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
921
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
922 922
                     }
923 923
                     // should we lazy-load?
924
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
925
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
924
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
925
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
926 926
                     }
927
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
927
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
928 928
                 }
929 929
             }
930 930
         }
931 931
 
932 932
         // and return the fully procesed $in.
933
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
933
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
934 934
 
935 935
         return $out;
936 936
     }
937 937
 
938
-    public function process_bgimage( $in ) {
939
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
938
+    public function process_bgimage($in) {
939
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
940 940
             $out = preg_replace_callback(
941 941
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
942
-                array( $this, 'lazyload_bgimg_callback' ),
942
+                array($this, 'lazyload_bgimg_callback'),
943 943
                 $in
944 944
             );
945 945
             return $out;
@@ -947,27 +947,27 @@  discard block
 block discarded – undo
947 947
         return $in;
948 948
     }
949 949
 
950
-    public function lazyload_bgimg_callback( $matches ) {
951
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
950
+    public function lazyload_bgimg_callback($matches) {
951
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
952 952
             // get placeholder & lazyload class strings.
953
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
954
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
953
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
954
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
955 955
             // replace background-image URL with SVG placeholder.
956
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
956
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
957 957
             // add data-bg attribute with real background-image URL for lazyload to pick up.
958
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
958
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
959 959
             // add lazyload class to tag.
960
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
960
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
961 961
             return $out;
962 962
         }
963 963
         return $matches[0];
964 964
     }
965 965
 
966
-    public function maybe_fix_missing_quotes( $tag_in ) {
966
+    public function maybe_fix_missing_quotes($tag_in) {
967 967
         // W3TC's Minify_HTML class removes quotes around attribute value, this re-adds them for the class and width/height attributes so we can lazyload properly.
968
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
969
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
970
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
968
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
969
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
970
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
971 971
             return $tag_out;
972 972
         } else {
973 973
             return $tag_in;
@@ -980,23 +980,23 @@  discard block
 block discarded – undo
980 980
     public function imgopt_admin_menu()
981 981
     {
982 982
         // no acces if multisite and not network admin and no site config allowed.
983
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
983
+        if (autoptimizeConfig::should_show_menu_tabs()) {
984 984
             add_submenu_page(
985 985
                 null,
986 986
                 'autoptimize_imgopt',
987 987
                 'autoptimize_imgopt',
988 988
                 'manage_options',
989 989
                 'autoptimize_imgopt',
990
-                array( $this, 'imgopt_options_page' )
990
+                array($this, 'imgopt_options_page')
991 991
             );
992 992
         }
993
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
993
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
994 994
     }
995 995
 
996
-    public function add_imgopt_tab( $in )
996
+    public function add_imgopt_tab($in)
997 997
     {
998
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
999
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
998
+        if (autoptimizeConfig::should_show_menu_tabs()) {
999
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1000 1000
         }
1001 1001
 
1002 1002
         return $in;
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     public function imgopt_options_page()
1006 1006
     {
1007 1007
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1008
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1008
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1009 1009
             $this->query_img_provider_stats();
1010 1010
         }
1011 1011
 
@@ -1017,47 +1017,47 @@  discard block
 block discarded – undo
1017 1017
         #ao_settings_form .form-table th {font-weight: normal;}
1018 1018
         #autoptimize_imgopt_descr{font-size: 120%;}
1019 1019
     </style>
1020
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1020
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1021 1021
     <div class="wrap">
1022
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1022
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1023 1023
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1024
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1024
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1025 1025
             <div class="notice-warning notice"><p>
1026 1026
             <?php
1027 1027
             // translators: "Autoptimize support forum" will appear in a "a href".
1028
-            echo sprintf( __( 'The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize' ), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>' );
1028
+            echo sprintf(__('The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize'), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>');
1029 1029
             ?>
1030 1030
             </p></div>
1031 1031
         <?php } ?>
1032 1032
 
1033
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1033
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1034 1034
             <div class="notice-warning notice"><p>
1035
-            <?php _e( 'The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize' ); ?>
1035
+            <?php _e('The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize'); ?>
1036 1036
             </p></div>
1037 1037
         <?php } ?>
1038 1038
 
1039
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1039
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1040 1040
             <div class="notice-warning notice"><p>
1041 1041
             <?php
1042 1042
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1043
-            echo sprintf( __( 'Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize' ), '<a href="admin.php?page=jetpack#/settings">', '</a>' );
1043
+            echo sprintf(__('Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize'), '<a href="admin.php?page=jetpack#/settings">', '</a>');
1044 1044
             ?>
1045 1045
             </p></div>
1046 1046
         <?php } ?>
1047
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1048
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1049
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1050
-        <span id='autoptimize_imgopt_descr'><?php _e( 'Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize' ); ?></span>
1047
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1048
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1049
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1050
+        <span id='autoptimize_imgopt_descr'><?php _e('Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize'); ?></span>
1051 1051
         <table class="form-table">
1052 1052
             <tr>
1053
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1053
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1054 1054
                 <td>
1055
-                    <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize' ); ?></label>
1055
+                    <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_1']) && '1' === $options['autoptimize_imgopt_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize'); ?></label>
1056 1056
                     <?php
1057 1057
                     // show shortpixel status.
1058 1058
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1059
-                    if ( $_notice ) {
1060
-                        switch ( $_notice['status'] ) {
1059
+                    if ($_notice) {
1060
+                        switch ($_notice['status']) {
1061 1061
                             case 2:
1062 1062
                                 $_notice_color = 'green';
1063 1063
                                 break;
@@ -1072,29 +1072,29 @@  discard block
 block discarded – undo
1072 1072
                             default:
1073 1073
                                 $_notice_color = 'green';
1074 1074
                         }
1075
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1075
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1076 1076
                     } else {
1077 1077
                         // translators: link points to shortpixel.
1078
-                        $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1079
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1080
-                            $upsell_msg_2 = __( 'For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize' );
1078
+                        $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1079
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1080
+                            $upsell_msg_2 = __('For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize');
1081 1081
                         } else {
1082 1082
                             // translators: link points to shortpixel.
1083
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive a 1 000 bonus + 50&#37; more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1083
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive a 1 000 bonus + 50&#37; more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1084 1084
                         }
1085
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1085
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1086 1086
                     }
1087 1087
                     // translators: link points to shortpixel FAQ.
1088
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>' );
1089
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1088
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>');
1089
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1090 1090
                     // translators: links points to shortpixel TOS & Privacy Policy.
1091
-                    $toscopy = sprintf( __( 'Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize' ), '<a href="https://shortpixel.com/tos' . $sp_url_suffix . '" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp' . $sp_url_suffix . '" target="_blank">', '</a>' );
1092
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1091
+                    $toscopy = sprintf(__('Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize'), '<a href="https://shortpixel.com/tos'.$sp_url_suffix.'" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp'.$sp_url_suffix.'" target="_blank">', '</a>');
1092
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1093 1093
                     ?>
1094 1094
                 </td>
1095 1095
             </tr>
1096
-            <tr id='autoptimize_imgopt_quality' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1097
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1096
+            <tr id='autoptimize_imgopt_quality' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1097
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1098 1098
                 <td>
1099 1099
                     <label>
1100 1100
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1102,12 +1102,12 @@  discard block
 block discarded – undo
1102 1102
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1103 1103
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1104 1104
 
1105
-                        foreach ( $_imgopt_array as $key => $value ) {
1106
-                            echo '<option value="' . $key . '"';
1107
-                            if ( $_imgopt_val == $key ) {
1105
+                        foreach ($_imgopt_array as $key => $value) {
1106
+                            echo '<option value="'.$key.'"';
1107
+                            if ($_imgopt_val == $key) {
1108 1108
                                 echo ' selected';
1109 1109
                             }
1110
-                            echo '>' . ucfirst( $value ) . '</option>';
1110
+                            echo '>'.ucfirst($value).'</option>';
1111 1111
                         }
1112 1112
                         echo "\n";
1113 1113
                         ?>
@@ -1116,31 +1116,31 @@  discard block
 block discarded – undo
1116 1116
                     <p>
1117 1117
                         <?php
1118 1118
                             // translators: link points to shortpixel image test page.
1119
-                            echo apply_filters( 'autoptimize_imgopt_imgopt_quality_copy', sprintf( __( 'You can %1$stest compression levels here%2$s.', 'autoptimize' ), '<a href="https://shortpixel.com/oic' . $sp_url_suffix . '" target="_blank">', '</a>' ) );
1119
+                            echo apply_filters('autoptimize_imgopt_imgopt_quality_copy', sprintf(__('You can %1$stest compression levels here%2$s.', 'autoptimize'), '<a href="https://shortpixel.com/oic'.$sp_url_suffix.'" target="_blank">', '</a>'));
1120 1120
                         ?>
1121 1121
                     </p>
1122 1122
                 </td>
1123 1123
             </tr>
1124
-            <tr id='autoptimize_imgopt_webp' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>>
1125
-                <th scope="row"><?php _e( 'Load WebP in supported browsers?', 'autoptimize' ); ?></th>
1124
+            <tr id='autoptimize_imgopt_webp' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>>
1125
+                <th scope="row"><?php _e('Load WebP in supported browsers?', 'autoptimize'); ?></th>
1126 1126
                 <td>
1127
-                    <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_4'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label>
1127
+                    <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_4']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label>
1128 1128
                 </td>
1129 1129
             </tr>
1130 1130
             <tr>
1131
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1131
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1132 1132
                 <td>
1133
-                    <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize' ); ?></label>
1133
+                    <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_3']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize'); ?></label>
1134 1134
                 </td>
1135 1135
             </tr>
1136
-            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="hidden"'; } ?>>
1137
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1136
+            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="hidden"'; } ?>>
1137
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1138 1138
                 <td>
1139
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label>
1139
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label>
1140 1140
                 </td>
1141 1141
             </tr>
1142 1142
         </table>
1143
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1143
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1144 1144
     </form>
1145 1145
     <script>
1146 1146
         jQuery(document).ready(function() {
@@ -1176,50 +1176,50 @@  discard block
 block discarded – undo
1176 1176
      * Ïmg opt status as used on dashboard.
1177 1177
      */
1178 1178
     public function get_imgopt_status_notice() {
1179
-        if ( $this->imgopt_active() ) {
1179
+        if ($this->imgopt_active()) {
1180 1180
             $_imgopt_notice  = '';
1181
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1181
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1182 1182
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1183
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1183
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1184 1184
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1185 1185
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1186 1186
 
1187
-            if ( is_array( $_stat ) ) {
1188
-                if ( 1 == $_stat['Status'] ) {
1187
+            if (is_array($_stat)) {
1188
+                if (1 == $_stat['Status']) {
1189 1189
                     // translators: "add more credits" will appear in a "a href".
1190
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1190
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1191 1191
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1192 1192
                     // translators: "add more credits" will appear in a "a href".
1193
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1193
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1194 1194
                     // translators: "associate your domain" will appear in a "a href".
1195
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '<a rel="noopener noreferrer" href="' . $_imgopt_assoc . '" target="_blank">', '</a>' );
1195
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize'), '<a rel="noopener noreferrer" href="'.$_imgopt_assoc.'" target="_blank">', '</a>');
1196 1196
                 } elseif ( -3 == $_stat['Status'] ) {
1197 1197
                     // translators: "check the documentation here" will appear in a "a href".
1198
-                    $_imgopt_notice = sprintf( __( 'It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize' ), '<a href="' . $_imgopt_unreach . '" target="_blank">', '</a>' );
1198
+                    $_imgopt_notice = sprintf(__('It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize'), '<a href="'.$_imgopt_unreach.'" target="_blank">', '</a>');
1199 1199
                 } else {
1200 1200
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1201 1201
                     // translators: "log in to check your account" will appear in a "a href".
1202
-                    $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' );
1202
+                    $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>');
1203 1203
                 }
1204 1204
 
1205 1205
                 // add info on freshness + refresh link if status is not 2 (good shape).
1206
-                if ( 2 != $_stat['Status'] ) {
1207
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1206
+                if (2 != $_stat['Status']) {
1207
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1208 1208
                         'page'                => 'autoptimize_imgopt',
1209 1209
                         'refreshImgProvStats' => '1',
1210
-                    ), admin_url( 'options-general.php' ) );
1211
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1212
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1210
+                    ), admin_url('options-general.php'));
1211
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1212
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1213 1213
                     } else {
1214
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1214
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1215 1215
                     }
1216
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1216
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1217 1217
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1218
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1218
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1219 1219
                 }
1220 1220
 
1221 1221
                 // and make the full notice filterable.
1222
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1222
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1223 1223
 
1224 1224
                 return array(
1225 1225
                     'status' => $_stat['Status'],
@@ -1240,14 +1240,14 @@  discard block
 block discarded – undo
1240 1240
      * Get img provider stats (used to display notice).
1241 1241
      */
1242 1242
     public function query_img_provider_stats() {
1243
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1243
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1244 1244
             $url      = '';
1245
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1245
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1246 1246
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1247 1247
 
1248 1248
             // make sure parse_url result makes sense, keeping $url empty if not.
1249
-            if ( $domain && ! empty( $domain ) ) {
1250
-                $url = $endpoint . $domain;
1249
+            if ($domain && !empty($domain)) {
1250
+                $url = $endpoint.$domain;
1251 1251
             }
1252 1252
 
1253 1253
             $url = apply_filters(
@@ -1257,12 +1257,12 @@  discard block
 block discarded – undo
1257 1257
 
1258 1258
             // only do the remote call if $url is not empty to make sure no parse_url
1259 1259
             // weirdness results in useless calls.
1260
-            if ( ! empty( $url ) ) {
1261
-                $response = wp_remote_get( $url );
1262
-                if ( ! is_wp_error( $response ) ) {
1263
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1264
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1265
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1260
+            if (!empty($url)) {
1261
+                $response = wp_remote_get($url);
1262
+                if (!is_wp_error($response)) {
1263
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1264
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1265
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1266 1266
                     }
1267 1267
                 }
1268 1268
             }
@@ -1285,15 +1285,15 @@  discard block
 block discarded – undo
1285 1285
     {
1286 1286
         static $launch_status = null;
1287 1287
 
1288
-        if ( null === $launch_status ) {
1288
+        if (null === $launch_status) {
1289 1289
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1290
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1291
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1290
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1291
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1292 1292
             $launch_status = false;
1293
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1293
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1294 1294
                 $launch_status = true;
1295
-                if ( ! $has_launched ) {
1296
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1295
+                if (!$has_launched) {
1296
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1297 1297
                 }
1298 1298
             }
1299 1299
         }
@@ -1310,16 +1310,16 @@  discard block
 block discarded – undo
1310 1310
     public function get_imgopt_provider_userstatus() {
1311 1311
         static $_provider_userstatus = null;
1312 1312
 
1313
-        if ( is_null( $_provider_userstatus ) ) {
1314
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1315
-            if ( is_array( $_stat ) ) {
1316
-                if ( array_key_exists( 'Status', $_stat ) ) {
1313
+        if (is_null($_provider_userstatus)) {
1314
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1315
+            if (is_array($_stat)) {
1316
+                if (array_key_exists('Status', $_stat)) {
1317 1317
                     $_provider_userstatus['Status'] = $_stat['Status'];
1318 1318
                 } else {
1319 1319
                     // if no stats then we assume all is well.
1320 1320
                     $_provider_userstatus['Status'] = 2;
1321 1321
                 }
1322
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1322
+                if (array_key_exists('timestamp', $_stat)) {
1323 1323
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1324 1324
                 } else {
1325 1325
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/external/php/minify-html.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     {
74 74
         $this->_html = str_replace("\r\n", "\n", trim($html));
75 75
         if (isset($options['xhtml'])) {
76
-            $this->_isXhtml = (bool)$options['xhtml'];
76
+            $this->_isXhtml = (bool) $options['xhtml'];
77 77
         }
78 78
         if (isset($options['cssMinifier'])) {
79 79
             $this->_cssMinifier = $options['cssMinifier'];
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
99 99
         }
100 100
 
101
-        $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
101
+        $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']);
102 102
         $this->_placeholders = array();
103 103
 
104 104
         // replace SCRIPTs (and minify) with placeholders
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             ,$this->_html);
115 115
 
116 116
         // remove HTML comments (not containing IE conditional comments).
117
-        if  ($this->_keepComments == false) {
117
+        if ($this->_keepComments == false) {
118 118
             $this->_html = preg_replace_callback(
119 119
                 '/<!--([\\s\\S]*?)-->/'
120 120
                 ,array($this, '_commentCB')
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
160 160
 
161 161
         // reverse order while preserving keys to ensure the last replacement is done first, etc ...
162
-        $this->_placeholders = array_reverse( $this->_placeholders, true );
162
+        $this->_placeholders = array_reverse($this->_placeholders, true);
163 163
 
164 164
         // fill placeholders
165 165
         $this->_html = str_replace(
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
     protected function _reservePlace($content)
181 181
     {
182
-        $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
182
+        $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%';
183 183
         $this->_placeholders[$placeholder] = $content;
184 184
         return $placeholder;
185 185
     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 
194 194
     protected function _outsideTagCB($m)
195 195
     {
196
-        return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
196
+        return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<';
197 197
     }
198 198
 
199 199
     protected function _removePreCB($m)
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     protected function _removeCdata($str)
266 266
     {
267 267
         return (false !== strpos($str, '<![CDATA['))
268
-            ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
268
+            ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str)
269 269
             : $str;
270 270
     }
271 271
 
Please login to merge, or discard this patch.
classes/autoptimizeMain.php 1 patch
Spacing   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @param string $version Version.
34 34
      * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks.
35 35
      */
36
-    public function __construct( $version, $filepath )
36
+    public function __construct($version, $filepath)
37 37
     {
38 38
         $this->version  = $version;
39 39
         $this->filepath = $filepath;
@@ -50,102 +50,102 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected function add_hooks()
52 52
     {
53
-        if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) {
54
-            define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' );
53
+        if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) {
54
+            define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded');
55 55
         }
56 56
 
57
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) );
58
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) );
57
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup'));
58
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge'));
59 59
 
60
-        add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) );
61
-        add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) );
62
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ), 15 );
63
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ), 20 );
64
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss' ), 11 );
65
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_notfound_fallback' ), 10 );
60
+        add_action('autoptimize_setup_done', array($this, 'version_upgrades_check'));
61
+        add_action('autoptimize_setup_done', array($this, 'check_cache_and_run'));
62
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'), 15);
63
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'), 20);
64
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_criticalcss'), 11);
65
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_notfound_fallback'), 10);
66 66
 
67
-        add_action( 'init', array( $this, 'load_textdomain' ) );
68
-        add_action( 'admin_init', array( 'PAnD', 'init' ) );
67
+        add_action('init', array($this, 'load_textdomain'));
68
+        add_action('admin_init', array('PAnD', 'init'));
69 69
 
70
-        if ( is_multisite() && is_admin() ) {
70
+        if (is_multisite() && is_admin()) {
71 71
             // Only if multisite and if in admin we want to check if we need to save options on network level.
72
-            add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' );
72
+            add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options');
73 73
         }
74 74
 
75 75
         // register uninstall & deactivation hooks.
76
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
77
-        register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' );
76
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
77
+        register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation');
78 78
     }
79 79
 
80 80
     public function load_textdomain()
81 81
     {
82
-        load_plugin_textdomain( 'autoptimize' );
82
+        load_plugin_textdomain('autoptimize');
83 83
     }
84 84
 
85 85
     public function setup()
86 86
     {
87 87
         // Do we gzip in php when caching or is the webserver doing it?
88
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) );
88
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip'));
89 89
 
90 90
         // These can be overridden by specifying them in wp-config.php or such.
91
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
92
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
91
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
92
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
93 93
         }
94
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
95
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
94
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
95
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
96 96
         }
97
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
98
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
97
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
98
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
99 99
         }
100 100
         // Note: trailing slash is not optional!
101
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
102
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
101
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
102
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
103 103
         }
104 104
 
105
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
105
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
106 106
 
107
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
108
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
109
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
107
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
108
+            if (function_exists('domain_mapping_siteurl')) {
109
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
110 110
             } else {
111
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
111
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
112 112
             }
113 113
         }
114
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
115
-            if ( function_exists( 'get_original_url' ) ) {
116
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
114
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
115
+            if (function_exists('get_original_url')) {
116
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
117 117
             } else {
118
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
118
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
119 119
             }
120 120
         }
121
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
122
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
121
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
122
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
123 123
                 $blog_id = get_current_blog_id();
124
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
124
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
125 125
             } else {
126
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
126
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
127 127
             }
128 128
         }
129
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
130
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
129
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
130
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
131 131
         }
132
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
133
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
132
+        if (!defined('AUTOPTIMIZE_HASH')) {
133
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
134 134
         }
135
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
136
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
135
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
136
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
137 137
         }
138 138
 
139 139
         // Multibyte-capable string replacements are available with a filter.
140 140
         // Also requires 'mbstring' extension.
141
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
142
-        if ( $with_mbstring ) {
143
-            autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) );
141
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
142
+        if ($with_mbstring) {
143
+            autoptimizeUtils::mbstring_available(\extension_loaded('mbstring'));
144 144
         } else {
145
-            autoptimizeUtils::mbstring_available( false );
145
+            autoptimizeUtils::mbstring_available(false);
146 146
         }
147 147
 
148
-        do_action( 'autoptimize_setup_done' );
148
+        do_action('autoptimize_setup_done');
149 149
     }
150 150
 
151 151
     /**
@@ -155,61 +155,61 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function version_upgrades_check()
157 157
     {
158
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
158
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
159 159
     }
160 160
 
161 161
     public function check_cache_and_run()
162 162
     {
163
-        if ( autoptimizeCache::cacheavail() ) {
163
+        if (autoptimizeCache::cacheavail()) {
164 164
             $conf = autoptimizeConfig::instance();
165
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) {
166
-                if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) {
165
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) {
166
+                if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) {
167 167
                     // Hook into WordPress frontend.
168
-                    if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
168
+                    if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
169 169
                         add_action(
170 170
                             'init',
171
-                            array( $this, 'start_buffering' ),
171
+                            array($this, 'start_buffering'),
172 172
                             self::INIT_EARLIER_PRIORITY
173 173
                         );
174 174
                     } else {
175
-                        if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
176
-                            define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
175
+                        if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
176
+                            define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
177 177
                         }
178 178
                         add_action(
179
-                            constant( 'AUTOPTIMIZE_HOOK_INTO' ),
180
-                            array( $this, 'start_buffering' ),
179
+                            constant('AUTOPTIMIZE_HOOK_INTO'),
180
+                            array($this, 'start_buffering'),
181 181
                             self::DEFAULT_HOOK_PRIORITY
182 182
                         );
183 183
                     }
184 184
                 }
185 185
 
186 186
                 // And disable Jetpack's site accelerator if JS or CSS opt. are active.
187
-                if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) {
188
-                    add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
187
+                if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) {
188
+                    add_filter('jetpack_force_disable_site_accelerator', '__return_true');
189 189
                 }
190 190
             }
191 191
         } else {
192
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
192
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
193 193
         }
194 194
     }
195 195
 
196 196
     public function maybe_run_ao_extra()
197 197
     {
198
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
198
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
199 199
             $ao_imgopt = new autoptimizeImages();
200 200
             $ao_imgopt->run();
201 201
             $ao_extra = new autoptimizeExtra();
202 202
             $ao_extra->run();
203 203
 
204 204
             // And show the imgopt notice.
205
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
205
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
206 206
         }
207 207
     }
208 208
 
209 209
     public function maybe_run_partners_tab()
210 210
     {
211 211
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
212
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
212
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
213 213
             new autoptimizePartners();
214 214
         }
215 215
     }
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
     public function maybe_run_criticalcss()
218 218
     {
219 219
         // Loads criticalcss if the power-up is not active and if the filter returns true.
220
-        if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
220
+        if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) {
221 221
             new autoptimizeCriticalCSSBase();
222 222
         }
223 223
     }
224 224
 
225 225
     public function maybe_run_notfound_fallback()
226 226
     {
227
-        if ( autoptimizeCache::do_fallback() ) {
228
-            add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) );
227
+        if (autoptimizeCache::do_fallback()) {
228
+            add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback'));
229 229
         }
230 230
     }
231 231
 
232 232
     public function hook_page_cache_purge()
233 233
     {
234 234
         // hook into a collection of page cache purge actions if filter allows.
235
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
235
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
236 236
             $page_cache_purge_actions = array(
237 237
                 'after_rocket_clean_domain', // exists.
238 238
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
                 'wpo_cache_flush', // wp-optimize.
248 248
                 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper.
249 249
             );
250
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
251
-            foreach ( $page_cache_purge_actions as $purge_action ) {
252
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
250
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
251
+            foreach ($page_cache_purge_actions as $purge_action) {
252
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
253 253
             }
254 254
         }
255 255
     }
@@ -261,38 +261,38 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function start_buffering()
263 263
     {
264
-        if ( $this->should_buffer() ) {
264
+        if ($this->should_buffer()) {
265 265
 
266 266
             // Load speedupper conditionally (true by default).
267
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
267
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
268 268
                 $ao_speedupper = new autoptimizeSpeedupper();
269 269
             }
270 270
 
271 271
             $conf = autoptimizeConfig::instance();
272 272
 
273
-            if ( $conf->get( 'autoptimize_js' ) ) {
274
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
275
-                    define( 'CONCATENATE_SCRIPTS', false );
273
+            if ($conf->get('autoptimize_js')) {
274
+                if (!defined('CONCATENATE_SCRIPTS')) {
275
+                    define('CONCATENATE_SCRIPTS', false);
276 276
                 }
277
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
278
-                    define( 'COMPRESS_SCRIPTS', false );
277
+                if (!defined('COMPRESS_SCRIPTS')) {
278
+                    define('COMPRESS_SCRIPTS', false);
279 279
                 }
280 280
             }
281 281
 
282
-            if ( $conf->get( 'autoptimize_css' ) ) {
283
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
284
-                    define( 'COMPRESS_CSS', false );
282
+            if ($conf->get('autoptimize_css')) {
283
+                if (!defined('COMPRESS_CSS')) {
284
+                    define('COMPRESS_CSS', false);
285 285
                 }
286 286
             }
287 287
 
288
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
289
-                while ( ob_get_level() > 0 ) {
288
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
289
+                while (ob_get_level() > 0) {
290 290
                     ob_end_clean();
291 291
                 }
292 292
             }
293 293
 
294 294
             // Now, start the real thing!
295
-            ob_start( array( $this, 'end_buffering' ) );
295
+            ob_start(array($this, 'end_buffering'));
296 296
         }
297 297
     }
298 298
 
@@ -303,31 +303,31 @@  discard block
 block discarded – undo
303 303
      *                          deciding once per request (for use in tests).
304 304
      * @return bool
305 305
      */
306
-    public static function should_buffer( $doing_tests = false )
306
+    public static function should_buffer($doing_tests = false)
307 307
     {
308 308
         static $do_buffering = null;
309 309
 
310 310
         // Only check once in case we're called multiple times by others but
311 311
         // still allows multiple calls when doing tests.
312
-        if ( null === $do_buffering || $doing_tests ) {
312
+        if (null === $do_buffering || $doing_tests) {
313 313
 
314 314
             $ao_noptimize = false;
315 315
 
316 316
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
317
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
317
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
318 318
                 $ao_noptimize = true;
319 319
             }
320 320
 
321 321
             // Skip checking query strings if they're disabled.
322
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
322
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
323 323
                 // Check for `ao_noptimize` (and other) keys in the query string
324 324
                 // to get non-optimized page for debugging.
325 325
                 $keys = array(
326 326
                     'ao_noptimize',
327 327
                     'ao_noptirocket',
328 328
                 );
329
-                foreach ( $keys as $key ) {
330
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
329
+                foreach ($keys as $key) {
330
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
331 331
                         $ao_noptimize = true;
332 332
                         break;
333 333
                     }
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
             }
336 336
 
337 337
             // If setting says not to optimize logged in user and user is logged in...
338
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
338
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
339 339
                 $ao_noptimize = true;
340 340
             }
341 341
 
342 342
             // If setting says not to optimize cart/checkout.
343
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) {
343
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) {
344 344
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
345
-                foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
346
-                    if ( function_exists( $func ) && $func() ) {
345
+                foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
346
+                    if (function_exists($func) && $func()) {
347 347
                         $ao_noptimize = true;
348 348
                         break;
349 349
                     }
@@ -351,10 +351,10 @@  discard block
 block discarded – undo
351 351
             }
352 352
 
353 353
             // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
354
-            if ( false === $ao_noptimize ) {
355
-                $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
356
-                foreach ( $_qs_pagebuilders as $_pagebuilder ) {
357
-                    if ( array_key_exists( $_pagebuilder, $_GET ) ) {
354
+            if (false === $ao_noptimize) {
355
+                $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor');
356
+                foreach ($_qs_pagebuilders as $_pagebuilder) {
357
+                    if (array_key_exists($_pagebuilder, $_GET)) {
358 358
                         $ao_noptimize = true;
359 359
                         break;
360 360
                     }
@@ -363,16 +363,16 @@  discard block
 block discarded – undo
363 363
 
364 364
             // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
365 365
             // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
366
-            if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
366
+            if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
367 367
                 $ao_noptimize = true;
368 368
             }
369 369
 
370 370
             // And finally allows blocking of autoptimization on your own terms regardless of above decisions.
371
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
371
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
372 372
 
373 373
             // Check for site being previewed in the Customizer (available since WP 4.0).
374 374
             $is_customize_preview = false;
375
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
375
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
376 376
                 $is_customize_preview = is_customize_preview();
377 377
             }
378 378
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
              * while the main query hasn't been ran yet. Thats why we use
384 384
              * AUTOPTIMIZE_INIT_EARLIER in tests.
385 385
              */
386
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview );
386
+            $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview);
387 387
         }
388 388
 
389 389
         return $do_buffering;
@@ -396,25 +396,25 @@  discard block
 block discarded – undo
396 396
      *
397 397
      * @return bool
398 398
      */
399
-    public function is_valid_buffer( $content )
399
+    public function is_valid_buffer($content)
400 400
     {
401 401
         // Defaults to true.
402 402
         $valid = true;
403 403
 
404
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
405
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) );
406
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 );
407
-        $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) );
404
+        $has_no_html_tag    = (false === stripos($content, '<html'));
405
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet'));
406
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0);
407
+        $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->'));
408 408
 
409
-        if ( $has_no_html_tag ) {
409
+        if ($has_no_html_tag) {
410 410
             // Can't be valid amp markup without an html tag preceding it.
411 411
             $is_amp_markup = false;
412 412
         } else {
413
-            $is_amp_markup = self::is_amp_markup( $content );
413
+            $is_amp_markup = self::is_amp_markup($content);
414 414
         }
415 415
 
416 416
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
417
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) {
417
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) {
418 418
             $valid = false;
419 419
         }
420 420
 
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
      *
430 430
      * @return bool
431 431
      */
432
-    public static function is_amp_markup( $content )
432
+    public static function is_amp_markup($content)
433 433
     {
434 434
         // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page.
435
-        if ( function_exists( 'is_amp_endpoint' ) ) {
435
+        if (function_exists('is_amp_endpoint')) {
436 436
             return is_amp_endpoint();
437 437
         }
438 438
 
439
-        $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content );
439
+        $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content);
440 440
 
441 441
         return (bool) $is_amp_markup;
442 442
     }
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
      *
450 450
      * @return string
451 451
      */
452
-    public function end_buffering( $content )
452
+    public function end_buffering($content)
453 453
     {
454 454
         // Bail early without modifying anything if we can't handle the content.
455
-        if ( ! $this->is_valid_buffer( $content ) ) {
455
+        if (!$this->is_valid_buffer($content)) {
456 456
             return $content;
457 457
         }
458 458
 
@@ -460,73 +460,73 @@  discard block
 block discarded – undo
460 460
 
461 461
         // Determine what needs to be ran.
462 462
         $classes = array();
463
-        if ( $conf->get( 'autoptimize_js' ) ) {
463
+        if ($conf->get('autoptimize_js')) {
464 464
             $classes[] = 'autoptimizeScripts';
465 465
         }
466
-        if ( $conf->get( 'autoptimize_css' ) ) {
466
+        if ($conf->get('autoptimize_css')) {
467 467
             $classes[] = 'autoptimizeStyles';
468 468
         }
469
-        if ( $conf->get( 'autoptimize_html' ) ) {
469
+        if ($conf->get('autoptimize_html')) {
470 470
             $classes[] = 'autoptimizeHTML';
471 471
         }
472 472
 
473 473
         $classoptions = array(
474 474
             'autoptimizeScripts' => array(
475
-                'aggregate'       => $conf->get( 'autoptimize_js_aggregate' ),
476
-                'justhead'        => $conf->get( 'autoptimize_js_justhead' ),
477
-                'forcehead'       => $conf->get( 'autoptimize_js_forcehead' ),
478
-                'trycatch'        => $conf->get( 'autoptimize_js_trycatch' ),
479
-                'js_exclude'      => $conf->get( 'autoptimize_js_exclude' ),
480
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
481
-                'include_inline'  => $conf->get( 'autoptimize_js_include_inline' ),
482
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
475
+                'aggregate'       => $conf->get('autoptimize_js_aggregate'),
476
+                'justhead'        => $conf->get('autoptimize_js_justhead'),
477
+                'forcehead'       => $conf->get('autoptimize_js_forcehead'),
478
+                'trycatch'        => $conf->get('autoptimize_js_trycatch'),
479
+                'js_exclude'      => $conf->get('autoptimize_js_exclude'),
480
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
481
+                'include_inline'  => $conf->get('autoptimize_js_include_inline'),
482
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
483 483
             ),
484 484
             'autoptimizeStyles'  => array(
485
-                'aggregate'       => $conf->get( 'autoptimize_css_aggregate' ),
486
-                'justhead'        => $conf->get( 'autoptimize_css_justhead' ),
487
-                'datauris'        => $conf->get( 'autoptimize_css_datauris' ),
488
-                'defer'           => $conf->get( 'autoptimize_css_defer' ),
489
-                'defer_inline'    => $conf->get( 'autoptimize_css_defer_inline' ),
490
-                'inline'          => $conf->get( 'autoptimize_css_inline' ),
491
-                'css_exclude'     => $conf->get( 'autoptimize_css_exclude' ),
492
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
493
-                'include_inline'  => $conf->get( 'autoptimize_css_include_inline' ),
494
-                'nogooglefont'    => $conf->get( 'autoptimize_css_nogooglefont' ),
495
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
485
+                'aggregate'       => $conf->get('autoptimize_css_aggregate'),
486
+                'justhead'        => $conf->get('autoptimize_css_justhead'),
487
+                'datauris'        => $conf->get('autoptimize_css_datauris'),
488
+                'defer'           => $conf->get('autoptimize_css_defer'),
489
+                'defer_inline'    => $conf->get('autoptimize_css_defer_inline'),
490
+                'inline'          => $conf->get('autoptimize_css_inline'),
491
+                'css_exclude'     => $conf->get('autoptimize_css_exclude'),
492
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
493
+                'include_inline'  => $conf->get('autoptimize_css_include_inline'),
494
+                'nogooglefont'    => $conf->get('autoptimize_css_nogooglefont'),
495
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
496 496
             ),
497 497
             'autoptimizeHTML'    => array(
498
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
498
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
499 499
             ),
500 500
         );
501 501
 
502
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
502
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
503 503
 
504 504
         // Run the classes!
505
-        foreach ( $classes as $name ) {
506
-            $instance = new $name( $content );
507
-            if ( $instance->read( $classoptions[ $name ] ) ) {
505
+        foreach ($classes as $name) {
506
+            $instance = new $name($content);
507
+            if ($instance->read($classoptions[$name])) {
508 508
                 $instance->minify();
509 509
                 $instance->cache();
510 510
                 $content = $instance->getcontent();
511 511
             }
512
-            unset( $instance );
512
+            unset($instance);
513 513
         }
514 514
 
515
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
515
+        $content = apply_filters('autoptimize_html_after_minify', $content);
516 516
 
517 517
         return $content;
518 518
     }
519 519
 
520
-    public static function autoptimize_nobuffer_optimize( $html_in ) {
520
+    public static function autoptimize_nobuffer_optimize($html_in) {
521 521
         $html_out = $html_in;
522 522
 
523
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
523
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
524 524
             $ao_speedupper = new autoptimizeSpeedupper();
525 525
         }
526 526
 
527
-        $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
528
-        if ( $self->should_buffer() ) {
529
-            $html_out = $self->end_buffering( $html_in );
527
+        $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
528
+        if ($self->should_buffer()) {
529
+            $html_out = $self->end_buffering($html_in);
530 530
         }
531 531
         return $html_out;
532 532
     }
@@ -588,45 +588,45 @@  discard block
 block discarded – undo
588 588
             'autoptimize_ccss_unloadccss',
589 589
         );
590 590
 
591
-        if ( ! is_multisite() ) {
592
-            foreach ( $delete_options as $del_opt ) {
593
-                delete_option( $del_opt );
591
+        if (!is_multisite()) {
592
+            foreach ($delete_options as $del_opt) {
593
+                delete_option($del_opt);
594 594
             }
595 595
             autoptimizeMain::remove_cronjobs();
596 596
         } else {
597 597
             global $wpdb;
598
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
598
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
599 599
             $original_blog_id = get_current_blog_id();
600
-            foreach ( $blog_ids as $blog_id ) {
601
-                switch_to_blog( $blog_id );
602
-                foreach ( $delete_options as $del_opt ) {
603
-                    delete_option( $del_opt );
600
+            foreach ($blog_ids as $blog_id) {
601
+                switch_to_blog($blog_id);
602
+                foreach ($delete_options as $del_opt) {
603
+                    delete_option($del_opt);
604 604
                 }
605 605
                 autoptimizeMain::remove_cronjobs();
606 606
             }
607
-            switch_to_blog( $original_blog_id );
607
+            switch_to_blog($original_blog_id);
608 608
         }
609 609
 
610 610
         // Remove AO CCSS cached files and directory.
611
-        $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/';
612
-        if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) {
611
+        $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/';
612
+        if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) {
613 613
             // fixme: should check for subdirs when in multisite and remove contents of those as well.
614
-            array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) );
615
-            rmdir( $ao_ccss_dir );
614
+            array_map('unlink', glob($ao_ccss_dir.'*.{css,html,json,log,zip,lock}', GLOB_BRACE));
615
+            rmdir($ao_ccss_dir);
616 616
         }
617 617
     }
618 618
 
619 619
     public static function on_deactivation()
620 620
     {
621
-        if ( is_multisite() && is_network_admin() ) {
621
+        if (is_multisite() && is_network_admin()) {
622 622
             global $wpdb;
623
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
623
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
624 624
             $original_blog_id = get_current_blog_id();
625
-            foreach ( $blog_ids as $blog_id ) {
626
-                switch_to_blog( $blog_id );
625
+            foreach ($blog_ids as $blog_id) {
626
+                switch_to_blog($blog_id);
627 627
                 autoptimizeMain::remove_cronjobs();
628 628
             }
629
-            switch_to_blog( $original_blog_id );
629
+            switch_to_blog($original_blog_id);
630 630
         } else {
631 631
             autoptimizeMain::remove_cronjobs();
632 632
         }
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
 
636 636
     public static function remove_cronjobs() {
637 637
         // Remove scheduled events.
638
-        foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) {
639
-            if ( wp_get_schedule( $_event ) ) {
640
-                wp_clear_scheduled_hook( $_event );
638
+        foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) {
639
+            if (wp_get_schedule($_event)) {
640
+                wp_clear_scheduled_hook($_event);
641 641
             }
642 642
         }
643 643
     }
@@ -646,35 +646,35 @@  discard block
 block discarded – undo
646 646
     {
647 647
         echo '<div class="error"><p>';
648 648
         // Translators: %s is the cache directory location.
649
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
649
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
650 650
         echo '</p></div>';
651 651
     }
652 652
 
653 653
     public static function notice_installed()
654 654
     {
655 655
         echo '<div class="updated"><p>';
656
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
656
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
657 657
         echo '</p></div>';
658 658
     }
659 659
 
660 660
     public static function notice_updated()
661 661
     {
662 662
         echo '<div class="updated"><p>';
663
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
663
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
664 664
         echo '</p></div>';
665 665
     }
666 666
 
667 667
     public static function notice_plug_imgopt()
668 668
     {
669 669
         // Translators: the URL added points to the Autopmize Extra settings.
670
-        $_ao_imgopt_plug_notice      = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' );
671
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
670
+        $_ao_imgopt_plug_notice      = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>');
671
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
672 672
         $_ao_imgopt_launch_ok        = autoptimizeImages::launch_ok_wrapper();
673 673
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
674 674
         $_ao_imgopt_active           = autoptimizeImages::imgopt_active();
675 675
 
676
-        if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) {
677
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
676
+        if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) {
677
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
678 678
             echo $_ao_imgopt_plug_notice;
679 679
             echo '</p></div>';
680 680
         }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSEnqueue.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS job enqueue logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
19 19
     }
20 20
 
21
-    public static function ao_ccss_enqueue( $hash ) {
21
+    public static function ao_ccss_enqueue($hash) {
22 22
         $self = new self();
23 23
         // Get key status.
24
-        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( false );
24
+        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(false);
25 25
 
26 26
         // Queue is available to anyone...
27 27
         $enqueue = true;
28 28
 
29 29
         // ... which are not the ones below.
30
-        if ( is_user_logged_in() || is_feed() || is_404() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters( 'autoptimize_filter_ccss_enqueue_should_enqueue', true ) ) {
30
+        if (is_user_logged_in() || is_feed() || is_404() || (defined('DOING_AJAX') && DOING_AJAX) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters('autoptimize_filter_ccss_enqueue_should_enqueue', true)) {
31 31
             $enqueue = false;
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( "Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log("Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3);
33 33
         }
34 34
 
35
-        if ( $enqueue ) {
35
+        if ($enqueue) {
36 36
             // Continue if queue is available
37 37
             // Attach required arrays/ vars.
38 38
             global $ao_ccss_rules;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             global $ao_ccss_forcepath;
42 42
 
43 43
             // Get request path and page type, and initialize the queue update flag.
44
-            $req_path        = strtok( $_SERVER['REQUEST_URI'], '?' );
44
+            $req_path        = strtok($_SERVER['REQUEST_URI'], '?');
45 45
             $req_type        = $self->ao_ccss_get_type();
46 46
             $job_qualify     = false;
47 47
             $target_rule     = false;
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             $queue_update    = false;
50 50
 
51 51
             // Match for paths in rules.
52
-            foreach ( $ao_ccss_rules['paths'] as $path => $props ) {
52
+            foreach ($ao_ccss_rules['paths'] as $path => $props) {
53 53
 
54 54
                 // Prepare rule target and log.
55
-                $target_rule = 'paths|' . $path;
56
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
55
+                $target_rule = 'paths|'.$path;
56
+                autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
57 57
 
58 58
                 // Path match
59 59
                 // -> exact match needed for AUTO rules
60 60
                 // -> partial match OK for MANUAL rules (which have empty hash and a file with CCSS).
61
-                if ( $path === $req_path || ( false == $props['hash'] && false != $props['file'] && preg_match( '|' . $path . '|', $req_path ) ) ) {
61
+                if ($path === $req_path || (false == $props['hash'] && false != $props['file'] && preg_match('|'.$path.'|', $req_path))) {
62 62
 
63 63
                     // There's a path match in the rule, so job QUALIFIES with a path rule match.
64 64
                     $job_qualify     = true;
65 65
                     $rule_properties = $props;
66
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
66
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
67 67
 
68 68
                     // Stop processing other path rules.
69 69
                     break;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
             }
72 72
 
73 73
             // Match for types in rules if no path rule matches and if we're not enforcing paths.
74
-            if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) {
75
-                foreach ( $ao_ccss_rules['types'] as $type => $props ) {
74
+            if (!$job_qualify && (!$ao_ccss_forcepath || !in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page'))) || !apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false))) {
75
+                foreach ($ao_ccss_rules['types'] as $type => $props) {
76 76
 
77 77
                     // Prepare rule target and log.
78
-                    $target_rule = 'types|' . $type;
79
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying page type <' . $req_type . '> on path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
78
+                    $target_rule = 'types|'.$type;
79
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying page type <'.$req_type.'> on path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
80 80
 
81
-                    if ( $req_type == $type ) {
81
+                    if ($req_type == $type) {
82 82
                         // Type match.
83 83
                         // There's a type match in the rule, so job QUALIFIES with a type rule match.
84 84
                         $job_qualify     = true;
85 85
                         $rule_properties = $props;
86
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Page type <' . $req_type . '> on path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
86
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Page type <'.$req_type.'> on path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
87 87
 
88 88
                         // Stop processing other type rules.
89 89
                         break;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 }
92 92
             }
93 93
 
94
-            if ( $job_qualify && ( ( false == $rule_properties['hash'] && false != $rule_properties['file'] ) || strpos( $req_type, 'template_' ) !== false ) ) {
94
+            if ($job_qualify && ((false == $rule_properties['hash'] && false != $rule_properties['file']) || strpos($req_type, 'template_') !== false)) {
95 95
                 // If job qualifies but rule hash is false and file isn't false (MANUAL rule) or if template, job does not qualify despite what previous evaluations says.
96 96
                 $job_qualify = false;
97
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission DISQUALIFIED by MANUAL rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
98
-            } elseif ( ! $job_qualify && empty( $rule_properties ) ) {
97
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission DISQUALIFIED by MANUAL rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
98
+            } elseif (!$job_qualify && empty($rule_properties)) {
99 99
                 // But if job does not qualify and rule properties are set, job qualifies as there is no matching rule for it yet
100 100
                 // Fill-in the new target rule.
101 101
                 $job_qualify = true;
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
                 // Should we switch to path-base AUTO-rules? Conditions:
104 104
                 // 1. forcepath option has to be enabled (off by default)
105 105
                 // 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category).
106
-                if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) {
107
-                    if ( '/' !== $req_path ) {
108
-                        $target_rule = 'paths|' . $req_path;
106
+                if (($ao_ccss_forcepath && in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page')))) || apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false)) {
107
+                    if ('/' !== $req_path) {
108
+                        $target_rule = 'paths|'.$req_path;
109 109
                     } else {
110 110
                         // Exception; we don't want a path-based rule for "/" as that messes things up, hard-switch this to a type-based is_front_page rule.
111
-                        $target_rule = 'types|' . 'is_front_page';
111
+                        $target_rule = 'types|'.'is_front_page';
112 112
                     }
113 113
                 } else {
114
-                    $target_rule = 'types|' . $req_type;
114
+                    $target_rule = 'types|'.$req_type;
115 115
                 }
116
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by MISSING rule for page type <' . $req_type . '> on path <' . $req_path . '>, new rule target is <' . $target_rule . '>', 3 );
116
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by MISSING rule for page type <'.$req_type.'> on path <'.$req_path.'>, new rule target is <'.$target_rule.'>', 3);
117 117
             } else {
118 118
                 // Or just log a job qualified by a matching rule.
119
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by AUTO rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
119
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by AUTO rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
120 120
             }
121 121
 
122 122
             // Submit job.
123
-            if ( $job_qualify ) {
124
-                if ( ! array_key_exists( $req_path, $ao_ccss_queue ) ) {
123
+            if ($job_qualify) {
124
+                if (!array_key_exists($req_path, $ao_ccss_queue)) {
125 125
                     // This is a NEW job
126 126
                     // Merge job into the queue.
127
-                    $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
127
+                    $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
128 128
                         $req_path,
129 129
                         $target_rule,
130 130
                         $req_type,
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
                 } else {
141 141
                     // This is an existing job
142 142
                     // The job is still NEW, most likely this is extra CSS file for the same page that needs a hash.
143
-                    if ( 'NEW' == $ao_ccss_queue[ $req_path ]['jqstat'] ) {
143
+                    if ('NEW' == $ao_ccss_queue[$req_path]['jqstat']) {
144 144
                         // Add hash if it's not already in the job.
145
-                        if ( ! in_array( $hash, $ao_ccss_queue[ $req_path ]['hashes'] ) ) {
145
+                        if (!in_array($hash, $ao_ccss_queue[$req_path]['hashes'])) {
146 146
                             // Push new hash to its array and update flag.
147
-                            $queue_update = array_push( $ao_ccss_queue[ $req_path ]['hashes'], $hash );
147
+                            $queue_update = array_push($ao_ccss_queue[$req_path]['hashes'], $hash);
148 148
 
149 149
                             // Log job update.
150
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Hashes UPDATED on local job id <' . $ao_ccss_queue[ $req_path ]['ljid'] . '>, job status NEW, target rule <' . $ao_ccss_queue[ $req_path ]['rtarget'] . '>, hash added: ' . $hash, 3 );
150
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Hashes UPDATED on local job id <'.$ao_ccss_queue[$req_path]['ljid'].'>, job status NEW, target rule <'.$ao_ccss_queue[$req_path]['rtarget'].'>, hash added: '.$hash, 3);
151 151
 
152 152
                             // Return from here as the hash array is already updated.
153 153
                             return true;
154 154
                         }
155
-                    } elseif ( 'NEW' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[ $req_path ]['jqstat'] ) {
155
+                    } elseif ('NEW' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[$req_path]['jqstat']) {
156 156
                         // Allow requeuing jobs that are not NEW, JOB_QUEUED or JOB_ONGOING
157 157
                         // Merge new job keeping some previous job values.
158
-                        $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
158
+                        $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
159 159
                             $req_path,
160 160
                             $target_rule,
161 161
                             $req_type,
162 162
                             $hash,
163
-                            $ao_ccss_queue[ $req_path ]['file'],
164
-                            $ao_ccss_queue[ $req_path ]['jid'],
165
-                            $ao_ccss_queue[ $req_path ]['jrstat'],
166
-                            $ao_ccss_queue[ $req_path ]['jvstat'],
163
+                            $ao_ccss_queue[$req_path]['file'],
164
+                            $ao_ccss_queue[$req_path]['jid'],
165
+                            $ao_ccss_queue[$req_path]['jrstat'],
166
+                            $ao_ccss_queue[$req_path]['jvstat'],
167 167
                             false
168 168
                         );
169 169
                         // Set update flag.
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
                     }
172 172
                 }
173 173
 
174
-                if ( $queue_update ) {
174
+                if ($queue_update) {
175 175
                     // Persist the job to the queue and return.
176
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
177
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
176
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
177
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
178 178
                     return true;
179 179
                 } else {
180 180
                     // Or just return false if no job was added.
181
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A job for path <' . $req_path . '> already exist with NEW or PENDING status, skipping job creation', 3 );
181
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A job for path <'.$req_path.'> already exist with NEW or PENDING status, skipping job creation', 3);
182 182
                     return false;
183 183
                 }
184 184
             }
@@ -195,29 +195,29 @@  discard block
 block discarded – undo
195 195
         $page_type = false;
196 196
 
197 197
         // Iterates over the array to match a type.
198
-        foreach ( $ao_ccss_types as $type ) {
199
-            if ( is_404() ) {
198
+        foreach ($ao_ccss_types as $type) {
199
+            if (is_404()) {
200 200
                 $page_type = 'is_404';
201 201
                 break;
202
-            } elseif ( strpos( $type, 'custom_post_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
202
+            } elseif (strpos($type, 'custom_post_') !== false && (!$ao_ccss_forcepath || !is_page())) {
203 203
                 // Match custom post types and not page or page not forced to path-based.
204
-                if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
204
+                if (get_post_type(get_the_ID()) === substr($type, 12)) {
205 205
                     $page_type = $type;
206 206
                     break;
207 207
                 }
208
-            } elseif ( strpos( $type, 'template_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
208
+            } elseif (strpos($type, 'template_') !== false && (!$ao_ccss_forcepath || !is_page())) {
209 209
                 // Match templates if not page or if page is not forced to path-based.
210
-                if ( is_page_template( substr( $type, 9 ) ) ) {
210
+                if (is_page_template(substr($type, 9))) {
211 211
                     $page_type = $type;
212 212
                     break;
213 213
                 }
214 214
             } else {
215 215
                 // Match all other existing types
216 216
                 // but remove prefix to be able to check if the function exists & returns true.
217
-                $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
218
-                if ( function_exists( $_type ) && call_user_func( $_type ) ) {
217
+                $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
218
+                if (function_exists($_type) && call_user_func($_type)) {
219 219
                     // Make sure we only return is_front_page (and is_home) for one page, not for the "paged frontpage" (/page/2 ..).
220
-                    if ( ( 'is_front_page' !== $_type && 'is_home' !== $_type ) || ! is_paged() ) {
220
+                    if (('is_front_page' !== $_type && 'is_home' !== $_type) || !is_paged()) {
221 221
                         $page_type = $type;
222 222
                         break;
223 223
                     }
@@ -229,44 +229,44 @@  discard block
 block discarded – undo
229 229
         return $page_type;
230 230
     }
231 231
 
232
-    public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
232
+    public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) {
233 233
         // Define a job entry to be created or updated
234 234
         // Define commom job properties.
235 235
         $path            = array();
236 236
         $path['ljid']    = $this->ao_ccss_job_id();
237 237
         $path['rtarget'] = $target;
238 238
         $path['ptype']   = $type;
239
-        $path['hashes']  = array( $hash );
239
+        $path['hashes']  = array($hash);
240 240
         $path['hash']    = $hash;
241 241
         $path['file']    = $file;
242 242
         $path['jid']     = $jid;
243 243
         $path['jqstat']  = 'NEW';
244 244
         $path['jrstat']  = $jrstat;
245 245
         $path['jvstat']  = $jvstat;
246
-        $path['jctime']  = microtime( true );
246
+        $path['jctime']  = microtime(true);
247 247
         $path['jftime']  = null;
248 248
 
249 249
         // Set operation requested.
250
-        if ( $create ) {
250
+        if ($create) {
251 251
             $operation = 'CREATED';
252 252
         } else {
253 253
             $operation = 'UPDATED';
254 254
         }
255 255
 
256 256
         // Log job creation.
257
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 );
257
+        autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3);
258 258
 
259 259
         return $path;
260 260
     }
261 261
 
262
-    public function ao_ccss_job_id( $length = 6 ) {
262
+    public function ao_ccss_job_id($length = 6) {
263 263
         // Generate random strings for the local job ID
264 264
         // Based on https://stackoverflow.com/a/4356295 .
265 265
         $characters        = '0123456789abcdefghijklmnopqrstuvwxyz';
266
-        $characters_length = strlen( $characters );
266
+        $characters_length = strlen($characters);
267 267
         $random_string     = 'j-';
268
-        for ( $i = 0; $i < $length; $i++ ) {
269
-            $random_string .= $characters[ rand( 0, $characters_length - 1 ) ];
268
+        for ($i = 0; $i < $length; $i++) {
269
+            $random_string .= $characters[rand(0, $characters_length - 1)];
270 270
         }
271 271
         return $random_string;
272 272
     }
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
     public function ao_ccss_ua() {
275 275
         // Check for criticalcss.com user agent.
276 276
         $agent = '';
277
-        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
277
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
278 278
             $agent = $_SERVER['HTTP_USER_AGENT'];
279 279
         }
280 280
 
281 281
         // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not.
282
-        $rtn = strpos( $agent, AO_CCSS_URL );
283
-        if ( 0 === $rtn ) {
282
+        $rtn = strpos($agent, AO_CCSS_URL);
283
+        if (0 === $rtn) {
284 284
             $rtn = true;
285 285
         } else {
286 286
             $rtn = false;
287 287
         }
288
-        return ( $rtn );
288
+        return ($rtn);
289 289
     }
290 290
 }
Please login to merge, or discard this patch.
classes/autoptimizeConfig.php 1 patch
Spacing   +219 added lines, -219 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,32 +35,32 @@  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' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46 46
 
47 47
             // Set meta info.
48
-            if ( function_exists( 'plugin_row_meta' ) ) {
48
+            if (function_exists('plugin_row_meta')) {
49 49
                 // 2.8 and higher.
50
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
51
-            } elseif ( function_exists( 'post_class' ) ) {
50
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
51
+            } elseif (function_exists('post_class')) {
52 52
                 // 2.7 and lower.
53
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
54
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
53
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
54
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
55 55
             }
56 56
 
57 57
             // Clean cache?
58
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
58
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
59 59
                 autoptimizeCache::clearall();
60
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
60
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
61 61
             }
62 62
 
63
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
63
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
64 64
         }
65 65
 
66 66
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     static public function instance()
77 77
     {
78 78
         // Only one instance.
79
-        if ( null === self::$instance ) {
79
+        if (null === self::$instance) {
80 80
             self::$instance = new autoptimizeConfig();
81 81
         }
82 82
 
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
     public function show_network_message() {
87 87
         ?>
88 88
         <div class="wrap">
89
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
89
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
90 90
             <?php echo $this->ao_admin_tabs(); ?>
91
-            <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>
91
+            <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 92
         </div>
93 93
         <?php
94 94
     }
@@ -181,32 +181,32 @@  discard block
 block discarded – undo
181 181
 <div class="wrap">
182 182
 
183 183
 <!-- Temporary nudge to disable aoccss power-up. -->
184
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
184
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
185 185
     <div class="notice-info notice"><p>
186
-        <?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' ); ?>
186
+        <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?>
187 187
     </p></div>
188 188
 <?php } ?>
189 189
 
190 190
 <div id="autoptimize_main">
191
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
191
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
192 192
     <?php echo $this->ao_admin_tabs(); ?>
193 193
 
194
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
195
-<?php settings_fields( 'autoptimize' ); ?>
194
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
195
+<?php settings_fields('autoptimize'); ?>
196 196
 
197 197
 <ul>
198 198
 
199 199
 <?php
200 200
 // Only show enable site configuration in network site option.
201
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
201
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
202 202
 ?>
203 203
     <li class="itemDetail multiSite">
204
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
204
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
205 205
         <table class="form-table">
206 206
             <tr valign="top">
207
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
208
-                <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" ' : ''; ?>/>
209
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
207
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
208
+                <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" ' : ''; ?>/>
209
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
210 210
             </tr>
211 211
         </table>
212 212
     </li>
@@ -215,115 +215,115 @@  discard block
 block discarded – undo
215 215
 <?php } ?>    
216 216
 
217 217
 <li class="itemDetail">
218
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
218
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
219 219
 <table class="form-table">
220 220
 <tr valign="top">
221
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
222
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
221
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
222
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
223 223
 </tr>
224 224
 <tr valign="top" class="js_sub">
225
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
226
-<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" ' : ''; ?>/>
227
-<?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>
225
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
226
+<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" ' : ''; ?>/>
227
+<?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 228
 </tr>
229 229
 <tr valign="top" class="js_sub js_aggregate">
230
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
231
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
232
-<?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>
230
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
231
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
232
+<?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>
233 233
 </tr>
234 234
 <tr valign="top" class="js_sub js_aggregate">
235
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
236
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
237
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
235
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
236
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
237
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
238 238
 </tr>
239
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
239
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
240 240
 <tr valign="top" class="js_sub js_aggregate">
241 241
 <th scope="row">
242 242
 <?php
243
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
244
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
243
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
244
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
245 245
 ?>
246 246
 </th>
247
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
248
-<?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>
247
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
248
+<?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>
249 249
 </tr>
250 250
 <?php } ?>
251 251
 <tr valign="top" class="js_sub">
252
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
253
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_html( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ) ); ?>"/><br />
252
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
253
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_html(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js')); ?>"/><br />
254 254
 <?php
255
-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' );
255
+echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
256 256
 ?>
257 257
 </label></td>
258 258
 </tr>
259 259
 <tr valign="top" class="js_sub js_aggregate">
260
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
261
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
262
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
260
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
261
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
262
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
263 263
 </tr>
264 264
 </table>
265 265
 </li>
266 266
 
267 267
 <li class="itemDetail">
268
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
268
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
269 269
 <table class="form-table">
270 270
 <tr valign="top">
271
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
272
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
271
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
272
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
273 273
 </tr>
274 274
 <tr class="css_sub" valign="top">
275
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
276
-<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" ' : ''; ?>/>
277
-<?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>
275
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
276
+<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" ' : ''; ?>/>
277
+<?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>
278 278
 </tr>
279 279
 <tr valign="top" class="css_sub css_aggregate">
280
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
281
-<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" ' : ''; ?>/>
282
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
280
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
281
+<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" ' : ''; ?>/>
282
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
283 283
 </tr>
284 284
 <tr class="css_sub css_aggregate" valign="top">
285
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
286
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
287
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
285
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
286
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
287
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
288 288
 </tr>
289
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
289
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
290 290
 <tr valign="top" class="css_sub css_aggregate">
291 291
 <th scope="row">
292 292
 <?php
293
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
294
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
293
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
294
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
295 295
 ?>
296 296
 </th>
297
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
298
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
297
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
298
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
299 299
 </tr>
300 300
 <?php } ?>
301 301
 <tr valign="top" class="css_sub">
302
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
303
-<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" ' : ''; ?>/>
302
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
303
+<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" ' : ''; ?>/>
304 304
 <?php
305
-_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' );
305
+_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize');
306 306
 echo ' ';
307
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
307
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
308 308
 // translators: links "autoptimize critical CSS" tab.
309
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
309
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
310 310
 ?>
311 311
 </label></td>
312 312
 </tr>
313 313
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
314 314
 <th scope="row"></th>
315
-<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>
315
+<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
316 316
 </tr>
317 317
 <tr valign="top" class="css_sub css_aggregate">
318
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
319
-<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" ' : ''; ?>/>
320
-<?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>
318
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
319
+<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" ' : ''; ?>/>
320
+<?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>
321 321
 </tr>
322 322
 <tr valign="top" class="css_sub">
323
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
324
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_html( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
323
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
324
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_html(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br />
325 325
 <?php
326
-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' );
326
+echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
327 327
 ?>
328 328
 </label></td>
329 329
 </tr>
@@ -331,55 +331,55 @@  discard block
 block discarded – undo
331 331
 </li>
332 332
 
333 333
 <li class="itemDetail">
334
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
334
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
335 335
 <table class="form-table">
336 336
 <tr valign="top">
337
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
338
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
337
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
338
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
339 339
 </tr>
340 340
 <tr class="html_sub" valign="top">
341
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
342
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
343
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
341
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
342
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
343
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
344 344
 </tr>
345 345
 </table>
346 346
 </li>
347 347
 
348 348
 <li class="itemDetail">
349
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
349
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
350 350
 <table class="form-table">
351 351
 <tr valign="top">
352
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
353
-<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 />
354
-<?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>
352
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
353
+<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 />
354
+<?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>
355 355
 </tr>
356 356
 </table>
357 357
 </li>
358 358
 
359 359
 <li class="itemDetail">
360
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
360
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
361 361
 <table class="form-table" >
362 362
 <tr valign="top" >
363
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
364
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
363
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
364
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
365 365
 </tr>
366 366
 <tr valign="top" >
367
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
368
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
367
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
368
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
369 369
 </tr>
370 370
 <tr valign="top" >
371
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
371
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
372 372
 <td>
373 373
     <?php
374 374
     $ao_stat_arr = autoptimizeCache::stats();
375
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
376
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
375
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
376
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
377 377
         $details       = '';
378
-        if ( $ao_cache_size > 0 ) {
379
-            $details = ', ~' . $ao_cache_size . ' total';
378
+        if ($ao_cache_size > 0) {
379
+            $details = ', ~'.$ao_cache_size.' total';
380 380
         }
381 381
         // translators: Kilobytes + timestamp shown.
382
-        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] ) );
382
+        printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2]));
383 383
     }
384 384
     ?>
385 385
 </td>
@@ -388,41 +388,41 @@  discard block
 block discarded – undo
388 388
 </li>
389 389
 
390 390
 <li class="itemDetail">
391
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
391
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
392 392
 <table class="form-table">
393 393
     <tr valign="top" >
394
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
395
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
396
-    <?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>
394
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
395
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
396
+    <?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>
397 397
     </tr>
398 398
     <?php
399 399
     $_min_excl_class = '';
400
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
400
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
401 401
         $_min_excl_class = 'hidden';
402 402
     }
403 403
     ?>
404 404
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
405
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
406
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
407
-        <?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>
405
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
406
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
407
+        <?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>
408 408
     </tr>
409 409
     <tr valign="top">
410
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
411
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
412
-        <?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>
410
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
411
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
412
+        <?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>
413 413
     </tr>
414 414
     <tr valign="top">
415
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
416
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
417
-    <?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>
415
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
416
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
417
+    <?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>
418 418
     </tr>
419 419
     <?php
420
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
420
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
421 421
     ?>
422 422
     <tr valign="top" >
423
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
424
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
425
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
423
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
424
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
425
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
426 426
         </td>
427 427
     </tr>
428 428
     <?php } ?>
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 </ul>
433 433
 
434 434
 <p class="submit">
435
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
436
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
435
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
436
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
437 437
 </p>
438 438
 
439 439
 </form>
@@ -442,46 +442,46 @@  discard block
 block discarded – undo
442 442
     <div class="autoptimize_banner hidden">
443 443
     <ul>
444 444
     <?php
445
-    if ( $this->settings_screen_do_remote_http ) {
446
-        $ao_banner = get_transient( 'autoptimize_banner' );
447
-        if ( empty( $ao_banner ) ) {
448
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
449
-            if ( ! is_wp_error( $banner_resp ) ) {
450
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
451
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
452
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
445
+    if ($this->settings_screen_do_remote_http) {
446
+        $ao_banner = get_transient('autoptimize_banner');
447
+        if (empty($ao_banner)) {
448
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
449
+            if (!is_wp_error($banner_resp)) {
450
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
451
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
452
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
453 453
                 }
454 454
             }
455 455
         }
456 456
         echo $ao_banner;
457 457
     }
458 458
     ?>
459
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
460
-        <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>
459
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
460
+        <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>
461 461
     </ul>
462 462
     </div>
463 463
     <div style="margin-left:10px;margin-top:-5px;">
464 464
         <h2>
465
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
465
+            <?php _e('futtta about', 'autoptimize'); ?>
466 466
             <select id="feed_dropdown" >
467
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
468
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
469
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
467
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
468
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
469
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
470 470
             </select>
471 471
         </h2>
472 472
         <div id="futtta_feed">
473 473
             <div id="autoptimizefeed">
474
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
474
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
475 475
             </div>
476 476
             <div id="wordpressfeed">
477
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
477
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
478 478
             </div>
479 479
             <div id="webtechfeed">
480
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
480
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
481 481
             </div>
482 482
         </div>
483 483
     </div>
484
-    <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>
484
+    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div>
485 485
 </div>
486 486
 
487 487
 <script type="text/javascript">
@@ -630,81 +630,81 @@  discard block
 block discarded – undo
630 630
 
631 631
     public function addmenu()
632 632
     {
633
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
633
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
634 634
             // multisite, network admin, ao network activated: add normal settings page at network level.
635
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
636
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
635
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
636
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
637 637
             // 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.
638
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
638
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
639 639
         } else {
640 640
             // 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.
641
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
641
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
642 642
         }
643 643
 
644
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
645
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
644
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
645
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
646 646
     }
647 647
 
648 648
     public function autoptimize_admin_scripts()
649 649
     {
650
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
651
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
650
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
651
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
652 652
     }
653 653
 
654 654
     public function autoptimize_admin_styles()
655 655
     {
656
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
657
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
656
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
657
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
658 658
     }
659 659
 
660 660
     public function registersettings() {
661
-        register_setting( 'autoptimize', 'autoptimize_html' );
662
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
663
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
664
-        register_setting( 'autoptimize', 'autoptimize_js' );
665
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
666
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
667
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
668
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
669
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
670
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
671
-        register_setting( 'autoptimize', 'autoptimize_css' );
672
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
673
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
674
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
675
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
676
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
677
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
678
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
679
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
680
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
681
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
682
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
683
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
684
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
685
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
686
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
661
+        register_setting('autoptimize', 'autoptimize_html');
662
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
663
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
664
+        register_setting('autoptimize', 'autoptimize_js');
665
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
666
+        register_setting('autoptimize', 'autoptimize_js_exclude');
667
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
668
+        register_setting('autoptimize', 'autoptimize_js_justhead');
669
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
670
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
671
+        register_setting('autoptimize', 'autoptimize_css');
672
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
673
+        register_setting('autoptimize', 'autoptimize_css_exclude');
674
+        register_setting('autoptimize', 'autoptimize_css_justhead');
675
+        register_setting('autoptimize', 'autoptimize_css_datauris');
676
+        register_setting('autoptimize', 'autoptimize_css_defer');
677
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
678
+        register_setting('autoptimize', 'autoptimize_css_inline');
679
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
680
+        register_setting('autoptimize', 'autoptimize_cdn_url');
681
+        register_setting('autoptimize', 'autoptimize_cache_clean');
682
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
683
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
684
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
685
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
686
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
687 687
     }
688 688
 
689
-    public function setmeta( $links, $file = null )
689
+    public function setmeta($links, $file = null)
690 690
     {
691 691
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
692 692
         // Do it only once - saves time.
693 693
         static $plugin;
694
-        if ( empty( $plugin ) ) {
695
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
694
+        if (empty($plugin)) {
695
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
696 696
         }
697 697
 
698
-        if ( null === $file ) {
698
+        if (null === $file) {
699 699
             // 2.7 and lower.
700
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
701
-            array_unshift( $links, $settings_link );
700
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
701
+            array_unshift($links, $settings_link);
702 702
         } else {
703 703
             // 2.8 and higher.
704 704
             // If it's us, add the link.
705
-            if ( $file === $plugin ) {
706
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
707
-                $links   = array_merge( $links, $newlink );
705
+            if ($file === $plugin) {
706
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
707
+                $links   = array_merge($links, $newlink);
708 708
             }
709 709
         }
710 710
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
781 781
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
782 782
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
783
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
783
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
784 784
         );
785 785
         return $defaults;
786 786
     }
@@ -792,58 +792,58 @@  discard block
 block discarded – undo
792 792
      *
793 793
      * @return string
794 794
      */
795
-    public static function get_ao_css_preload_onload( $media = 'all' )
795
+    public static function get_ao_css_preload_onload($media = 'all')
796 796
     {
797
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
797
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
798 798
         return $preload_onload;
799 799
     }
800 800
 
801
-    public function get( $key )
801
+    public function get($key)
802 802
     {
803
-        if ( ! is_array( $this->config ) ) {
803
+        if (!is_array($this->config)) {
804 804
             // Default config.
805 805
             $config = self::get_defaults();
806 806
 
807 807
             // Override with user settings.
808
-            foreach ( array_keys( $config ) as $name ) {
809
-                $conf = autoptimizeOptionWrapper::get_option( $name );
810
-                if ( false !== $conf ) {
808
+            foreach (array_keys($config) as $name) {
809
+                $conf = autoptimizeOptionWrapper::get_option($name);
810
+                if (false !== $conf) {
811 811
                     // It was set before!
812
-                    $config[ $name ] = $conf;
812
+                    $config[$name] = $conf;
813 813
                 }
814 814
             }
815 815
 
816 816
             // Save for next call.
817
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
817
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
818 818
         }
819 819
 
820
-        if ( isset( $this->config[ $key ] ) ) {
821
-            return $this->config[ $key ];
820
+        if (isset($this->config[$key])) {
821
+            return $this->config[$key];
822 822
         }
823 823
 
824 824
         return false;
825 825
     }
826 826
 
827
-    private function get_futtta_feeds( $url ) {
828
-        if ( $this->settings_screen_do_remote_http ) {
829
-            $rss      = fetch_feed( $url );
827
+    private function get_futtta_feeds($url) {
828
+        if ($this->settings_screen_do_remote_http) {
829
+            $rss      = fetch_feed($url);
830 830
             $maxitems = 0;
831 831
 
832
-            if ( ! is_wp_error( $rss ) ) {
833
-                $maxitems  = $rss->get_item_quantity( 7 );
834
-                $rss_items = $rss->get_items( 0, $maxitems );
832
+            if (!is_wp_error($rss)) {
833
+                $maxitems  = $rss->get_item_quantity(7);
834
+                $rss_items = $rss->get_items(0, $maxitems);
835 835
             }
836 836
             ?>
837 837
             <ul>
838
-                <?php if ( 0 == $maxitems ) : ?>
839
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
838
+                <?php if (0 == $maxitems) : ?>
839
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
840 840
                 <?php else : ?>
841
-                    <?php foreach ( $rss_items as $item ) : ?>
841
+                    <?php foreach ($rss_items as $item) : ?>
842 842
                         <li>
843
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
843
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
844 844
                                 <?php // translators: the variable contains a date. ?>
845
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
846
-                                <?php echo esc_html( $item->get_title() ); ?>
845
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
846
+                                <?php echo esc_html($item->get_title()); ?>
847 847
                             </a>
848 848
                         </li>
849 849
                     <?php endforeach; ?>
@@ -856,23 +856,23 @@  discard block
 block discarded – undo
856 856
     static function ao_admin_tabs()
857 857
     {
858 858
         // based on http://wordpress.stackexchange.com/a/58826 .
859
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
859
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
860 860
         $tab_content = '';
861
-        $tabs_count  = count( $tabs );
862
-        if ( $tabs_count > 1 ) {
863
-            if ( isset( $_GET['page'] ) ) {
861
+        $tabs_count  = count($tabs);
862
+        if ($tabs_count > 1) {
863
+            if (isset($_GET['page'])) {
864 864
                 $current_id = $_GET['page'];
865 865
             } else {
866 866
                 $current_id = 'autoptimize';
867 867
             }
868 868
             $tab_content .= '<h2 class="nav-tab-wrapper">';
869
-            foreach ( $tabs as $tab_id => $tab_name ) {
870
-                if ( $current_id == $tab_id ) {
869
+            foreach ($tabs as $tab_id => $tab_name) {
870
+                if ($current_id == $tab_id) {
871 871
                     $class = ' nav-tab-active';
872 872
                 } else {
873 873
                     $class = '';
874 874
                 }
875
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
875
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
876 876
             }
877 877
             $tab_content .= '</h2>';
878 878
         } else {
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
      */
890 890
     public static function is_admin_and_not_ajax()
891 891
     {
892
-        return ( is_admin() && ! self::doing_ajax() );
892
+        return (is_admin() && !self::doing_ajax());
893 893
     }
894 894
 
895 895
     /**
@@ -899,10 +899,10 @@  discard block
 block discarded – undo
899 899
      */
900 900
     protected static function doing_ajax()
901 901
     {
902
-        if ( function_exists( 'wp_doing_ajax' ) ) {
902
+        if (function_exists('wp_doing_ajax')) {
903 903
             return wp_doing_ajax();
904 904
         }
905
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
905
+        return (defined('DOING_AJAX') && DOING_AJAX);
906 906
     }
907 907
 
908 908
     /**
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
      * @return bool
912 912
      */
913 913
     public static function should_show_menu_tabs() {
914
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
914
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
915 915
             return true;
916 916
         } else {
917 917
             return false;
Please login to merge, or discard this patch.