Completed
Push — master ( 8cd4be...fd6893 )
by frank
02:38
created
classes/critcss-inc/admin_settings_queue.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,21 +11,21 @@  discard block
 block discarded – undo
11 11
     global $ao_ccss_queue;
12 12
 
13 13
     // Prepare the queue object.
14
-    if ( empty( $ao_ccss_queue ) ) {
14
+    if (empty($ao_ccss_queue)) {
15 15
         $ao_ccss_queue = '';
16 16
     } else {
17
-        $ao_ccss_queue = json_encode( $ao_ccss_queue );
17
+        $ao_ccss_queue = json_encode($ao_ccss_queue);
18 18
     }
19 19
 ?>
20 20
 
21 21
     <ul id="queue-panel">
22 22
         <li class="itemDetail">
23
-            <h2 class="itemTitle fleft"><?php _e( 'Job Queue', 'autoptimize' ); ?></h2>
23
+            <h2 class="itemTitle fleft"><?php _e('Job Queue', 'autoptimize'); ?></h2>
24 24
             <button type="button" class="toggle-btn">
25 25
                 <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
26 26
             </button>
27 27
             <?php
28
-            if ( autoptimizeCriticalCSSSettings::ao_ccss_has_autorules() ) {
28
+            if (autoptimizeCriticalCSSSettings::ao_ccss_has_autorules()) {
29 29
                 $_queue_visibility = 'hidden';
30 30
             } else {
31 31
                 $_queue_visibility = 'visible';
@@ -34,54 +34,54 @@  discard block
 block discarded – undo
34 34
             <div class="collapsible <?php echo $_queue_visibility; ?>">
35 35
                 <!-- BEGIN Queue dialogs -->
36 36
                 <!-- Retry dialog -->
37
-                <div id="queue-confirm-retry" title="<?php _e( 'Retry Job', 'autoptimize' ); ?>" class="hidden">
38
-                    <p><?php _e( 'Are you sure you want to retry this job?', 'autoptimize' ); ?></p>
37
+                <div id="queue-confirm-retry" title="<?php _e('Retry Job', 'autoptimize'); ?>" class="hidden">
38
+                    <p><?php _e('Are you sure you want to retry this job?', 'autoptimize'); ?></p>
39 39
                 </div>
40 40
 
41 41
                 <!-- Remove dialog -->
42
-                <div id="queue-confirm-rm" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>" class="hidden">
43
-                    <p><?php _e( 'Are you sure you want to delete this job?', 'autoptimize' ); ?></p>
42
+                <div id="queue-confirm-rm" title="<?php _e('Delete Job', 'autoptimize'); ?>" class="hidden">
43
+                    <p><?php _e('Are you sure you want to delete this job?', 'autoptimize'); ?></p>
44 44
                 </div>
45 45
 
46 46
                 <!-- Remove all dialog -->
47
-                <div id="queue-confirm-rm-all" title="<?php _e( 'Delete all jobs', 'autoptimize' ); ?>" class="hidden">
48
-                    <p><?php _e( 'This will delete all jobs, are you sure?', 'autoptimize' ); ?></p>
47
+                <div id="queue-confirm-rm-all" title="<?php _e('Delete all jobs', 'autoptimize'); ?>" class="hidden">
48
+                    <p><?php _e('This will delete all jobs, are you sure?', 'autoptimize'); ?></p>
49 49
                 </div>
50 50
                 <!-- END Queue dialogs -->
51 51
 
52 52
                 <!-- BEGIN Queue UI -->
53 53
                 <div class="howto">
54 54
                     <div class="title-wrap">
55
-                        <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Queue', 'autoptimize' ); ?></h4>
56
-                        <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p>
55
+                        <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Queue', 'autoptimize'); ?></h4>
56
+                        <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p>
57 57
                     </div>
58 58
                     <button type="button" class="toggle-btn">
59 59
                         <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
60 60
                     </button>
61 61
                     <div class="howto-wrap hidden">
62
-                        <p><?php _e( 'TL;DR:<br /><strong>Queue runs every 10 minutes.</strong> Job statuses are <span class="badge new">N</span> for NEW, <span class="badge pending">P</span> for PENDING, <span class="badge error">E</span> for ERROR and <span class="badge unknown">U</span> for UNKOWN.', 'autoptimize' ); ?></p>
62
+                        <p><?php _e('TL;DR:<br /><strong>Queue runs every 10 minutes.</strong> Job statuses are <span class="badge new">N</span> for NEW, <span class="badge pending">P</span> for PENDING, <span class="badge error">E</span> for ERROR and <span class="badge unknown">U</span> for UNKOWN.', 'autoptimize'); ?></p>
63 63
                         <ol>
64
-                            <li><?php _e( 'The queue operates <strong>automatically, asynchronously and on regular intervals of 10 minutes.</strong> To view updated queue status, refresh this page.', 'autoptimize' ); ?></li>
65
-                            <li><?php _e( 'When the conditions to create a job are met (i.e. user not logged in, no matching <span class="badge manual">MANUAL</span> rule or CSS files has changed for an <span class="badge auto">AUTO</span> rule), a <span class="badge new">N</span> job is created in the queue.', 'autoptimize' ); ?></li>
66
-                            <li><?php _e( "Autoptimize CriticalCSS Power-Up constantly query the queue for <span class='badge new'>N</span> jobs. When it finds one, gears spins and jobs becomes <span class='badge pending'>P</span> while they are running and <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> doesn't return a result.", 'autoptimize' ); ?></li>
67
-                            <li><?php _e( 'As soon as <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> returns a valid critical CSS file, the job is then finished and removed from the queue.', 'autoptimize' ); ?></li>
68
-                            <li><?php _e( 'When things go wrong, a job is marked as <span class="badge error">E</span>. You can retry faulty jobs, delete them or get in touch with <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize' ); ?></li>
69
-                            <li><?php _e( 'Sometimes an unknown condition can happen. In this case, the job status becomes <span class="badge unknown">U</span> and you may want to ask <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for help or just delete it.', 'autoptimize' ); ?></li>
70
-                            <li><?php _e( 'To get more information about jobs statuses, specially the ones with <span class="badge error">E</span> and <span class="badge unknown">U</span> status, hover your mouse in the status badge of that job. This information might be crucial when contacting <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize' ); ?></li>
71
-                            <li><?php _e( '<strong>A word about WordPress cron:</strong> Autoptimize CriticalCSS Power-Up watch the queue by using WordPress Cron (or WP-Cron for short.) It <a href="https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/#limitations-of-wordpress-cron-and-solutions-to-fix-em" target="_blank">could be faulty</a> on very light or very heavy loads. If your site receives just a few or thousands visits a day, it might be a good idea to <a href="https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/" target="_blank">turn WP-Cron off and use your system task scheduler</a> to fire it instead.', 'autoptimize' ); ?></li>
64
+                            <li><?php _e('The queue operates <strong>automatically, asynchronously and on regular intervals of 10 minutes.</strong> To view updated queue status, refresh this page.', 'autoptimize'); ?></li>
65
+                            <li><?php _e('When the conditions to create a job are met (i.e. user not logged in, no matching <span class="badge manual">MANUAL</span> rule or CSS files has changed for an <span class="badge auto">AUTO</span> rule), a <span class="badge new">N</span> job is created in the queue.', 'autoptimize'); ?></li>
66
+                            <li><?php _e("Autoptimize CriticalCSS Power-Up constantly query the queue for <span class='badge new'>N</span> jobs. When it finds one, gears spins and jobs becomes <span class='badge pending'>P</span> while they are running and <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> doesn't return a result.", 'autoptimize'); ?></li>
67
+                            <li><?php _e('As soon as <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> returns a valid critical CSS file, the job is then finished and removed from the queue.', 'autoptimize'); ?></li>
68
+                            <li><?php _e('When things go wrong, a job is marked as <span class="badge error">E</span>. You can retry faulty jobs, delete them or get in touch with <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize'); ?></li>
69
+                            <li><?php _e('Sometimes an unknown condition can happen. In this case, the job status becomes <span class="badge unknown">U</span> and you may want to ask <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for help or just delete it.', 'autoptimize'); ?></li>
70
+                            <li><?php _e('To get more information about jobs statuses, specially the ones with <span class="badge error">E</span> and <span class="badge unknown">U</span> status, hover your mouse in the status badge of that job. This information might be crucial when contacting <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for assistance.', 'autoptimize'); ?></li>
71
+                            <li><?php _e('<strong>A word about WordPress cron:</strong> Autoptimize CriticalCSS Power-Up watch the queue by using WordPress Cron (or WP-Cron for short.) It <a href="https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/#limitations-of-wordpress-cron-and-solutions-to-fix-em" target="_blank">could be faulty</a> on very light or very heavy loads. If your site receives just a few or thousands visits a day, it might be a good idea to <a href="https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/" target="_blank">turn WP-Cron off and use your system task scheduler</a> to fire it instead.', 'autoptimize'); ?></li>
72 72
                         </ol>
73 73
                     </div>
74 74
                 </div>
75 75
                 <table id="queue-tbl" class="queue tablesorter" cellspacing="0">
76 76
                     <thead>
77
-                        <tr><th class="status"><?php _e( 'Status', 'autoptimize' ); ?></th><th><?php _e( 'Target Rule', 'autoptimize' ); ?></th><th><?php _e( 'Page Path', 'autoptimize' ); ?></th><th><?php _e( 'Page Type', 'autoptimize' ); ?></th><th><?php _e( 'Creation Date', 'autoptimize' ); ?></th><th><?php _e( 'Finish Date', 'autoptimize' ); ?></th><th class="btn"><?php _e( 'Actions', 'autoptimize' ); ?></th></tr>
77
+                        <tr><th class="status"><?php _e('Status', 'autoptimize'); ?></th><th><?php _e('Target Rule', 'autoptimize'); ?></th><th><?php _e('Page Path', 'autoptimize'); ?></th><th><?php _e('Page Type', 'autoptimize'); ?></th><th><?php _e('Creation Date', 'autoptimize'); ?></th><th><?php _e('Finish Date', 'autoptimize'); ?></th><th class="btn"><?php _e('Actions', 'autoptimize'); ?></th></tr>
78 78
                     </thead>
79 79
                     <tbody id="queue"></tbody>
80 80
                 </table>
81
-                <input class="hidden" type="text" id="ao-ccss-queue" name="autoptimize_ccss_queue" value='<?php echo( $ao_ccss_queue ); ?>'>
81
+                <input class="hidden" type="text" id="ao-ccss-queue" name="autoptimize_ccss_queue" value='<?php echo($ao_ccss_queue); ?>'>
82 82
                 <div class="submit jobs-btn">
83 83
                     <div class="alignright">
84
-                        <span id="removeAllJobs" class="button-secondary" style="color:red;"><?php _e( 'Remove all jobs', 'autoptimize' ); ?></span>
84
+                        <span id="removeAllJobs" class="button-secondary" style="color:red;"><?php _e('Remove all jobs', 'autoptimize'); ?></span>
85 85
                     </div>
86 86
                 </div>
87 87
             </div>
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_explain.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,29 +12,29 @@
 block discarded – undo
12 12
         .ao_settings_div {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;}
13 13
         .ao_settings_div .form-table th {font-weight: normal;}
14 14
     </style>
15
-    <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
15
+    <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
16 16
     <ul id="explain-panel">
17 17
         <div class="ao_settings_div">
18 18
             <?php
19 19
             $ccss_explanation = '';
20 20
 
21 21
             // get the HTML with the explanation of what critical CSS is.
22
-            if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
23
-                $ccss_explanation = get_transient( 'ao_ccss_explain' );
24
-                if ( empty( $ccss_explanation ) ) {
25
-                    $ccss_expl_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
26
-                    if ( ! is_wp_error( $ccss_expl_resp ) ) {
27
-                        if ( '200' == wp_remote_retrieve_response_code( $ccss_expl_resp ) ) {
28
-                            $ccss_explanation = wp_kses_post( wp_remote_retrieve_body( $ccss_expl_resp ) );
29
-                            set_transient( 'ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS );
22
+            if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
23
+                $ccss_explanation = get_transient('ao_ccss_explain');
24
+                if (empty($ccss_explanation)) {
25
+                    $ccss_expl_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_ccss_explain_i18n.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
26
+                    if (!is_wp_error($ccss_expl_resp)) {
27
+                        if ('200' == wp_remote_retrieve_response_code($ccss_expl_resp)) {
28
+                            $ccss_explanation = wp_kses_post(wp_remote_retrieve_body($ccss_expl_resp));
29
+                            set_transient('ao_ccss_explain', $ccss_explanation, WEEK_IN_SECONDS);
30 30
                         }
31 31
                     }
32 32
                 }
33 33
             }
34 34
 
35 35
             // placeholder text in case HTML is empty.
36
-            if ( empty( $ccss_explanation ) ) {
37
-                $ccss_explanation = __( '<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize' );
36
+            if (empty($ccss_explanation)) {
37
+                $ccss_explanation = __('<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><p>The next step is to sign up at <a href="https://criticalcss.com/?aff=1" target="_blank">https://criticalcss.com</a> (this is a premium service, priced 2 GBP/month for membership and 5 GBP/month per domain) <strong>and get the API key, which you can copy from <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">the API-keys page</a></strong> and paste below.</p><p>If you have any questions or need support, head on over to <a href="https://wordpress.org/support/plugin/autoptimize" target="_blank">our support forum</a> and we\'ll help you get up and running in no time!</p>', 'autoptimize');
38 38
             } else {
39 39
                 // we were able to fetch the explenation, so add the JS to show correct language.
40 40
                 $ccss_explanation .= "<script>jQuery('.ao_i18n').hide();d=document;lang=d.getElementsByTagName('html')[0].getAttribute('lang').substring(0,2);if(d.getElementById(lang)!= null){jQuery('#'+lang).show();}else{jQuery('#default').show();}</script>";
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.
config/autoptimize_404_handler.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,24 +20,24 @@
 block discarded – undo
20 20
  * to files that don't exist in AO's cache.
21 21
  */
22 22
 
23
-$original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
23
+$original_request = strtok($_SERVER['REQUEST_URI'], '?');
24 24
 
25
-if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
26
-    $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
25
+if (strpos($original_request, 'uucss/uucss-') !== false) {
26
+    $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
27 27
 }
28 28
 
29
-$fallback_target  = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
29
+$fallback_target  = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
30 30
 $ao_cache_dir     = '<!--ao-cache-dir-->';
31
-$js_or_css        = pathinfo( $original_request, PATHINFO_EXTENSION );
32
-$fallback_path    = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
31
+$js_or_css        = pathinfo($original_request, PATHINFO_EXTENSION);
32
+$fallback_path    = $ao_cache_dir.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
33 33
 
34
-if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
34
+if ($original_request !== $fallback_target && file_exists($fallback_path)) {
35 35
     // error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' );
36
-    header( 'HTTP/1.1 301 Moved Permanently' );
37
-    header( 'Location: ' . $fallback_target );
36
+    header('HTTP/1.1 301 Moved Permanently');
37
+    header('Location: '.$fallback_target);
38 38
 } else {
39 39
     // error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' );
40
-    header( 'HTTP/1.1 410 Gone' );
40
+    header('HTTP/1.1 410 Gone');
41 41
 }
42 42
 
43 43
 exit();
Please login to merge, or discard this patch.
classes/autoptimizeCache.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @param string $data Data to cache.
92 92
      * @param string $mime Mimetype.
93 93
      *
94
-     * @return void
94
+     * @return boolean|null
95 95
      */
96 96
     public function cache( $data, $mime )
97 97
     {
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
      * size = total filesize (in bytes) of found files
490 490
      * timestamp = unix timestamp when the scan was last performed/finished.
491 491
      *
492
-     * @return array
492
+     * @return integer[]
493 493
      */
494 494
     protected static function stats_scan()
495 495
     {
Please login to merge, or discard this patch.
Spacing   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles disk-cache-related operations.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
      * @param string $md5 Hash.
39 39
      * @param string $ext Extension.
40 40
      */
41
-    public function __construct( $md5, $ext = 'php' )
41
+    public function __construct($md5, $ext = 'php')
42 42
     {
43 43
         $_min_ext = '';
44
-        if ( apply_filters( 'autoptimize_filter_cache_url_add_min_ext', false ) ) {
44
+        if (apply_filters('autoptimize_filter_cache_url_add_min_ext', false)) {
45 45
             $_min_ext = '.min';
46 46
         }
47 47
 
48 48
         $this->cachedir = AUTOPTIMIZE_CACHE_DIR;
49 49
         $this->nogzip   = AUTOPTIMIZE_CACHE_NOGZIP;
50
-        if ( ! $this->nogzip ) {
51
-            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.php';
50
+        if (!$this->nogzip) {
51
+            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.php';
52 52
         } else {
53
-            if ( in_array( $ext, array( 'js', 'css' ) ) ) {
54
-                $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
53
+            if (in_array($ext, array('js', 'css'))) {
54
+                $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
55 55
             } else {
56
-                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
56
+                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
57 57
             }
58 58
         }
59 59
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function check()
67 67
     {
68
-        return file_exists( $this->cachedir . $this->filename );
68
+        return file_exists($this->cachedir.$this->filename);
69 69
     }
70 70
 
71 71
     /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function retrieve()
77 77
     {
78
-        if ( $this->check() ) {
79
-            if ( false == $this->nogzip ) {
80
-                return file_get_contents( $this->cachedir . $this->filename . '.none' );
78
+        if ($this->check()) {
79
+            if (false == $this->nogzip) {
80
+                return file_get_contents($this->cachedir.$this->filename.'.none');
81 81
             } else {
82
-                return file_get_contents( $this->cachedir . $this->filename );
82
+                return file_get_contents($this->cachedir.$this->filename);
83 83
             }
84 84
         }
85 85
         return false;
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return void
95 95
      */
96
-    public function cache( $data, $mime )
96
+    public function cache($data, $mime)
97 97
     {
98 98
         // readonly FS explicitly OK'ed by developer, so just pretend all is OK.
99
-        if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
99
+        if (defined('AUTOPTIMIZE_CACHE_READONLY')) {
100 100
             return true;
101 101
         }
102 102
 
@@ -104,44 +104,44 @@  discard block
 block discarded – undo
104 104
         //
105 105
         // to be activated for users that experience these ugly errors;
106 106
         // PHP Warning: file_put_contents failed to open stream: No such file or directory.
107
-        if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) {
107
+        if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) {
108 108
             $this->check_and_create_dirs();
109 109
         }
110 110
 
111
-        if ( false === $this->nogzip ) {
111
+        if (false === $this->nogzip) {
112 112
             // We handle gzipping ourselves.
113 113
             $file    = 'default.php';
114
-            $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file );
115
-            $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode );
114
+            $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file);
115
+            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode);
116 116
 
117
-            file_put_contents( $this->cachedir . $this->filename, $phpcode );
118
-            file_put_contents( $this->cachedir . $this->filename . '.none', $data );
117
+            file_put_contents($this->cachedir.$this->filename, $phpcode);
118
+            file_put_contents($this->cachedir.$this->filename.'.none', $data);
119 119
         } else {
120 120
             // Write code to cache without doing anything else.
121
-            file_put_contents( $this->cachedir . $this->filename, $data );
121
+            file_put_contents($this->cachedir.$this->filename, $data);
122 122
 
123 123
             // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single.
124
-            if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) {
125
-                $_extension     = pathinfo( $this->filename, PATHINFO_EXTENSION );
126
-                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension;
127
-                if ( ( 'css' === $_extension || 'js' === $_extension ) && ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) {
128
-                    file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data );
124
+            if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) {
125
+                $_extension     = pathinfo($this->filename, PATHINFO_EXTENSION);
126
+                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension;
127
+                if (('css' === $_extension || 'js' === $_extension) && !file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) {
128
+                    file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data);
129 129
                 }
130 130
             }
131 131
 
132
-            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) {
132
+            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) {
133 133
                 // Create an additional cached gzip file.
134
-                file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) );
134
+                file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP));
135 135
                 // If PHP Brotli extension is installed, create an additional cached Brotli file.
136
-                if ( function_exists( 'brotli_compress' ) ) {
137
-                    file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) );
136
+                if (function_exists('brotli_compress')) {
137
+                    file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC));
138 138
                 }
139 139
             }
140 140
         }
141 141
 
142 142
         // Provide 3rd party action hook for every cache file that is created.
143 143
         // This hook can for example be used to inject a copy of the created cache file to a other domain.
144
-        do_action( 'autoptimize_action_cache_file_created', $this->cachedir . $this->filename );
144
+        do_action('autoptimize_action_cache_file_created', $this->cachedir.$this->filename);
145 145
     }
146 146
 
147 147
     /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         // The original idea here was to provide 3rd party code a hook so that
157 157
         // it can "listen" to all the complete autoptimized-urls that the page
158 158
         // will emit... Or something to that effect I think?
159
-        apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename );
159
+        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename);
160 160
 
161 161
         return $this->filename;
162 162
     }
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
      * @param string $file Filename.
