Completed
Push — master ( d10a3b...267ab8 )
by frank
01:54
created
classes/critcss-inc/admin_settings_key.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
  * @param string $message      Message.
13 13
  * @param string $color        Color to highlight message in.
14 14
  */
15
-function ao_ccss_render_key( $key, $status, $status_msg, $message, $color ) {
16
-    if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
17
-        $key = __( 'API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize' );
15
+function ao_ccss_render_key($key, $status, $status_msg, $message, $color) {
16
+    if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
17
+        $key = __('API key provided by your host/ WordPress administrator, no need to enter anything here. In case of problems with the API key, contact your host/ WordPress administrator.', 'autoptimize');
18 18
     }
19 19
     ?>
20 20
     <ul id="key-panel">
21 21
         <li class="itemDetail">
22
-            <h2 class="itemTitle fleft"><?php _e( 'API Key', 'autoptimize' ); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2>
22
+            <h2 class="itemTitle fleft"><?php _e('API Key', 'autoptimize'); ?>: <span style="color:<?php echo $color; ?>;"><?php echo $status_msg; ?></span></h2>
23 23
             <button type="button" class="toggle-btn">
24
-                <?php if ( 'valid' != $status ) { ?>
24
+                <?php if ('valid' != $status) { ?>
25 25
                     <span class="toggle-indicator dashicons dashicons-arrow-up"></span>
26 26
                 <?php } else { ?>
27 27
                     <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
28 28
                 <?php } ?>
29 29
             </button>
30
-            <?php if ( 'valid' != $status ) { ?>
30
+            <?php if ('valid' != $status) { ?>
31 31
                 <div class="collapsible">
32 32
             <?php } else { ?>
33 33
                 <div class="collapsible hidden">
34 34
             <?php } ?>
35
-            <?php if ( 'valid' != $status ) { ?>
35
+            <?php if ('valid' != $status) { ?>
36 36
                 <div style="clear:both;padding:2px 10px;border-left:solid;border-left-width:5px;border-left-color:<?php echo $color; ?>;background-color:white;">
37 37
                     <p><?php echo $message; ?></p>
38 38
                 </div>
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
                 <table id="key" class="form-table">
41 41
                     <tr>
42 42
                         <th scope="row">
43
-                            <?php _e( 'Your API Key', 'autoptimize' ); ?>
43
+                            <?php _e('Your API Key', 'autoptimize'); ?>
44 44
                         </th>
45 45
                         <td>
46
-                            <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e( 'Please enter your criticalcss.com API key here.', 'autoptimize' ); ?>"><?php echo trim( $key ); ?></textarea>
46
+                            <textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e('Please enter your criticalcss.com API key here.', 'autoptimize'); ?>"><?php echo trim($key); ?></textarea>
47 47
                             <p class="notes">
48
-                                <?php _e( 'Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize' ); ?>
48
+                                <?php _e('Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize'); ?>
49 49
                             </p>
50 50
                         </td>
51 51
                     </tr>
Please login to merge, or discard this patch.
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/autoptimizeImages.php 2 patches
Doc Comments   +13 added lines, -1 removed lines patch added patch discarded remove patch
@@ -378,6 +378,9 @@  discard block
 block discarded – undo
378 378
         }
379 379
     }
380 380
 
381
+    /**
382
+     * @return string
383
+     */
381 384
     private function get_imgopt_base_url()
382 385
     {
383 386
         static $imgopt_base_url = null;
@@ -750,6 +753,9 @@  discard block
 block discarded – undo
750 753
         return $out;
751 754
     }
752 755
 
756
+    /**
757
+     * @param string $tag
758
+     */
753 759
     public function add_lazyload( $tag, $placeholder = '' ) {
754 760
         // adds actual lazyload-attributes to an image node.
755 761
         if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
@@ -832,6 +838,9 @@  discard block
 block discarded – undo
832 838
         }
833 839
     }
834 840
 
841
+    /**
842
+     * @return string
843
+     */
835 844
     public function get_cdn_url() {
836 845
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
837 846
         static $cdn_url = null;
@@ -935,6 +944,9 @@  discard block
 block discarded – undo
935 944
         return $out;
936 945
     }
937 946
 
947
+    /**
948
+     * @return string
949
+     */
938 950
     public function process_bgimage( $in ) {
939 951
         if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
940 952
             $out = preg_replace_callback(
@@ -1279,7 +1291,7 @@  discard block
 block discarded – undo
1279 1291
     /**
1280 1292
      * Determines and returns the service launch status.
1281 1293
      *
1282
-     * @return bool
1294
+     * @return null|boolean
1283 1295
      */
1284 1296
     public function launch_ok()
1285 1297
     {
Please login to merge, or discard this patch.
Spacing   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles optimizing images.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
      */
24 24
     protected static $instance = null;
25 25
 
26
-    public function __construct( array $options = array() )
26
+    public function __construct(array $options = array())
27 27
     {
28 28
         // If options are not provided, fetch them.
29
-        if ( empty( $options ) ) {
29
+        if (empty($options)) {
30 30
             $options = $this->fetch_options();
31 31
         }
32 32
 
33
-        $this->set_options( $options );
33
+        $this->set_options($options);
34 34
     }
35 35
 
36
-    public function set_options( array $options )
36
+    public function set_options(array $options)
37 37
     {
38 38
         $this->options = $options;
39 39
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 
43 43
     public static function fetch_options()
44 44
     {
45
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
46
-        if ( empty( $value ) ) {
45
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
46
+        if (empty($value)) {
47 47
             // Fallback to returning defaults when no stored option exists yet.
48 48
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
49 49
         }
50 50
 
51 51
         // get service availability and add it to the options-array.
52
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
52
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
53 53
 
54
-        if ( empty( $value['availabilities'] ) ) {
55
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
54
+        if (empty($value['availabilities'])) {
55
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
56 56
         }
57 57
 
58 58
         return $value;
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         // and does not use/ request the availablity data (which could slow things down).
66 66
         static $imgopt_active = null;
67 67
 
68
-        if ( null === $imgopt_active ) {
69
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
70
-            if ( ! empty( $opts ) && is_array( $opts ) && array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $opts ) && ! empty( $opts['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $opts['autoptimize_imgopt_checkbox_field_1'] ) {
68
+        if (null === $imgopt_active) {
69
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
70
+            if (!empty($opts) && is_array($opts) && array_key_exists('autoptimize_imgopt_checkbox_field_1', $opts) && !empty($opts['autoptimize_imgopt_checkbox_field_1']) && '1' === $opts['autoptimize_imgopt_checkbox_field_1']) {
71 71
                 $imgopt_active = true;
72 72
             } else {
73 73
                 $imgopt_active = false;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public static function instance()
89 89
     {
90
-        if ( null === self::$instance ) {
90
+        if (null === self::$instance) {
91 91
             self::$instance = new self();
92 92
         }
93 93
 
@@ -96,34 +96,34 @@  discard block
 block discarded – undo
96 96
 
97 97
     public function run()
98 98
     {
99
-        if ( is_admin() ) {
100
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
101
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
99
+        if (is_admin()) {
100
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
101
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
102 102
             } else {
103
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
103
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
104 104
             }
105
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
105
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
106 106
         } else {
107
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
107
+            add_action('wp', array($this, 'run_on_frontend'));
108 108
         }
109 109
     }
110 110
 
111 111
     public function run_on_frontend() {
112
-        if ( ! $this->should_run() ) {
113
-            if ( $this->should_lazyload() ) {
112
+        if (!$this->should_run()) {
113
+            if ($this->should_lazyload()) {
114 114
                 add_filter(
115 115
                     'wp_lazy_loading_enabled',
116 116
                     '__return_false'
117 117
                 );
118 118
                 add_filter(
119 119
                     'autoptimize_html_after_minify',
120
-                    array( $this, 'filter_lazyload_images' ),
120
+                    array($this, 'filter_lazyload_images'),
121 121
                     10,
122 122
                     1
123 123
                 );
124 124
                 add_action(
125 125
                     'wp_footer',
126
-                    array( $this, 'add_lazyload_js_footer' ),
126
+                    array($this, 'add_lazyload_js_footer'),
127 127
                     10,
128 128
                     0
129 129
                 );
@@ -133,43 +133,43 @@  discard block
 block discarded – undo
133 133
 
134 134
         $active = false;
135 135
 
136
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
136
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
137 137
             add_filter(
138 138
                 'autoptimize_html_after_minify',
139
-                array( $this, 'filter_optimize_images' ),
139
+                array($this, 'filter_optimize_images'),
140 140
                 10,
141 141
                 1
142 142
             );
143 143
             $active = true;
144 144
         }
145 145
 
146
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
146
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
147 147
             add_filter(
148 148
                 'autoptimize_filter_base_replace_cdn',
149
-                array( $this, 'filter_optimize_css_images' ),
149
+                array($this, 'filter_optimize_css_images'),
150 150
                 10,
151 151
                 1
152 152
             );
153 153
             $active = true;
154 154
         }
155 155
 
156
-        if ( $active ) {
156
+        if ($active) {
157 157
             add_filter(
158 158
                 'autoptimize_extra_filter_tobepreconn',
159
-                array( $this, 'filter_preconnect_imgopt_url' ),
159
+                array($this, 'filter_preconnect_imgopt_url'),
160 160
                 10,
161 161
                 1
162 162
             );
163 163
         }
164 164
 
165
-        if ( $this->should_lazyload() ) {
165
+        if ($this->should_lazyload()) {
166 166
             add_filter(
167 167
                 'wp_lazy_loading_enabled',
168 168
                 '__return_false'
169 169
             );
170 170
             add_action(
171 171
                 'wp_footer',
172
-                array( $this, 'add_lazyload_js_footer' ),
172
+                array($this, 'add_lazyload_js_footer'),
173 173
                 10,
174 174
                 0
175 175
             );
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
     protected function should_run()
185 185
     {
186 186
         $opts              = $this->options;
187
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
188
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
187
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
188
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
189 189
 
190 190
         $do_cdn      = true;
191 191
         $_userstatus = $this->get_imgopt_provider_userstatus();
192
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
192
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
193 193
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
194 194
             $do_cdn = false;
195 195
         }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $this->imgopt_active()
199 199
             && $do_cdn
200 200
             && $service_not_down
201
-            && ( $not_launch_status || $this->launch_ok() )
201
+            && ($not_launch_status || $this->launch_ok())
202 202
         ) {
203 203
             return true;
204 204
         }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     {
210 210
         static $imgopt_host = null;
211 211
 
212
-        if ( null === $imgopt_host ) {
212
+        if (null === $imgopt_host) {
213 213
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
214 214
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
215
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
216
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
215
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
216
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
217 217
             }
218
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
218
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
219 219
         }
220 220
 
221 221
         return $imgopt_host;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
     public static function get_service_url_suffix()
232 232
     {
233
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
233
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
234 234
 
235 235
         return $suffix;
236 236
     }
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
     {
240 240
         static $quality = null;
241 241
 
242
-        if ( null === $quality ) {
242
+        if (null === $quality) {
243 243
             $q_array = $this->get_img_quality_array();
244 244
             $setting = $this->get_img_quality_setting();
245 245
             $quality = apply_filters(
246 246
                 'autoptimize_filter_imgopt_quality',
247
-                'q_' . $q_array[ $setting ]
247
+                'q_'.$q_array[$setting]
248 248
             );
249 249
         }
250 250
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     {
256 256
         static $map = null;
257 257
 
258
-        if ( null === $map ) {
258
+        if (null === $map) {
259 259
             $map = array(
260 260
                 '1' => 'lossy',
261 261
                 '2' => 'glossy',
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
     {
275 275
         static $q = null;
276 276
 
277
-        if ( null === $q ) {
278
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
277
+        if (null === $q) {
278
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
279 279
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
280 280
             }
281 281
 
282
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
282
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
283 283
                 // default image opt. value is 2 ("glossy").
284 284
                 $q = '2';
285 285
             } else {
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
         return $q;
291 291
     }
292 292
 
293
-    public function filter_preconnect_imgopt_url( array $in )
293
+    public function filter_preconnect_imgopt_url(array $in)
294 294
     {
295
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
296
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
295
+        $url_parts = parse_url($this->get_imgopt_base_url());
296
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
297 297
 
298 298
         return $in;
299 299
     }
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
      *
307 307
      * @return string
308 308
      */
309
-    private function normalize_img_url( $in )
309
+    private function normalize_img_url($in)
310 310
     {
311 311
         // Only parse the site url once.
312 312
         static $parsed_site_url = null;
313
-        if ( null === $parsed_site_url ) {
314
-            $parsed_site_url = parse_url( site_url() );
313
+        if (null === $parsed_site_url) {
314
+            $parsed_site_url = parse_url(site_url());
315 315
         }
316 316
 
317 317
         // get CDN domain once.
318 318
         static $cdn_domain = null;
319
-        if ( is_null( $cdn_domain ) ) {
319
+        if (is_null($cdn_domain)) {
320 320
             $cdn_url = $this->get_cdn_url();
321
-            if ( ! empty( $cdn_url ) ) {
322
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
321
+            if (!empty($cdn_url)) {
322
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
323 323
             } else {
324 324
                 $cdn_domain = '';
325 325
             }
@@ -335,49 +335,49 @@  discard block
 block discarded – undo
335 335
          * identical string operations).
336 336
          */
337 337
         static $cache = null;
338
-        if ( null === $cache ) {
338
+        if (null === $cache) {
339 339
             $cache = array();
340 340
         }
341 341
 
342 342
         // Do the work on cache miss only.
343
-        if ( ! isset( $cache[ $in ] ) ) {
343
+        if (!isset($cache[$in])) {
344 344
             // Default to (the trimmed version of) what was given to us.
345
-            $result = trim( $in );
345
+            $result = trim($in);
346 346
 
347 347
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
348
-            if ( strpos( $result, '&quot;' ) !== false ) {
349
-                $result = str_replace( '&quot;', '', $result );
348
+            if (strpos($result, '&quot;') !== false) {
349
+                $result = str_replace('&quot;', '', $result);
350 350
             }
351 351
 
352
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
353
-                $result = $parsed_site_url['scheme'] . ':' . $result;
354
-            } elseif ( 0 === strpos( $result, '/' ) ) {
352
+            if (autoptimizeUtils::is_protocol_relative($result)) {
353
+                $result = $parsed_site_url['scheme'].':'.$result;
354
+            } elseif (0 === strpos($result, '/')) {
355 355
                 // Root-relative...
356
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
357
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
358
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
356
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
357
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
358
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
359 359
             }
360 360
 
361 361
             // filter (default off) to remove QS from image URL's to avoid eating away optimization credits.
362
-            if ( apply_filters( 'autoptimize_filter_imgopt_no_querystring', false ) && strpos( $result, '?' ) !== false ) {
363
-                $result = strtok( $result, '?' );
362
+            if (apply_filters('autoptimize_filter_imgopt_no_querystring', false) && strpos($result, '?') !== false) {
363
+                $result = strtok($result, '?');
364 364
             }
365 365
 
366
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
366
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
367 367
 
368 368
             // Store in cache.
369
-            $cache[ $in ] = $result;
369
+            $cache[$in] = $result;
370 370
         }
371 371
 
372
-        return $cache[ $in ];
372
+        return $cache[$in];
373 373
     }
374 374
 
375
-    public function filter_optimize_css_images( $in )
375
+    public function filter_optimize_css_images($in)
376 376
     {
377
-        $in = $this->normalize_img_url( $in );
377
+        $in = $this->normalize_img_url($in);
378 378
 
379
-        if ( $this->can_optimize_image( $in ) ) {
380
-            return $this->build_imgopt_url( $in, '', '' );
379
+        if ($this->can_optimize_image($in)) {
380
+            return $this->build_imgopt_url($in, '', '');
381 381
         } else {
382 382
             return $in;
383 383
         }
@@ -387,50 +387,50 @@  discard block
 block discarded – undo
387 387
     {
388 388
         static $imgopt_base_url = null;
389 389
 
390
-        if ( null === $imgopt_base_url ) {
390
+        if (null === $imgopt_base_url) {
391 391
             $imgopt_host     = $this->get_imgopt_host();
392 392
             $quality         = $this->get_img_quality_string();
393
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
394
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
395
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
393
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
394
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
395
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
396 396
         }
397 397
 
398 398
         return $imgopt_base_url;
399 399
     }
400 400
 
401
-    private function can_optimize_image( $url, $tag = '' )
401
+    private function can_optimize_image($url, $tag = '')
402 402
     {
403 403
         static $cdn_url      = null;
404 404
         static $nopti_images = null;
405 405
 
406
-        if ( null === $cdn_url ) {
406
+        if (null === $cdn_url) {
407 407
             $cdn_url = apply_filters(
408 408
                 'autoptimize_filter_base_cdnurl',
409
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
409
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
410 410
             );
411 411
         }
412 412
 
413
-        if ( null === $nopti_images ) {
414
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' );
413
+        if (null === $nopti_images) {
414
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', '');
415 415
         }
416 416
 
417 417
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
418
-        $url        = $this->normalize_img_url( $url );
419
-        $url_parsed = parse_url( $url );
418
+        $url        = $this->normalize_img_url($url);
419
+        $url_parsed = parse_url($url);
420 420
 
421
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
421
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
422 422
             return false;
423
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
423
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
424 424
             return false;
425
-        } elseif ( strpos( $url, '.php' ) !== false ) {
425
+        } elseif (strpos($url, '.php') !== false) {
426 426
             return false;
427
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
427
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif'), '', $url_parsed['path']) === $url_parsed['path']) {
428 428
             // fixme: better check against end of string.
429 429
             return false;
430
-        } elseif ( ! empty( $nopti_images ) ) {
431
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
432
-            foreach ( $nopti_images_array as $nopti_image ) {
433
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
430
+        } elseif (!empty($nopti_images)) {
431
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
432
+            foreach ($nopti_images_array as $nopti_image) {
433
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
434 434
                     return false;
435 435
                 }
436 436
             }
@@ -438,13 +438,13 @@  discard block
 block discarded – undo
438 438
         return true;
439 439
     }
440 440
 
441
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
441
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
442 442
     {
443 443
         // sanitize width and height.
444
-        if ( strpos( $width, '%' ) !== false ) {
444
+        if (strpos($width, '%') !== false) {
445 445
             $width = 0;
446 446
         }
447
-        if ( strpos( $height, '%' ) !== false ) {
447
+        if (strpos($height, '%') !== false) {
448 448
             $height = 0;
449 449
         }
450 450
         $width  = (int) $width;
@@ -458,56 +458,56 @@  discard block
 block discarded – undo
458 458
         );
459 459
 
460 460
         // If filter modified the url, return that.
461
-        if ( $filtered_url !== $orig_url ) {
461
+        if ($filtered_url !== $orig_url) {
462 462
             return $filtered_url;
463 463
         }
464 464
 
465
-        $orig_url        = $this->normalize_img_url( $orig_url );
465
+        $orig_url        = $this->normalize_img_url($orig_url);
466 466
         $imgopt_base_url = $this->get_imgopt_base_url();
467 467
         $imgopt_size     = '';
468 468
 
469
-        if ( $width && 0 !== $width ) {
470
-            $imgopt_size = ',w_' . $width;
469
+        if ($width && 0 !== $width) {
470
+            $imgopt_size = ',w_'.$width;
471 471
         }
472 472
 
473
-        if ( $height && 0 !== $height ) {
474
-            $imgopt_size .= ',h_' . $height;
473
+        if ($height && 0 !== $height) {
474
+            $imgopt_size .= ',h_'.$height;
475 475
         }
476 476
 
477
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
477
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
478 478
 
479 479
         return $url;
480 480
     }
481 481
 
482
-    public function replace_data_thumbs( $matches )
482
+    public function replace_data_thumbs($matches)
483 483
     {
484
-        return $this->replace_img_callback( $matches, 150, 150 );
484
+        return $this->replace_img_callback($matches, 150, 150);
485 485
     }
486 486
 
487
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
487
+    public function replace_img_callback($matches, $width = 0, $height = 0)
488 488
     {
489
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
490
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
491
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
489
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
490
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
491
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
492 492
         } else {
493 493
             return $matches[0];
494 494
         }
495 495
     }
496 496
 
497
-    public function replace_icon_callback( $matches )
497
+    public function replace_icon_callback($matches)
498 498
     {
499
-        if ( array_key_exists( '2', $matches ) ) {
500
-            $sizes  = explode( 'x', $matches[2] );
499
+        if (array_key_exists('2', $matches)) {
500
+            $sizes  = explode('x', $matches[2]);
501 501
             $width  = $sizes[0];
502 502
             $height = $sizes[1];
503 503
         } else {
504 504
             $width  = 180;
505 505
             $height = 180;
506 506
         }
507
-        return $this->replace_img_callback( $matches, $width, $height );
507
+        return $this->replace_img_callback($matches, $width, $height);
508 508
     }
509 509
 
510
-    public function filter_optimize_images( $in )
510
+    public function filter_optimize_images($in)
511 511
     {
512 512
         /*
513 513
          * potential future functional improvements:
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
         $to_replace = array();
518 518
 
519 519
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
520
-        if ( $this->should_lazyload() ) {
520
+        if ($this->should_lazyload()) {
521 521
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
522 522
                 'SCRIPT',
523 523
                 '<script',
@@ -527,161 +527,161 @@  discard block
 block discarded – undo
527 527
         }
528 528
 
529 529
         // extract img tags.
530
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
531
-            foreach ( $matches[0] as $tag ) {
530
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
531
+            foreach ($matches[0] as $tag) {
532 532
                 $orig_tag = $tag;
533 533
                 $imgopt_w = '';
534 534
                 $imgopt_h = '';
535 535
 
536 536
                 // first do (data-)srcsets.
537
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
538
-                    foreach ( $allsrcsets as $srcset ) {
537
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
538
+                    foreach ($allsrcsets as $srcset) {
539 539
                         $srcset      = $srcset[2];
540 540
                         $orig_srcset = $srcset;
541
-                        $srcsets     = explode( ',', $srcset );
542
-                        foreach ( $srcsets as $indiv_srcset ) {
543
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
544
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
545
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
541
+                        $srcsets     = explode(',', $srcset);
542
+                        foreach ($srcsets as $indiv_srcset) {
543
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
544
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
545
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
546 546
                             }
547
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag ) ) {
548
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
549
-                                $srcset     = str_replace( $indiv_srcset_parts[0], $imgopt_url, $srcset );
547
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag)) {
548
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
549
+                                $srcset     = str_replace($indiv_srcset_parts[0], $imgopt_url, $srcset);
550 550
                             }
551 551
                         }
552
-                        $tag = str_replace( $orig_srcset, $srcset, $tag );
552
+                        $tag = str_replace($orig_srcset, $srcset, $tag);
553 553
                     }
554 554
                 }
555 555
 
556 556
                 // proceed with img src.
557 557
                 // get width and height and add to $imgopt_size.
558
-                $_get_size = $this->get_size_from_tag( $tag );
558
+                $_get_size = $this->get_size_from_tag($tag);
559 559
                 $imgopt_w  = $_get_size['width'];
560 560
                 $imgopt_h  = $_get_size['height'];
561 561
 
562 562
                 // then start replacing images src.
563
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
564
-                    foreach ( $urls as $url ) {
563
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
564
+                    foreach ($urls as $url) {
565 565
                         $full_src_orig = $url[0];
566 566
                         $url           = $url[1];
567
-                        if ( $this->can_optimize_image( $url, $full_src_orig ) ) {
568
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
569
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
570
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
567
+                        if ($this->can_optimize_image($url, $full_src_orig)) {
568
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
569
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
570
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
571 571
                         }
572 572
                     }
573 573
                 }
574 574
 
575 575
                 // do lazyload stuff.
576
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
576
+                if ($this->should_lazyload($in) && !empty($url)) {
577 577
                     // first do lpiq placeholder logic.
578
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
578
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
579 579
                         // if all img src have been replaced during srcset, we have to extract the
580 580
                         // origin url from the imgopt one to be able to set a lqip placeholder.
581
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
581
+                        $_url = substr($url, strpos($url, '/http') + 1);
582 582
                     } else {
583 583
                         $_url = $url;
584 584
                     }
585 585
 
586
-                    $_url = $this->normalize_img_url( $_url );
586
+                    $_url = $this->normalize_img_url($_url);
587 587
 
588 588
                     $placeholder = '';
589
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
589
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
590 590
                         $lqip_w = '';
591 591
                         $lqip_h = '';
592
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
593
-                            $lqip_w = ',w_' . $imgopt_w;
592
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
593
+                            $lqip_w = ',w_'.$imgopt_w;
594 594
                         }
595
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
596
-                            $lqip_h = ',h_' . $imgopt_h;
595
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
596
+                            $lqip_h = ',h_'.$imgopt_h;
597 597
                         }
598
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
598
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
599 599
                     }
600 600
                     // then call add_lazyload-function with lpiq placeholder if set.
601
-                    $tag = $this->add_lazyload( $tag, $placeholder );
601
+                    $tag = $this->add_lazyload($tag, $placeholder);
602 602
                 }
603 603
 
604 604
                 // and add tag to array for later replacement.
605
-                if ( $tag !== $orig_tag ) {
606
-                    $to_replace[ $orig_tag ] = $tag;
605
+                if ($tag !== $orig_tag) {
606
+                    $to_replace[$orig_tag] = $tag;
607 607
                 }
608 608
             }
609 609
         }
610 610
 
611 611
         // and replace all.
612
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
612
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
613 613
 
614 614
         // img thumbnails in e.g. woocommerce.
615
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
615
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
616 616
             $out = preg_replace_callback(
617 617
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
618
-                array( $this, 'replace_data_thumbs' ),
618
+                array($this, 'replace_data_thumbs'),
619 619
                 $out
620 620
             );
621 621
         }
622 622
 
623 623
         // background-image in inline style.
624
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
624
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
625 625
             $out = preg_replace_callback(
626 626
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
627
-                array( $this, 'replace_img_callback' ),
627
+                array($this, 'replace_img_callback'),
628 628
                 $out
629 629
             );
630 630
         }
631 631
 
632 632
         // act on icon links.
633
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
633
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
634 634
             $out = preg_replace_callback(
635 635
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
636
-                array( $this, 'replace_icon_callback' ),
636
+                array($this, 'replace_icon_callback'),
637 637
                 $out
638 638
             );
639 639
         }
640 640
 
641 641
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
642
-        if ( $this->should_lazyload() ) {
642
+        if ($this->should_lazyload()) {
643 643
             $out = autoptimizeBase::restore_marked_content(
644 644
                 'SCRIPT',
645 645
                 $out
646 646
             );
647 647
 
648
-            $out = $this->process_picture_tag( $out, true, true );
649
-            $out = $this->process_bgimage( $out );
648
+            $out = $this->process_picture_tag($out, true, true);
649
+            $out = $this->process_bgimage($out);
650 650
         } else {
651
-            $out = $this->process_picture_tag( $out, true, false );
651
+            $out = $this->process_picture_tag($out, true, false);
652 652
         }
653 653
 
654 654
         return $out;
655 655
     }
656 656
 
657
-    public function get_size_from_tag( $tag ) {
657
+    public function get_size_from_tag($tag) {
658 658
         // reusable function to extract widht and height from an image tag
659 659
         // enforcing a filterable maximum width and height (default 4999X4999).
660 660
         $width  = '';
661 661
         $height = '';
662 662
 
663
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
664
-            if ( strpos( $_width[2], '%' ) === false ) {
663
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
664
+            if (strpos($_width[2], '%') === false) {
665 665
                 $width = (int) $_width[2];
666 666
             }
667 667
         }
668
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
669
-            if ( strpos( $_height[2], '%' ) === false ) {
668
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
669
+            if (strpos($_height[2], '%') === false) {
670 670
                 $height = (int) $_height[2];
671 671
             }
672 672
         }
673 673
 
674 674
         // check for and enforce (filterable) max sizes.
675
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
676
-        if ( $width > $_max_width ) {
675
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
676
+        if ($width > $_max_width) {
677 677
             $_width = $_max_width;
678
-            $height = $_width / $width * $height;
678
+            $height = $_width/$width*$height;
679 679
             $width  = $_width;
680 680
         }
681
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
682
-        if ( $height > $_max_height ) {
681
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
682
+        if ($height > $_max_height) {
683 683
             $_height = $_max_height;
684
-            $width   = $_height / $height * $width;
684
+            $width   = $_height/$height*$width;
685 685
             $height  = $_height;
686 686
         }
687 687
 
@@ -700,26 +700,26 @@  discard block
 block discarded – undo
700 700
         return $self->should_lazyload();
701 701
     }
702 702
 
703
-    public function should_lazyload( $context = '' ) {
704
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
703
+    public function should_lazyload($context = '') {
704
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
705 705
             $lazyload_return = true;
706 706
         } else {
707 707
             $lazyload_return = false;
708 708
         }
709
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
709
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
710 710
 
711 711
         return $lazyload_return;
712 712
     }
713 713
 
714 714
     public function check_nolazy() {
715
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
715
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
716 716
             return true;
717 717
         } else {
718 718
             return false;
719 719
         }
720 720
     }
721 721
 
722
-    public function filter_lazyload_images( $in )
722
+    public function filter_lazyload_images($in)
723 723
     {
724 724
         // only used is image optimization is NOT active but lazyload is.
725 725
         $to_replace = array();
@@ -733,20 +733,20 @@  discard block
 block discarded – undo
733 733
         );
734 734
 
735 735
         // extract img tags and add lazyload attribs.
736
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
737
-            foreach ( $matches[0] as $tag ) {
738
-                if ( $this->should_lazyload( $out ) ) {
739
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
736
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
737
+            foreach ($matches[0] as $tag) {
738
+                if ($this->should_lazyload($out)) {
739
+                    $to_replace[$tag] = $this->add_lazyload($tag);
740 740
                 }
741 741
             }
742
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
742
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
743 743
         }
744 744
 
745 745
         // and also lazyload picture tag.
746
-        $out = $this->process_picture_tag( $out, false, true );
746
+        $out = $this->process_picture_tag($out, false, true);
747 747
 
748 748
         // and inline style blocks with background-image.
749
-        $out = $this->process_bgimage( $out );
749
+        $out = $this->process_bgimage($out);
750 750
 
751 751
         // restore noscript tags.
752 752
         $out = autoptimizeBase::restore_marked_content(
@@ -757,84 +757,84 @@  discard block
 block discarded – undo
757 757
         return $out;
758 758
     }
759 759
 
760
-    public function add_lazyload( $tag, $placeholder = '' ) {
760
+    public function add_lazyload($tag, $placeholder = '') {
761 761
         // adds actual lazyload-attributes to an image node.
762
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
763
-            $tag = $this->maybe_fix_missing_quotes( $tag );
762
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) {
763
+            $tag = $this->maybe_fix_missing_quotes($tag);
764 764
 
765 765
             // store original tag for use in noscript version.
766
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
766
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
767 767
 
768
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
768
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
769 769
 
770 770
             // insert lazyload class.
771
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
771
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
772 772
 
773
-            if ( ! $placeholder || empty( $placeholder ) ) {
773
+            if (!$placeholder || empty($placeholder)) {
774 774
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
775
-                $_get_size = $this->get_size_from_tag( $tag );
775
+                $_get_size = $this->get_size_from_tag($tag);
776 776
                 $width     = $_get_size['width'];
777 777
                 $height    = $_get_size['height'];
778
-                if ( false === $width || empty( $width ) ) {
778
+                if (false === $width || empty($width)) {
779 779
                     $width = 210; // default width for SVG placeholder.
780 780
                 }
781
-                if ( false === $height || empty( $height ) ) {
782
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
781
+                if (false === $height || empty($height)) {
782
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
783 783
                 }
784 784
 
785 785
                 // insert the actual lazyload stuff.
786 786
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
787
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
787
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
788 788
             }
789 789
 
790
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
791
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
790
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
791
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
792 792
 
793 793
             // move sizes to data-sizes unless filter says no.
794
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
795
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
794
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
795
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
796 796
             }
797 797
 
798 798
             // add the noscript-tag from earlier.
799
-            $tag = $noscript_tag . $tag;
800
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
799
+            $tag = $noscript_tag.$tag;
800
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
801 801
         }
802 802
 
803 803
         return $tag;
804 804
     }
805 805
 
806 806
     public function add_lazyload_js_footer() {
807
-        if ( false === autoptimizeMain::should_buffer() ) {
807
+        if (false === autoptimizeMain::should_buffer()) {
808 808
             return;
809 809
         }
810 810
 
811 811
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
812 812
         $noptimize_flag = '';
813
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
813
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
814 814
             $noptimize_flag = ' data-noptimize="1"';
815 815
         }
816 816
 
817
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
817
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
818 818
         $cdn_url      = $this->get_cdn_url();
819
-        if ( ! empty( $cdn_url ) ) {
820
-            $cdn_url      = rtrim( $cdn_url, '/' );
821
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
819
+        if (!empty($cdn_url)) {
820
+            $cdn_url      = rtrim($cdn_url, '/');
821
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
822 822
         }
823 823
 
824 824
         $type_js = '';
825
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
825
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
826 826
             $type_js = ' type="text/javascript"';
827 827
         }
828 828
 
829 829
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
830
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
831
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
832
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
830
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
831
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
832
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
833 833
 
834 834
         // And add webp detection and loading JS.
835
-        if ( $this->should_ngimg() ) {
835
+        if ($this->should_ngimg()) {
836 836
             // Add AVIF code, can be disabled for now to only do webp.
837
-            if ( apply_filters( 'autoptimize_filter_imgopt_do_avif', true ) ) {
837
+            if (apply_filters('autoptimize_filter_imgopt_do_avif', true)) {
838 838
                 $_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");';
839 839
                 $_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+","))})});';
840 840
             } else {
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
                 $_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,'))})});";
843 843
             }
844 844
             // Keeping autoptimize_filter_imgopt_webp_js filter for now, but it is deprecated as not only for webp any more.
845
-            $_ngimg_output = apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_ngimg_detect . $_ngimg_load . '</script>' );
846
-            echo apply_filters( 'autoptimize_filter_imgopt_ngimg_js', $_ngimg_output );
845
+            $_ngimg_output = apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_ngimg_detect.$_ngimg_load.'</script>');
846
+            echo apply_filters('autoptimize_filter_imgopt_ngimg_js', $_ngimg_output);
847 847
         }
848 848
     }
849 849
 
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
852 852
         static $cdn_url = null;
853 853
 
854
-        if ( null === $cdn_url ) {
855
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
856
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
857
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
854
+        if (null === $cdn_url) {
855
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
856
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
857
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
858 858
         }
859 859
 
860 860
         return $cdn_url;
@@ -864,47 +864,47 @@  discard block
 block discarded – undo
864 864
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
865 865
         static $exclude_lazyload_array = null;
866 866
 
867
-        if ( null === $exclude_lazyload_array ) {
867
+        if (null === $exclude_lazyload_array) {
868 868
             $options = $this->options;
869 869
 
870 870
             // set default exclusions.
871
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
871
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
872 872
 
873 873
             // add from setting.
874
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
874
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
875 875
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
876
-                if ( ! empty( $exclude_lazyload_option ) ) {
877
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
876
+                if (!empty($exclude_lazyload_option)) {
877
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
878 878
                 }
879 879
             }
880 880
 
881 881
             // and filter for developer-initiated changes.
882
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
882
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
883 883
         }
884 884
 
885 885
         return $exclude_lazyload_array;
886 886
     }
887 887
 
888
-    public function inject_classes_in_tag( $tag, $target_class ) {
889
-        if ( strpos( $tag, 'class=' ) !== false ) {
890
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
888
+    public function inject_classes_in_tag($tag, $target_class) {
889
+        if (strpos($tag, 'class=') !== false) {
890
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
891 891
         } else {
892
-            $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
892
+            $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag);
893 893
         }
894 894
 
895 895
         return $tag;
896 896
     }
897 897
 
898
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
899
-        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';
898
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
899
+        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';
900 900
     }
901 901
 
902 902
     public function should_ngimg() {
903 903
         static $ngimg_return = null;
904 904
 
905
-        if ( is_null( $ngimg_return ) ) {
905
+        if (is_null($ngimg_return)) {
906 906
             // webp only works if imgopt and lazyload are also active.
907
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
907
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
908 908
                 $ngimg_return = true;
909 909
             } else {
910 910
                 $ngimg_return = false;
@@ -914,9 +914,9 @@  discard block
 block discarded – undo
914 914
         return $ngimg_return;
915 915
     }
916 916
 
917
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
917
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
918 918
         // check if "<picture" is present and if filter allows us to process <picture>.
919
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
919
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
920 920
             return $in;
921 921
         }
922 922
 
@@ -924,37 +924,37 @@  discard block
 block discarded – undo
924 924
         $to_replace_pict = array();
925 925
 
926 926
         // extract and process each picture-node.
927
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
928
-        foreach ( $_pictures as $_picture ) {
929
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
930
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
931
-                foreach ( $_sources as $_source ) {
927
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
928
+        foreach ($_pictures as $_picture) {
929
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
930
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
931
+                foreach ($_sources as $_source) {
932 932
                     $_picture_replacement = $_source[0];
933 933
 
934 934
                     // should we optimize the image?
935
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
936
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
935
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
936
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
937 937
                     }
938 938
                     // should we lazy-load?
939
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
940
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
939
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
940
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
941 941
                     }
942
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
942
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
943 943
                 }
944 944
             }
945 945
         }
946 946
 
947 947
         // and return the fully procesed $in.
948
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
948
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
949 949
 
950 950
         return $out;
951 951
     }
952 952
 
953
-    public function process_bgimage( $in ) {
954
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
953
+    public function process_bgimage($in) {
954
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
955 955
             $out = preg_replace_callback(
956 956
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
957
-                array( $this, 'lazyload_bgimg_callback' ),
957
+                array($this, 'lazyload_bgimg_callback'),
958 958
                 $in
959 959
             );
960 960
             return $out;
@@ -962,27 +962,27 @@  discard block
 block discarded – undo
962 962
         return $in;
963 963
     }
964 964
 
965
-    public function lazyload_bgimg_callback( $matches ) {
966
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
965
+    public function lazyload_bgimg_callback($matches) {
966
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
967 967
             // get placeholder & lazyload class strings.
968
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
969
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
968
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
969
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
970 970
             // replace background-image URL with SVG placeholder.
971
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
971
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
972 972
             // add data-bg attribute with real background-image URL for lazyload to pick up.
973
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
973
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
974 974
             // add lazyload class to tag.
975
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
975
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
976 976
             return $out;
977 977
         }
978 978
         return $matches[0];
979 979
     }
980 980
 
981
-    public function maybe_fix_missing_quotes( $tag_in ) {
981
+    public function maybe_fix_missing_quotes($tag_in) {
982 982
         // 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.
983
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
984
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
985
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
983
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
984
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
985
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
986 986
             return $tag_out;
987 987
         } else {
988 988
             return $tag_in;
@@ -995,23 +995,23 @@  discard block
 block discarded – undo
995 995
     public function imgopt_admin_menu()
996 996
     {
997 997
         // no acces if multisite and not network admin and no site config allowed.
998
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
998
+        if (autoptimizeConfig::should_show_menu_tabs()) {
999 999
             add_submenu_page(
1000 1000
                 null,
1001 1001
                 'autoptimize_imgopt',
1002 1002
                 'autoptimize_imgopt',
1003 1003
                 'manage_options',
1004 1004
                 'autoptimize_imgopt',
1005
-                array( $this, 'imgopt_options_page' )
1005
+                array($this, 'imgopt_options_page')
1006 1006
             );
1007 1007
         }
1008
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
1008
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
1009 1009
     }
1010 1010
 
1011
-    public function add_imgopt_tab( $in )
1011
+    public function add_imgopt_tab($in)
1012 1012
     {
1013
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1014
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
1013
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1014
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1015 1015
         }
1016 1016
 
1017 1017
         return $in;
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
     public function imgopt_options_page()
1021 1021
     {
1022 1022
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1023
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1023
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1024 1024
             $this->query_img_provider_stats();
1025 1025
         }
1026 1026
 
@@ -1032,47 +1032,47 @@  discard block
 block discarded – undo
1032 1032
         #ao_settings_form .form-table th {font-weight: normal;}
1033 1033
         #autoptimize_imgopt_descr{font-size: 120%;}
1034 1034
     </style>
1035
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1035
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1036 1036
     <div class="wrap">
1037
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1037
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1038 1038
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1039
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1039
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1040 1040
             <div class="notice-warning notice"><p>
1041 1041
             <?php
1042 1042
             // translators: "Autoptimize support forum" will appear in a "a href".
1043
-            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>' );
1043
+            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>');
1044 1044
             ?>
1045 1045
             </p></div>
1046 1046
         <?php } ?>
1047 1047
 
1048
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1048
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1049 1049
             <div class="notice-warning notice"><p>
1050
-            <?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' ); ?>
1050
+            <?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'); ?>
1051 1051
             </p></div>
1052 1052
         <?php } ?>
1053 1053
 
1054
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1054
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1055 1055
             <div class="notice-warning notice"><p>
1056 1056
             <?php
1057 1057
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1058
-            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>' );
1058
+            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>');
1059 1059
             ?>
1060 1060
             </p></div>
1061 1061
         <?php } ?>
1062
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1063
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1064
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1065
-        <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>
1062
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1063
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1064
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1065
+        <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>
1066 1066
         <table class="form-table">
1067 1067
             <tr>
1068
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1068
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1069 1069
                 <td>
1070
-                    <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>
1070
+                    <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>
1071 1071
                     <?php
1072 1072
                     // show shortpixel status.
1073 1073
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1074
-                    if ( $_notice ) {
1075
-                        switch ( $_notice['status'] ) {
1074
+                    if ($_notice) {
1075
+                        switch ($_notice['status']) {
1076 1076
                             case 2:
1077 1077
                                 $_notice_color = 'green';
1078 1078
                                 break;
@@ -1087,29 +1087,29 @@  discard block
 block discarded – undo
1087 1087
                             default:
1088 1088
                                 $_notice_color = 'green';
1089 1089
                         }
1090
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1090
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1091 1091
                     } else {
1092 1092
                         // translators: link points to shortpixel.
1093
-                        $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>' );
1094
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1095
-                            $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' );
1093
+                        $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>');
1094
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1095
+                            $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');
1096 1096
                         } else {
1097 1097
                             // translators: link points to shortpixel.
1098
-                            $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>' );
1098
+                            $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>');
1099 1099
                         }
1100
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1100
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1101 1101
                     }
1102 1102
                     // translators: link points to shortpixel FAQ.
1103
-                    $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>' );
1104
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1103
+                    $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>');
1104
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1105 1105
                     // translators: links points to shortpixel TOS & Privacy Policy.
1106
-                    $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>' );
1107
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1106
+                    $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>');
1107
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1108 1108
                     ?>
1109 1109
                 </td>
1110 1110
             </tr>
1111
-            <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"'; } ?>>
1112
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1111
+            <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"'; } ?>>
1112
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1113 1113
                 <td>
1114 1114
                     <label>
1115 1115
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1117,12 +1117,12 @@  discard block
 block discarded – undo
1117 1117
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1118 1118
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1119 1119
 
1120
-                        foreach ( $_imgopt_array as $key => $value ) {
1121
-                            echo '<option value="' . $key . '"';
1122
-                            if ( $_imgopt_val == $key ) {
1120
+                        foreach ($_imgopt_array as $key => $value) {
1121
+                            echo '<option value="'.$key.'"';
1122
+                            if ($_imgopt_val == $key) {
1123 1123
                                 echo ' selected';
1124 1124
                             }
1125
-                            echo '>' . ucfirst( $value ) . '</option>';
1125
+                            echo '>'.ucfirst($value).'</option>';
1126 1126
                         }
1127 1127
                         echo "\n";
1128 1128
                         ?>
@@ -1131,31 +1131,31 @@  discard block
 block discarded – undo
1131 1131
                     <p>
1132 1132
                         <?php
1133 1133
                             // translators: link points to shortpixel image test page.
1134
-                            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>' ) );
1134
+                            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>'));
1135 1135
                         ?>
1136 1136
                     </p>
1137 1137
                 </td>
1138 1138
             </tr>
1139
-            <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"'; } ?>>
1140
-                <th scope="row"><?php _e( 'Load WebP or AVIF in supported browsers?', 'autoptimize' ); ?></th>
1139
+            <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"'; } ?>>
1140
+                <th scope="row"><?php _e('Load WebP or AVIF in supported browsers?', 'autoptimize'); ?></th>
1141 1141
                 <td>
1142
-                    <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>
1142
+                    <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>
1143 1143
                 </td>
1144 1144
             </tr>
1145 1145
             <tr>
1146
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1146
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1147 1147
                 <td>
1148
-                    <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>
1148
+                    <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>
1149 1149
                 </td>
1150 1150
             </tr>
1151
-            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="hidden"'; } ?>>
1152
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1151
+            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="hidden"'; } ?>>
1152
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1153 1153
                 <td>
1154
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label>
1154
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label>
1155 1155
                 </td>
1156 1156
             </tr>
1157 1157
         </table>
1158
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1158
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1159 1159
     </form>
1160 1160
     <script>
1161 1161
         jQuery(document).ready(function() {
@@ -1191,50 +1191,50 @@  discard block
 block discarded – undo
1191 1191
      * Ïmg opt status as used on dashboard.
1192 1192
      */
1193 1193
     public function get_imgopt_status_notice() {
1194
-        if ( $this->imgopt_active() ) {
1194
+        if ($this->imgopt_active()) {
1195 1195
             $_imgopt_notice  = '';
1196
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1196
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1197 1197
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1198
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1198
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1199 1199
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1200 1200
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1201 1201
 
1202
-            if ( is_array( $_stat ) ) {
1203
-                if ( 1 == $_stat['Status'] ) {
1202
+            if (is_array($_stat)) {
1203
+                if (1 == $_stat['Status']) {
1204 1204
                     // translators: "add more credits" will appear in a "a href".
1205
-                    $_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>' );
1205
+                    $_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>');
1206 1206
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1207 1207
                     // translators: "add more credits" will appear in a "a href".
1208
-                    $_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>' );
1208
+                    $_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>');
1209 1209
                     // translators: "associate your domain" will appear in a "a href".
1210
-                    $_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>' );
1210
+                    $_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>');
1211 1211
                 } elseif ( -3 == $_stat['Status'] ) {
1212 1212
                     // translators: "check the documentation here" will appear in a "a href".
1213
-                    $_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>' );
1213
+                    $_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>');
1214 1214
                 } else {
1215 1215
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1216 1216
                     // translators: "log in to check your account" will appear in a "a href".
1217
-                    $_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>' );
1217
+                    $_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>');
1218 1218
                 }
1219 1219
 
1220 1220
                 // add info on freshness + refresh link if status is not 2 (good shape).
1221
-                if ( 2 != $_stat['Status'] ) {
1222
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1221
+                if (2 != $_stat['Status']) {
1222
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1223 1223
                         'page'                => 'autoptimize_imgopt',
1224 1224
                         'refreshImgProvStats' => '1',
1225
-                    ), admin_url( 'options-general.php' ) );
1226
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1227
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1225
+                    ), admin_url('options-general.php'));
1226
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1227
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1228 1228
                     } else {
1229
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1229
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1230 1230
                     }
1231
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1231
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1232 1232
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1233
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1233
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1234 1234
                 }
1235 1235
 
1236 1236
                 // and make the full notice filterable.
1237
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1237
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1238 1238
 
1239 1239
                 return array(
1240 1240
                     'status' => $_stat['Status'],
@@ -1255,14 +1255,14 @@  discard block
 block discarded – undo
1255 1255
      * Get img provider stats (used to display notice).
1256 1256
      */
1257 1257
     public function query_img_provider_stats() {
1258
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1258
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1259 1259
             $url      = '';
1260
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1260
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1261 1261
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1262 1262
 
1263 1263
             // make sure parse_url result makes sense, keeping $url empty if not.
1264
-            if ( $domain && ! empty( $domain ) ) {
1265
-                $url = $endpoint . $domain;
1264
+            if ($domain && !empty($domain)) {
1265
+                $url = $endpoint.$domain;
1266 1266
             }
1267 1267
 
1268 1268
             $url = apply_filters(
@@ -1272,12 +1272,12 @@  discard block
 block discarded – undo
1272 1272
 
1273 1273
             // only do the remote call if $url is not empty to make sure no parse_url
1274 1274
             // weirdness results in useless calls.
1275
-            if ( ! empty( $url ) ) {
1276
-                $response = wp_remote_get( $url );
1277
-                if ( ! is_wp_error( $response ) ) {
1278
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1279
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1280
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1275
+            if (!empty($url)) {
1276
+                $response = wp_remote_get($url);
1277
+                if (!is_wp_error($response)) {
1278
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1279
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1280
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1281 1281
                     }
1282 1282
                 }
1283 1283
             }
@@ -1300,15 +1300,15 @@  discard block
 block discarded – undo
1300 1300
     {
1301 1301
         static $launch_status = null;
1302 1302
 
1303
-        if ( null === $launch_status ) {
1303
+        if (null === $launch_status) {
1304 1304
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1305
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1306
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1305
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1306
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1307 1307
             $launch_status = false;
1308
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1308
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1309 1309
                 $launch_status = true;
1310
-                if ( ! $has_launched ) {
1311
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1310
+                if (!$has_launched) {
1311
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1312 1312
                 }
1313 1313
             }
1314 1314
         }
@@ -1325,16 +1325,16 @@  discard block
 block discarded – undo
1325 1325
     public function get_imgopt_provider_userstatus() {
1326 1326
         static $_provider_userstatus = null;
1327 1327
 
1328
-        if ( is_null( $_provider_userstatus ) ) {
1329
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1330
-            if ( is_array( $_stat ) ) {
1331
-                if ( array_key_exists( 'Status', $_stat ) ) {
1328
+        if (is_null($_provider_userstatus)) {
1329
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1330
+            if (is_array($_stat)) {
1331
+                if (array_key_exists('Status', $_stat)) {
1332 1332
                     $_provider_userstatus['Status'] = $_stat['Status'];
1333 1333
                 } else {
1334 1334
                     // if no stats then we assume all is well.
1335 1335
                     $_provider_userstatus['Status'] = 2;
1336 1336
                 }
1337
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1337
+                if (array_key_exists('timestamp', $_stat)) {
1338 1338
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1339 1339
                 } else {
1340 1340
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeExtra.php 1 patch
Spacing   +198 added lines, -198 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,151 +218,151 @@  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
-                    $font = str_replace( array( 'wght@', 'wght%40', ';', '%3B' ), array( '', '', ',', ',' ), $font );
240
+                    $font = str_replace(array('wght@', 'wght%40', ';', '%3B'), array('', '', ',', ','), $font);
241 241
                 }
242
-                $font = explode( 'family=', $font );
243
-                $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
242
+                $font = explode('family=', $font);
243
+                $font = (isset($font[1])) ? explode('&', $font[1]) : array();
244 244
                 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
245
-                $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) );
246
-                if ( ! empty( $_thisfont ) ) {
247
-                    $fonts_collection[ $i ]['fonts'] = $_thisfont;
245
+                $_thisfont = array_values(array_filter(explode('|', reset($font))));
246
+                if (!empty($_thisfont)) {
247
+                    $fonts_collection[$i]['fonts'] = $_thisfont;
248 248
                     // And add subset if any!
249
-                    $subset = ( is_array( $font ) ) ? end( $font ) : '';
250
-                    if ( false !== strpos( $subset, 'subset=' ) ) {
251
-                        $subset                            = str_replace( array( '%2C', '%2c' ), ',', $subset );
252
-                        $subset                            = explode( 'subset=', $subset );
253
-                        $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] );
249
+                    $subset = (is_array($font)) ? end($font) : '';
250
+                    if (false !== strpos($subset, 'subset=')) {
251
+                        $subset                            = str_replace(array('%2C', '%2c'), ',', $subset);
252
+                        $subset                            = explode('subset=', $subset);
253
+                        $fonts_collection[$i]['subsets'] = explode(',', $subset[1]);
254 254
                     }
255 255
                 }
256 256
                 // And remove Google Fonts.
257
-                $in = str_replace( $matches[0][ $i ], '', $in );
257
+                $in = str_replace($matches[0][$i], '', $in);
258 258
             }
259 259
             $i++;
260 260
         }
261 261
 
262 262
         $options      = $this->options;
263 263
         $fonts_markup = '';
264
-        if ( '2' === $options['autoptimize_extra_radio_field_4'] ) {
264
+        if ('2' === $options['autoptimize_extra_radio_field_4']) {
265 265
             // Remove Google Fonts.
266
-            unset( $fonts_collection );
266
+            unset($fonts_collection);
267 267
             return $in;
268
-        } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) {
268
+        } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) {
269 269
             // Aggregate & link!
270 270
             $fonts_string  = '';
271 271
             $subset_string = '';
272
-            foreach ( $fonts_collection as $font ) {
273
-                $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' );
274
-                if ( ! empty( $font['subsets'] ) ) {
275
-                    $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' );
272
+            foreach ($fonts_collection as $font) {
273
+                $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|');
274
+                if (!empty($font['subsets'])) {
275
+                    $subset_string .= ','.trim(implode(',', $font['subsets']), ',');
276 276
                 }
277 277
             }
278 278
 
279
-            if ( ! empty( $subset_string ) ) {
280
-                $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) );
281
-                $fonts_string  = $fonts_string . '&#038;subset=' . $subset_string;
279
+            if (!empty($subset_string)) {
280
+                $subset_string = str_replace(',', '%2C', ltrim($subset_string, ','));
281
+                $fonts_string  = $fonts_string.'&#038;subset='.$subset_string;
282 282
             }
283 283
 
284
-            $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) );
284
+            $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|')));
285 285
             // only add display parameter if there is none in $fonts_string (by virtue of the filter).
286
-            if ( strpos( $fonts_string, 'display=' ) === false ) {
287
-                $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&amp;display=swap' );
286
+            if (strpos($fonts_string, 'display=') === false) {
287
+                $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&amp;display=swap');
288 288
             }
289 289
 
290
-            if ( ! empty( $fonts_string ) ) {
291
-                if ( '5' === $options['autoptimize_extra_radio_field_4'] ) {
292
-                    $rel_string = 'rel="stylesheet" media="print" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
290
+            if (!empty($fonts_string)) {
291
+                if ('5' === $options['autoptimize_extra_radio_field_4']) {
292
+                    $rel_string = 'rel="stylesheet" media="print" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"';
293 293
                 } else {
294 294
                     $rel_string = 'rel="stylesheet"';
295 295
                 }
296
-                $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />';
296
+                $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />';
297 297
             }
298
-        } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) {
298
+        } elseif ('4' === $options['autoptimize_extra_radio_field_4']) {
299 299
             // Aggregate & load async (webfont.js impl.)!
300 300
             $fonts_array = array();
301
-            foreach ( $fonts_collection as $_fonts ) {
302
-                if ( ! empty( $_fonts['subsets'] ) ) {
303
-                    $_subset = implode( ',', $_fonts['subsets'] );
304
-                    foreach ( $_fonts['fonts'] as $key => $_one_font ) {
305
-                        $_one_font               = $_one_font . ':' . $_subset;
306
-                        $_fonts['fonts'][ $key ] = $_one_font;
301
+            foreach ($fonts_collection as $_fonts) {
302
+                if (!empty($_fonts['subsets'])) {
303
+                    $_subset = implode(',', $_fonts['subsets']);
304
+                    foreach ($_fonts['fonts'] as $key => $_one_font) {
305
+                        $_one_font               = $_one_font.':'.$_subset;
306
+                        $_fonts['fonts'][$key] = $_one_font;
307 307
                     }
308 308
                 }
309
-                $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
309
+                $fonts_array = array_merge($fonts_array, $_fonts['fonts']);
310 310
             }
311 311
 
312
-            $fonts_array = array_map( 'urldecode', $fonts_array );
312
+            $fonts_array = array_map('urldecode', $fonts_array);
313 313
             $fonts_array = array_map(
314
-                function( $_f ) {
315
-                    return trim( $_f, ',' );
314
+                function($_f) {
315
+                    return trim($_f, ',');
316 316
                 },
317 317
                 $fonts_array
318 318
             );
319 319
 
320 320
             // type attrib on <script not added by default.
321 321
             $type_js = '';
322
-            if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
322
+            if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
323 323
                 $type_js = 'type="text/javascript" ';
324 324
             }
325 325
 
326
-            $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>';
327
-            $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>';
328
-            $in                   = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
326
+            $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>';
327
+            $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>';
328
+            $in                   = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>'));
329 329
         }
330 330
 
331 331
         // Replace back in markup.
332
-        $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
333
-        $out          = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
334
-        unset( $fonts_collection );
332
+        $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link');
333
+        $out          = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point));
334
+        unset($fonts_collection);
335 335
 
336 336
         return $out;
337 337
     }
338 338
 
339
-    public function filter_preconnect( $hints, $relation_type )
339
+    public function filter_preconnect($hints, $relation_type)
340 340
     {
341 341
         $options  = $this->options;
342 342
         $preconns = array();
343 343
 
344 344
         // Get settings and store in array.
345
-        if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) {
346
-            $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
345
+        if (array_key_exists('autoptimize_extra_text_field_2', $options)) {
346
+            $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2'])));
347 347
         }
348
-        $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
348
+        $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns);
349 349
 
350 350
         // Walk array, extract domain and add to new array with crossorigin attribute.
351
-        foreach ( $preconns as $preconn ) {
351
+        foreach ($preconns as $preconn) {
352 352
             $domain = '';
353
-            $parsed = parse_url( $preconn );
354
-            if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) {
355
-                $domain = '//' . $parsed['host'];
356
-            } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) {
357
-                $domain = $parsed['scheme'] . '://' . $parsed['host'];
353
+            $parsed = parse_url($preconn);
354
+            if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) {
355
+                $domain = '//'.$parsed['host'];
356
+            } elseif (is_array($parsed) && !empty($parsed['host'])) {
357
+                $domain = $parsed['scheme'].'://'.$parsed['host'];
358 358
             }
359 359
 
360
-            if ( ! empty( $domain ) ) {
361
-                $hint = array( 'href' => $domain );
360
+            if (!empty($domain)) {
361
+                $hint = array('href' => $domain);
362 362
                 // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set
363 363
                 // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed.
364
-                $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) );
365
-                if ( in_array( $domain, $crossorigins ) ) {
364
+                $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com'));
365
+                if (in_array($domain, $crossorigins)) {
366 366
                     $hint['crossorigin'] = 'anonymous';
367 367
                 }
368 368
                 $new_hints[] = $hint;
@@ -370,21 +370,21 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Merge in WP's preconnect hints.
373
-        if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) {
374
-            $hints = array_merge( $hints, $new_hints );
373
+        if ('preconnect' === $relation_type && !empty($new_hints)) {
374
+            $hints = array_merge($hints, $new_hints);
375 375
         }
376 376
 
377 377
         return $hints;
378 378
     }
379 379
 
380
-    public function filter_preconnect_google_fonts( $in )
380
+    public function filter_preconnect_google_fonts($in)
381 381
     {
382
-        if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) {
382
+        if ('2' !== $this->options['autoptimize_extra_radio_field_4']) {
383 383
             // Preconnect to fonts.gstatic.com unless we remove gfonts.
384 384
             $in[] = 'https://fonts.gstatic.com';
385 385
         }
386 386
 
387
-        if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) {
387
+        if ('4' === $this->options['autoptimize_extra_radio_field_4']) {
388 388
             // Preconnect even more hosts for webfont.js!
389 389
             $in[] = 'https://ajax.googleapis.com';
390 390
             $in[] = 'https://fonts.googleapis.com';
@@ -393,76 +393,76 @@  discard block
 block discarded – undo
393 393
         return $in;
394 394
     }
395 395
 
396
-    public function filter_preload( $in ) {
396
+    public function filter_preload($in) {
397 397
         // make array from comma separated list.
398 398
         $options  = $this->options;
399 399
         $preloads = array();
400
-        if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) {
401
-            $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) );
400
+        if (array_key_exists('autoptimize_extra_text_field_7', $options)) {
401
+            $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7'])));
402 402
         }
403
-        $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads );
403
+        $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads);
404 404
 
405 405
         // immediately return if nothing to be preloaded.
406
-        if ( empty( $preloads ) ) {
406
+        if (empty($preloads)) {
407 407
             return $in;
408 408
         }
409 409
 
410 410
         // iterate through array and add preload link to tmp string.
411 411
         $preload_output = '';
412
-        foreach ( $preloads as $preload ) {
412
+        foreach ($preloads as $preload) {
413 413
             $crossorigin = '';
414 414
             $preload_as  = '';
415 415
             $mime_type   = '';
416
-            $_preload    = strtok( $preload, '?' );
416
+            $_preload    = strtok($preload, '?');
417 417
 
418
-            if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) {
418
+            if (autoptimizeUtils::str_ends_in($_preload, '.css')) {
419 419
                 $preload_as = 'style';
420
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) {
420
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) {
421 421
                 $preload_as = 'script';
422
-            } 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' ) ) {
422
+            } 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')) {
423 423
                 $preload_as  = 'font';
424 424
                 $crossorigin = ' crossorigin';
425
-                $mime_type   = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
426
-                if ( ' type="font/eot"' === $mime_type ) {
425
+                $mime_type   = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"';
426
+                if (' type="font/eot"' === $mime_type) {
427 427
                     $mime_type = 'application/vnd.ms-fontobject';
428 428
                 }
429
-            } 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' ) ) {
429
+            } 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')) {
430 430
                 $preload_as = 'image';
431 431
             } else {
432 432
                 $preload_as = 'other';
433 433
             }
434 434
 
435
-            $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
435
+            $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>';
436 436
         }
437
-        $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output );
437
+        $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output);
438 438
 
439 439
         // add string to head (before first link node by default).
440
-        $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' );
441
-        $position       = autoptimizeUtils::strpos( $in, $preload_inject );
440
+        $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link');
441
+        $position       = autoptimizeUtils::strpos($in, $preload_inject);
442 442
 
443
-        return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) );
443
+        return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject));
444 444
     }
445 445
 
446 446
     public function admin_menu()
447 447
     {
448 448
         // no acces if multisite and not network admin and no site config allowed.
449
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
449
+        if (autoptimizeConfig::should_show_menu_tabs()) {
450 450
             add_submenu_page(
451 451
                 null,
452 452
                 'autoptimize_extra',
453 453
                 'autoptimize_extra',
454 454
                 'manage_options',
455 455
                 'autoptimize_extra',
456
-                array( $this, 'options_page' )
456
+                array($this, 'options_page')
457 457
             );
458 458
         }
459
-        register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
459
+        register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings');
460 460
     }
461 461
 
462
-    public function add_extra_tab( $in )
462
+    public function add_extra_tab($in)
463 463
     {
464
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
465
-            $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) );
464
+        if (autoptimizeConfig::should_show_menu_tabs()) {
465
+            $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize')));
466 466
         }
467 467
 
468 468
         return $in;
@@ -482,97 +482,97 @@  discard block
 block discarded – undo
482 482
         #ao_settings_form .form-table th {font-weight: normal;}
483 483
         #autoptimize_extra_descr{font-size: 120%;}
484 484
     </style>
485
-    <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
485
+    <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script>
486 486
     <div class="wrap">
487
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
487
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
488 488
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
489
-        <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
489
+        <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?>
490 490
             <div class="notice-warning notice"><p>
491
-            <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
491
+            <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?>
492 492
             </p></div>
493 493
         <?php } ?>
494 494
 
495
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
496
-        <?php settings_fields( 'autoptimize_extra_settings' ); ?>
497
-        <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
498
-        <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
495
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
496
+        <?php settings_fields('autoptimize_extra_settings'); ?>
497
+        <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2>
498
+        <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span>
499 499
         <table class="form-table">
500 500
             <tr>
501
-                <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th>
501
+                <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th>
502 502
                 <td>
503
-                    <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/>
504
-                    <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/>
503
+                    <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/>
504
+                    <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 505
                     <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
506
-                    <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/>
506
+                    <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/>
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="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/>
509
-                    <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/>
508
+                    <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/>
509
+                    <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 510
                 </td>
511 511
             </tr>
512 512
             <tr>
513
-                <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th>
513
+                <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th>
514 514
                 <td>
515
-                    <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>
515
+                    <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>
516 516
                 </td>
517 517
             </tr>
518 518
             <tr>
519
-                <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
519
+                <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th>
520 520
                 <td>
521
-                    <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>
521
+                    <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>
522 522
                 </td>
523 523
             </tr>
524 524
             <tr>
525
-                <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>
525
+                <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th>
526 526
                 <td>
527
-                    <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>
527
+                    <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>
528 528
                 </td>
529 529
             </tr>
530 530
             <tr>
531
-                <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th>
531
+                <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th>
532 532
                 <td>
533
-                    <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>
533
+                    <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>
534 534
                 </td>
535 535
             </tr>
536 536
             <tr>
537
-                <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th>
537
+                <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th>
538 538
                 <td>
539 539
                     <?php
540
-                    if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) {
540
+                    if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) {
541 541
                         // translators: link points Async Javascript settings page.
542
-                        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>' );
542
+                        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>');
543 543
                     } else {
544 544
                         ?>
545
-                        <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'] ); } ?>'>
545
+                        <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']); } ?>'>
546 546
                         <br />
547 547
                         <?php
548
-                            _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' );
548
+                            _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');
549 549
                             // translators: %s will be replaced by a link to the "async javascript" plugin.
550
-                            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>"' );
551
-                            $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term';
552
-                            echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
550
+                            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>"');
551
+                            $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term';
552
+                            echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
553 553
                     }
554 554
                     ?>
555 555
                 </td>
556 556
             </tr>
557 557
             <tr>
558
-                <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
558
+                <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th>
559 559
                 <td>
560 560
                     <?php
561
-                    if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) {
562
-                        _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
561
+                    if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) {
562
+                        _e('Great, you have WP YouTube Lyte installed.', 'autoptimize');
563 563
                         $lyte_config_url = 'options-general.php?page=lyte_settings_page';
564
-                        echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) );
564
+                        echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize'));
565 565
                     } else {
566 566
                         // translators: %s will be replaced by a link to "wp youtube lyte" plugin.
567
-                        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>' );
568
-                        $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term';
569
-                        echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
567
+                        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>');
568
+                        $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term';
569
+                        echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
570 570
                     }
571 571
                     ?>
572 572
                 </td>
573 573
             </tr>
574 574
         </table>
575
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
575
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
576 576
     </form>
577 577
         <?php
578 578
     }
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( 'Request Limit', 'autoptimize' ); ?>
62
+                            <?php _e('Request Limit', 'autoptimize'); ?>
63 63
                         </th>
64 64
                         <td>
65 65
                             <input type="number" id="autoptimize_ccss_rlimit" name="autoptimize_ccss_rlimit" min="1" max="240" placeholder="0" value="<?php echo $ao_ccss_rlimit; ?>" />
66 66
                             <p class="notes">
67
-                                <?php _e( 'Certain hosting services impose hard limitations to background processes on either execution time, requests made from your server to any third party services, or both. This could lead to a faulty operation of the queue background process triggered by WP-Cron. If automated rules are not being created, you may be facing this limitation from your hosting provider. In that case, set the request limit to a reasonable number between 1 and 240. The queue fire a request to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> on every 15 seconds (due to service limitations). If your hosting provider allows a 60 seconds time span to background processes runtime, set this value to 3 or 4 so the queue can operate within the boundaries. The maximum value of 240 allows enough requests for one hour long. To disable this limit and to let requests be made at will, just delete any values in this setting (a grey 0 will show).', 'autoptimize' ); ?>
67
+                                <?php _e('Certain hosting services impose hard limitations to background processes on either execution time, requests made from your server to any third party services, or both. This could lead to a faulty operation of the queue background process triggered by WP-Cron. If automated rules are not being created, you may be facing this limitation from your hosting provider. In that case, set the request limit to a reasonable number between 1 and 240. The queue fire a request to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> on every 15 seconds (due to service limitations). If your hosting provider allows a 60 seconds time span to background processes runtime, set this value to 3 or 4 so the queue can operate within the boundaries. The maximum value of 240 allows enough requests for one hour long. To disable this limit and to let requests be made at will, just delete any values in this setting (a grey 0 will show).', '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/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 ) ) {
636
-            $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
637
-            $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
638
-            $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
639
-            if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
640
-                $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
635
+        if (!file_exists($_fallback_php)) {
636
+            $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename);
637
+            $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents);
638
+            $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents);
639
+            if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) {
640
+                $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents);
641 641
             }
642
-            $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
642
+            $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents);
643 643
         }
644 644
 
645 645
         return $_fallback_status;
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
     public static function do_fallback() {
657 657
         static $_do_fallback = null;
658 658
 
659
-        if ( null === $_do_fallback ) {
660
-            $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) );
659
+        if (null === $_do_fallback) {
660
+            $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1'));
661 661
         }
662 662
 
663 663
         return $_do_fallback;
@@ -669,31 +669,31 @@  discard block
 block discarded – undo
669 669
      * and 410'ing ("Gone") if fallback not available.
670 670
      */
671 671
     public static function wordpress_notfound_fallback() {
672
-        $original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
673
-        if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) {
672
+        $original_request = strtok($_SERVER['REQUEST_URI'], '?');
673
+        if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) {
674 674
             // make sure this is not considered a 404.
675 675
             global $wp_query;
676 676
             $wp_query->is_404 = false;
677 677
 
678 678
             // set fallback path.
679
-            $js_or_css     = pathinfo( $original_request, PATHINFO_EXTENSION );
680
-            $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
679
+            $js_or_css     = pathinfo($original_request, PATHINFO_EXTENSION);
680
+            $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
681 681
 
682 682
             // prepare for Shakeeb's Unused CSS files to be 404-handled as well.
683
-            if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
684
-                $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
683
+            if (strpos($original_request, 'uucss/uucss-') !== false) {
684
+                $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
685 685
             }
686 686
 
687 687
             // set fallback URL.
688
-            $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
688
+            $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
689 689
 
690 690
             // redirect to fallback if possible.
691
-            if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
691
+            if ($original_request !== $fallback_target && file_exists($fallback_path)) {
692 692
                 // redirect to fallback.
693
-                wp_redirect( $fallback_target, 302 );
693
+                wp_redirect($fallback_target, 302);
694 694
             } else {
695 695
                 // return HTTP 410 (gone) reponse.
696
-                status_header( 410 );
696
+                status_header(410);
697 697
             }
698 698
         }
699 699
     }
@@ -705,13 +705,13 @@  discard block
 block discarded – undo
705 705
      * @return bool
706 706
      */
707 707
     public static function check_and_create_dirs() {
708
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
708
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
709 709
             // We didn't set a cache.
710 710
             return false;
711 711
         }
712 712
 
713
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
714
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
713
+        foreach (array('', 'js', 'css') as $dir) {
714
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
715 715
                 return false;
716 716
             }
717 717
         }
@@ -726,25 +726,25 @@  discard block
 block discarded – undo
726 726
      *
727 727
      * @return bool
728 728
      */
729
-    protected static function check_cache_dir( $dir )
729
+    protected static function check_cache_dir($dir)
730 730
     {
731 731
         // Try creating the dir if it doesn't exist.
732
-        if ( ! file_exists( $dir ) ) {
733
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
734
-            if ( ! file_exists( $dir ) ) {
732
+        if (!file_exists($dir)) {
733
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
734
+            if (!file_exists($dir)) {
735 735
                 return false;
736 736
             }
737 737
         }
738 738
 
739 739
         // If we still cannot write, bail.
740
-        if ( ! is_writable( $dir ) ) {
740
+        if (!is_writable($dir)) {
741 741
             return false;
742 742
         }
743 743
 
744 744
         // Create an index.html in there to avoid prying eyes!
745
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
746
-        if ( ! is_file( $idx_file ) ) {
747
-            @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine
745
+        $idx_file = rtrim($dir, '/\\').'/index.html';
746
+        if (!is_file($idx_file)) {
747
+            @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine
748 748
         }
749 749
 
750 750
         return true;
@@ -758,54 +758,54 @@  discard block
 block discarded – undo
758 758
     // @codingStandardsIgnoreStart
759 759
     public static function flushPageCache()
760 760
     {
761
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
762
-            if ( is_multisite() ) {
761
+        if (function_exists('wp_cache_clear_cache')) {
762
+            if (is_multisite()) {
763 763
                 $blog_id = get_current_blog_id();
764
-                wp_cache_clear_cache( $blog_id );
764
+                wp_cache_clear_cache($blog_id);
765 765
             } else {
766 766
                 wp_cache_clear_cache();
767 767
             }
768
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
769
-            do_action( 'cachify_flush_cache' );
770
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
768
+        } elseif (has_action('cachify_flush_cache')) {
769
+            do_action('cachify_flush_cache');
770
+        } elseif (function_exists('w3tc_pgcache_flush')) {
771 771
             w3tc_pgcache_flush();
772
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
772
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
773 773
             wp_fast_cache_bulk_delete_all();
774
-        } elseif ( function_exists( 'rapidcache_clear_cache' ) ) {
774
+        } elseif (function_exists('rapidcache_clear_cache')) {
775 775
             rapidcache_clear_cache();
776
-        } elseif ( class_exists( 'Swift_Performance_Cache' ) ) {
776
+        } elseif (class_exists('Swift_Performance_Cache')) {
777 777
             Swift_Performance_Cache::clear_all_cache();
778
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
778
+        } elseif (class_exists('WpFastestCache')) {
779 779
             $wpfc = new WpFastestCache();
780 780
             $wpfc->deleteCache();
781
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
781
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
782 782
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
783
-        } elseif ( class_exists( 'zencache' ) ) {
783
+        } elseif (class_exists('zencache')) {
784 784
             zencache::clear();
785
-        } elseif ( class_exists( 'comet_cache' ) ) {
785
+        } elseif (class_exists('comet_cache')) {
786 786
             comet_cache::clear();
787
-        } elseif ( class_exists( 'WpeCommon' ) ) {
787
+        } elseif (class_exists('WpeCommon')) {
788 788
             // WPEngine cache purge/flush methods to call by default
789 789
             $wpe_methods = array(
790 790
                 'purge_varnish_cache',
791 791
             );
792 792
 
793 793
             // More agressive clear/flush/purge behind a filter
794
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
795
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
794
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
795
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
796 796
             }
797 797
 
798 798
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
799
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
799
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
800 800
 
801
-            foreach ( $wpe_methods as $wpe_method ) {
802
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
801
+            foreach ($wpe_methods as $wpe_method) {
802
+                if (method_exists('WpeCommon', $wpe_method)) {
803 803
                     WpeCommon::$wpe_method();
804 804
                 }
805 805
             }
806
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
806
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
807 807
             sg_cachepress_purge_cache();
808
-        } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
808
+        } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) {
809 809
             $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
810 810
             $_kinsta_response        = wp_remote_get(
811 811
                 $_kinsta_clear_cache_url,
@@ -814,18 +814,18 @@  discard block
 block discarded – undo
814 814
                     'timeout' => 5,
815 815
                     )
816 816
             );
817
-        } elseif ( defined('NGINX_HELPER_BASENAME') ) {
818
-            do_action( 'rt_nginx_helper_purge_all' );
819
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
817
+        } elseif (defined('NGINX_HELPER_BASENAME')) {
818
+            do_action('rt_nginx_helper_purge_all');
819
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
820 820
             // fallback for WP-Super-Cache
821 821
             global $cache_path;
822
-            if ( is_multisite() ) {
822
+            if (is_multisite()) {
823 823
                 $blog_id = get_current_blog_id();
824
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
825
-                prune_super_cache( $cache_path . 'blogs/', true );
824
+                prune_super_cache(get_supercache_dir($blog_id), true);
825
+                prune_super_cache($cache_path.'blogs/', true);
826 826
             } else {
827
-                prune_super_cache( $cache_path . 'supercache/', true );
828
-                prune_super_cache( $cache_path, true );
827
+                prune_super_cache($cache_path.'supercache/', true);
828
+                prune_super_cache($cache_path, true);
829 829
             }
830 830
         }
831 831
     }
Please login to merge, or discard this patch.