170 170
      * @return bool
171 171
      */
172
-    protected static function is_valid_cache_file( $dir, $file )
172
+    protected static function is_valid_cache_file($dir, $file)
173 173
     {
174
-        if ( '.' !== $file && '..' !== $file &&
175
-            false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) &&
176
-            is_file( $dir . $file ) ) {
174
+        if ('.' !== $file && '..' !== $file &&
175
+            false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) &&
176
+            is_file($dir.$file)) {
177 177
 
178 178
             // It's a valid file!
179 179
             return true;
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
     protected static function clear_cache_classic()
192 192
     {
193 193
         $contents = self::get_cache_contents();
194
-        foreach ( $contents as $name => $files ) {
195
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
196
-            foreach ( $files as $file ) {
197
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
198
-                    @unlink( $dir . $file ); // @codingStandardsIgnoreLine
194
+        foreach ($contents as $name => $files) {
195
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
196
+            foreach ($files as $file) {
197
+                if (self::is_valid_cache_file($dir, $file)) {
198
+                    @unlink($dir.$file); // @codingStandardsIgnoreLine
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203
-        @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine
203
+        @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine
204 204
     }
205 205
 
206 206
     /**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return bool
213 213
      */
214
-    protected static function rmdir( $pathname )
214
+    protected static function rmdir($pathname)
215 215
     {
216
-        $files = self::get_dir_contents( $pathname );
217
-        foreach ( $files as $file ) {
218
-            $path = $pathname . '/' . $file;
219
-            if ( is_dir( $path ) ) {
220
-                self::rmdir( $path );
216
+        $files = self::get_dir_contents($pathname);
217
+        foreach ($files as $file) {
218
+            $path = $pathname.'/'.$file;
219
+            if (is_dir($path)) {
220
+                self::rmdir($path);
221 221
             } else {
222
-                unlink( $path );
222
+                unlink($path);
223 223
             }
224 224
         }
225 225
 
226
-        return rmdir( $pathname );
226
+        return rmdir($pathname);
227 227
     }
228 228
 
229 229
     /**
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
         $new_name = self::get_unique_name();
245 245
 
246 246
         // Makes sure the new pathname is on the same level...
247
-        $new_pathname = dirname( $dir ) . '/' . $new_name;
248
-        $renamed      = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine
247
+        $new_pathname = dirname($dir).'/'.$new_name;
248
+        $renamed      = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine
249 249
 
250 250
         // When renamed, re-create the default cache directory back so it's
251 251
         // available again...
252
-        if ( $renamed ) {
252
+        if ($renamed) {
253 253
             $ok = self::cacheavail();
254 254
         }
255 255
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public static function advanced_cache_clear_enabled()
265 265
     {
266
-        return apply_filters( 'autoptimize_filter_cache_clear_advanced', false );
266
+        return apply_filters('autoptimize_filter_cache_clear_advanced', false);
267 267
     }
268 268
 
269 269
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     protected static function get_unique_name()
275 275
     {
276 276
         $prefix   = self::get_advanced_cache_clear_prefix();
277
-        $new_name = uniqid( $prefix, true );
277
+        $new_name = uniqid($prefix, true);
278 278
 
279 279
         return $new_name;
280 280
     }
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
     protected static function get_advanced_cache_clear_prefix()
288 288
     {
289 289
         $pathname = self::get_pathname_base();
290
-        $basename = basename( $pathname );
291
-        $prefix   = $basename . '-artifact-';
290
+        $basename = basename($pathname);
291
+        $prefix   = $basename.'-artifact-';
292 292
 
293 293
         return $prefix;
294 294
     }
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
      *
302 302
      * @return array
303 303
      */
304
-    protected static function get_dir_contents( $pathname )
304
+    protected static function get_dir_contents($pathname)
305 305
     {
306
-        return array_slice( scandir( $pathname ), 2 );
306
+        return array_slice(scandir($pathname), 2);
307 307
     }
308 308
 
309 309
     /**
@@ -316,24 +316,24 @@  discard block
 block discarded – undo
316 316
     public static function delete_advanced_cache_clear_artifacts()
317 317
     {
318 318
         // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active.
319
-        if ( ! self::advanced_cache_clear_enabled() ) {
319
+        if (!self::advanced_cache_clear_enabled()) {
320 320
             return false;
321 321
         }
322 322
 
323 323
         $dir    = self::get_pathname_base();
324 324
         $prefix = self::get_advanced_cache_clear_prefix();
325
-        $parent = dirname( $dir );
325
+        $parent = dirname($dir);
326 326
         $ok     = false;
327 327
 
328 328
         // Returns the list of files without '.' and '..' elements.
329
-        $files = self::get_dir_contents( $parent );
330
-        if ( is_array( $files ) && ! empty( $files ) ) {
331
-            foreach ( $files as $file ) {
332
-                $path     = $parent . '/' . $file;
333
-                $prefixed = ( false !== strpos( $path, $prefix ) );
329
+        $files = self::get_dir_contents($parent);
330
+        if (is_array($files) && !empty($files)) {
331
+            foreach ($files as $file) {
332
+                $path     = $parent.'/'.$file;
333
+                $prefixed = (false !== strpos($path, $prefix));
334 334
                 // Removing only our own (prefixed) directories...
335
-                if ( is_dir( $path ) && $prefixed ) {
336
-                    $ok = self::rmdir( $path );
335
+                if (is_dir($path) && $prefixed) {
336
+                    $ok = self::rmdir($path);
337 337
                 }
338 338
             }
339 339
         }
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
     {
354 354
         $pathname = self::get_pathname_base();
355 355
 
356
-        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
356
+        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
357 357
             $blog_id   = get_current_blog_id();
358
-            $pathname .= $blog_id . '/';
358
+            $pathname .= $blog_id.'/';
359 359
         }
360 360
 
361 361
         return $pathname;
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     protected static function get_pathname_base()
370 370
     {
371
-        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
371
+        $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR;
372 372
 
373 373
         return $pathname;
374 374
     }
@@ -380,46 +380,46 @@  discard block
 block discarded – undo
380 380
      *
381 381
      * @return bool
382 382
      */
383
-    public static function clearall( $propagate = true )
383
+    public static function clearall($propagate = true)
384 384
     {
385
-        if ( ! self::cacheavail() ) {
385
+        if (!self::cacheavail()) {
386 386
             return false;
387 387
         }
388 388
 
389 389
         // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
390
-        if ( self::advanced_cache_clear_enabled() ) {
390
+        if (self::advanced_cache_clear_enabled()) {
391 391
             self::clear_cache_via_rename();
392 392
         } else {
393 393
             self::clear_cache_classic();
394 394
         }
395 395
 
396 396
         // Remove 404 handler if required.
397
-        if ( self::do_fallback() ) {
398
-            $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php';
399
-            @unlink( $_fallback_php ); // @codingStandardsIgnoreLine
397
+        if (self::do_fallback()) {
398
+            $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php';
399
+            @unlink($_fallback_php); // @codingStandardsIgnoreLine
400 400
         }
401 401
 
402 402
         // Remove the transient so it gets regenerated...
403
-        delete_transient( 'autoptimize_stats' );
403
+        delete_transient('autoptimize_stats');
404 404
 
405 405
         // Cache was just purged, clear page cache and allow others to hook into our purging...
406
-        if ( true === $propagate ) {
407
-            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) {
406
+        if (true === $propagate) {
407
+            if (!function_exists('autoptimize_do_cachepurged_action')) {
408 408
                 function autoptimize_do_cachepurged_action() {
409
-                    do_action( 'autoptimize_action_cachepurged' );
409
+                    do_action('autoptimize_action_cachepurged');
410 410
                 }
411 411
             }
412
-            add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 );
413
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 );
412
+            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11);
413
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0);
414 414
         }
415 415
 
416 416
         // Warm cache (part of speedupper)!
417
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) {
418
-            set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 );
419
-            $url   = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 );
420
-            $url   = apply_filters( 'autoptimize_filter_cache_warmer_url', $url );
421
-            $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine
422
-            unset( $cache );
417
+        if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) {
418
+            set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10);
419
+            $url   = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000);
420
+            $url   = apply_filters('autoptimize_filter_cache_warmer_url', $url);
421
+            $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine
422
+            unset($cache);
423 423
         }
424 424
 
425 425
         return true;
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      */
435 435
     public static function clearall_actionless()
436 436
     {
437
-        return self::clearall( false );
437
+        return self::clearall(false);
438 438
     }
439 439
 
440 440
     /**
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
     {
447 447
         $contents = array();
448 448
 
449
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
450
-            $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir );
449
+        foreach (array('', 'js', 'css') as $dir) {
450
+            $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir);
451 451
         }
452 452
 
453 453
         return $contents;
@@ -460,21 +460,21 @@  discard block
 block discarded – undo
460 460
      */
461 461
     public static function stats()
462 462
     {
463
-        $stats = get_transient( 'autoptimize_stats' );
463
+        $stats = get_transient('autoptimize_stats');
464 464
 
465 465
         // If no transient, do the actual scan!
466
-        if ( ! is_array( $stats ) ) {
467
-            if ( ! self::cacheavail() ) {
466
+        if (!is_array($stats)) {
467
+            if (!self::cacheavail()) {
468 468
                 return 0;
469 469
             }
470 470
             $stats = self::stats_scan();
471 471
             $count = $stats[0];
472
-            if ( $count > 100 ) {
472
+            if ($count > 100) {
473 473
                 // Store results in transient.
474 474
                 set_transient(
475 475
                     'autoptimize_stats',
476 476
                     $stats,
477
-                    apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS )
477
+                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS)
478 478
                 );
479 479
             }
480 480
         }
@@ -497,30 +497,30 @@  discard block
 block discarded – undo
497 497
         $size  = 0;
498 498
 
499 499
         // Scan everything in our cache directories.
500
-        foreach ( self::get_cache_contents() as $name => $files ) {
501
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
502
-            foreach ( $files as $file ) {
503
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
504
-                    if ( AUTOPTIMIZE_CACHE_NOGZIP &&
500
+        foreach (self::get_cache_contents() as $name => $files) {
501
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
502
+            foreach ($files as $file) {
503
+                if (self::is_valid_cache_file($dir, $file)) {
504
+                    if (AUTOPTIMIZE_CACHE_NOGZIP &&
505 505
                         (
506
-                            false !== strpos( $file, '.js' ) ||
507
-                            false !== strpos( $file, '.css' ) ||
508
-                            false !== strpos( $file, '.img' ) ||
509
-                            false !== strpos( $file, '.txt' )
506
+                            false !== strpos($file, '.js') ||
507
+                            false !== strpos($file, '.css') ||
508
+                            false !== strpos($file, '.img') ||
509
+                            false !== strpos($file, '.txt')
510 510
                         )
511 511
                     ) {
512 512
                         // Web server is gzipping, we count .js|.css|.img|.txt files.
513 513
                         $count++;
514
-                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) {
514
+                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) {
515 515
                         // We are gzipping ourselves via php, counting only .none files.
516 516
                         $count++;
517 517
                     }
518
-                    $size += filesize( $dir . $file );
518
+                    $size += filesize($dir.$file);
519 519
                 }
520 520
             }
521 521
         }
522 522
 
523
-        $stats = array( $count, $size, time() );
523
+        $stats = array($count, $size, time());
524 524
 
525 525
         return $stats;
526 526
     }
@@ -535,26 +535,26 @@  discard block
 block discarded – undo
535 535
     public static function cacheavail()
536 536
     {
537 537
         // readonly FS explicitly OK'ed by dev, let's assume the cache dirs are there!
538
-        if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
538
+        if (defined('AUTOPTIMIZE_CACHE_READONLY')) {
539 539
             return true;
540 540
         }
541 541
 
542
-        if ( false === autoptimizeCache::check_and_create_dirs() ) {
542
+        if (false === autoptimizeCache::check_and_create_dirs()) {
543 543
             return false;
544 544
         }
545 545
 
546 546
         // Using .htaccess inside our cache folder to overrule wp-super-cache.
547
-        $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
548
-        if ( ! is_file( $htaccess ) ) {
547
+        $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess';
548
+        if (!is_file($htaccess)) {
549 549
             /**
550 550
              * Create `wp-content/AO_htaccess_tmpl` file with
551 551
              * whatever htaccess rules you might need
552 552
              * if you want to override default AO htaccess
553 553
              */
554
-            $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl';
555
-            if ( is_file( $htaccess_tmpl ) ) {
556
-                $content = file_get_contents( $htaccess_tmpl );
557
-            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) {
554
+            $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl';
555
+            if (is_file($htaccess_tmpl)) {
556
+                $content = file_get_contents($htaccess_tmpl);
557
+            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) {
558 558
                 $content = '<IfModule mod_expires.c>
559 559
         ExpiresActive On
560 560
         ExpiresByType text/css A30672000
@@ -608,13 +608,13 @@  discard block
 block discarded – undo
608 608
 </IfModule>';
609 609
             }
610 610
 
611
-            if ( self::do_fallback() === true ) {
612
-                $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
611
+            if (self::do_fallback() === true) {
612
+                $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php';
613 613
             }
614
-            @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
614
+            @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine
615 615
         }
616 616
 
617
-        if ( self::do_fallback() ) {
617
+        if (self::do_fallback()) {
618 618
             self::check_fallback_php();
619 619
         }
620 620
 
@@ -629,17 +629,17 @@  discard block
 block discarded – undo
629 629
      */
630 630
     public static function check_fallback_php() {
631 631
         $_fallback_filename = 'autoptimize_404_handler.php';
632
-        $_fallback_php      = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename;
632
+        $_fallback_php      = trailingslashit(WP_CONTENT_DIR).$_fallback_filename;
633 633
         $_fallback_status   = true;
634 634
 
635
-        if ( ! file_exists( $_fallback_php ) && is_writable( WP_CONTENT_DIR ) ) {
636
-            $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
637
-            $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
638
-            $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
639
-            if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
640
-                $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
635
+        if (!file_exists($_fallback_php) && is_writable(WP_CONTENT_DIR)) {
636
+            $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename);
637
+            $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents);
638
+            $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents);
639
+            if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) {
640
+                $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents);
641 641
             }
642
-            $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
642
+            $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents);
643 643
         }
644 644
 
645 645
         return $_fallback_status;
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
     public static function do_fallback() {
657 657
         static $_do_fallback = null;
658 658
 
659
-        if ( null === $_do_fallback ) {
660
-            $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) );
659
+        if (null === $_do_fallback) {
660
+            $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1'));
661 661
         }
662 662
 
663 663
         return $_do_fallback;
@@ -669,31 +669,31 @@  discard block
 block discarded – undo
669 669
      * and 410'ing ("Gone") if fallback not available.
670 670
      */
671 671
     public static function wordpress_notfound_fallback() {
672
-        $original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
673
-        if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) {
672
+        $original_request = strtok($_SERVER['REQUEST_URI'], '?');
673
+        if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) {
674 674
             // make sure this is not considered a 404.
675 675
             global $wp_query;
676 676
             $wp_query->is_404 = false;
677 677
 
678 678
             // set fallback path.
679
-            $js_or_css     = pathinfo( $original_request, PATHINFO_EXTENSION );
680
-            $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
679
+            $js_or_css     = pathinfo($original_request, PATHINFO_EXTENSION);
680
+            $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
681 681
 
682 682
             // prepare for Shakeeb's Unused CSS files to be 404-handled as well.
683
-            if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
684
-                $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
683
+            if (strpos($original_request, 'uucss/uucss-') !== false) {
684
+                $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
685 685
             }
686 686
 
687 687
             // set fallback URL.
688
-            $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
688
+            $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
689 689
 
690 690
             // redirect to fallback if possible.
691
-            if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
691
+            if ($original_request !== $fallback_target && file_exists($fallback_path)) {
692 692
                 // redirect to fallback.
693
-                wp_redirect( $fallback_target, 302 );
693
+                wp_redirect($fallback_target, 302);
694 694
             } else {
695 695
                 // return HTTP 410 (gone) reponse.
696
-                status_header( 410 );
696
+                status_header(410);
697 697
             }
698 698
         }
699 699
     }
@@ -705,13 +705,13 @@  discard block
 block discarded – undo
705 705
      * @return bool
706 706
      */
707 707
     public static function check_and_create_dirs() {
708
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
708
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
709 709
             // We didn't set a cache.
710 710
             return false;
711 711
         }
712 712
 
713
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
714
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
713
+        foreach (array('', 'js', 'css') as $dir) {
714
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
715 715
                 return false;
716 716
             }
717 717
         }
@@ -726,25 +726,25 @@  discard block
 block discarded – undo
726 726
      *
727 727
      * @return bool
728 728
      */
729
-    protected static function check_cache_dir( $dir )
729
+    protected static function check_cache_dir($dir)
730 730
     {
731 731
         // Try creating the dir if it doesn't exist.
732
-        if ( ! file_exists( $dir ) ) {
733
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
734
-            if ( ! file_exists( $dir ) ) {
732
+        if (!file_exists($dir)) {
733
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
734
+            if (!file_exists($dir)) {
735 735
                 return false;
736 736
             }
737 737
         }
738 738
 
739 739
         // If we still cannot write, bail.
740
-        if ( ! is_writable( $dir ) ) {
740
+        if (!is_writable($dir)) {
741 741
             return false;
742 742
         }
743 743
 
744 744
         // Create an index.html in there to avoid prying eyes!
745
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
746
-        if ( ! is_file( $idx_file ) ) {
747
-            @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine
745
+        $idx_file = rtrim($dir, '/\\').'/index.html';
746
+        if (!is_file($idx_file)) {
747
+            @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine
748 748
         }
749 749
 
750 750
         return true;
@@ -758,54 +758,54 @@  discard block
 block discarded – undo
758 758
     // @codingStandardsIgnoreStart
759 759
     public static function flushPageCache()
760 760
     {
761
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
762
-            if ( is_multisite() ) {
761
+        if (function_exists('wp_cache_clear_cache')) {
762
+            if (is_multisite()) {
763 763
                 $blog_id = get_current_blog_id();
764
-                wp_cache_clear_cache( $blog_id );
764
+                wp_cache_clear_cache($blog_id);
765 765
             } else {
766 766
                 wp_cache_clear_cache();
767 767
             }
768
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
769
-            do_action( 'cachify_flush_cache' );
770
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
768
+        } elseif (has_action('cachify_flush_cache')) {
769
+            do_action('cachify_flush_cache');
770
+        } elseif (function_exists('w3tc_pgcache_flush')) {
771 771
             w3tc_pgcache_flush();
772
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
772
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
773 773
             wp_fast_cache_bulk_delete_all();
774
-        } elseif ( function_exists( 'rapidcache_clear_cache' ) ) {
774
+        } elseif (function_exists('rapidcache_clear_cache')) {
775 775
             rapidcache_clear_cache();
776
-        } elseif ( class_exists( 'Swift_Performance_Cache' ) ) {
776
+        } elseif (class_exists('Swift_Performance_Cache')) {
777 777
             Swift_Performance_Cache::clear_all_cache();
778
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
778
+        } elseif (class_exists('WpFastestCache')) {
779 779
             $wpfc = new WpFastestCache();
780 780
             $wpfc->deleteCache();
781
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
781
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
782 782
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
783
-        } elseif ( class_exists( 'zencache' ) ) {
783
+        } elseif (class_exists('zencache')) {
784 784
             zencache::clear();
785
-        } elseif ( class_exists( 'comet_cache' ) ) {
785
+        } elseif (class_exists('comet_cache')) {
786 786
             comet_cache::clear();
787
-        } elseif ( class_exists( 'WpeCommon' ) ) {
787
+        } elseif (class_exists('WpeCommon')) {
788 788
             // WPEngine cache purge/flush methods to call by default
789 789
             $wpe_methods = array(
790 790
                 'purge_varnish_cache',
791 791
             );
792 792
 
793 793
             // More agressive clear/flush/purge behind a filter
794
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
795
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
794
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
795
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
796 796
             }
797 797
 
798 798
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
799
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
799
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
800 800
 
801
-            foreach ( $wpe_methods as $wpe_method ) {
802
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
801
+            foreach ($wpe_methods as $wpe_method) {
802
+                if (method_exists('WpeCommon', $wpe_method)) {
803 803
                     WpeCommon::$wpe_method();
804 804
                 }
805 805
             }
806
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
806
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
807 807
             sg_cachepress_purge_cache();
808
-        } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
808
+        } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) {
809 809
             $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
810 810
             $_kinsta_response        = wp_remote_get(
811 811
                 $_kinsta_clear_cache_url,
@@ -814,18 +814,18 @@  discard block
 block discarded – undo
814 814
                     'timeout' => 5,
815 815
                     )
816 816
             );
817
-        } elseif ( defined('NGINX_HELPER_BASENAME') ) {
818
-            do_action( 'rt_nginx_helper_purge_all' );
819
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
817
+        } elseif (defined('NGINX_HELPER_BASENAME')) {
818
+            do_action('rt_nginx_helper_purge_all');
819
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
820 820
             // fallback for WP-Super-Cache
821 821
             global $cache_path;
822
-            if ( is_multisite() ) {
822
+            if (is_multisite()) {
823 823
                 $blog_id = get_current_blog_id();
824
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
825
-                prune_super_cache( $cache_path . 'blogs/', true );
824
+                prune_super_cache(get_supercache_dir($blog_id), true);
825
+                prune_super_cache($cache_path.'blogs/', true);
826 826
             } else {
827
-                prune_super_cache( $cache_path . 'supercache/', true );
828
-                prune_super_cache( $cache_path, true );
827
+                prune_super_cache($cache_path.'supercache/', true);
828
+                prune_super_cache($cache_path, true);
829 829
             }
830 830
         }
831 831
     }
Please login to merge, or discard this patch.
classes/autoptimizeImages.php 2 patches
Doc Comments   +13 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,6 +384,9 @@  discard block
 block discarded – undo
384 384
         }
385 385
     }
386 386
 
387
+    /**
388
+     * @return string
389
+     */
387 390
     private function get_imgopt_base_url()
388 391
     {
389 392
         static $imgopt_base_url = null;
@@ -767,6 +770,9 @@  discard block
 block discarded – undo
767 770
         return $out;
768 771
     }
769 772
 
773
+    /**
774
+     * @param string $tag
775
+     */
770 776
     public function add_lazyload( $tag, $placeholder = '' ) {
771 777
         // adds actual lazyload-attributes to an image node.
772 778
         $this->lazyload_counter++;
@@ -858,6 +864,9 @@  discard block
 block discarded – undo
858 864
         }
859 865
     }
860 866
 
867
+    /**
868
+     * @return string
869
+     */
861 870
     public function get_cdn_url() {
862 871
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
863 872
         static $cdn_url = null;
@@ -961,6 +970,9 @@  discard block
 block discarded – undo
961 970
         return $out;
962 971
     }
963 972
 
973
+    /**
974
+     * @return string
975
+     */
964 976
     public function process_bgimage( $in ) {
965 977
         if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
966 978
             $out = preg_replace_callback(
@@ -1313,7 +1325,7 @@  discard block
 block discarded – undo
1313 1325
     /**
1314 1326
      * Determines and returns the service launch status.
1315 1327
      *
1316
-     * @return bool
1328
+     * @return null|boolean
1317 1329
      */
1318 1330
     public function launch_ok()
1319 1331
     {
Please login to merge, or discard this patch.
Spacing   +359 added lines, -359 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,18 +23,18 @@  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
         $this->lazyload_counter = 0;
35 35
     }
36 36
 
37
-    public function set_options( array $options )
37
+    public function set_options(array $options)
38 38
     {
39 39
         $this->options = $options;
40 40
 
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
 
44 44
     public static function fetch_options()
45 45
     {
46
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
47
-        if ( empty( $value ) ) {
46
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
47
+        if (empty($value)) {
48 48
             // Fallback to returning defaults when no stored option exists yet.
49 49
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
50 50
         }
51 51
 
52 52
         // get service availability and add it to the options-array.
53
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
53
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
54 54
 
55
-        if ( empty( $value['availabilities'] ) ) {
56
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
55
+        if (empty($value['availabilities'])) {
56
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
57 57
         }
58 58
 
59 59
         return $value;
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
         // and does not use/ request the availablity data (which could slow things down).
67 67
         static $imgopt_active = null;
68 68
 
69
-        if ( null === $imgopt_active ) {
70
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
71
-            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'] ) {
69
+        if (null === $imgopt_active) {
70
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
71
+            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']) {
72 72
                 $imgopt_active = true;
73 73
             } else {
74 74
                 $imgopt_active = false;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public static function instance()
90 90
     {
91
-        if ( null === self::$instance ) {
91
+        if (null === self::$instance) {
92 92
             self::$instance = new self();
93 93
         }
94 94
 
@@ -97,34 +97,34 @@  discard block
 block discarded – undo
97 97
 
98 98
     public function run()
99 99
     {
100
-        if ( is_admin() ) {
101
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
102
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
100
+        if (is_admin()) {
101
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
102
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
103 103
             } else {
104
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
104
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
105 105
             }
106
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
106
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
107 107
         } else {
108
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
108
+            add_action('wp', array($this, 'run_on_frontend'));
109 109
         }
110 110
     }
111 111
 
112 112
     public function run_on_frontend() {
113
-        if ( ! $this->should_run() ) {
114
-            if ( $this->should_lazyload() ) {
113
+        if (!$this->should_run()) {
114
+            if ($this->should_lazyload()) {
115 115
                 add_filter(
116 116
                     'wp_lazy_loading_enabled',
117 117
                     '__return_false'
118 118
                 );
119 119
                 add_filter(
120 120
                     'autoptimize_html_after_minify',
121
-                    array( $this, 'filter_lazyload_images' ),
121
+                    array($this, 'filter_lazyload_images'),
122 122
                     10,
123 123
                     1
124 124
                 );
125 125
                 add_action(
126 126
                     'wp_footer',
127
-                    array( $this, 'add_lazyload_js_footer' ),
127
+                    array($this, 'add_lazyload_js_footer'),
128 128
                     10,
129 129
                     0
130 130
                 );
@@ -134,43 +134,43 @@  discard block
 block discarded – undo
134 134
 
135 135
         $active = false;
136 136
 
137
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
137
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
138 138
             add_filter(
139 139
                 'autoptimize_html_after_minify',
140
-                array( $this, 'filter_optimize_images' ),
140
+                array($this, 'filter_optimize_images'),
141 141
                 10,
142 142
                 1
143 143
             );
144 144
             $active = true;
145 145
         }
146 146
 
147
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
147
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
148 148
             add_filter(
149 149
                 'autoptimize_filter_base_replace_cdn',
150
-                array( $this, 'filter_optimize_css_images' ),
150
+                array($this, 'filter_optimize_css_images'),
151 151
                 10,
152 152
                 1
153 153
             );
154 154
             $active = true;
155 155
         }
156 156
 
157
-        if ( $active ) {
157
+        if ($active) {
158 158
             add_filter(
159 159
                 'autoptimize_extra_filter_tobepreconn',
160
-                array( $this, 'filter_preconnect_imgopt_url' ),
160
+                array($this, 'filter_preconnect_imgopt_url'),
161 161
                 10,
162 162
                 1
163 163
             );
164 164
         }
165 165
 
166
-        if ( $this->should_lazyload() ) {
166
+        if ($this->should_lazyload()) {
167 167
             add_filter(
168 168
                 'wp_lazy_loading_enabled',
169 169
                 '__return_false'
170 170
             );
171 171
             add_action(
172 172
                 'wp_footer',
173
-                array( $this, 'add_lazyload_js_footer' ),
173
+                array($this, 'add_lazyload_js_footer'),
174 174
                 10,
175 175
                 0
176 176
             );
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
     protected function should_run()
186 186
     {
187 187
         $opts              = $this->options;
188
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
189
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
188
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
189
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
190 190
 
191 191
         $do_cdn      = true;
192 192
         $_userstatus = $this->get_imgopt_provider_userstatus();
193
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
193
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
194 194
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
195 195
             $do_cdn = false;
196 196
         }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             $this->imgopt_active()
200 200
             && $do_cdn
201 201
             && $service_not_down
202
-            && ( $not_launch_status || $this->launch_ok() )
202
+            && ($not_launch_status || $this->launch_ok())
203 203
         ) {
204 204
             return true;
205 205
         }
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
     {
211 211
         static $imgopt_host = null;
212 212
 
213
-        if ( null === $imgopt_host ) {
213
+        if (null === $imgopt_host) {
214 214
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
215 215
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
216
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
217
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
216
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
217
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
218 218
             }
219
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
219
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
220 220
         }
221 221
 
222 222
         return $imgopt_host;
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
     public static function get_service_url_suffix()
233 233
     {
234
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
234
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
235 235
 
236 236
         return $suffix;
237 237
     }
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
     {
241 241
         static $quality = null;
242 242
 
243
-        if ( null === $quality ) {
243
+        if (null === $quality) {
244 244
             $q_array = $this->get_img_quality_array();
245 245
             $setting = $this->get_img_quality_setting();
246 246
             $quality = apply_filters(
247 247
                 'autoptimize_filter_imgopt_quality',
248
-                'q_' . $q_array[ $setting ]
248
+                'q_'.$q_array[$setting]
249 249
             );
250 250
         }
251 251
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         static $map = null;
258 258
 
259
-        if ( null === $map ) {
259
+        if (null === $map) {
260 260
             $map = array(
261 261
                 '1' => 'lossy',
262 262
                 '2' => 'glossy',
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
     {
276 276
         static $q = null;
277 277
 
278
-        if ( null === $q ) {
279
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
278
+        if (null === $q) {
279
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
280 280
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
281 281
             }
282 282
 
283
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
283
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
284 284
                 // default image opt. value is 2 ("glossy").
285 285
                 $q = '2';
286 286
             } else {
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
         return $q;
292 292
     }
293 293
 
294
-    public function filter_preconnect_imgopt_url( array $in )
294
+    public function filter_preconnect_imgopt_url(array $in)
295 295
     {
296
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
297
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
296
+        $url_parts = parse_url($this->get_imgopt_base_url());
297
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
298 298
 
299 299
         return $in;
300 300
     }
@@ -307,20 +307,20 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return string
309 309
      */
310
-    private function normalize_img_url( $in )
310
+    private function normalize_img_url($in)
311 311
     {
312 312
         // Only parse the site url once.
313 313
         static $parsed_site_url = null;
314
-        if ( null === $parsed_site_url ) {
315
-            $parsed_site_url = parse_url( site_url() );
314
+        if (null === $parsed_site_url) {
315
+            $parsed_site_url = parse_url(site_url());
316 316
         }
317 317
 
318 318
         // get CDN domain once.
319 319
         static $cdn_domain = null;
320
-        if ( is_null( $cdn_domain ) ) {
320
+        if (is_null($cdn_domain)) {
321 321
             $cdn_url = $this->get_cdn_url();
322
-            if ( ! empty( $cdn_url ) ) {
323
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
322
+            if (!empty($cdn_url)) {
323
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
324 324
             } else {
325 325
                 $cdn_domain = '';
326 326
             }
@@ -336,49 +336,49 @@  discard block
 block discarded – undo
336 336
          * identical string operations).
337 337
          */
338 338
         static $cache = null;
339
-        if ( null === $cache ) {
339
+        if (null === $cache) {
340 340
             $cache = array();
341 341
         }
342 342
 
343 343
         // Do the work on cache miss only.
344
-        if ( ! isset( $cache[ $in ] ) ) {
344
+        if (!isset($cache[$in])) {
345 345
             // Default to (the trimmed version of) what was given to us.
346
-            $result = trim( $in );
346
+            $result = trim($in);
347 347
 
348 348
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
349
-            if ( strpos( $result, '&quot;' ) !== false ) {
350
-                $result = str_replace( '&quot;', '', $result );
349
+            if (strpos($result, '&quot;') !== false) {
350
+                $result = str_replace('&quot;', '', $result);
351 351
             }
352 352
 
353
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
354
-                $result = $parsed_site_url['scheme'] . ':' . $result;
355
-            } elseif ( 0 === strpos( $result, '/' ) ) {
353
+            if (autoptimizeUtils::is_protocol_relative($result)) {
354
+                $result = $parsed_site_url['scheme'].':'.$result;
355
+            } elseif (0 === strpos($result, '/')) {
356 356
                 // Root-relative...
357
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
358
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
359
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
357
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
358
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
359
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
360 360
             }
361 361
 
362 362
             // filter (default off) to remove QS from image URL's to avoid eating away optimization credits.
363
-            if ( apply_filters( 'autoptimize_filter_imgopt_no_querystring', false ) && strpos( $result, '?' ) !== false ) {
364
-                $result = strtok( $result, '?' );
363
+            if (apply_filters('autoptimize_filter_imgopt_no_querystring', false) && strpos($result, '?') !== false) {
364
+                $result = strtok($result, '?');
365 365
             }
366 366
 
367
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
367
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
368 368
 
369 369
             // Store in cache.
370
-            $cache[ $in ] = $result;
370
+            $cache[$in] = $result;
371 371
         }
372 372
 
373
-        return $cache[ $in ];
373
+        return $cache[$in];
374 374
     }
375 375
 
376
-    public function filter_optimize_css_images( $in )
376
+    public function filter_optimize_css_images($in)
377 377
     {
378
-        $in = $this->normalize_img_url( $in );
378
+        $in = $this->normalize_img_url($in);
379 379
 
380
-        if ( $this->can_optimize_image( $in ) ) {
381
-            return $this->build_imgopt_url( $in, '', '' );
380
+        if ($this->can_optimize_image($in)) {
381
+            return $this->build_imgopt_url($in, '', '');
382 382
         } else {
383 383
             return $in;
384 384
         }
@@ -388,53 +388,53 @@  discard block
 block discarded – undo
388 388
     {
389 389
         static $imgopt_base_url = null;
390 390
 
391
-        if ( null === $imgopt_base_url ) {
391
+        if (null === $imgopt_base_url) {
392 392
             $imgopt_host     = $this->get_imgopt_host();
393 393
             $quality         = $this->get_img_quality_string();
394
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
395
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
396
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
394
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
395
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
396
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
397 397
         }
398 398
 
399 399
         return $imgopt_base_url;
400 400
     }
401 401
 
402
-    private function can_optimize_image( $url, $tag = '', $testing = false )
402
+    private function can_optimize_image($url, $tag = '', $testing = false)
403 403
     {
404 404
         static $cdn_url      = null;
405 405
         static $nopti_images = null;
406 406
 
407
-        if ( null === $cdn_url ) {
407
+        if (null === $cdn_url) {
408 408
             $cdn_url = apply_filters(
409 409
                 'autoptimize_filter_base_cdnurl',
410
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
410
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
411 411
             );
412 412
         }
413 413
 
414
-        if ( null === $nopti_images || $testing ) {
415
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_text_field_6', $this->options ) ) {
414
+        if (null === $nopti_images || $testing) {
415
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_text_field_6', $this->options)) {
416 416
                 $nopti_images = $this->options['autoptimize_imgopt_text_field_6'];
417 417
             }
418
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', $nopti_images );
418
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', $nopti_images);
419 419
         }
420 420
 
421 421
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
422
-        $url        = $this->normalize_img_url( $url );
423
-        $url_parsed = parse_url( $url );
422
+        $url        = $this->normalize_img_url($url);
423
+        $url_parsed = parse_url($url);
424 424
 
425
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
425
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
426 426
             return false;
427
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
427
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
428 428
             return false;
429
-        } elseif ( strpos( $url, '.php' ) !== false ) {
429
+        } elseif (strpos($url, '.php') !== false) {
430 430
             return false;
431
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
431
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif'), '', $url_parsed['path']) === $url_parsed['path']) {
432 432
             // fixme: better check against end of string.
433 433
             return false;
434
-        } elseif ( ! empty( $nopti_images ) ) {
435
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
436
-            foreach ( $nopti_images_array as $nopti_image ) {
437
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
434
+        } elseif (!empty($nopti_images)) {
435
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
436
+            foreach ($nopti_images_array as $nopti_image) {
437
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
438 438
                     return false;
439 439
                 }
440 440
             }
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
         return true;
443 443
     }
444 444
 
445
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
445
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
446 446
     {
447 447
         // sanitize width and height.
448
-        if ( strpos( $width, '%' ) !== false ) {
448
+        if (strpos($width, '%') !== false) {
449 449
             $width = 0;
450 450
         }
451
-        if ( strpos( $height, '%' ) !== false ) {
451
+        if (strpos($height, '%') !== false) {
452 452
             $height = 0;
453 453
         }
454 454
         $width  = (int) $width;
@@ -462,46 +462,46 @@  discard block
 block discarded – undo
462 462
         );
463 463
 
464 464
         // If filter modified the url, return that.
465
-        if ( $filtered_url !== $orig_url ) {
465
+        if ($filtered_url !== $orig_url) {
466 466
             return $filtered_url;
467 467
         }
468 468
 
469
-        $orig_url        = $this->normalize_img_url( $orig_url );
469
+        $orig_url        = $this->normalize_img_url($orig_url);
470 470
         $imgopt_base_url = $this->get_imgopt_base_url();
471 471
         $imgopt_size     = '';
472 472
 
473
-        if ( $width && 0 !== $width ) {
474
-            $imgopt_size = ',w_' . $width;
473
+        if ($width && 0 !== $width) {
474
+            $imgopt_size = ',w_'.$width;
475 475
         }
476 476
 
477
-        if ( $height && 0 !== $height ) {
478
-            $imgopt_size .= ',h_' . $height;
477
+        if ($height && 0 !== $height) {
478
+            $imgopt_size .= ',h_'.$height;
479 479
         }
480 480
 
481
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
481
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
482 482
 
483 483
         return $url;
484 484
     }
485 485
 
486
-    public function replace_data_thumbs( $matches )
486
+    public function replace_data_thumbs($matches)
487 487
     {
488
-        return $this->replace_img_callback( $matches, 150, 150 );
488
+        return $this->replace_img_callback($matches, 150, 150);
489 489
     }
490 490
 
491
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
491
+    public function replace_img_callback($matches, $width = 0, $height = 0)
492 492
     {
493
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
494
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
495
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
493
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
494
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
495
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
496 496
         } else {
497 497
             return $matches[0];
498 498
         }
499 499
     }
500 500
 
501
-    public function replace_icon_callback( $matches )
501
+    public function replace_icon_callback($matches)
502 502
     {
503
-        if ( array_key_exists( '2', $matches ) ) {
504
-            $sizes  = explode( 'x', $matches[2] );
503
+        if (array_key_exists('2', $matches)) {
504
+            $sizes  = explode('x', $matches[2]);
505 505
             $width  = $sizes[0];
506 506
             $height = $sizes[1];
507 507
         } else {
@@ -510,14 +510,14 @@  discard block
 block discarded – undo
510 510
         }
511 511
 
512 512
         // make sure we're not trying to optimize a *.ico file
513
-        if ( strpos( $matches[1], '.ico' ) === false ) {
514
-            return $this->replace_img_callback( $matches, $width, $height );
513
+        if (strpos($matches[1], '.ico') === false) {
514
+            return $this->replace_img_callback($matches, $width, $height);
515 515
         } else {
516 516
             return $matches[0];
517 517
         }
518 518
     }
519 519
 
520
-    public function filter_optimize_images( $in, $testing = false )
520
+    public function filter_optimize_images($in, $testing = false)
521 521
     {
522 522
         /*
523 523
          * potential future functional improvements:
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
         $to_replace = array();
528 528
 
529 529
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
530
-        if ( $this->should_lazyload() ) {
530
+        if ($this->should_lazyload()) {
531 531
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
532 532
                 'SCRIPT',
533 533
                 '<script',
@@ -537,161 +537,161 @@  discard block
 block discarded – undo
537 537
         }
538 538
 
539 539
         // extract img tags.
540
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
541
-            foreach ( $matches[0] as $tag ) {
540
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
541
+            foreach ($matches[0] as $tag) {
542 542
                 $orig_tag = $tag;
543 543
                 $imgopt_w = '';
544 544
                 $imgopt_h = '';
545 545
 
546 546
                 // first do (data-)srcsets.
547
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
548
-                    foreach ( $allsrcsets as $srcset ) {
547
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
548
+                    foreach ($allsrcsets as $srcset) {
549 549
                         $srcset      = $srcset[2];
550 550
                         $orig_srcset = $srcset;
551
-                        $srcsets     = explode( ',', $srcset );
552
-                        foreach ( $srcsets as $indiv_srcset ) {
553
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
554
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
555
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
551
+                        $srcsets     = explode(',', $srcset);
552
+                        foreach ($srcsets as $indiv_srcset) {
553
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
554
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
555
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
556 556
                             }
557
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag, $testing ) ) {
558
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
559
-                                $srcset     = str_replace( $indiv_srcset_parts[0], $imgopt_url, $srcset );
557
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag, $testing)) {
558
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
559
+                                $srcset     = str_replace($indiv_srcset_parts[0], $imgopt_url, $srcset);
560 560
                             }
561 561
                         }
562
-                        $tag = str_replace( $orig_srcset, $srcset, $tag );
562
+                        $tag = str_replace($orig_srcset, $srcset, $tag);
563 563
                     }
564 564
                 }
565 565
 
566 566
                 // proceed with img src.
567 567
                 // get width and height and add to $imgopt_size.
568
-                $_get_size = $this->get_size_from_tag( $tag );
568
+                $_get_size = $this->get_size_from_tag($tag);
569 569
                 $imgopt_w  = $_get_size['width'];
570 570
                 $imgopt_h  = $_get_size['height'];
571 571
 
572 572
                 // then start replacing images src.
573
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
574
-                    foreach ( $urls as $url ) {
573
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
574
+                    foreach ($urls as $url) {
575 575
                         $full_src_orig = $url[0];
576 576
                         $url           = $url[1];
577
-                        if ( $this->can_optimize_image( $url, $full_src_orig, $testing ) ) {
578
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
579
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
580
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
577
+                        if ($this->can_optimize_image($url, $full_src_orig, $testing)) {
578
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
579
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
580
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
581 581
                         }
582 582
                     }
583 583
                 }
584 584
 
585 585
                 // do lazyload stuff.
586
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
586
+                if ($this->should_lazyload($in) && !empty($url)) {
587 587
                     // first do lpiq placeholder logic.
588
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
588
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
589 589
                         // if all img src have been replaced during srcset, we have to extract the
590 590
                         // origin url from the imgopt one to be able to set a lqip placeholder.
591
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
591
+                        $_url = substr($url, strpos($url, '/http') + 1);
592 592
                     } else {
593 593
                         $_url = $url;
594 594
                     }
595 595
 
596
-                    $_url = $this->normalize_img_url( $_url );
596
+                    $_url = $this->normalize_img_url($_url);
597 597
 
598 598
                     $placeholder = '';
599
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true, $_url ) ) {
599
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true, $_url)) {
600 600
                         $lqip_w = '';
601 601
                         $lqip_h = '';
602
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
603
-                            $lqip_w = ',w_' . $imgopt_w;
602
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
603
+                            $lqip_w = ',w_'.$imgopt_w;
604 604
                         }
605
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
606
-                            $lqip_h = ',h_' . $imgopt_h;
605
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
606
+                            $lqip_h = ',h_'.$imgopt_h;
607 607
                         }
608
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
608
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
609 609
                     }
610 610
                     // then call add_lazyload-function with lpiq placeholder if set.
611
-                    $tag = $this->add_lazyload( $tag, $placeholder );
611
+                    $tag = $this->add_lazyload($tag, $placeholder);
612 612
                 }
613 613
 
614 614
                 // and add tag to array for later replacement.
615
-                if ( $tag !== $orig_tag ) {
616
-                    $to_replace[ $orig_tag ] = $tag;
615
+                if ($tag !== $orig_tag) {
616
+                    $to_replace[$orig_tag] = $tag;
617 617
                 }
618 618
             }
619 619
         }
620 620
 
621 621
         // and replace all.
622
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
622
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
623 623
 
624 624
         // img thumbnails in e.g. woocommerce.
625
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
625
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
626 626
             $out = preg_replace_callback(
627 627
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
628
-                array( $this, 'replace_data_thumbs' ),
628
+                array($this, 'replace_data_thumbs'),
629 629
                 $out
630 630
             );
631 631
         }
632 632
 
633 633
         // background-image in inline style.
634
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
634
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
635 635
             $out = preg_replace_callback(
636 636
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
637
-                array( $this, 'replace_img_callback' ),
637
+                array($this, 'replace_img_callback'),
638 638
                 $out
639 639
             );
640 640
         }
641 641
 
642 642
         // act on icon links.
643
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
643
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
644 644
             $out = preg_replace_callback(
645 645
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
646
-                array( $this, 'replace_icon_callback' ),
646
+                array($this, 'replace_icon_callback'),
647 647
                 $out
648 648
             );
649 649
         }
650 650
 
651 651
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
652
-        if ( $this->should_lazyload() ) {
652
+        if ($this->should_lazyload()) {
653 653
             $out = autoptimizeBase::restore_marked_content(
654 654
                 'SCRIPT',
655 655
                 $out
656 656
             );
657 657
 
658
-            $out = $this->process_picture_tag( $out, true, true );
659
-            $out = $this->process_bgimage( $out );
658
+            $out = $this->process_picture_tag($out, true, true);
659
+            $out = $this->process_bgimage($out);
660 660
         } else {
661
-            $out = $this->process_picture_tag( $out, true, false );
661
+            $out = $this->process_picture_tag($out, true, false);
662 662
         }
663 663
 
664 664
         return $out;
665 665
     }
666 666
 
667
-    public function get_size_from_tag( $tag ) {
667
+    public function get_size_from_tag($tag) {
668 668
         // reusable function to extract widht and height from an image tag
669 669
         // enforcing a filterable maximum width and height (default 4999X4999).
670 670
         $width  = '';
671 671
         $height = '';
672 672
 
673
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
674
-            if ( strpos( $_width[2], '%' ) === false ) {
673
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
674
+            if (strpos($_width[2], '%') === false) {
675 675
                 $width = (int) $_width[2];
676 676
             }
677 677
         }
678
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
679
-            if ( strpos( $_height[2], '%' ) === false ) {
678
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
679
+            if (strpos($_height[2], '%') === false) {
680 680
                 $height = (int) $_height[2];
681 681
             }
682 682
         }
683 683
 
684 684
         // check for and enforce (filterable) max sizes.
685
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
686
-        if ( $width > $_max_width ) {
685
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
686
+        if ($width > $_max_width) {
687 687
             $_width = $_max_width;
688
-            $height = $_width / $width * $height;
688
+            $height = $_width/$width*$height;
689 689
             $width  = $_width;
690 690
         }
691
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
692
-        if ( $height > $_max_height ) {
691
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
692
+        if ($height > $_max_height) {
693 693
             $_height = $_max_height;
694
-            $width   = $_height / $height * $width;
694
+            $width   = $_height/$height*$width;
695 695
             $height  = $_height;
696 696
         }
697 697
 
@@ -710,26 +710,26 @@  discard block
 block discarded – undo
710 710
         return $self->should_lazyload();
711 711
     }
712 712
 
713
-    public function should_lazyload( $context = '' ) {
714
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
713
+    public function should_lazyload($context = '') {
714
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
715 715
             $lazyload_return = true;
716 716
         } else {
717 717
             $lazyload_return = false;
718 718
         }
719
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
719
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
720 720
 
721 721
         return $lazyload_return;
722 722
     }
723 723
 
724 724
     public function check_nolazy() {
725
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
725
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
726 726
             return true;
727 727
         } else {
728 728
             return false;
729 729
         }
730 730
     }
731 731
 
732
-    public function filter_lazyload_images( $in )
732
+    public function filter_lazyload_images($in)
733 733
     {
734 734
         // only used is image optimization is NOT active but lazyload is.
735 735
         $to_replace = array();
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
         );
744 744
 
745 745
         // extract img tags and add lazyload attribs.
746
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
747
-            foreach ( $matches[0] as $tag ) {
748
-                if ( $this->should_lazyload( $out ) ) {
749
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
746
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
747
+            foreach ($matches[0] as $tag) {
748
+                if ($this->should_lazyload($out)) {
749
+                    $to_replace[$tag] = $this->add_lazyload($tag);
750 750
                 }
751 751
             }
752
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
752
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
753 753
         }
754 754
 
755 755
         // and also lazyload picture tag.
756
-        $out = $this->process_picture_tag( $out, false, true );
756
+        $out = $this->process_picture_tag($out, false, true);
757 757
 
758 758
         // and inline style blocks with background-image.
759
-        $out = $this->process_bgimage( $out );
759
+        $out = $this->process_bgimage($out);
760 760
 
761 761
         // restore noscript tags.
762 762
         $out = autoptimizeBase::restore_marked_content(
@@ -767,86 +767,86 @@  discard block
 block discarded – undo
767 767
         return $out;
768 768
     }
769 769
 
770
-    public function add_lazyload( $tag, $placeholder = '' ) {
770
+    public function add_lazyload($tag, $placeholder = '') {
771 771
         // adds actual lazyload-attributes to an image node.
772 772
         $this->lazyload_counter++;
773
-        $_lazyload_from_nth = apply_filters( 'autoptimize_filter_imgopt_lazyload_from_nth', $this->options['autoptimize_imgopt_number_field_7'] );
774
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag && $this->lazyload_counter >= $_lazyload_from_nth ) {
775
-            $tag = $this->maybe_fix_missing_quotes( $tag );
773
+        $_lazyload_from_nth = apply_filters('autoptimize_filter_imgopt_lazyload_from_nth', $this->options['autoptimize_imgopt_number_field_7']);
774
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag && $this->lazyload_counter >= $_lazyload_from_nth) {
775
+            $tag = $this->maybe_fix_missing_quotes($tag);
776 776
 
777 777
             // store original tag for use in noscript version.
778
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
778
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
779 779
 
780
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
780
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
781 781
 
782 782
             // insert lazyload class.
783
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
783
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
784 784
 
785
-            if ( ! $placeholder || empty( $placeholder ) ) {
785
+            if (!$placeholder || empty($placeholder)) {
786 786
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
787
-                $_get_size = $this->get_size_from_tag( $tag );
787
+                $_get_size = $this->get_size_from_tag($tag);
788 788
                 $width     = $_get_size['width'];
789 789
                 $height    = $_get_size['height'];
790
-                if ( false === $width || empty( $width ) ) {
790
+                if (false === $width || empty($width)) {
791 791
                     $width = 210; // default width for SVG placeholder.
792 792
                 }
793
-                if ( false === $height || empty( $height ) ) {
794
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
793
+                if (false === $height || empty($height)) {
794
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
795 795
                 }
796 796
 
797 797
                 // insert the actual lazyload stuff.
798 798
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
799
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
799
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
800 800
             }
801 801
 
802
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
803
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
802
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
803
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
804 804
 
805 805
             // move sizes to data-sizes unless filter says no.
806
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
807
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
806
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
807
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
808 808
             }
809 809
 
810 810
             // add the noscript-tag from earlier.
811
-            $tag = $noscript_tag . $tag;
812
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
811
+            $tag = $noscript_tag.$tag;
812
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
813 813
         }
814 814
 
815 815
         return $tag;
816 816
     }
817 817
 
818 818
     public function add_lazyload_js_footer() {
819
-        if ( false === autoptimizeMain::should_buffer() ) {
819
+        if (false === autoptimizeMain::should_buffer()) {
820 820
             return;
821 821
         }
822 822
 
823 823
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
824 824
         $noptimize_flag = '';
825
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
825
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
826 826
             $noptimize_flag = ' data-noptimize="1"';
827 827
         }
828 828
 
829
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
829
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
830 830
         $cdn_url      = $this->get_cdn_url();
831
-        if ( ! empty( $cdn_url ) ) {
832
-            $cdn_url      = rtrim( $cdn_url, '/' );
833
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
831
+        if (!empty($cdn_url)) {
832
+            $cdn_url      = rtrim($cdn_url, '/');
833
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
834 834
         }
835 835
 
836 836
         $type_js = '';
837
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
837
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
838 838
             $type_js = ' type="text/javascript"';
839 839
         }
840 840
 
841 841
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
842
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
843
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
844
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
842
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
843
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
844
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
845 845
 
846 846
         // And add webp detection and loading JS.
847
-        if ( $this->should_ngimg() ) {
847
+        if ($this->should_ngimg()) {
848 848
             // Add AVIF code, can be disabled for now to only do webp.
849
-            if ( apply_filters( 'autoptimize_filter_imgopt_do_avif', true ) ) {
849
+            if (apply_filters('autoptimize_filter_imgopt_do_avif', true)) {
850 850
                 $_ngimg_detect = 'function c_img(a,b){src="avif"==b?"data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABoAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACJtZGF0EgAKCBgADsgQEAwgMgwf8AAAWAAAAACvJ+o=":"data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==";var c=new Image;c.onload=function(){var d=0<c.width&&0<c.height;a(d,b)},c.onerror=function(){a(!1,b)},c.src=src}function s_img(a,b){w=window,"avif"==b?!1==a?c_img(s_img,"webp"):w.ngImg="avif":!1==a?w.ngImg=!1:w.ngImg="webp"}c_img(s_img,"avif");';
851 851
                 $_ngimg_load   = 'document.addEventListener("lazybeforeunveil",function({target:a}){window.ngImg&&["data-src","data-srcset"].forEach(function(b){attr=a.getAttribute(b),null!==attr&&-1==attr.indexOf("/client/to_")&&a.setAttribute(b,attr.replace(/\/client\//,"/client/to_"+window.ngImg+","))})});';
852 852
             } else {
@@ -854,8 +854,8 @@  discard block
 block discarded – undo
854 854
                 $_ngimg_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,'))})});";
855 855
             }
856 856
             // Keeping autoptimize_filter_imgopt_webp_js filter for now, but it is deprecated as not only for webp any more.
857
-            $_ngimg_output = apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_ngimg_detect . $_ngimg_load . '</script>' );
858
-            echo apply_filters( 'autoptimize_filter_imgopt_ngimg_js', $_ngimg_output );
857
+            $_ngimg_output = apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_ngimg_detect.$_ngimg_load.'</script>');
858
+            echo apply_filters('autoptimize_filter_imgopt_ngimg_js', $_ngimg_output);
859 859
         }
860 860
     }
861 861
 
@@ -863,10 +863,10 @@  discard block
 block discarded – undo
863 863
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
864 864
         static $cdn_url = null;
865 865
 
866
-        if ( null === $cdn_url ) {
867
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
868
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
869
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
866
+        if (null === $cdn_url) {
867
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
868
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
869
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
870 870
         }
871 871
 
872 872
         return $cdn_url;
@@ -876,47 +876,47 @@  discard block
 block discarded – undo
876 876
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
877 877
         static $exclude_lazyload_array = null;
878 878
 
879
-        if ( null === $exclude_lazyload_array ) {
879
+        if (null === $exclude_lazyload_array) {
880 880
             $options = $this->options;
881 881
 
882 882
             // set default exclusions.
883
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
883
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
884 884
 
885 885
             // add from setting.
886
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
886
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
887 887
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
888
-                if ( ! empty( $exclude_lazyload_option ) ) {
889
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
888
+                if (!empty($exclude_lazyload_option)) {
889
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
890 890
                 }
891 891
             }
892 892
 
893 893
             // and filter for developer-initiated changes.
894
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
894
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
895 895
         }
896 896
 
897 897
         return $exclude_lazyload_array;
898 898
     }
899 899
 
900
-    public function inject_classes_in_tag( $tag, $target_class ) {
901
-        if ( strpos( $tag, 'class=' ) !== false ) {
902
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
900
+    public function inject_classes_in_tag($tag, $target_class) {
901
+        if (strpos($tag, 'class=') !== false) {
902
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
903 903
         } else {
904
-            $tag = preg_replace( '/(<[a-zA-Z]*)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
904
+            $tag = preg_replace('/(<[a-zA-Z]*)\s/', '$1 class="'.trim($target_class).'" ', $tag);
905 905
         }
906 906
 
907 907
         return $tag;
908 908
     }
909 909
 
910
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
911
-        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';
910
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
911
+        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';
912 912
     }
913 913
 
914 914
     public function should_ngimg() {
915 915
         static $ngimg_return = null;
916 916
 
917
-        if ( is_null( $ngimg_return ) ) {
917
+        if (is_null($ngimg_return)) {
918 918
             // webp only works if imgopt and lazyload are also active.
919
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
919
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
920 920
                 $ngimg_return = true;
921 921
             } else {
922 922
                 $ngimg_return = false;
@@ -926,9 +926,9 @@  discard block
 block discarded – undo
926 926
         return $ngimg_return;
927 927
     }
928 928
 
929
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
929
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
930 930
         // check if "<picture" is present and if filter allows us to process <picture>.
931
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
931
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
932 932
             return $in;
933 933
         }
934 934
 
@@ -936,37 +936,37 @@  discard block
 block discarded – undo
936 936
         $to_replace_pict = array();
937 937
 
938 938
         // extract and process each picture-node.
939
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
940
-        foreach ( $_pictures as $_picture ) {
941
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
942
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
943
-                foreach ( $_sources as $_source ) {
939
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
940
+        foreach ($_pictures as $_picture) {
941
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
942
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
943
+                foreach ($_sources as $_source) {
944 944
                     $_picture_replacement = $_source[0];
945 945
 
946 946
                     // should we optimize the image?
947
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
948
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
947
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
948
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
949 949
                     }
950 950
                     // should we lazy-load?
951
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
952
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
951
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
952
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
953 953
                     }
954
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
954
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
955 955
                 }
956 956
             }
957 957
         }
958 958
 
959 959
         // and return the fully procesed $in.
960
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
960
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
961 961
 
962 962
         return $out;
963 963
     }
964 964
 
965
-    public function process_bgimage( $in ) {
966
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
965
+    public function process_bgimage($in) {
966
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
967 967
             $out = preg_replace_callback(
968 968
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
969
-                array( $this, 'lazyload_bgimg_callback' ),
969
+                array($this, 'lazyload_bgimg_callback'),
970 970
                 $in
971 971
             );
972 972
             return $out;
@@ -974,27 +974,27 @@  discard block
 block discarded – undo
974 974
         return $in;
975 975
     }
976 976
 
977
-    public function lazyload_bgimg_callback( $matches ) {
978
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
977
+    public function lazyload_bgimg_callback($matches) {
978
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
979 979
             // get placeholder & lazyload class strings.
980
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
981
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
980
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
981
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
982 982
             // replace background-image URL with SVG placeholder.
983
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
983
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
984 984
             // add data-bg attribute with real background-image URL for lazyload to pick up.
985
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
985
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
986 986
             // add lazyload class to tag.
987
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
987
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
988 988
             return $out;
989 989
         }
990 990
         return $matches[0];
991 991
     }
992 992
 
993
-    public function maybe_fix_missing_quotes( $tag_in ) {
993
+    public function maybe_fix_missing_quotes($tag_in) {
994 994
         // 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.
995
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
996
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
997
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
995
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
996
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
997
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
998 998
             return $tag_out;
999 999
         } else {
1000 1000
             return $tag_in;
@@ -1007,23 +1007,23 @@  discard block
 block discarded – undo
1007 1007
     public function imgopt_admin_menu()
1008 1008
     {
1009 1009
         // no acces if multisite and not network admin and no site config allowed.
1010
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1010
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1011 1011
             add_submenu_page(
1012 1012
                 null,
1013 1013
                 'autoptimize_imgopt',
1014 1014
                 'autoptimize_imgopt',
1015 1015
                 'manage_options',
1016 1016
                 'autoptimize_imgopt',
1017
-                array( $this, 'imgopt_options_page' )
1017
+                array($this, 'imgopt_options_page')
1018 1018
             );
1019 1019
         }
1020
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
1020
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
1021 1021
     }
1022 1022
 
1023
-    public function add_imgopt_tab( $in )
1023
+    public function add_imgopt_tab($in)
1024 1024
     {
1025
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1026
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
1025
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1026
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1027 1027
         }
1028 1028
 
1029 1029
         return $in;
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
     public function imgopt_options_page()
1033 1033
     {
1034 1034
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1035
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1035
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1036 1036
             $this->query_img_provider_stats();
1037 1037
         }
1038 1038
 
@@ -1044,47 +1044,47 @@  discard block
 block discarded – undo
1044 1044
         #ao_settings_form .form-table th {font-weight: normal;}
1045 1045
         #autoptimize_imgopt_descr{font-size: 120%;}
1046 1046
     </style>
1047
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1047
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1048 1048
     <div class="wrap">
1049
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1049
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1050 1050
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1051
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1051
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1052 1052
             <div class="notice-warning notice"><p>
1053 1053
             <?php
1054 1054
             // translators: "Autoptimize support forum" will appear in a "a href".
1055
-            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>' );
1055
+            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>');
1056 1056
             ?>
1057 1057
             </p></div>
1058 1058
         <?php } ?>
1059 1059
 
1060
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1060
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1061 1061
             <div class="notice-warning notice"><p>
1062
-            <?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' ); ?>
1062
+            <?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'); ?>
1063 1063
             </p></div>
1064 1064
         <?php } ?>
1065 1065
 
1066
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1066
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1067 1067
             <div class="notice-warning notice"><p>
1068 1068
             <?php
1069 1069
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1070
-            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>' );
1070
+            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>');
1071 1071
             ?>
1072 1072
             </p></div>
1073 1073
         <?php } ?>
1074
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1075
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1076
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1077
-        <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 and AVIF support included!', 'autoptimize' ); ?></span>
1074
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1075
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1076
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1077
+        <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 and AVIF support included!', 'autoptimize'); ?></span>
1078 1078
         <table class="form-table">
1079 1079
             <tr>
1080
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1080
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1081 1081
                 <td>
1082
-                    <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>
1082
+                    <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>
1083 1083
                     <?php
1084 1084
                     // show shortpixel status.
1085 1085
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1086
-                    if ( $_notice ) {
1087
-                        switch ( $_notice['status'] ) {
1086
+                    if ($_notice) {
1087
+                        switch ($_notice['status']) {
1088 1088
                             case 2:
1089 1089
                                 $_notice_color = 'green';
1090 1090
                                 break;
@@ -1099,35 +1099,35 @@  discard block
 block discarded – undo
1099 1099
                             default:
1100 1100
                                 $_notice_color = 'green';
1101 1101
                         }
1102
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1102
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1103 1103
                     } else {
1104 1104
                         // translators: link points to shortpixel.
1105
-                        $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 and AVIF 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>' );
1106
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1107
-                            $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' );
1105
+                        $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 and AVIF 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>');
1106
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1107
+                            $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');
1108 1108
                         } else {
1109 1109
                             // translators: link points to shortpixel.
1110
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1110
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1111 1111
                         }
1112
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1112
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1113 1113
                     }
1114 1114
                     // translators: link points to shortpixel FAQ.
1115
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>' );
1116
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1115
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>');
1116
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1117 1117
                     // translators: links points to shortpixel TOS & Privacy Policy.
1118
-                    $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>' );
1119
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1118
+                    $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>');
1119
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1120 1120
                     ?>
1121 1121
                 </td>
1122 1122
             </tr>
1123
-            <tr id='autoptimize_imgopt_optimization_exclusions' <?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"'; } ?>>
1124
-                <th scope="row"><?php _e( 'Optimization exclusions', 'autoptimize' ); ?></th>
1123
+            <tr id='autoptimize_imgopt_optimization_exclusions' <?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"'; } ?>>
1124
+                <th scope="row"><?php _e('Optimization exclusions', 'autoptimize'); ?></th>
1125 1125
                 <td>
1126
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_optimization_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_6]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_6'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_6'] ); } ?>'><br /><?php _e( 'Comma-separated list of image classes or filenames that should not be optimized.', 'autoptimize' ); ?></label>
1126
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_optimization_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_6]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_6'])) { echo esc_attr($options['autoptimize_imgopt_text_field_6']); } ?>'><br /><?php _e('Comma-separated list of image classes or filenames that should not be optimized.', 'autoptimize'); ?></label>
1127 1127
                 </td>
1128 1128
             </tr>
1129
-            <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"'; } ?>>
1130
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1129
+            <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"'; } ?>>
1130
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1131 1131
                 <td>
1132 1132
                     <label>
1133 1133
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1135,12 +1135,12 @@  discard block
 block discarded – undo
1135 1135
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1136 1136
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1137 1137
 
1138
-                        foreach ( $_imgopt_array as $key => $value ) {
1139
-                            echo '<option value="' . $key . '"';
1140
-                            if ( $_imgopt_val == $key ) {
1138
+                        foreach ($_imgopt_array as $key => $value) {
1139
+                            echo '<option value="'.$key.'"';
1140
+                            if ($_imgopt_val == $key) {
1141 1141
                                 echo ' selected';
1142 1142
                             }
1143
-                            echo '>' . ucfirst( $value ) . '</option>';
1143
+                            echo '>'.ucfirst($value).'</option>';
1144 1144
                         }
1145 1145
                         echo "\n";
1146 1146
                         ?>
@@ -1149,37 +1149,37 @@  discard block
 block discarded – undo
1149 1149
                     <p>
1150 1150
                         <?php
1151 1151
                             // translators: link points to shortpixel image test page.
1152
-                            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>' ) );
1152
+                            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>'));
1153 1153
                         ?>
1154 1154
                     </p>
1155 1155
                 </td>
1156 1156
             </tr>
1157
-            <tr id='autoptimize_imgopt_ngimg' <?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"'; } ?>>
1158
-                <th scope="row"><?php _e( 'Load WebP or AVIF in supported browsers?', 'autoptimize' ); ?></th>
1157
+            <tr id='autoptimize_imgopt_ngimg' <?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"'; } ?>>
1158
+                <th scope="row"><?php _e('Load WebP or AVIF in supported browsers?', 'autoptimize'); ?></th>
1159 1159
                 <td>
1160
-                    <label><input type='checkbox' id='autoptimize_imgopt_ngimg_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 or AVIF image formats to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label>
1160
+                    <label><input type='checkbox' id='autoptimize_imgopt_ngimg_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 or AVIF image formats to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label>
1161 1161
                 </td>
1162 1162
             </tr>
1163 1163
             <tr>
1164
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1164
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1165 1165
                 <td>
1166
-                    <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>
1166
+                    <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>
1167 1167
                 </td>
1168 1168
             </tr>
1169
-            <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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1170
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1169
+            <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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1170
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1171 1171
                 <td>
1172
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions_text' 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>
1172
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions_text' 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>
1173 1173
                 </td>
1174 1174
             </tr>
1175
-            <tr id='autoptimize_imgopt_lazyload_from_nth_image' <?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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1176
-                <th scope="row"><?php _e( 'Lazy-load from nth image', 'autoptimize' ); ?></th>
1175
+            <tr id='autoptimize_imgopt_lazyload_from_nth_image' <?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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1176
+                <th scope="row"><?php _e('Lazy-load from nth image', 'autoptimize'); ?></th>
1177 1177
                 <td>
1178
-                    <label><input type='number' min='0' max='50' style='width:80%' id='autoptimize_imgopt_lazyload_from_nth_image_number' name='autoptimize_imgopt_settings[autoptimize_imgopt_number_field_7]' value='<?php if ( ! empty( $options['autoptimize_imgopt_number_field_7'] ) ) { echo esc_attr( $options['autoptimize_imgopt_number_field_7'] ); } else { echo '0'; } ?>'><br /><?php _e( 'Don\'t lazyload the first X images, \'0\' lazyloads all.', 'autoptimize' ); ?></label>
1178
+                    <label><input type='number' min='0' max='50' style='width:80%' id='autoptimize_imgopt_lazyload_from_nth_image_number' name='autoptimize_imgopt_settings[autoptimize_imgopt_number_field_7]' value='<?php if (!empty($options['autoptimize_imgopt_number_field_7'])) { echo esc_attr($options['autoptimize_imgopt_number_field_7']); } else { echo '0'; } ?>'><br /><?php _e('Don\'t lazyload the first X images, \'0\' lazyloads all.', 'autoptimize'); ?></label>
1179 1179
                 </td>
1180 1180
             </tr>
1181 1181
         </table>
1182
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1182
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1183 1183
     </form>
1184 1184
     <script>
1185 1185
         jQuery(document).ready(function() {
@@ -1217,50 +1217,50 @@  discard block
 block discarded – undo
1217 1217
      * Ïmg opt status as used on dashboard.
1218 1218
      */
1219 1219
     public function get_imgopt_status_notice() {
1220
-        if ( $this->imgopt_active() ) {
1220
+        if ($this->imgopt_active()) {
1221 1221
             $_imgopt_notice  = '';
1222
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1222
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1223 1223
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1224
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1224
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1225 1225
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1226 1226
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1227 1227
 
1228
-            if ( is_array( $_stat ) ) {
1229
-                if ( 1 == $_stat['Status'] ) {
1228
+            if (is_array($_stat)) {
1229
+                if (1 == $_stat['Status']) {
1230 1230
                     // translators: "add more credits" will appear in a "a href".
1231
-                    $_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>' );
1231
+                    $_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>');
1232 1232
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1233 1233
                     // translators: "add more credits" will appear in a "a href".
1234
-                    $_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>' );
1234
+                    $_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>');
1235 1235
                     // translators: "associate your domain" will appear in a "a href".
1236
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you have enough credits/ CDN quota remaining, 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>' );
1236
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you have enough credits/ CDN quota remaining, 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>');
1237 1237
                 } elseif ( -3 == $_stat['Status'] ) {
1238 1238
                     // translators: "check the documentation here" will appear in a "a href".
1239
-                    $_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>' );
1239
+                    $_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>');
1240 1240
                 } else {
1241 1241
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1242 1242
                     // translators: "log in to check your account" will appear in a "a href".
1243
-                    $_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>' );
1243
+                    $_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>');
1244 1244
                 }
1245 1245
 
1246 1246
                 // add info on freshness + refresh link if status is not 2 (good shape).
1247
-                if ( 2 != $_stat['Status'] ) {
1248
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1247
+                if (2 != $_stat['Status']) {
1248
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1249 1249
                         'page'                => 'autoptimize_imgopt',
1250 1250
                         'refreshImgProvStats' => '1',
1251
-                    ), admin_url( 'options-general.php' ) );
1252
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1253
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1251
+                    ), admin_url('options-general.php'));
1252
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1253
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1254 1254
                     } else {
1255
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1255
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1256 1256
                     }
1257
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1257
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1258 1258
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1259
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1259
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1260 1260
                 }
1261 1261
 
1262 1262
                 // and make the full notice filterable.
1263
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1263
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1264 1264
 
1265 1265
                 return array(
1266 1266
                     'status' => $_stat['Status'],
@@ -1281,14 +1281,14 @@  discard block
 block discarded – undo
1281 1281
      * Get img provider stats (used to display notice).
1282 1282
      */
1283 1283
     public function query_img_provider_stats() {
1284
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1284
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1285 1285
             $url      = '';
1286
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1286
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1287 1287
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1288 1288
 
1289 1289
             // make sure parse_url result makes sense, keeping $url empty if not.
1290
-            if ( $domain && ! empty( $domain ) ) {
1291
-                $url = $endpoint . $domain;
1290
+            if ($domain && !empty($domain)) {
1291
+                $url = $endpoint.$domain;
1292 1292
             }
1293 1293
 
1294 1294
             $url = apply_filters(
@@ -1298,12 +1298,12 @@  discard block
 block discarded – undo
1298 1298
 
1299 1299
             // only do the remote call if $url is not empty to make sure no parse_url
1300 1300
             // weirdness results in useless calls.
1301
-            if ( ! empty( $url ) ) {
1302
-                $response = wp_remote_get( $url );
1303
-                if ( ! is_wp_error( $response ) ) {
1304
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1305
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1306
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1301
+            if (!empty($url)) {
1302
+                $response = wp_remote_get($url);
1303
+                if (!is_wp_error($response)) {
1304
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1305
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1306
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1307 1307
                     }
1308 1308
                 }
1309 1309
             }
@@ -1326,15 +1326,15 @@  discard block
 block discarded – undo
1326 1326
     {
1327 1327
         static $launch_status = null;
1328 1328
 
1329
-        if ( null === $launch_status ) {
1329
+        if (null === $launch_status) {
1330 1330
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1331
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1332
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1331
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1332
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1333 1333
             $launch_status = false;
1334
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1334
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1335 1335
                 $launch_status = true;
1336
-                if ( ! $has_launched ) {
1337
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1336
+                if (!$has_launched) {
1337
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1338 1338
                 }
1339 1339
             }
1340 1340
         }
@@ -1351,16 +1351,16 @@  discard block
 block discarded – undo
1351 1351
     public function get_imgopt_provider_userstatus() {
1352 1352
         static $_provider_userstatus = null;
1353 1353
 
1354
-        if ( is_null( $_provider_userstatus ) ) {
1355
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1356
-            if ( is_array( $_stat ) ) {
1357
-                if ( array_key_exists( 'Status', $_stat ) ) {
1354
+        if (is_null($_provider_userstatus)) {
1355
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1356
+            if (is_array($_stat)) {
1357
+                if (array_key_exists('Status', $_stat)) {
1358 1358
                     $_provider_userstatus['Status'] = $_stat['Status'];
1359 1359
                 } else {
1360 1360
                     // if no stats then we assume all is well.
1361 1361
                     $_provider_userstatus['Status'] = 2;
1362 1362
                 }
1363
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1363
+                if (array_key_exists('timestamp', $_stat)) {
1364 1364
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1365 1365
                 } else {
1366 1366
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeExtra.php 1 patch
Spacing   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles autoptimizeExtra frontend features + admin options page
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @param array $options Optional. Allows overriding options without having to specify them via admin options page.
30 30
      */
31
-    public function __construct( $options = array() )
31
+    public function __construct($options = array())
32 32
     {
33
-        if ( empty( $options ) ) {
33
+        if (empty($options)) {
34 34
             $options = self::fetch_options();
35 35
         }
36 36
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public static function instance()
49 49
     {
50
-        if ( null === self::$instance ) {
50
+        if (null === self::$instance) {
51 51
             self::$instance = new self();
52 52
         }
53 53
 
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
 
57 57
     public function run()
58 58
     {
59
-        if ( is_admin() ) {
60
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
61
-                add_action( 'network_admin_menu', array( $this, 'admin_menu' ) );
59
+        if (is_admin()) {
60
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
61
+                add_action('network_admin_menu', array($this, 'admin_menu'));
62 62
             } else {
63
-                add_action( 'admin_menu', array( $this, 'admin_menu' ) );
63
+                add_action('admin_menu', array($this, 'admin_menu'));
64 64
             }
65
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) );
65
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab'));
66 66
         } else {
67
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
67
+            add_action('wp', array($this, 'run_on_frontend'));
68 68
         }
69 69
     }
70 70
 
71
-    public function set_options( array $options )
71
+    public function set_options(array $options)
72 72
     {
73 73
         $this->options = $options;
74 74
 
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 
78 78
     public static function fetch_options()
79 79
     {
80
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings' );
81
-        if ( empty( $value ) ) {
80
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings');
81
+        if (empty($value)) {
82 82
             // Fallback to returning defaults when no stored option exists yet.
83 83
             $value = autoptimizeConfig::get_ao_extra_default_options();
84 84
         }
@@ -89,55 +89,55 @@  discard block
 block discarded – undo
89 89
     public function disable_emojis()
90 90
     {
91 91
         // Removing all actions related to emojis!
92
-        remove_action( 'admin_print_styles', 'print_emoji_styles' );
93
-        remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
94
-        remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
95
-        remove_action( 'wp_print_styles', 'print_emoji_styles' );
96
-        remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
97
-        remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
98
-        remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
92
+        remove_action('admin_print_styles', 'print_emoji_styles');
93
+        remove_action('wp_head', 'print_emoji_detection_script', 7);
94
+        remove_action('admin_print_scripts', 'print_emoji_detection_script');
95
+        remove_action('wp_print_styles', 'print_emoji_styles');
96
+        remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
97
+        remove_filter('the_content_feed', 'wp_staticize_emoji');
98
+        remove_filter('comment_text_rss', 'wp_staticize_emoji');
99 99
 
100 100
         // Removes TinyMCE emojis.
101
-        add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) );
101
+        add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce'));
102 102
 
103 103
         // Removes emoji dns-preftech.
104
-        add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 );
104
+        add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2);
105 105
     }
106 106
 
107
-    public function filter_disable_emojis_tinymce( $plugins )
107
+    public function filter_disable_emojis_tinymce($plugins)
108 108
     {
109
-        if ( is_array( $plugins ) ) {
110
-            return array_diff( $plugins, array( 'wpemoji' ) );
109
+        if (is_array($plugins)) {
110
+            return array_diff($plugins, array('wpemoji'));
111 111
         } else {
112 112
             return array();
113 113
         }
114 114
     }
115 115
 
116
-    public function filter_remove_qs( $src )
116
+    public function filter_remove_qs($src)
117 117
     {
118
-        if ( strpos( $src, '?ver=' ) ) {
119
-            $src = remove_query_arg( 'ver', $src );
118
+        if (strpos($src, '?ver=')) {
119
+            $src = remove_query_arg('ver', $src);
120 120
         }
121 121
 
122 122
         return $src;
123 123
     }
124 124
 
125
-    public function extra_async_js( $in )
125
+    public function extra_async_js($in)
126 126
     {
127 127
         $exclusions = array();
128
-        if ( ! empty( $in ) ) {
129
-            $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' );
128
+        if (!empty($in)) {
129
+            $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), '');
130 130
         }
131 131
 
132 132
         $settings = $this->options['autoptimize_extra_text_field_3'];
133
-        $async    = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' );
134
-        $attr     = apply_filters( 'autoptimize_filter_extra_async', 'async' );
135
-        foreach ( $async as $k => $v ) {
136
-            $async[ $k ] = $attr;
133
+        $async    = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), '');
134
+        $attr     = apply_filters('autoptimize_filter_extra_async', 'async');
135
+        foreach ($async as $k => $v) {
136
+            $async[$k] = $attr;
137 137
         }
138 138
 
139 139
         // Merge exclusions & asyncs in one array and return to AO API.
140
-        $merged = array_merge( $exclusions, $async );
140
+        $merged = array_merge($exclusions, $async);
141 141
 
142 142
         return $merged;
143 143
     }
@@ -148,68 +148,68 @@  discard block
 block discarded – undo
148 148
         // for optimizations are met, this to ensure e.g. removing querystrings
149 149
         // is not done when optimizing for logged in users is off, breaking
150 150
         // some pagebuilders (Divi & Elementor).
151
-        if ( false === autoptimizeMain::should_buffer() ) {
151
+        if (false === autoptimizeMain::should_buffer()) {
152 152
             return;
153 153
         }
154 154
 
155 155
         $options = $this->options;
156 156
 
157 157
         // Disable emojis if specified.
158
-        if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) {
158
+        if (!empty($options['autoptimize_extra_checkbox_field_1'])) {
159 159
             $this->disable_emojis();
160 160
         }
161 161
 
162 162
         // Remove version query parameters.
163
-        if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) {
164
-            add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 );
165
-            add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 );
163
+        if (!empty($options['autoptimize_extra_checkbox_field_0'])) {
164
+            add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1);
165
+            add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1);
166 166
         }
167 167
 
168 168
         // Avoiding conflicts of interest when async-javascript plugin is active!
169
-        $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' );
170
-        if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) {
171
-            add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 );
169
+        $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php');
170
+        if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) {
171
+            add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1);
172 172
         }
173 173
 
174 174
         // Optimize google fonts!
175
-        if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) {
176
-            add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 );
177
-            add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 );
178
-            add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 );
175
+        if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) {
176
+            add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2);
177
+            add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1);
178
+            add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1);
179 179
         }
180 180
 
181 181
         // Preconnect!
182
-        if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) {
183
-            add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 );
182
+        if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) {
183
+            add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2);
184 184
         }
185 185
 
186 186
         // Preload!
187
-        if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) ) {
188
-            add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 );
187
+        if (!empty($options['autoptimize_extra_text_field_7']) || has_filter('autoptimize_filter_extra_tobepreloaded')) {
188
+            add_filter('autoptimize_html_after_minify', array($this, 'filter_preload'), 10, 2);
189 189
         }
190 190
     }
191 191
 
192
-    public function filter_remove_emoji_dns_prefetch( $urls, $relation_type )
192
+    public function filter_remove_emoji_dns_prefetch($urls, $relation_type)
193 193
     {
194
-        $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' );
194
+        $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/');
195 195
 
196
-        return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url );
196
+        return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url);
197 197
     }
198 198
 
199
-    public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type )
199
+    public function filter_remove_gfonts_dnsprefetch($urls, $relation_type)
200 200
     {
201
-        return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' );
201
+        return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com');
202 202
     }
203 203
 
204
-    public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove )
204
+    public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove)
205 205
     {
206 206
         $url_to_remove = (string) $url_to_remove;
207 207
 
208
-        if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) {
208
+        if (!empty($url_to_remove) && 'dns-prefetch' === $relation_type) {
209 209
             $cnt = 0;
210
-            foreach ( $urls as $url ) {
211
-                if ( false !== strpos( $url, $url_to_remove ) ) {
212
-                    unset( $urls[ $cnt ] );
210
+            foreach ($urls as $url) {
211
+                if (false !== strpos($url, $url_to_remove)) {
212
+                    unset($urls[$cnt]);
213 213
                 }
214 214
                 $cnt++;
215 215
             }
@@ -218,153 +218,153 @@  discard block
 block discarded – undo
218 218
         return $urls;
219 219
     }
220 220
 
221
-    public function filter_optimize_google_fonts( $in )
221
+    public function filter_optimize_google_fonts($in)
222 222
     {
223 223
         // Extract fonts, partly based on wp rocket's extraction code.
224
-        $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in );
225
-        preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches );
224
+        $markup = preg_replace('/<!--(.*)-->/Uis', '', $in);
225
+        preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches);
226 226
 
227 227
         $fonts_collection = array();
228
-        if ( ! $matches[2] ) {
228
+        if (!$matches[2]) {
229 229
             return $in;
230 230
         }
231 231
 
232 232
         // Store them in $fonts array.
233 233
         $i = 0;
234
-        foreach ( $matches[2] as $font ) {
235
-            if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) {
234
+        foreach ($matches[2] as $font) {
235
+            if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) {
236 236
                 // Get fonts name.
237
-                $font = str_replace( array( '%7C', '%7c' ), '|', $font );
238
-                if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) {
237
+                $font = str_replace(array('%7C', '%7c'), '|', $font);
238
+                if (strpos($font, 'fonts.googleapis.com/css2') !== false) {
239 239
                     // (Somewhat) change Google Fonts APIv2 syntax back to v1.
240 240
                     // todo: support for 100..900
241
-                    $font = rawurldecode( $font );
242
-                    $font = str_replace( array( 'css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family=' ), array( 'css?', '', '', '', '', 'italic', ':italic', ',', '%7C' ), $font );
241
+                    $font = rawurldecode($font);
242
+                    $font = str_replace(array('css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family='), array('css?', '', '', '', '', 'italic', ':italic', ',', '%7C'), $font);
243 243
                 }
244
-                $font = explode( 'family=', $font );
245
-                $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
244
+                $font = explode('family=', $font);
245
+                $font = (isset($font[1])) ? explode('&', $font[1]) : array();
246 246
                 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
247
-                $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) );
248
-                if ( ! empty( $_thisfont ) ) {
249
-                    $fonts_collection[ $i ]['fonts'] = $_thisfont;
247
+                $_thisfont = array_values(array_filter(explode('|', reset($font))));
248
+                if (!empty($_thisfont)) {
249
+                    $fonts_collection[$i]['fonts'] = $_thisfont;
250 250
                     // And add subset if any!
251
-                    $subset = ( is_array( $font ) ) ? end( $font ) : '';
252
-                    if ( false !== strpos( $subset, 'subset=' ) ) {
253
-                        $subset                            = str_replace( array( '%2C', '%2c' ), ',', $subset );
254
-                        $subset                            = explode( 'subset=', $subset );
255
-                        $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] );
251
+                    $subset = (is_array($font)) ? end($font) : '';
252
+                    if (false !== strpos($subset, 'subset=')) {
253
+                        $subset                            = str_replace(array('%2C', '%2c'), ',', $subset);
254
+                        $subset                            = explode('subset=', $subset);
255
+                        $fonts_collection[$i]['subsets'] = explode(',', $subset[1]);
256 256
                     }
257 257
                 }
258 258
                 // And remove Google Fonts.
259
-                $in = str_replace( $matches[0][ $i ], '', $in );
259
+                $in = str_replace($matches[0][$i], '', $in);
260 260
             }
261 261
             $i++;
262 262
         }
263 263
 
264 264
         $options      = $this->options;
265 265
         $fonts_markup = '';
266
-        if ( '2' === $options['autoptimize_extra_radio_field_4'] ) {
266
+        if ('2' === $options['autoptimize_extra_radio_field_4']) {
267 267
             // Remove Google Fonts.
268
-            unset( $fonts_collection );
268
+            unset($fonts_collection);
269 269
             return $in;
270
-        } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) {
270
+        } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) {
271 271
             // Aggregate & link!
272 272
             $fonts_string  = '';
273 273
             $subset_string = '';
274
-            foreach ( $fonts_collection as $font ) {
275
-                $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' );
276
-                if ( ! empty( $font['subsets'] ) ) {
277
-                    $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' );
274
+            foreach ($fonts_collection as $font) {
275
+                $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|');
276
+                if (!empty($font['subsets'])) {
277
+                    $subset_string .= ','.trim(implode(',', $font['subsets']), ',');
278 278
                 }
279 279
             }
280 280
 
281
-            if ( ! empty( $subset_string ) ) {
282
-                $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) );
283
-                $fonts_string  = $fonts_string . '&#038;subset=' . $subset_string;
281
+            if (!empty($subset_string)) {
282
+                $subset_string = str_replace(',', '%2C', ltrim($subset_string, ','));
283
+                $fonts_string  = $fonts_string.'&#038;subset='.$subset_string;
284 284
             }
285 285
 
286
-            $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) );
286
+            $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|')));
287 287
             // only add display parameter if there is none in $fonts_string (by virtue of the filter).
288
-            if ( strpos( $fonts_string, 'display=' ) === false ) {
289
-                $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&amp;display=swap' );
288
+            if (strpos($fonts_string, 'display=') === false) {
289
+                $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&amp;display=swap');
290 290
             }
291 291
 
292
-            if ( ! empty( $fonts_string ) ) {
293
-                if ( '5' === $options['autoptimize_extra_radio_field_4'] ) {
294
-                    $rel_string = 'rel="stylesheet" media="print" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
292
+            if (!empty($fonts_string)) {
293
+                if ('5' === $options['autoptimize_extra_radio_field_4']) {
294
+                    $rel_string = 'rel="stylesheet" media="print" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"';
295 295
                 } else {
296 296
                     $rel_string = 'rel="stylesheet"';
297 297
                 }
298
-                $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />';
298
+                $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />';
299 299
             }
300
-        } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) {
300
+        } elseif ('4' === $options['autoptimize_extra_radio_field_4']) {
301 301
             // Aggregate & load async (webfont.js impl.)!
302 302
             $fonts_array = array();
303
-            foreach ( $fonts_collection as $_fonts ) {
304
-                if ( ! empty( $_fonts['subsets'] ) ) {
305
-                    $_subset = implode( ',', $_fonts['subsets'] );
306
-                    foreach ( $_fonts['fonts'] as $key => $_one_font ) {
307
-                        $_one_font               = $_one_font . ':' . $_subset;
308
-                        $_fonts['fonts'][ $key ] = $_one_font;
303
+            foreach ($fonts_collection as $_fonts) {
304
+                if (!empty($_fonts['subsets'])) {
305
+                    $_subset = implode(',', $_fonts['subsets']);
306
+                    foreach ($_fonts['fonts'] as $key => $_one_font) {
307
+                        $_one_font               = $_one_font.':'.$_subset;
308
+                        $_fonts['fonts'][$key] = $_one_font;
309 309
                     }
310 310
                 }
311
-                $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
311
+                $fonts_array = array_merge($fonts_array, $_fonts['fonts']);
312 312
             }
313 313
 
314
-            $fonts_array = array_map( 'urldecode', $fonts_array );
314
+            $fonts_array = array_map('urldecode', $fonts_array);
315 315
             $fonts_array = array_map(
316
-                function( $_f ) {
317
-                    return trim( $_f, ',' );
316
+                function($_f) {
317
+                    return trim($_f, ',');
318 318
                 },
319 319
                 $fonts_array
320 320
             );
321 321
 
322 322
             // type attrib on <script not added by default.
323 323
             $type_js = '';
324
-            if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
324
+            if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
325 325
                 $type_js = 'type="text/javascript" ';
326 326
             }
327 327
 
328
-            $fonts_markup         = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>';
329
-            $fonts_library_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
330
-            $in                   = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
328
+            $fonts_markup         = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>';
329
+            $fonts_library_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
330
+            $in                   = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>'));
331 331
         }
332 332
 
333 333
         // Replace back in markup.
334
-        $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
335
-        $out          = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
336
-        unset( $fonts_collection );
334
+        $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link');
335
+        $out          = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point));
336
+        unset($fonts_collection);
337 337
 
338 338
         return $out;
339 339
     }
340 340
 
341
-    public function filter_preconnect( $hints, $relation_type )
341
+    public function filter_preconnect($hints, $relation_type)
342 342
     {
343 343
         $options  = $this->options;
344 344
         $preconns = array();
345 345
 
346 346
         // Get settings and store in array.
347
-        if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) {
348
-            $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
347
+        if (array_key_exists('autoptimize_extra_text_field_2', $options)) {
348
+            $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2'])));
349 349
         }
350
-        $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
350
+        $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns);
351 351
 
352 352
         // Walk array, extract domain and add to new array with crossorigin attribute.
353
-        foreach ( $preconns as $preconn ) {
353
+        foreach ($preconns as $preconn) {
354 354
             $domain = '';
355
-            $parsed = parse_url( $preconn );
356
-            if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) {
357
-                $domain = '//' . $parsed['host'];
358
-            } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) {
359
-                $domain = $parsed['scheme'] . '://' . $parsed['host'];
355
+            $parsed = parse_url($preconn);
356
+            if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) {
357
+                $domain = '//'.$parsed['host'];
358
+            } elseif (is_array($parsed) && !empty($parsed['host'])) {
359
+                $domain = $parsed['scheme'].'://'.$parsed['host'];
360 360
             }
361 361
 
362
-            if ( ! empty( $domain ) ) {
363
-                $hint = array( 'href' => $domain );
362
+            if (!empty($domain)) {
363
+                $hint = array('href' => $domain);
364 364
                 // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set
365 365
                 // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed.
366
-                $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) );
367
-                if ( in_array( $domain, $crossorigins ) ) {
366
+                $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com'));
367
+                if (in_array($domain, $crossorigins)) {
368 368
                     $hint['crossorigin'] = 'anonymous';
369 369
                 }
370 370
                 $new_hints[] = $hint;
@@ -372,21 +372,21 @@  discard block
 block discarded – undo
372 372
         }
373 373
 
374 374
         // Merge in WP's preconnect hints.
375
-        if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) {
376
-            $hints = array_merge( $hints, $new_hints );
375
+        if ('preconnect' === $relation_type && !empty($new_hints)) {
376
+            $hints = array_merge($hints, $new_hints);
377 377
         }
378 378
 
379 379
         return $hints;
380 380
     }
381 381
 
382
-    public function filter_preconnect_google_fonts( $in )
382
+    public function filter_preconnect_google_fonts($in)
383 383
     {
384
-        if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) {
384
+        if ('2' !== $this->options['autoptimize_extra_radio_field_4']) {
385 385
             // Preconnect to fonts.gstatic.com unless we remove gfonts.
386 386
             $in[] = 'https://fonts.gstatic.com';
387 387
         }
388 388
 
389
-        if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) {
389
+        if ('4' === $this->options['autoptimize_extra_radio_field_4']) {
390 390
             // Preconnect even more hosts for webfont.js!
391 391
             $in[] = 'https://ajax.googleapis.com';
392 392
             $in[] = 'https://fonts.googleapis.com';
@@ -395,76 +395,76 @@  discard block
 block discarded – undo
395 395
         return $in;
396 396
     }
397 397
 
398
-    public function filter_preload( $in ) {
398
+    public function filter_preload($in) {
399 399
         // make array from comma separated list.
400 400
         $options  = $this->options;
401 401
         $preloads = array();
402
-        if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) {
403
-            $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) );
402
+        if (array_key_exists('autoptimize_extra_text_field_7', $options)) {
403
+            $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7'])));
404 404
         }
405
-        $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads );
405
+        $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads);
406 406
 
407 407
         // immediately return if nothing to be preloaded.
408
-        if ( empty( $preloads ) ) {
408
+        if (empty($preloads)) {
409 409
             return $in;
410 410
         }
411 411
 
412 412
         // iterate through array and add preload link to tmp string.
413 413
         $preload_output = '';
414
-        foreach ( $preloads as $preload ) {
414
+        foreach ($preloads as $preload) {
415 415
             $crossorigin = '';
416 416
             $preload_as  = '';
417 417
             $mime_type   = '';
418
-            $_preload    = strtok( $preload, '?' );
418
+            $_preload    = strtok($preload, '?');
419 419
 
420
-            if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) {
420
+            if (autoptimizeUtils::str_ends_in($_preload, '.css')) {
421 421
                 $preload_as = 'style';
422
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) {
422
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) {
423 423
                 $preload_as = 'script';
424
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.woff' ) || autoptimizeUtils::str_ends_in( $_preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $_preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $_preload, '.eot' ) || autoptimizeUtils::str_ends_in( $_preload, '.otf' ) ) {
424
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.woff') || autoptimizeUtils::str_ends_in($_preload, '.woff2') || autoptimizeUtils::str_ends_in($_preload, '.ttf') || autoptimizeUtils::str_ends_in($_preload, '.eot') || autoptimizeUtils::str_ends_in($_preload, '.otf')) {
425 425
                 $preload_as  = 'font';
426 426
                 $crossorigin = ' crossorigin';
427
-                $mime_type   = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
428
-                if ( ' type="font/eot"' === $mime_type ) {
427
+                $mime_type   = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"';
428
+                if (' type="font/eot"' === $mime_type) {
429 429
                     $mime_type = 'application/vnd.ms-fontobject';
430 430
                 }
431
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $_preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $_preload, '.webp' ) || autoptimizeUtils::str_ends_in( $_preload, '.png' ) || autoptimizeUtils::str_ends_in( $_preload, '.gif' ) ) {
431
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.jpeg') || autoptimizeUtils::str_ends_in($_preload, '.jpg') || autoptimizeUtils::str_ends_in($_preload, '.webp') || autoptimizeUtils::str_ends_in($_preload, '.png') || autoptimizeUtils::str_ends_in($_preload, '.gif')) {
432 432
                 $preload_as = 'image';
433 433
             } else {
434 434
                 $preload_as = 'other';
435 435
             }
436 436
 
437
-            $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
437
+            $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>';
438 438
         }
439
-        $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output );
439
+        $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output);
440 440
 
441 441
         // add string to head (before first link node by default).
442
-        $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' );
443
-        $position       = autoptimizeUtils::strpos( $in, $preload_inject );
442
+        $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link');
443
+        $position       = autoptimizeUtils::strpos($in, $preload_inject);
444 444
 
445
-        return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) );
445
+        return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject));
446 446
     }
447 447
 
448 448
     public function admin_menu()
449 449
     {
450 450
         // no acces if multisite and not network admin and no site config allowed.
451
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
451
+        if (autoptimizeConfig::should_show_menu_tabs()) {
452 452
             add_submenu_page(
453 453
                 null,
454 454
                 'autoptimize_extra',
455 455
                 'autoptimize_extra',
456 456
                 'manage_options',
457 457
                 'autoptimize_extra',
458
-                array( $this, 'options_page' )
458
+                array($this, 'options_page')
459 459
             );
460 460
         }
461
-        register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
461
+        register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings');
462 462
     }
463 463
 
464
-    public function add_extra_tab( $in )
464
+    public function add_extra_tab($in)
465 465
     {
466
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
467
-            $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) );
466
+        if (autoptimizeConfig::should_show_menu_tabs()) {
467
+            $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize')));
468 468
         }
469 469
 
470 470
         return $in;
@@ -484,97 +484,97 @@  discard block
 block discarded – undo
484 484
         #ao_settings_form .form-table th {font-weight: normal;}
485 485
         #autoptimize_extra_descr{font-size: 120%;}
486 486
     </style>
487
-    <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
487
+    <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script>
488 488
     <div class="wrap">
489
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
489
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
490 490
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
491
-        <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
491
+        <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?>
492 492
             <div class="notice-warning notice"><p>
493
-            <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
493
+            <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?>
494 494
             </p></div>
495 495
         <?php } ?>
496 496
 
497
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
498
-        <?php settings_fields( 'autoptimize_extra_settings' ); ?>
499
-        <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
500
-        <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
497
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
498
+        <?php settings_fields('autoptimize_extra_settings'); ?>
499
+        <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2>
500
+        <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span>
501 501
         <table class="form-table">
502 502
             <tr>
503
-                <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th>
503
+                <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th>
504 504
                 <td>
505
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/>
506
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/>
505
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/>
506
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/>
507 507
                     <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
508
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo __( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
508
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php echo __('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/>
509 509
                     <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
510
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/>
511
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php echo __( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ) . ' ' . __( '(deprecated)', 'autoptimize' ); ?><br/>
510
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php echo __('Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/>
511
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php echo __('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize').' '.__('(deprecated)', 'autoptimize'); ?><br/>
512 512
                 </td>
513 513
             </tr>
514 514
             <tr>
515
-                <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th>
515
+                <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th>
516 516
                 <td>
517
-                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label>
517
+                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label>
518 518
                 </td>
519 519
             </tr>
520 520
             <tr>
521
-                <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
521
+                <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th>
522 522
                 <td>
523
-                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label>
523
+                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label>
524 524
                 </td>
525 525
             </tr>
526 526
             <tr>
527
-                <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>
527
+                <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th>
528 528
                 <td>
529
-                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label>
529
+                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label>
530 530
                 </td>
531 531
             </tr>
532 532
             <tr>
533
-                <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th>
533
+                <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th>
534 534
                 <td>
535
-                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php _e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label>
535
+                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if (array_key_exists('autoptimize_extra_text_field_7', $options)) { echo esc_attr($options['autoptimize_extra_text_field_7']); } ?>'><br /><?php _e('Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize'); ?></label>
536 536
                 </td>
537 537
             </tr>
538 538
             <tr>
539
-                <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th>
539
+                <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th>
540 540
                 <td>
541 541
                     <?php
542
-                    if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) {
542
+                    if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) {
543 543
                         // translators: link points Async Javascript settings page.
544
-                        printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' );
544
+                        printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>');
545 545
                     } else {
546 546
                         ?>
547
-                        <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'>
547
+                        <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'>
548 548
                         <br />
549 549
                         <?php
550
-                            _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' );
550
+                            _e('Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize');
551 551
                             // translators: %s will be replaced by a link to the "async javascript" plugin.
552
-                            echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' );
553
-                            $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term';
554
-                            echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
552
+                            echo sprintf(__('Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize'), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"');
553
+                            $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term';
554
+                            echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
555 555
                     }
556 556
                     ?>
557 557
                 </td>
558 558
             </tr>
559 559
             <tr>
560
-                <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
560
+                <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th>
561 561
                 <td>
562 562
                     <?php
563
-                    if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) {
564
-                        _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
563
+                    if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) {
564
+                        _e('Great, you have WP YouTube Lyte installed.', 'autoptimize');
565 565
                         $lyte_config_url = 'options-general.php?page=lyte_settings_page';
566
-                        echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) );
566
+                        echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize'));
567 567
                     } else {
568 568
                         // translators: %s will be replaced by a link to "wp youtube lyte" plugin.
569
-                        echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' );
570
-                        $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term';
571
-                        echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
569
+                        echo sprintf(__('%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize'), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>');
570
+                        $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term';
571
+                        echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
572 572
                     }
573 573
                     ?>
574 574
                 </td>
575 575
             </tr>
576 576
         </table>
577
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
577
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
578 578
     </form>
579 579
         <?php
580 580
     }
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_adv.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     global $ao_ccss_unloadccss;
20 20
 
21 21
     // In case domain is not set yet (done in cron.php).
22
-    if ( empty( $ao_ccss_domain ) ) {
22
+    if (empty($ao_ccss_domain)) {
23 23
         $ao_ccss_domain = get_site_url();
24 24
     }
25 25
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 ?>
29 29
     <ul id="adv-panel">
30 30
         <li class="itemDetail">
31
-            <h2 class="itemTitle fleft"><?php _e( 'Advanced Settings', 'autoptimize' ); ?></h2>
31
+            <h2 class="itemTitle fleft"><?php _e('Advanced Settings', 'autoptimize'); ?></h2>
32 32
             <button type="button" class="toggle-btn">
33 33
                 <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
34 34
             </button>
@@ -36,114 +36,114 @@  discard block
 block discarded – undo
36 36
                 <table id="key" class="form-table">
37 37
                     <tr>
38 38
                         <th scope="row">
39
-                            <?php _e( 'Viewport Size', 'autoptimize' ); ?>
39
+                            <?php _e('Viewport Size', 'autoptimize'); ?>
40 40
                         </th>
41 41
                         <td>
42
-                            <label for="autoptimize_ccss_vw"><?php _e( 'Width', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" />&nbsp;&nbsp;
43
-                            <label for="autoptimize_ccss_vh"><?php _e( 'Height', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" />
42
+                            <label for="autoptimize_ccss_vw"><?php _e('Width', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" />&nbsp;&nbsp;
43
+                            <label for="autoptimize_ccss_vh"><?php _e('Height', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" />
44 44
                             <p class="notes">
45
-                                <?php _e( '<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize' ); ?>
45
+                                <?php _e('<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize'); ?>
46 46
                             </p>
47 47
                         </td>
48 48
                     </tr>
49 49
                     <tr>
50 50
                         <th scope="row">
51
-                            <?php _e( 'Force Include CSS selectors', 'autoptimize' ); ?>
51
+                            <?php _e('Force Include CSS selectors', 'autoptimize'); ?>
52 52
                         </th>
53 53
                         <td>
54
-                            <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e( '.button-special,//#footer', 'autoptimize' ); ?>"><?php echo trim( $ao_ccss_finclude ); ?></textarea>
54
+                            <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e('.button-special,//#footer', 'autoptimize'); ?>"><?php echo trim($ao_ccss_finclude); ?></textarea>
55 55
                             <p class="notes">
56
-                                <?php _e( 'Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize' ); ?>
56
+                                <?php _e('Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize'); ?>
57 57
                             </p>
58 58
                         </td>
59 59
                     </tr>
60 60
                     <tr>
61 61
                         <th scope="row">
62
-                            <?php _e( 'Queue processing time limit', 'autoptimize' ); ?>
62
+                            <?php _e('Queue processing time limit', 'autoptimize'); ?>
63 63
                         </th>
64 64
                         <td>
65 65
                             <input type="number" id="autoptimize_ccss_rtimelimit" name="autoptimize_ccss_rtimelimit" min="0" max="240" placeholder="0" value="<?php echo $ao_ccss_rtimelimit; ?>" />
66 66
                             <p class="notes">
67
-                                <?php _e( 'The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize' ); ?>
67
+                                <?php _e('The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize'); ?>
68 68
                             </p>
69 69
                         </td>
70 70
                     </tr>
71 71
                     <tr>
72 72
                         <th scope="row">
73
-                            <?php _e( 'Fetch Original CSS', 'autoptimize' ); ?>
73
+                            <?php _e('Fetch Original CSS', 'autoptimize'); ?>
74 74
                         </th>
75 75
                         <td>
76
-                            <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked( 1 == $ao_ccss_noptimize ); ?>>
76
+                            <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked(1 == $ao_ccss_noptimize); ?>>
77 77
                             <p class="notes">
78
-                                <?php _e( 'In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize' ); ?>
78
+                                <?php _e('In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize'); ?>
79 79
                             </p>
80 80
                         </td>
81 81
                     </tr>
82 82
                     <tr>
83 83
                         <th scope="row">
84
-                            <?php _e( 'Add CCSS for logged in users?', 'autoptimize' ); ?>
84
+                            <?php _e('Add CCSS for logged in users?', 'autoptimize'); ?>
85 85
                         </th>
86 86
                         <td>
87
-                            <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked( 1 == $ao_ccss_loggedin ); ?>>
87
+                            <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked(1 == $ao_ccss_loggedin); ?>>
88 88
                             <p class="notes">
89
-                                <?php _e( 'Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize' ); ?>
89
+                                <?php _e('Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize'); ?>
90 90
                             </p>
91 91
                         </td>
92 92
                     </tr>
93 93
                     <tr>
94 94
                         <th scope="row">
95
-                            <?php _e( 'Force path-based rules to be generated for pages?', 'autoptimize' ); ?>
95
+                            <?php _e('Force path-based rules to be generated for pages?', 'autoptimize'); ?>
96 96
                         </th>
97 97
                         <td>
98
-                            <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked( 1 == $ao_ccss_forcepath ); ?>>
98
+                            <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked(1 == $ao_ccss_forcepath); ?>>
99 99
                             <p class="notes">
100
-                                <?php _e( 'By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize' ); ?>
100
+                                <?php _e('By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize'); ?>
101 101
                             </p>
102 102
                         </td>
103 103
                     </tr>
104 104
                     <tr>
105 105
                         <th scope="row">
106
-                            <?php _e( 'Defer jQuery and other non-aggregated JS-files?', 'autoptimize' ); ?>
106
+                            <?php _e('Defer jQuery and other non-aggregated JS-files?', 'autoptimize'); ?>
107 107
                         </th>
108 108
                         <td>
109
-                            <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked( 1 == $ao_ccss_deferjquery ); ?>>
109
+                            <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked(1 == $ao_ccss_deferjquery); ?>>
110 110
                             <p class="notes">
111
-                                <?php _e( 'Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize' ); ?>
111
+                                <?php _e('Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize'); ?>
112 112
                             </p>
113 113
                         </td>
114 114
                     </tr>
115 115
                     <tr>
116 116
                         <th scope="row">
117
-                            <?php _e( 'Unload critical CSS after page load?', 'autoptimize' ); ?>
117
+                            <?php _e('Unload critical CSS after page load?', 'autoptimize'); ?>
118 118
                         </th>
119 119
                         <td>
120
-                            <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked( 1 == $ao_ccss_unloadccss ); ?>>
120
+                            <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked(1 == $ao_ccss_unloadccss); ?>>
121 121
                             <p class="notes">
122
-                                <?php _e( 'In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize' ); ?>
122
+                                <?php _e('In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize'); ?>
123 123
                             </p>
124 124
                         </td>
125 125
                     </tr>
126 126
                     <tr>
127 127
                         <th scope="row">
128
-                            <?php _e( 'Bound domain', 'autoptimize' ); ?>
128
+                            <?php _e('Bound domain', 'autoptimize'); ?>
129 129
                         </th>
130 130
                         <td>
131
-                            <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e( 'Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize' ); ?>" value="<?php echo trim( $ao_ccss_domain ); ?>">
131
+                            <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e('Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize'); ?>" value="<?php echo trim($ao_ccss_domain); ?>">
132 132
                             <p class="notes">
133
-                                <?php _e( 'Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize' ); ?>
133
+                                <?php _e('Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize'); ?>
134 134
                             </p>
135 135
                         </td>
136 136
                     </tr>
137 137
                     <tr>
138 138
                         <th scope="row">
139
-                            <?php _e( 'Debug Mode', 'autoptimize' ); ?>
139
+                            <?php _e('Debug Mode', 'autoptimize'); ?>
140 140
                         </th>
141 141
                         <td>
142
-                            <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked( 1 == $ao_ccss_debug ); ?>>
142
+                            <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked(1 == $ao_ccss_debug); ?>>
143 143
                             <p class="notes">
144 144
                                 <?php
145
-                                _e( '<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize' );
146
-                                echo '<code>' . AO_CCSS_LOG . '</code>';
145
+                                _e('<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize');
146
+                                echo '<code>'.AO_CCSS_LOG.'</code>';
147 147
                                 ?>
148 148
                             </p>
149 149
                         </td>
Please login to merge, or discard this patch.
classes/autoptimizeVersionUpdatesHandler.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles version updates and should only be instantiated in autoptimize.php if/when needed.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      */
17 17
     protected $current_major_version = null;
18 18
 
19
-    public function __construct( $current_version )
19
+    public function __construct($current_version)
20 20
     {
21
-        $this->current_major_version = substr( $current_version, 0, 3 );
21
+        $this->current_major_version = substr($current_version, 0, 3);
22 22
     }
23 23
 
24 24
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $major_update = false;
31 31
 
32
-        switch ( $this->current_major_version ) {
32
+        switch ($this->current_major_version) {
33 33
             case '1.6':
34 34
                 $this->upgrade_from_1_6();
35 35
                 $major_update = true;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
                 $major_update = true;
48 48
                 // No break, intentionally, so all upgrades are ran during a single request...
49 49
             case '2.4':
50
-                if ( autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' ) == '2.4.2' ) {
50
+                if (autoptimizeOptionWrapper::get_option('autoptimize_version', 'none') == '2.4.2') {
51 51
                     $this->upgrade_from_2_4_2();
52 52
                 }
53 53
                 $this->upgrade_from_2_4();
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 // No break, intentionally, so all upgrades are ran during a single request...
60 60
         }
61 61
 
62
-        if ( true === $major_update ) {
62
+        if (true === $major_update) {
63 63
             $this->on_major_version_update();
64 64
         }
65 65
     }
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @param string $target Target version to check against (ie., the currently running one).
73 73
      */
74
-    public static function check_installed_and_update( $target )
74
+    public static function check_installed_and_update($target)
75 75
     {
76
-        $db_version = autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' );
77
-        if ( $db_version !== $target ) {
78
-            if ( 'none' === $db_version ) {
79
-                add_action( 'admin_notices', 'autoptimizeMain::notice_installed' );
76
+        $db_version = autoptimizeOptionWrapper::get_option('autoptimize_version', 'none');
77
+        if ($db_version !== $target) {
78
+            if ('none' === $db_version) {
79
+                add_action('admin_notices', 'autoptimizeMain::notice_installed');
80 80
             } else {
81
-                $updater = new self( $db_version );
81
+                $updater = new self($db_version);
82 82
                 $updater->run_needed_major_upgrades();
83 83
             }
84 84
 
85 85
             // Versions differed, upgrades happened if needed, store the new version.
86
-            autoptimizeOptionWrapper::update_option( 'autoptimize_version', $target );
86
+            autoptimizeOptionWrapper::update_option('autoptimize_version', $target);
87 87
         }
88 88
     }
89 89
 
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
     protected function on_major_version_update()
95 95
     {
96 96
         // The transients guard here prevents stale object caches from busting the cache on every request.
97
-        if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) {
98
-            set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS );
97
+        if (false == get_transient('autoptimize_stale_option_buster')) {
98
+            set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS);
99 99
             autoptimizeCache::clearall();
100
-            add_action( 'admin_notices', 'autoptimizeMain::notice_updated' );
100
+            add_action('admin_notices', 'autoptimizeMain::notice_updated');
101 101
         }
102 102
     }
103 103
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     private function upgrade_from_1_6()
108 108
     {
109 109
         // If user was on version 1.6.x, force advanced options to be shown by default.
110
-        autoptimizeOptionWrapper::update_option( 'autoptimize_show_adv', '1' );
110
+        autoptimizeOptionWrapper::update_option('autoptimize_show_adv', '1');
111 111
 
112 112
         // And remove old options.
113 113
         $to_delete_options = array(
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
             'autoptimize_cdn_img_url',
120 120
             'autoptimize_css_yui',
121 121
         );
122
-        foreach ( $to_delete_options as $del_opt ) {
123
-            delete_option( $del_opt );
122
+        foreach ($to_delete_options as $del_opt) {
123
+            delete_option($del_opt);
124 124
         }
125 125
     }
126 126
 
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
      */
132 132
     private function upgrade_from_1_7()
133 133
     {
134
-        if ( ! is_multisite() ) {
135
-            $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' );
136
-            if ( empty( $css_exclude ) ) {
134
+        if (!is_multisite()) {
135
+            $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude');
136
+            if (empty($css_exclude)) {
137 137
                 $css_exclude = 'admin-bar.min.css, dashicons.min.css';
138
-            } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
138
+            } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
139 139
                 $css_exclude .= ', dashicons.min.css';
140 140
             }
141
-            autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude );
141
+            autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude);
142 142
         } else {
143 143
             global $wpdb;
144
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
144
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
145 145
             $original_blog_id = get_current_blog_id();
146
-            foreach ( $blog_ids as $blog_id ) {
147
-                switch_to_blog( $blog_id );
148
-                $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' );
149
-                if ( empty( $css_exclude ) ) {
146
+            foreach ($blog_ids as $blog_id) {
147
+                switch_to_blog($blog_id);
148
+                $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude');
149
+                if (empty($css_exclude)) {
150 150
                     $css_exclude = 'admin-bar.min.css, dashicons.min.css';
151
-                } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
151
+                } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
152 152
                     $css_exclude .= ', dashicons.min.css';
153 153
                 }
154
-                autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude );
154
+                autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude);
155 155
             }
156
-            switch_to_blog( $original_blog_id );
156
+            switch_to_blog($original_blog_id);
157 157
         }
158 158
     }
159 159
 
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private function upgrade_from_1_9()
167 167
     {
168
-        if ( ! is_multisite() ) {
169
-            autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' );
170
-            autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' );
168
+        if (!is_multisite()) {
169
+            autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on');
170
+            autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on');
171 171
         } else {
172 172
             global $wpdb;
173
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
173
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
174 174
             $original_blog_id = get_current_blog_id();
175
-            foreach ( $blog_ids as $blog_id ) {
176
-                switch_to_blog( $blog_id );
177
-                autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' );
178
-                autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' );
175
+            foreach ($blog_ids as $blog_id) {
176
+                switch_to_blog($blog_id);
177
+                autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on');
178
+                autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on');
179 179
             }
180
-            switch_to_blog( $original_blog_id );
180
+            switch_to_blog($original_blog_id);
181 181
         }
182 182
     }
183 183
 
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
      */
189 189
     private function upgrade_from_2_2()
190 190
     {
191
-        if ( ! is_multisite() ) {
191
+        if (!is_multisite()) {
192 192
             $this->do_2_2_settings_update();
193 193
         } else {
194 194
             global $wpdb;
195
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
195
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
196 196
             $original_blog_id = get_current_blog_id();
197
-            foreach ( $blog_ids as $blog_id ) {
198
-                switch_to_blog( $blog_id );
197
+            foreach ($blog_ids as $blog_id) {
198
+                switch_to_blog($blog_id);
199 199
                 $this->do_2_2_settings_update();
200 200
             }
201
-            switch_to_blog( $original_blog_id );
201
+            switch_to_blog($original_blog_id);
202 202
         }
203 203
     }
204 204
 
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
      */
208 208
     private function do_2_2_settings_update()
209 209
     {
210
-        $nogooglefont    = autoptimizeOptionWrapper::get_option( 'autoptimize_css_nogooglefont', '' );
211
-        $ao_extrasetting = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' );
212
-        if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) {
213
-            autoptimizeOptionWrapper::update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() );
210
+        $nogooglefont    = autoptimizeOptionWrapper::get_option('autoptimize_css_nogooglefont', '');
211
+        $ao_extrasetting = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', '');
212
+        if (($nogooglefont) && (empty($ao_extrasetting))) {
213
+            autoptimizeOptionWrapper::update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options());
214 214
         }
215
-        delete_option( 'autoptimize_css_nogooglefont' );
215
+        delete_option('autoptimize_css_nogooglefont');
216 216
     }
217 217
 
218 218
     /**
@@ -224,33 +224,33 @@  discard block
 block discarded – undo
224 224
         $jobs = _get_cron_array();
225 225
 
226 226
         // Remove all ao_cachechecker cron jobs (for now).
227
-        foreach ( $jobs as $when => $job ) {
228
-            $name = key( $job );
227
+        foreach ($jobs as $when => $job) {
228
+            $name = key($job);
229 229
 
230
-            if ( false !== strpos( $name, 'ao_cachechecker' ) ) {
231
-                unset( $jobs[ $when ] );
230
+            if (false !== strpos($name, 'ao_cachechecker')) {
231
+                unset($jobs[$when]);
232 232
             }
233 233
         }
234 234
 
235 235
         // Save the data.
236
-        _set_cron_array( $jobs );
236
+        _set_cron_array($jobs);
237 237
     }
238 238
 
239 239
     /**
240 240
      * Migrate imgopt options from autoptimize_extra_settings to autoptimize_imgopt_settings
241 241
      */
242 242
     private function upgrade_from_2_4() {
243
-        $extra_settings  = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' );
244
-        $imgopt_settings = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
245
-        if ( empty( $imgopt_settings ) && ! empty( $extra_settings ) ) {
243
+        $extra_settings  = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', '');
244
+        $imgopt_settings = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
245
+        if (empty($imgopt_settings) && !empty($extra_settings)) {
246 246
             $imgopt_settings = autoptimizeConfig::get_ao_imgopt_default_options();
247
-            if ( array_key_exists( 'autoptimize_extra_checkbox_field_5', $extra_settings ) ) {
247
+            if (array_key_exists('autoptimize_extra_checkbox_field_5', $extra_settings)) {
248 248
                 $imgopt_settings['autoptimize_imgopt_checkbox_field_1'] = $extra_settings['autoptimize_extra_checkbox_field_5'];
249 249
             }
250
-            if ( array_key_exists( 'autoptimize_extra_select_field_6', $extra_settings ) ) {
250
+            if (array_key_exists('autoptimize_extra_select_field_6', $extra_settings)) {
251 251
                 $imgopt_settings['autoptimize_imgopt_select_field_2'] = $extra_settings['autoptimize_extra_select_field_6'];
252 252
             }
253
-            autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_settings', $imgopt_settings );
253
+            autoptimizeOptionWrapper::update_option('autoptimize_imgopt_settings', $imgopt_settings);
254 254
         }
255 255
     }
256 256
 
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
      * remove CCSS request limit option + update jquery exclusion to include WordPress 5.6 jquery.min.js.
259 259
      */    
260 260
     private function upgrade_from_2_7() {
261
-        delete_option( 'autoptimize_ccss_rlimit' );
262
-        $js_exclusions = get_option( 'autoptimize_js_exclude', '' );
263
-        if ( strpos( $js_exclusions, 'js/jquery/jquery.js' ) !== false && strpos( $js_exclusions, 'js/jquery/jquery.min.js' ) === false ) {
261
+        delete_option('autoptimize_ccss_rlimit');
262
+        $js_exclusions = get_option('autoptimize_js_exclude', '');
263
+        if (strpos($js_exclusions, 'js/jquery/jquery.js') !== false && strpos($js_exclusions, 'js/jquery/jquery.min.js') === false) {
264 264
             $js_exclusions .= ', js/jquery/jquery.min.js';
265
-            update_option( 'autoptimize_js_exclude', $js_exclusions );
265
+            update_option('autoptimize_js_exclude', $js_exclusions);
266 266
         }
267 267
     }
268 268
 }
Please login to merge, or discard this patch.