@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | $ao_options = $wpdb->get_results(' |
11 | 11 | SELECT option_name AS name, |
12 | 12 | option_value AS value |
13 | - FROM ' . $wpdb->options . ' |
|
13 | + FROM ' . $wpdb->options.' |
|
14 | 14 | WHERE option_name LIKE "autoptimize_%%" |
15 | 15 | ORDER BY name |
16 | 16 | ', ARRAY_A); |
@@ -19,27 +19,27 @@ discard block |
||
19 | 19 | $ao_trans = $wpdb->get_results(' |
20 | 20 | SELECT option_name AS name, |
21 | 21 | option_value AS value |
22 | - FROM ' . $wpdb->options . ' |
|
22 | + FROM ' . $wpdb->options.' |
|
23 | 23 | WHERE option_name LIKE "_transient_autoptimize_%%" |
24 | 24 | OR option_name LIKE "_transient_timeout_autoptimize_%%" |
25 | 25 | ', ARRAY_A); |
26 | 26 | |
27 | 27 | // Render debug panel if there's something to show. |
28 | -if ( $ao_options || $ao_trans ) { |
|
28 | +if ($ao_options || $ao_trans) { |
|
29 | 29 | ?> |
30 | 30 | <!-- BEGIN: Settings Debug --> |
31 | 31 | <ul> |
32 | 32 | <li class="itemDetail"> |
33 | - <h2 class="itemTitle"><?php _e( 'Debug Information', 'autoptimize' ); ?></h2> |
|
33 | + <h2 class="itemTitle"><?php _e('Debug Information', 'autoptimize'); ?></h2> |
|
34 | 34 | |
35 | 35 | <?php |
36 | 36 | // Render options. |
37 | - if ( $ao_options ) { |
|
37 | + if ($ao_options) { |
|
38 | 38 | ?> |
39 | - <h4><?php _e( 'Options', 'autoptimize' ); ?>:</h4> |
|
39 | + <h4><?php _e('Options', 'autoptimize'); ?>:</h4> |
|
40 | 40 | <table class="form-table debug"> |
41 | 41 | <?php |
42 | - foreach ( $ao_options as $option ) { |
|
42 | + foreach ($ao_options as $option) { |
|
43 | 43 | ?> |
44 | 44 | <tr> |
45 | 45 | <th scope="row"> |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | </th> |
48 | 48 | <td> |
49 | 49 | <?php |
50 | - if ( 'autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name'] ) { |
|
51 | - $value = print_r( json_decode( $option['value'], true ), true ); |
|
52 | - if ( $value ) { |
|
53 | - echo "Raw JSON:\n<pre>" . $option['value'] . "</pre>\n\nDecoded JSON:\n<pre>" . $value . '</pre>'; |
|
50 | + if ('autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name']) { |
|
51 | + $value = print_r(json_decode($option['value'], true), true); |
|
52 | + if ($value) { |
|
53 | + echo "Raw JSON:\n<pre>".$option['value']."</pre>\n\nDecoded JSON:\n<pre>".$value.'</pre>'; |
|
54 | 54 | } else { |
55 | 55 | echo 'Empty'; |
56 | 56 | } |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | } |
70 | 70 | // Render WP-Cron intervals and scheduled events. |
71 | 71 | ?> |
72 | - <h4><?php _e( 'WP-Cron Intervals', 'autoptimize' ); ?>:</h4> |
|
73 | - <pre><?php print_r( wp_get_schedules() ); ?></pre> |
|
72 | + <h4><?php _e('WP-Cron Intervals', 'autoptimize'); ?>:</h4> |
|
73 | + <pre><?php print_r(wp_get_schedules()); ?></pre> |
|
74 | 74 | <hr /> |
75 | - <h4><?php _e( 'WP-Cron Scheduled Events', 'autoptimize' ); ?>:</h4> |
|
76 | - <pre><?php print_r( _get_cron_array() ); ?></pre> |
|
75 | + <h4><?php _e('WP-Cron Scheduled Events', 'autoptimize'); ?>:</h4> |
|
76 | + <pre><?php print_r(_get_cron_array()); ?></pre> |
|
77 | 77 | </li> |
78 | 78 | </ul> |
79 | 79 | <!-- END: Settings Debug --> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Critical CSS settings AJAX logic. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | { |
13 | 13 | // fetch all options at once and populate them individually explicitely as globals. |
14 | 14 | $all_options = autoptimizeCriticalCSSBase::fetch_options(); |
15 | - foreach ( $all_options as $_option => $_value ) { |
|
15 | + foreach ($all_options as $_option => $_value) { |
|
16 | 16 | global ${$_option}; |
17 | 17 | ${$_option} = $_value; |
18 | 18 | } |
@@ -21,47 +21,47 @@ discard block |
||
21 | 21 | |
22 | 22 | public function run() { |
23 | 23 | // add filters. |
24 | - add_action( 'wp_ajax_fetch_critcss', array( $this, 'critcss_fetch_callback' ) ); |
|
25 | - add_action( 'wp_ajax_save_critcss', array( $this, 'critcss_save_callback' ) ); |
|
26 | - add_action( 'wp_ajax_rm_critcss', array( $this, 'critcss_rm_callback' ) ); |
|
27 | - add_action( 'wp_ajax_rm_critcss_all', array( $this, 'critcss_rm_all_callback' ) ); |
|
28 | - add_action( 'wp_ajax_ao_ccss_export', array( $this, 'ao_ccss_export_callback' ) ); |
|
29 | - add_action( 'wp_ajax_ao_ccss_import', array( $this, 'ao_ccss_import_callback' ) ); |
|
24 | + add_action('wp_ajax_fetch_critcss', array($this, 'critcss_fetch_callback')); |
|
25 | + add_action('wp_ajax_save_critcss', array($this, 'critcss_save_callback')); |
|
26 | + add_action('wp_ajax_rm_critcss', array($this, 'critcss_rm_callback')); |
|
27 | + add_action('wp_ajax_rm_critcss_all', array($this, 'critcss_rm_all_callback')); |
|
28 | + add_action('wp_ajax_ao_ccss_export', array($this, 'ao_ccss_export_callback')); |
|
29 | + add_action('wp_ajax_ao_ccss_import', array($this, 'ao_ccss_import_callback')); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function critcss_fetch_callback() { |
33 | 33 | // Ajax handler to obtain a critical CSS file from the filesystem. |
34 | 34 | // Check referer. |
35 | - check_ajax_referer( 'fetch_critcss_nonce', 'critcss_fetch_nonce' ); |
|
35 | + check_ajax_referer('fetch_critcss_nonce', 'critcss_fetch_nonce'); |
|
36 | 36 | |
37 | 37 | // Initialize error flag. |
38 | 38 | $error = true; |
39 | 39 | |
40 | 40 | // Allow no content for MANUAL rules (as they may not exist just yet). |
41 | - if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) { |
|
41 | + if (current_user_can('manage_options') && empty($_POST['critcssfile'])) { |
|
42 | 42 | $content = ''; |
43 | 43 | $error = false; |
44 | - } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) { |
|
44 | + } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) { |
|
45 | 45 | // Or check user permissios and filename. |
46 | 46 | // Set file path and obtain its content. |
47 | - $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] ); |
|
48 | - if ( file_exists( $critcssfile ) ) { |
|
49 | - $content = file_get_contents( $critcssfile ); |
|
47 | + $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']); |
|
48 | + if (file_exists($critcssfile)) { |
|
49 | + $content = file_get_contents($critcssfile); |
|
50 | 50 | $error = false; |
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | 54 | // Prepare response. |
55 | - if ( $error ) { |
|
55 | + if ($error) { |
|
56 | 56 | $response['code'] = '500'; |
57 | - $response['string'] = 'Error reading file ' . $critcssfile . '.'; |
|
57 | + $response['string'] = 'Error reading file '.$critcssfile.'.'; |
|
58 | 58 | } else { |
59 | 59 | $response['code'] = '200'; |
60 | 60 | $response['string'] = $content; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // Dispatch respose. |
64 | - echo json_encode( $response ); |
|
64 | + echo json_encode($response); |
|
65 | 65 | |
66 | 66 | // Close ajax request. |
67 | 67 | wp_die(); |
@@ -74,22 +74,22 @@ discard block |
||
74 | 74 | |
75 | 75 | // Ajax handler to write a critical CSS to the filesystem |
76 | 76 | // Check referer. |
77 | - check_ajax_referer( 'save_critcss_nonce', 'critcss_save_nonce' ); |
|
77 | + check_ajax_referer('save_critcss_nonce', 'critcss_save_nonce'); |
|
78 | 78 | |
79 | 79 | // Allow empty contents for MANUAL rules (as they are fetched later). |
80 | - if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) { |
|
80 | + if (current_user_can('manage_options') && empty($_POST['critcssfile'])) { |
|
81 | 81 | $critcssfile = false; |
82 | 82 | $status = true; |
83 | - } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) { |
|
83 | + } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) { |
|
84 | 84 | // Or check user permissios and filename |
85 | 85 | // Set critical CSS content. |
86 | - $critcsscontents = stripslashes( $_POST['critcsscontents'] ); |
|
86 | + $critcsscontents = stripslashes($_POST['critcsscontents']); |
|
87 | 87 | |
88 | 88 | // If there is content and it's valid, write the file. |
89 | - if ( $critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents( $critcsscontents ) ) { |
|
89 | + if ($critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents($critcsscontents)) { |
|
90 | 90 | // Set file path and status. |
91 | - $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] ); |
|
92 | - $status = file_put_contents( $critcssfile, $critcsscontents, LOCK_EX ); |
|
91 | + $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']); |
|
92 | + $status = file_put_contents($critcssfile, $critcsscontents, LOCK_EX); |
|
93 | 93 | // Or set as error. |
94 | 94 | } else { |
95 | 95 | $error = true; |
@@ -100,20 +100,20 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | // Prepare response. |
103 | - if ( ! $status || $error ) { |
|
103 | + if (!$status || $error) { |
|
104 | 104 | $response['code'] = '500'; |
105 | - $response['string'] = 'Error saving file ' . $critcssfile . '.'; |
|
105 | + $response['string'] = 'Error saving file '.$critcssfile.'.'; |
|
106 | 106 | } else { |
107 | 107 | $response['code'] = '200'; |
108 | - if ( $critcssfile ) { |
|
109 | - $response['string'] = 'File ' . $critcssfile . ' saved.'; |
|
108 | + if ($critcssfile) { |
|
109 | + $response['string'] = 'File '.$critcssfile.' saved.'; |
|
110 | 110 | } else { |
111 | 111 | $response['string'] = 'Empty content do not need to be saved.'; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | 115 | // Dispatch respose. |
116 | - echo json_encode( $response ); |
|
116 | + echo json_encode($response); |
|
117 | 117 | |
118 | 118 | // Close ajax request. |
119 | 119 | wp_die(); |
@@ -123,40 +123,40 @@ discard block |
||
123 | 123 | public function critcss_rm_callback() { |
124 | 124 | // Ajax handler to delete a critical CSS from the filesystem |
125 | 125 | // Check referer. |
126 | - check_ajax_referer( 'rm_critcss_nonce', 'critcss_rm_nonce' ); |
|
126 | + check_ajax_referer('rm_critcss_nonce', 'critcss_rm_nonce'); |
|
127 | 127 | |
128 | 128 | // Initialize error and status flags. |
129 | 129 | $error = true; |
130 | 130 | $status = false; |
131 | 131 | |
132 | 132 | // Allow no file for MANUAL rules (as they may not exist just yet). |
133 | - if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) { |
|
133 | + if (current_user_can('manage_options') && empty($_POST['critcssfile'])) { |
|
134 | 134 | $error = false; |
135 | - } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) { |
|
135 | + } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) { |
|
136 | 136 | // Or check user permissios and filename |
137 | 137 | // Set file path and delete it. |
138 | - $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] ); |
|
139 | - if ( file_exists( $critcssfile ) ) { |
|
140 | - $status = unlink( $critcssfile ); |
|
138 | + $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']); |
|
139 | + if (file_exists($critcssfile)) { |
|
140 | + $status = unlink($critcssfile); |
|
141 | 141 | $error = false; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | 145 | // Prepare response. |
146 | - if ( $error ) { |
|
146 | + if ($error) { |
|
147 | 147 | $response['code'] = '500'; |
148 | - $response['string'] = 'Error removing file ' . $critcssfile . '.'; |
|
148 | + $response['string'] = 'Error removing file '.$critcssfile.'.'; |
|
149 | 149 | } else { |
150 | 150 | $response['code'] = '200'; |
151 | - if ( $status ) { |
|
152 | - $response['string'] = 'File ' . $critcssfile . ' removed.'; |
|
151 | + if ($status) { |
|
152 | + $response['string'] = 'File '.$critcssfile.' removed.'; |
|
153 | 153 | } else { |
154 | 154 | $response['string'] = 'No file to be removed.'; |
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Dispatch respose. |
159 | - echo json_encode( $response ); |
|
159 | + echo json_encode($response); |
|
160 | 160 | |
161 | 161 | // Close ajax request. |
162 | 162 | wp_die(); |
@@ -165,28 +165,28 @@ discard block |
||
165 | 165 | public function critcss_rm_all_callback() { |
166 | 166 | // Ajax handler to delete a critical CSS from the filesystem |
167 | 167 | // Check referer. |
168 | - check_ajax_referer( 'rm_critcss_all_nonce', 'critcss_rm_all_nonce' ); |
|
168 | + check_ajax_referer('rm_critcss_all_nonce', 'critcss_rm_all_nonce'); |
|
169 | 169 | |
170 | 170 | // Initialize error and status flags. |
171 | 171 | $error = true; |
172 | 172 | $status = false; |
173 | 173 | |
174 | 174 | // Remove all ccss files on filesystem. |
175 | - if ( current_user_can( 'manage_options' ) ) { |
|
176 | - if ( file_exists( AO_CCSS_DIR ) && is_dir( AO_CCSS_DIR ) ) { |
|
177 | - array_map( 'unlink', glob( AO_CCSS_DIR . 'ccss_*.css', GLOB_BRACE ) ); |
|
175 | + if (current_user_can('manage_options')) { |
|
176 | + if (file_exists(AO_CCSS_DIR) && is_dir(AO_CCSS_DIR)) { |
|
177 | + array_map('unlink', glob(AO_CCSS_DIR.'ccss_*.css', GLOB_BRACE)); |
|
178 | 178 | $error = false; |
179 | 179 | $status = true; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Prepare response. |
184 | - if ( $error ) { |
|
184 | + if ($error) { |
|
185 | 185 | $response['code'] = '500'; |
186 | 186 | $response['string'] = 'Error removing all critical CSS files.'; |
187 | 187 | } else { |
188 | 188 | $response['code'] = '200'; |
189 | - if ( $status ) { |
|
189 | + if ($status) { |
|
190 | 190 | $response['string'] = 'Critical CSS Files removed.'; |
191 | 191 | } else { |
192 | 192 | $response['string'] = 'No file removed.'; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | // Dispatch respose. |
197 | - echo json_encode( $response ); |
|
197 | + echo json_encode($response); |
|
198 | 198 | |
199 | 199 | // Close ajax request. |
200 | 200 | wp_die(); |
@@ -203,70 +203,70 @@ discard block |
||
203 | 203 | public function ao_ccss_export_callback() { |
204 | 204 | // Ajax handler export settings |
205 | 205 | // Check referer. |
206 | - check_ajax_referer( 'ao_ccss_export_nonce', 'ao_ccss_export_nonce' ); |
|
206 | + check_ajax_referer('ao_ccss_export_nonce', 'ao_ccss_export_nonce'); |
|
207 | 207 | |
208 | - if ( ! class_exists( 'ZipArchive' ) ) { |
|
208 | + if (!class_exists('ZipArchive')) { |
|
209 | 209 | $response['code'] = '500'; |
210 | 210 | $response['msg'] = 'PHP ZipArchive not present, cannot create zipfile'; |
211 | - echo json_encode( $response ); |
|
211 | + echo json_encode($response); |
|
212 | 212 | wp_die(); |
213 | 213 | } |
214 | 214 | |
215 | 215 | // Init array, get options and prepare the raw object. |
216 | 216 | $settings = array(); |
217 | - $settings['rules'] = get_option( 'autoptimize_ccss_rules' ); |
|
218 | - $settings['additional'] = get_option( 'autoptimize_ccss_additional' ); |
|
219 | - $settings['viewport'] = get_option( 'autoptimize_ccss_viewport' ); |
|
220 | - $settings['finclude'] = get_option( 'autoptimize_ccss_finclude' ); |
|
221 | - $settings['rlimit'] = get_option( 'autoptimize_ccss_rlimit' ); |
|
222 | - $settings['noptimize'] = get_option( 'autoptimize_ccss_noptimize' ); |
|
223 | - $settings['debug'] = get_option( 'autoptimize_ccss_debug' ); |
|
224 | - $settings['key'] = get_option( 'autoptimize_ccss_key' ); |
|
217 | + $settings['rules'] = get_option('autoptimize_ccss_rules'); |
|
218 | + $settings['additional'] = get_option('autoptimize_ccss_additional'); |
|
219 | + $settings['viewport'] = get_option('autoptimize_ccss_viewport'); |
|
220 | + $settings['finclude'] = get_option('autoptimize_ccss_finclude'); |
|
221 | + $settings['rlimit'] = get_option('autoptimize_ccss_rlimit'); |
|
222 | + $settings['noptimize'] = get_option('autoptimize_ccss_noptimize'); |
|
223 | + $settings['debug'] = get_option('autoptimize_ccss_debug'); |
|
224 | + $settings['key'] = get_option('autoptimize_ccss_key'); |
|
225 | 225 | |
226 | 226 | // Initialize error flag. |
227 | 227 | $error = true; |
228 | 228 | |
229 | 229 | // Check user permissions. |
230 | - if ( current_user_can( 'manage_options' ) ) { |
|
230 | + if (current_user_can('manage_options')) { |
|
231 | 231 | // Prepare settings file path and content. |
232 | - $exportfile = AO_CCSS_DIR . 'settings.json'; |
|
233 | - $contents = json_encode( $settings ); |
|
234 | - $status = file_put_contents( $exportfile, $contents, LOCK_EX ); |
|
232 | + $exportfile = AO_CCSS_DIR.'settings.json'; |
|
233 | + $contents = json_encode($settings); |
|
234 | + $status = file_put_contents($exportfile, $contents, LOCK_EX); |
|
235 | 235 | $error = false; |
236 | 236 | } |
237 | 237 | |
238 | 238 | // Prepare archive. |
239 | - $zipfile = AO_CCSS_DIR . date( 'Ymd-H\hi' ) . '_ao_ccss_settings.zip'; |
|
240 | - $file = pathinfo( $zipfile, PATHINFO_BASENAME ); |
|
239 | + $zipfile = AO_CCSS_DIR.date('Ymd-H\hi').'_ao_ccss_settings.zip'; |
|
240 | + $file = pathinfo($zipfile, PATHINFO_BASENAME); |
|
241 | 241 | $zip = new ZipArchive(); |
242 | - $ret = $zip->open( $zipfile, ZipArchive::CREATE ); |
|
243 | - if ( true !== $ret ) { |
|
242 | + $ret = $zip->open($zipfile, ZipArchive::CREATE); |
|
243 | + if (true !== $ret) { |
|
244 | 244 | $error = true; |
245 | 245 | } else { |
246 | - $zip->addFile( AO_CCSS_DIR . 'settings.json', 'settings.json' ); |
|
247 | - if ( file_exists( AO_CCSS_DIR . 'queue.json' ) ) { |
|
248 | - $zip->addFile( AO_CCSS_DIR . 'queue.json', 'queue.json' ); |
|
246 | + $zip->addFile(AO_CCSS_DIR.'settings.json', 'settings.json'); |
|
247 | + if (file_exists(AO_CCSS_DIR.'queue.json')) { |
|
248 | + $zip->addFile(AO_CCSS_DIR.'queue.json', 'queue.json'); |
|
249 | 249 | } |
250 | 250 | $options = array( |
251 | 251 | 'add_path' => './', |
252 | 252 | 'remove_all_path' => true, |
253 | 253 | ); |
254 | - $zip->addGlob( AO_CCSS_DIR . '*.css', 0, $options ); |
|
254 | + $zip->addGlob(AO_CCSS_DIR.'*.css', 0, $options); |
|
255 | 255 | $zip->close(); |
256 | 256 | } |
257 | 257 | |
258 | 258 | // Prepare response. |
259 | - if ( ! $status || $error ) { |
|
259 | + if (!$status || $error) { |
|
260 | 260 | $response['code'] = '500'; |
261 | - $response['msg'] = 'Error saving file ' . $file . ', code: ' . $ret; |
|
261 | + $response['msg'] = 'Error saving file '.$file.', code: '.$ret; |
|
262 | 262 | } else { |
263 | 263 | $response['code'] = '200'; |
264 | - $response['msg'] = 'File ' . $file . ' saved.'; |
|
264 | + $response['msg'] = 'File '.$file.' saved.'; |
|
265 | 265 | $response['file'] = $file; |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Dispatch respose. |
269 | - echo json_encode( $response ); |
|
269 | + echo json_encode($response); |
|
270 | 270 | |
271 | 271 | // Close ajax request. |
272 | 272 | wp_die(); |
@@ -275,44 +275,44 @@ discard block |
||
275 | 275 | public function ao_ccss_import_callback() { |
276 | 276 | // Ajax handler import settings |
277 | 277 | // Check referer. |
278 | - check_ajax_referer( 'ao_ccss_import_nonce', 'ao_ccss_import_nonce' ); |
|
278 | + check_ajax_referer('ao_ccss_import_nonce', 'ao_ccss_import_nonce'); |
|
279 | 279 | |
280 | 280 | // Initialize error flag. |
281 | 281 | $error = false; |
282 | 282 | |
283 | 283 | // Process an uploaded file with no errors. |
284 | - if ( ! $_FILES['file']['error'] ) { |
|
284 | + if (!$_FILES['file']['error']) { |
|
285 | 285 | // Save file to the cache directory. |
286 | - $zipfile = AO_CCSS_DIR . $_FILES['file']['name']; |
|
287 | - move_uploaded_file( $_FILES['file']['tmp_name'], $zipfile ); |
|
286 | + $zipfile = AO_CCSS_DIR.$_FILES['file']['name']; |
|
287 | + move_uploaded_file($_FILES['file']['tmp_name'], $zipfile); |
|
288 | 288 | |
289 | 289 | // Extract archive. |
290 | 290 | $zip = new ZipArchive; |
291 | - if ( $zip->open( $zipfile ) === true ) { |
|
292 | - $zip->extractTo( AO_CCSS_DIR ); |
|
291 | + if ($zip->open($zipfile) === true) { |
|
292 | + $zip->extractTo(AO_CCSS_DIR); |
|
293 | 293 | $zip->close(); |
294 | 294 | } else { |
295 | 295 | $error = 'extracting'; |
296 | 296 | } |
297 | 297 | |
298 | - if ( ! $error ) { |
|
298 | + if (!$error) { |
|
299 | 299 | // Archive extraction ok, continue settings importing |
300 | 300 | // Settings file. |
301 | - $importfile = AO_CCSS_DIR . 'settings.json'; |
|
301 | + $importfile = AO_CCSS_DIR.'settings.json'; |
|
302 | 302 | |
303 | - if ( file_exists( $importfile ) ) { |
|
303 | + if (file_exists($importfile)) { |
|
304 | 304 | // Get settings and turn them into an object. |
305 | - $settings = json_decode( file_get_contents( $importfile ), true ); |
|
305 | + $settings = json_decode(file_get_contents($importfile), true); |
|
306 | 306 | |
307 | 307 | // Update options. |
308 | - update_option( 'autoptimize_ccss_rules', $settings['rules'] ); |
|
309 | - update_option( 'autoptimize_ccss_additional', $settings['additional'] ); |
|
310 | - update_option( 'autoptimize_ccss_viewport', $settings['viewport'] ); |
|
311 | - update_option( 'autoptimize_ccss_finclude', $settings['finclude'] ); |
|
312 | - update_option( 'autoptimize_ccss_rlimit', $settings['rlimit'] ); |
|
313 | - update_option( 'autoptimize_ccss_noptimize', $settings['noptimize'] ); |
|
314 | - update_option( 'autoptimize_ccss_debug', $settings['debug'] ); |
|
315 | - update_option( 'autoptimize_ccss_key', $settings['key'] ); |
|
308 | + update_option('autoptimize_ccss_rules', $settings['rules']); |
|
309 | + update_option('autoptimize_ccss_additional', $settings['additional']); |
|
310 | + update_option('autoptimize_ccss_viewport', $settings['viewport']); |
|
311 | + update_option('autoptimize_ccss_finclude', $settings['finclude']); |
|
312 | + update_option('autoptimize_ccss_rlimit', $settings['rlimit']); |
|
313 | + update_option('autoptimize_ccss_noptimize', $settings['noptimize']); |
|
314 | + update_option('autoptimize_ccss_debug', $settings['debug']); |
|
315 | + update_option('autoptimize_ccss_key', $settings['key']); |
|
316 | 316 | } else { |
317 | 317 | // Settings file doesn't exist, update error flag. |
318 | 318 | $error = 'settings file does not exist'; |
@@ -321,28 +321,28 @@ discard block |
||
321 | 321 | } |
322 | 322 | |
323 | 323 | // Prepare response. |
324 | - if ( $error ) { |
|
324 | + if ($error) { |
|
325 | 325 | $response['code'] = '500'; |
326 | - $response['msg'] = 'Error importing settings: ' . $error; |
|
326 | + $response['msg'] = 'Error importing settings: '.$error; |
|
327 | 327 | } else { |
328 | 328 | $response['code'] = '200'; |
329 | 329 | $response['msg'] = 'Settings imported successfully'; |
330 | 330 | } |
331 | 331 | |
332 | 332 | // Dispatch respose. |
333 | - echo json_encode( $response ); |
|
333 | + echo json_encode($response); |
|
334 | 334 | |
335 | 335 | // Close ajax request. |
336 | 336 | wp_die(); |
337 | 337 | } |
338 | 338 | |
339 | - public function critcss_check_filename( $filename ) { |
|
339 | + public function critcss_check_filename($filename) { |
|
340 | 340 | // Try to avoid directory traversal when reading/writing/deleting critical CSS files. |
341 | - if ( strpos( $filename, 'ccss_' ) !== 0 ) { |
|
341 | + if (strpos($filename, 'ccss_') !== 0) { |
|
342 | 342 | return false; |
343 | - } elseif ( substr( $filename, -4, 4 ) !== '.css' ) { |
|
343 | + } elseif (substr($filename, -4, 4) !== '.css') { |
|
344 | 344 | return false; |
345 | - } elseif ( sanitize_file_name( $filename ) !== $filename ) { |
|
345 | + } elseif (sanitize_file_name($filename) !== $filename) { |
|
346 | 346 | // Use WordPress core's sanitize_file_name to see if anything fishy is going on. |
347 | 347 | return false; |
348 | 348 | } else { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | "empty" : |
21 | 21 | aoCssQueue; |
22 | 22 | <?php |
23 | - if ( $ao_ccss_debug ) { |
|
23 | + if ($ao_ccss_debug) { |
|
24 | 24 | echo "console.log( 'Queue Object:', aoCssQueueLog );\n"; |
25 | 25 | } |
26 | 26 | ?> |
@@ -62,34 +62,34 @@ discard block |
||
62 | 62 | // Status: NEW (N, sort order 1) |
63 | 63 | status = '<span class="hidden">1</span>N'; |
64 | 64 | statusClass = 'new'; |
65 | - title = '<?php _e( 'New', 'autoptimize' ); ?> (' + ljid + ')'; |
|
66 | - buttons = '<?php _e( 'None', 'autoptimize' ); ?>'; |
|
65 | + title = '<?php _e('New', 'autoptimize'); ?> (' + ljid + ')'; |
|
66 | + buttons = '<?php _e('None', 'autoptimize'); ?>'; |
|
67 | 67 | } else if (keys.jqstat === 'JOB_QUEUED' || keys.jqstat === 'JOB_ONGOING') { |
68 | 68 | // Status: PENDING (P, sort order 2) |
69 | 69 | status = '<span class="hidden">2</span>P'; |
70 | 70 | statusClass = 'pending'; |
71 | - title = '<?php _e( 'PENDING', 'autoptimize' ); ?> (' + ljid + ')'; |
|
72 | - buttons = '<?php _e( 'None', 'autoptimize' ); ?>'; |
|
71 | + title = '<?php _e('PENDING', 'autoptimize'); ?> (' + ljid + ')'; |
|
72 | + buttons = '<?php _e('None', 'autoptimize'); ?>'; |
|
73 | 73 | } else if (keys.jqstat === 'JOB_DONE' && keys.jrstat === 'GOOD' && (keys.jvstat === 'WARN' || keys.jvstat === 'BAD')) { |
74 | 74 | // Status: REVIEW (R, sort order 5) |
75 | 75 | status = '<span class="hidden">5</span>R'; |
76 | 76 | statusClass = 'review'; |
77 | - title = "<?php _e( 'REVIEW', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat; |
|
78 | - buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>'; |
|
77 | + title = "<?php _e('REVIEW', 'autoptimize'); ?> (" + ljid + ")\n<?php _e('Info from criticalcss.com:', 'autoptimize'); ?>\n<?php _e('- Job ID: ', 'autoptimize'); ?>" + keys.jid + "\n<?php _e('- Status: ', 'autoptimize'); ?>" + keys.jqstat + "\n<?php _e('- Result: ', 'autoptimize'); ?>" + keys.jrstat + "\n<?php _e('- Validation: ', 'autoptimize'); ?>" + keys.jvstat; |
|
78 | + buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e('Delete Job', 'autoptimize'); ?>"><span class="dashicons dashicons-trash"></span></span>'; |
|
79 | 79 | dbtn = true; |
80 | 80 | } else if (keys.jqstat === 'JOB_DONE') { |
81 | 81 | // Status: DONE (D, sort order 6) |
82 | 82 | status = '<span class="hidden">6</span>D'; |
83 | 83 | statusClass = 'done'; |
84 | - title = '<?php _e( 'DONE', 'autoptimize' ); ?> (' + ljid + ')'; |
|
85 | - buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>'; |
|
84 | + title = '<?php _e('DONE', 'autoptimize'); ?> (' + ljid + ')'; |
|
85 | + buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e('Delete Job', 'autoptimize'); ?>"><span class="dashicons dashicons-trash"></span></span>'; |
|
86 | 86 | dbtn = true; |
87 | 87 | } else if (keys.jqstat === 'JOB_FAILED' || keys.jqstat === 'STATUS_JOB_BAD' || keys.jqstat === 'INVALID_JWT_TOKEN' || keys.jqstat === 'NO_CSS' || keys.jqstat === 'NO_RESPONSE') { |
88 | 88 | // Status: ERROR (E, sort order 4) |
89 | 89 | status = '<span class="hidden">4</span>E'; |
90 | 90 | statusClass = 'error'; |
91 | - title = "<?php _e( 'ERROR', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat; |
|
92 | - buttons = '<span class="button-secondary" id="' + ljid + '_retry" title="<?php _e( 'Retry Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-update"></span></span><span class="button-secondary to-right" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>'; |
|
91 | + title = "<?php _e('ERROR', 'autoptimize'); ?> (" + ljid + ")\n<?php _e('Info from criticalcss.com:', 'autoptimize'); ?>\n<?php _e('- Job ID: ', 'autoptimize'); ?>" + keys.jid + "\n<?php _e('- Status: ', 'autoptimize'); ?>" + keys.jqstat + "\n<?php _e('- Result: ', 'autoptimize'); ?>" + keys.jrstat + "\n<?php _e('- Validation: ', 'autoptimize'); ?>" + keys.jvstat; |
|
92 | + buttons = '<span class="button-secondary" id="' + ljid + '_retry" title="<?php _e('Retry Job', 'autoptimize'); ?>"><span class="dashicons dashicons-update"></span></span><span class="button-secondary to-right" id="' + ljid + '_remove" title="<?php _e('Delete Job', 'autoptimize'); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e('Get Help', 'autoptimize'); ?>"><span class="dashicons dashicons-sos"></span></span>'; |
|
93 | 93 | rbtn = true; |
94 | 94 | dbtn = true; |
95 | 95 | hbtn = true; |
@@ -97,21 +97,21 @@ discard block |
||
97 | 97 | // Status: UNKNOWN (U, sort order 5) |
98 | 98 | status = '<span class="hidden">5</span>U'; |
99 | 99 | statusClass = 'unknown'; |
100 | - title = "<?php _e( 'UNKNOWN', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat; |
|
101 | - buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>'; |
|
100 | + title = "<?php _e('UNKNOWN', 'autoptimize'); ?> (" + ljid + ")\n<?php _e('Info from criticalcss.com:', 'autoptimize'); ?>\n<?php _e('- Job ID: ', 'autoptimize'); ?>" + keys.jid + "\n<?php _e('- Status: ', 'autoptimize'); ?>" + keys.jqstat + "\n<?php _e('- Result: ', 'autoptimize'); ?>" + keys.jrstat + "\n<?php _e('- Validation: ', 'autoptimize'); ?>" + keys.jvstat; |
|
101 | + buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e('Delete Job', 'autoptimize'); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e('Get Help', 'autoptimize'); ?>"><span class="dashicons dashicons-sos"></span></span>'; |
|
102 | 102 | dbtn = true; |
103 | 103 | hbtn = true; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Prepare job finish time |
107 | 107 | if (keys.jftime === null) { |
108 | - ftime = '<?php _e( 'N/A', 'autoptimize' ); ?>'; |
|
108 | + ftime = '<?php _e('N/A', 'autoptimize'); ?>'; |
|
109 | 109 | } else { |
110 | 110 | ftime = EpochToDate(keys.jftime); |
111 | 111 | } |
112 | 112 | |
113 | 113 | // Append job entry |
114 | - jQuery("#queue").append("<tr id='" + ljid + "' class='job " + statusClass + "'><td class='status'><span class='badge " + statusClass + "' title='<?php _e( 'Job status is ', 'autoptimize' ); ?>" + title + "'>" + status + "</span></td><td>" + target.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + path + "</td><td>" + type.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + ctime + "</td><td>" + ftime + "</td><td class='btn'>" + buttons + "</td></tr>"); |
|
114 | + jQuery("#queue").append("<tr id='" + ljid + "' class='job " + statusClass + "'><td class='status'><span class='badge " + statusClass + "' title='<?php _e('Job status is ', 'autoptimize'); ?>" + title + "'>" + status + "</span></td><td>" + target.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + path + "</td><td>" + type.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + ctime + "</td><td>" + ftime + "</td><td class='btn'>" + buttons + "</td></tr>"); |
|
115 | 115 | |
116 | 116 | // Attach button actions |
117 | 117 | if (rbtn) { |
@@ -134,12 +134,12 @@ discard block |
||
134 | 134 | height: 180, |
135 | 135 | modal: true, |
136 | 136 | buttons: { |
137 | - "<?php _e( 'Delete', 'autoptimize' ); ?>": function() { |
|
137 | + "<?php _e('Delete', 'autoptimize'); ?>": function() { |
|
138 | 138 | delete queue[jpath]; |
139 | 139 | updateQueue(queue); |
140 | 140 | jQuery(this).dialog('close' ); |
141 | 141 | }, |
142 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
142 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
143 | 143 | jQuery(this).dialog('close' ); |
144 | 144 | } |
145 | 145 | } |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | height:235, |
153 | 153 | modal: true, |
154 | 154 | buttons: { |
155 | - "<?php _e( 'Delete all jobs?', 'autoptimize' ); ?>": function() { |
|
155 | + "<?php _e('Delete all jobs?', 'autoptimize'); ?>": function() { |
|
156 | 156 | queue=[]; |
157 | 157 | updateQueue(queue); |
158 | 158 | jQuery( this ).dialog( "close" ); |
159 | 159 | }, |
160 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
160 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
161 | 161 | jQuery( this ).dialog( "close" ); |
162 | 162 | } |
163 | 163 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | height: 180, |
173 | 173 | modal: true, |
174 | 174 | buttons: { |
175 | - "<?php _e( 'Retry', 'autoptimize' ); ?>": function() { |
|
175 | + "<?php _e('Retry', 'autoptimize'); ?>": function() { |
|
176 | 176 | <?php |
177 | - if ( $ao_ccss_debug ) { |
|
177 | + if ($ao_ccss_debug) { |
|
178 | 178 | echo "console.log( 'SHOULD retry job:', jid[0], jpath );\n"; |
179 | 179 | } |
180 | 180 | ?> |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | updateQueue(queue); |
188 | 188 | jQuery(this).dialog('close' ); |
189 | 189 | }, |
190 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
190 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
191 | 191 | jQuery(this).dialog('close' ); |
192 | 192 | } |
193 | 193 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | jQuery('#unSavedWarning').show(); |
202 | 202 | document.getElementById('ao_title_and_button').scrollIntoView(); |
203 | 203 | <?php |
204 | - if ( $ao_ccss_debug ) { |
|
204 | + if ($ao_ccss_debug) { |
|
205 | 205 | echo "console.log('Updated Queue Object:', queue);\n"; |
206 | 206 | } |
207 | 207 | ?> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Outputs JS code for the rules panel. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( $ao_ccss_debug ) { |
|
6 | +if ($ao_ccss_debug) { |
|
7 | 7 | echo "console.log('[WARN] Autoptimize CriticalCSS Power-Up is in DEBUG MODE!');\n"; |
8 | 8 | echo "console.log('[WARN] Avoid using debug mode on production/live environments unless for ad-hoc troubleshooting purposes and make sure to disable it after!');\n"; |
9 | 9 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | jQuery(document).ready(function() { |
24 | 24 | critCssArray=JSON.parse(document.getElementById("critCssOrigin").value); |
25 | 25 | <?php |
26 | - if ( $ao_ccss_debug ) { |
|
26 | + if ($ao_ccss_debug) { |
|
27 | 27 | echo "console.log('Rules Object:', critCssArray);\n"; |
28 | 28 | } |
29 | 29 | ?> |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | jQuery("#rules-list").empty(); |
40 | 40 | jQuery.each(critCssArray,function(k,v) { |
41 | 41 | if (k=="paths") { |
42 | - kstring="<?php _e( 'Path Based Rules', 'autoptimize' ); ?>"; |
|
42 | + kstring="<?php _e('Path Based Rules', 'autoptimize'); ?>"; |
|
43 | 43 | } else { |
44 | - kstring="<?php _e( 'Conditional Tags, Custom Post Types and Page Templates Rules', 'autoptimize' ); ?>"; |
|
44 | + kstring="<?php _e('Conditional Tags, Custom Post Types and Page Templates Rules', 'autoptimize'); ?>"; |
|
45 | 45 | } |
46 | 46 | if (!(jQuery.isEmptyObject(v))) { |
47 | 47 | jQuery("#rules-list").append("<tr><td colspan='5'><h4>" + kstring + "</h4></td></tr>"); |
48 | - jQuery("#rules-list").append("<tr class='header "+k+"Rule'><th><?php _e( 'Type', 'autoptimize' ); ?></th><th><?php _e( 'Target', 'autoptimize' ); ?></th><th><?php _e( 'Critical CSS File', 'autoptimize' ); ?></th><th colspan='2'><?php _e( 'Actions', 'autoptimize' ); ?></th></tr>"); |
|
48 | + jQuery("#rules-list").append("<tr class='header "+k+"Rule'><th><?php _e('Type', 'autoptimize'); ?></th><th><?php _e('Target', 'autoptimize'); ?></th><th><?php _e('Critical CSS File', 'autoptimize'); ?></th><th colspan='2'><?php _e('Actions', 'autoptimize'); ?></th></tr>"); |
|
49 | 49 | } |
50 | 50 | nodeNumber=0; |
51 | 51 | jQuery.each(v,function(i,nv){ |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | file=nv.file; |
56 | 56 | filest=nv.file; |
57 | 57 | if (file == 0) { |
58 | - file='<?php _e( 'To be fetched from criticalcss.com in the next queue run...', 'autoptimize' ); ?>'; |
|
58 | + file='<?php _e('To be fetched from criticalcss.com in the next queue run...', 'autoptimize'); ?>'; |
|
59 | 59 | } |
60 | 60 | if (nv.hash === 0 && filest != 0) { |
61 | - type='<?php _e( 'MANUAL', 'autoptimize' ); ?>'; |
|
61 | + type='<?php _e('MANUAL', 'autoptimize'); ?>'; |
|
62 | 62 | typeClass = 'manual'; |
63 | 63 | } else { |
64 | - type='<?php _e( 'AUTO', 'autoptimize' ); ?>'; |
|
64 | + type='<?php _e('AUTO', 'autoptimize'); ?>'; |
|
65 | 65 | typeClass = 'auto'; |
66 | 66 | } |
67 | 67 | if (file && typeof file == 'string') { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } else { |
78 | 78 | target = i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,''); |
79 | 79 | } |
80 | - jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e( 'Edit', 'autoptimize' ); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e( 'Remove', 'autoptimize' ); ?></span></td></tr>"); |
|
80 | + jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e('Edit', 'autoptimize'); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e('Remove', 'autoptimize'); ?></span></td></tr>"); |
|
81 | 81 | jQuery("#" + nodeId + "_edit").click(function(){addEditRow(this.id);}); |
82 | 82 | jQuery("#" + nodeId + "_remove").click(function(){confirmRemove(this.id);}); |
83 | 83 | }) |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | height:235, |
91 | 91 | modal: true, |
92 | 92 | buttons: { |
93 | - "<?php _e( 'Delete', 'autoptimize' ); ?>": function() { |
|
93 | + "<?php _e('Delete', 'autoptimize'); ?>": function() { |
|
94 | 94 | removeRow(idToRemove); |
95 | 95 | updateAfterChange(); |
96 | 96 | jQuery( this ).dialog( "close" ); |
97 | 97 | }, |
98 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
98 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
99 | 99 | jQuery( this ).dialog( "close" ); |
100 | 100 | } |
101 | 101 | } |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | height:235, |
109 | 109 | modal: true, |
110 | 110 | buttons: { |
111 | - "<?php _e( 'Delete All', 'autoptimize' ); ?>": function() { |
|
111 | + "<?php _e('Delete All', 'autoptimize'); ?>": function() { |
|
112 | 112 | critCssArray={'paths':[],'types':[]}; |
113 | 113 | drawTable(critCssArray); |
114 | 114 | updateAfterChange(); |
115 | 115 | removeAllCcssFilesOnServer(); |
116 | 116 | jQuery( this ).dialog( "close" ); |
117 | 117 | }, |
118 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
118 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
119 | 119 | jQuery( this ).dialog( "close" ); |
120 | 120 | } |
121 | 121 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | var data = { |
134 | 134 | 'action': 'rm_critcss', |
135 | - 'critcss_rm_nonce': '<?php echo wp_create_nonce( 'rm_critcss_nonce' ); ?>', |
|
135 | + 'critcss_rm_nonce': '<?php echo wp_create_nonce('rm_critcss_nonce'); ?>', |
|
136 | 136 | 'cachebustingtimestamp': new Date().getTime(), |
137 | 137 | 'critcssfile': crit_file |
138 | 138 | }; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | function removeAllCcssFilesOnServer() { |
154 | 154 | var data = { |
155 | 155 | 'action': 'rm_critcss_all', |
156 | - 'critcss_rm_all_nonce': '<?php echo wp_create_nonce( 'rm_critcss_all_nonce' ); ?>', |
|
156 | + 'critcss_rm_all_nonce': '<?php echo wp_create_nonce('rm_critcss_all_nonce'); ?>', |
|
157 | 157 | 'cachebustingtimestamp': new Date().getTime() |
158 | 158 | }; |
159 | 159 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | function addEditRow(idToEdit) { |
174 | 174 | resetForm(); |
175 | 175 | if (idToEdit) { |
176 | - dialogTitle="<?php _e( 'Edit Critical CSS Rule', 'autoptimize' ); ?>"; |
|
176 | + dialogTitle="<?php _e('Edit Critical CSS Rule', 'autoptimize'); ?>"; |
|
177 | 177 | |
178 | 178 | splits=idToEdit.split(/_/); |
179 | 179 | crit_type=splits[0]; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | jQuery("#critcss_addedit_id").val(idToEdit); |
185 | 185 | jQuery("#critcss_addedit_type").val(crit_type); |
186 | 186 | jQuery("#critcss_addedit_file").val(crit_file); |
187 | - jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'Loading critical CSS...', 'autoptimize' ); ?>"); |
|
187 | + jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('Loading critical CSS...', 'autoptimize'); ?>"); |
|
188 | 188 | jQuery("#critcss_addedit_type").attr("disabled",true); |
189 | 189 | |
190 | 190 | if (crit_type==="paths") { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | var data = { |
201 | 201 | 'action': 'fetch_critcss', |
202 | - 'critcss_fetch_nonce': '<?php echo wp_create_nonce( 'fetch_critcss_nonce' ); ?>', |
|
202 | + 'critcss_fetch_nonce': '<?php echo wp_create_nonce('fetch_critcss_nonce'); ?>', |
|
203 | 203 | 'cachebustingtimestamp': new Date().getTime(), |
204 | 204 | 'critcssfile': crit_file |
205 | 205 | }; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | } |
214 | 214 | }); |
215 | 215 | } else { |
216 | - dialogTitle="<?php _e( 'Add Critical CSS Rule', 'autotimize' ); ?>"; |
|
216 | + dialogTitle="<?php _e('Add Critical CSS Rule', 'autotimize'); ?>"; |
|
217 | 217 | |
218 | 218 | // default: paths, hide content type field |
219 | 219 | jQuery("#critcss_addedit_type").val("paths"); |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | if(this.value==="types") { |
225 | 225 | jQuery("#critcss_addedit_pagetype_wrapper").show(); |
226 | 226 | jQuery("#critcss_addedit_path_wrapper").hide(); |
227 | - jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For type based rules, paste your specific and minified critical CSS here and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\".', 'autoptimize' ); ?>"); |
|
227 | + jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For type based rules, paste your specific and minified critical CSS here and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\".', 'autoptimize'); ?>"); |
|
228 | 228 | } else { |
229 | 229 | jQuery("#critcss_addedit_path_wrapper").show(); |
230 | 230 | jQuery("#critcss_addedit_pagetype_wrapper").hide(); |
231 | - jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize' ); ?>"); |
|
231 | + jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize'); ?>"); |
|
232 | 232 | } |
233 | 233 | }); |
234 | 234 | } |
@@ -240,21 +240,21 @@ discard block |
||
240 | 240 | title: dialogTitle, |
241 | 241 | modal: true, |
242 | 242 | buttons: { |
243 | - "<?php _e( 'Submit', 'autoptimize' ); ?>": function() { |
|
243 | + "<?php _e('Submit', 'autoptimize'); ?>": function() { |
|
244 | 244 | rpath = jQuery("#critcss_addedit_path").val(); |
245 | 245 | rtype = jQuery("#critcss_addedit_pagetype option:selected").val(); |
246 | 246 | rccss = jQuery("#critcss_addedit_css").val(); |
247 | 247 | console.log('rpath: ' + rpath, 'rtype: ' + rtype, 'rccss: ' + rccss); |
248 | 248 | if (rpath === '' && rtype === '') { |
249 | - alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize' ); ?>'); |
|
249 | + alert('<?php _e("RULE VALIDATION ERROR!\\n\\nBased on your rule type, you SHOULD set a path or conditional tag.", 'autoptimize'); ?>'); |
|
250 | 250 | } else if (rtype !== '' && rccss == '') { |
251 | - alert('<?php _e( "RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize' ); ?>'); |
|
251 | + alert('<?php _e("RULE VALIDATION ERROR!\\n\\nType based rules REQUIRES a minified critical CSS.", 'autoptimize'); ?>'); |
|
252 | 252 | } else { |
253 | 253 | saveEditCritCss(); |
254 | 254 | jQuery(this).dialog('close'); |
255 | 255 | } |
256 | 256 | }, |
257 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
257 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
258 | 258 | resetForm(); |
259 | 259 | jQuery(this).dialog("close"); |
260 | 260 | } |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | autoOpen: true, |
269 | 269 | height: 505, |
270 | 270 | width: 700, |
271 | - title: "<?php _e( 'Default Critical CSS', 'autoptimize' ); ?>", |
|
271 | + title: "<?php _e('Default Critical CSS', 'autoptimize'); ?>", |
|
272 | 272 | modal: true, |
273 | 273 | buttons: { |
274 | - "<?php _e( 'Submit', 'autoptimize' ); ?>": function() { |
|
274 | + "<?php _e('Submit', 'autoptimize'); ?>": function() { |
|
275 | 275 | document.getElementById("autoptimize_css_defer_inline").value=document.getElementById("dummyDefault").value; |
276 | 276 | jQuery("#unSavedWarning").show(); |
277 | 277 | jQuery("#default_critcss_wrapper").dialog( "close" ); |
278 | 278 | }, |
279 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
279 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
280 | 280 | jQuery("#default_critcss_wrapper").dialog( "close" ); |
281 | 281 | } |
282 | 282 | } |
@@ -289,15 +289,15 @@ discard block |
||
289 | 289 | autoOpen: true, |
290 | 290 | height: 505, |
291 | 291 | width: 700, |
292 | - title: "<?php _e( 'Additional Critical CSS', 'autoptimize' ); ?>", |
|
292 | + title: "<?php _e('Additional Critical CSS', 'autoptimize'); ?>", |
|
293 | 293 | modal: true, |
294 | 294 | buttons: { |
295 | - "<?php _e( 'Submit', 'autoptimize' ); ?>": function() { |
|
295 | + "<?php _e('Submit', 'autoptimize'); ?>": function() { |
|
296 | 296 | document.getElementById("autoptimize_ccss_additional").value=document.getElementById("dummyAdditional").value; |
297 | 297 | jQuery("#unSavedWarning").show(); |
298 | 298 | jQuery("#additional_critcss_wrapper").dialog( "close" ); |
299 | 299 | }, |
300 | - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() { |
|
300 | + "<?php _e('Cancel', 'autoptimize'); ?>": function() { |
|
301 | 301 | jQuery("#additional_critcss_wrapper").dialog( "close" ); |
302 | 302 | } |
303 | 303 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | critCssArray[critcsstype][critcsstarget].file=critcssfile; |
334 | 334 | |
335 | 335 | <?php |
336 | - if ( $ao_ccss_debug ) { |
|
336 | + if ($ao_ccss_debug) { |
|
337 | 337 | echo "console.log('[RULE PROPERTIES] Type:', critcsstype, ', Target:', critcsstarget, ', Hash:', 0, ', File:', critcssfile);"; |
338 | 338 | } |
339 | 339 | ?> |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | |
343 | 343 | var data = { |
344 | 344 | 'action': 'save_critcss', |
345 | - 'critcss_save_nonce': '<?php echo wp_create_nonce( 'save_critcss_nonce' ); ?>', |
|
345 | + 'critcss_save_nonce': '<?php echo wp_create_nonce('save_critcss_nonce'); ?>', |
|
346 | 346 | 'critcssfile': critcssfile, |
347 | 347 | 'critcsscontents': critcsscontents |
348 | 348 | }; |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | } |
368 | 368 | |
369 | 369 | function resetForm() { |
370 | - jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e( 'For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize' ); ?>"); |
|
370 | + jQuery("#critcss_addedit_css").attr("placeholder", "<?php _e('For path based rules, paste your specific and minified critical CSS here or leave this empty to fetch it from criticalcss.com and hit submit to save. If you want to create a rule to exclude from critical CSS injection, enter \"none\"', 'autoptimize'); ?>"); |
|
371 | 371 | jQuery("#critcss_addedit_type").attr("disabled",false); |
372 | 372 | jQuery("#critcss_addedit_path_wrapper").show(); |
373 | 373 | jQuery("#critcss_addedit_id").val(""); |
@@ -12,27 +12,27 @@ discard block |
||
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 |
||
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> |
@@ -11,21 +11,21 @@ discard block |
||
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 |
||
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> |
@@ -12,29 +12,29 @@ |
||
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>"; |
@@ -378,6 +378,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -3,7 +3,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
306 | 306 | * |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - private function normalize_img_url( $in ) |
|
309 | + private function normalize_img_url($in) |
|
310 | 310 | { |
311 | 311 | // Only parse the site url once. |
312 | 312 | static $parsed_site_url = null; |
313 | - if ( null === $parsed_site_url ) { |
|
314 | - $parsed_site_url = parse_url( site_url() ); |
|
313 | + if (null === $parsed_site_url) { |
|
314 | + $parsed_site_url = parse_url(site_url()); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | // get CDN domain once. |
318 | 318 | static $cdn_domain = null; |
319 | - if ( is_null( $cdn_domain ) ) { |
|
319 | + if (is_null($cdn_domain)) { |
|
320 | 320 | $cdn_url = $this->get_cdn_url(); |
321 | - if ( ! empty( $cdn_url ) ) { |
|
322 | - $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST ); |
|
321 | + if (!empty($cdn_url)) { |
|
322 | + $cdn_domain = parse_url($cdn_url, PHP_URL_HOST); |
|
323 | 323 | } else { |
324 | 324 | $cdn_domain = ''; |
325 | 325 | } |
@@ -335,44 +335,44 @@ discard block |
||
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, '"' ) !== false ) { |
|
349 | - $result = str_replace( '"', '', $result ); |
|
348 | + if (strpos($result, '"') !== false) { |
|
349 | + $result = str_replace('"', '', $result); |
|
350 | 350 | } |
351 | 351 | |
352 | - if ( autoptimizeUtils::is_protocol_relative( $result ) ) { |
|
353 | - $result = $parsed_site_url['scheme'] . ':' . $result; |
|
354 | - } elseif ( 0 === strpos( $result, '/' ) ) { |
|
352 | + if (autoptimizeUtils::is_protocol_relative($result)) { |
|
353 | + $result = $parsed_site_url['scheme'].':'.$result; |
|
354 | + } elseif (0 === strpos($result, '/')) { |
|
355 | 355 | // Root-relative... |
356 | - $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result; |
|
357 | - } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) { |
|
358 | - $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result ); |
|
356 | + $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result; |
|
357 | + } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) { |
|
358 | + $result = str_replace($cdn_domain, $parsed_site_url['host'], $result); |
|
359 | 359 | } |
360 | 360 | |
361 | - $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result ); |
|
361 | + $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result); |
|
362 | 362 | |
363 | 363 | // Store in cache. |
364 | - $cache[ $in ] = $result; |
|
364 | + $cache[$in] = $result; |
|
365 | 365 | } |
366 | 366 | |
367 | - return $cache[ $in ]; |
|
367 | + return $cache[$in]; |
|
368 | 368 | } |
369 | 369 | |
370 | - public function filter_optimize_css_images( $in ) |
|
370 | + public function filter_optimize_css_images($in) |
|
371 | 371 | { |
372 | - $in = $this->normalize_img_url( $in ); |
|
372 | + $in = $this->normalize_img_url($in); |
|
373 | 373 | |
374 | - if ( $this->can_optimize_image( $in ) ) { |
|
375 | - return $this->build_imgopt_url( $in, '', '' ); |
|
374 | + if ($this->can_optimize_image($in)) { |
|
375 | + return $this->build_imgopt_url($in, '', ''); |
|
376 | 376 | } else { |
377 | 377 | return $in; |
378 | 378 | } |
@@ -382,50 +382,50 @@ discard block |
||
382 | 382 | { |
383 | 383 | static $imgopt_base_url = null; |
384 | 384 | |
385 | - if ( null === $imgopt_base_url ) { |
|
385 | + if (null === $imgopt_base_url) { |
|
386 | 386 | $imgopt_host = $this->get_imgopt_host(); |
387 | 387 | $quality = $this->get_img_quality_string(); |
388 | - $ret_val = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank. |
|
389 | - $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val; |
|
390 | - $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url ); |
|
388 | + $ret_val = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank. |
|
389 | + $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val; |
|
390 | + $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | return $imgopt_base_url; |
394 | 394 | } |
395 | 395 | |
396 | - private function can_optimize_image( $url ) |
|
396 | + private function can_optimize_image($url) |
|
397 | 397 | { |
398 | 398 | static $cdn_url = null; |
399 | 399 | static $nopti_images = null; |
400 | 400 | |
401 | - if ( null === $cdn_url ) { |
|
401 | + if (null === $cdn_url) { |
|
402 | 402 | $cdn_url = apply_filters( |
403 | 403 | 'autoptimize_filter_base_cdnurl', |
404 | - autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ) |
|
404 | + autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '') |
|
405 | 405 | ); |
406 | 406 | } |
407 | 407 | |
408 | - if ( null === $nopti_images ) { |
|
409 | - $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' ); |
|
408 | + if (null === $nopti_images) { |
|
409 | + $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', ''); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $site_host = AUTOPTIMIZE_SITE_DOMAIN; |
413 | - $url = $this->normalize_img_url( $url ); |
|
414 | - $url_parsed = parse_url( $url ); |
|
413 | + $url = $this->normalize_img_url($url); |
|
414 | + $url_parsed = parse_url($url); |
|
415 | 415 | |
416 | - if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) { |
|
416 | + if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) { |
|
417 | 417 | return false; |
418 | - } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) { |
|
418 | + } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) { |
|
419 | 419 | return false; |
420 | - } elseif ( strpos( $url, '.php' ) !== false ) { |
|
420 | + } elseif (strpos($url, '.php') !== false) { |
|
421 | 421 | return false; |
422 | - } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) { |
|
422 | + } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp'), '', $url_parsed['path']) === $url_parsed['path']) { |
|
423 | 423 | // fixme: better check against end of string. |
424 | 424 | return false; |
425 | - } elseif ( ! empty( $nopti_images ) ) { |
|
426 | - $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) ); |
|
427 | - foreach ( $nopti_images_array as $nopti_image ) { |
|
428 | - if ( strpos( $url, $nopti_image ) !== false ) { |
|
425 | + } elseif (!empty($nopti_images)) { |
|
426 | + $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images))); |
|
427 | + foreach ($nopti_images_array as $nopti_image) { |
|
428 | + if (strpos($url, $nopti_image) !== false) { |
|
429 | 429 | return false; |
430 | 430 | } |
431 | 431 | } |
@@ -433,13 +433,13 @@ discard block |
||
433 | 433 | return true; |
434 | 434 | } |
435 | 435 | |
436 | - private function build_imgopt_url( $orig_url, $width = 0, $height = 0 ) |
|
436 | + private function build_imgopt_url($orig_url, $width = 0, $height = 0) |
|
437 | 437 | { |
438 | 438 | // sanitize width and height. |
439 | - if ( strpos( $width, '%' ) !== false ) { |
|
439 | + if (strpos($width, '%') !== false) { |
|
440 | 440 | $width = 0; |
441 | 441 | } |
442 | - if ( strpos( $height, '%' ) !== false ) { |
|
442 | + if (strpos($height, '%') !== false) { |
|
443 | 443 | $height = 0; |
444 | 444 | } |
445 | 445 | $width = (int) $width; |
@@ -453,56 +453,56 @@ discard block |
||
453 | 453 | ); |
454 | 454 | |
455 | 455 | // If filter modified the url, return that. |
456 | - if ( $filtered_url !== $orig_url ) { |
|
456 | + if ($filtered_url !== $orig_url) { |
|
457 | 457 | return $filtered_url; |
458 | 458 | } |
459 | 459 | |
460 | - $orig_url = $this->normalize_img_url( $orig_url ); |
|
460 | + $orig_url = $this->normalize_img_url($orig_url); |
|
461 | 461 | $imgopt_base_url = $this->get_imgopt_base_url(); |
462 | 462 | $imgopt_size = ''; |
463 | 463 | |
464 | - if ( $width && 0 !== $width ) { |
|
465 | - $imgopt_size = ',w_' . $width; |
|
464 | + if ($width && 0 !== $width) { |
|
465 | + $imgopt_size = ',w_'.$width; |
|
466 | 466 | } |
467 | 467 | |
468 | - if ( $height && 0 !== $height ) { |
|
469 | - $imgopt_size .= ',h_' . $height; |
|
468 | + if ($height && 0 !== $height) { |
|
469 | + $imgopt_size .= ',h_'.$height; |
|
470 | 470 | } |
471 | 471 | |
472 | - $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url; |
|
472 | + $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url; |
|
473 | 473 | |
474 | 474 | return $url; |
475 | 475 | } |
476 | 476 | |
477 | - public function replace_data_thumbs( $matches ) |
|
477 | + public function replace_data_thumbs($matches) |
|
478 | 478 | { |
479 | - return $this->replace_img_callback( $matches, 150, 150 ); |
|
479 | + return $this->replace_img_callback($matches, 150, 150); |
|
480 | 480 | } |
481 | 481 | |
482 | - public function replace_img_callback( $matches, $width = 0, $height = 0 ) |
|
482 | + public function replace_img_callback($matches, $width = 0, $height = 0) |
|
483 | 483 | { |
484 | - $_normalized_img_url = $this->normalize_img_url( $matches[1] ); |
|
485 | - if ( $this->can_optimize_image( $matches[1] ) ) { |
|
486 | - return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] ); |
|
484 | + $_normalized_img_url = $this->normalize_img_url($matches[1]); |
|
485 | + if ($this->can_optimize_image($matches[1])) { |
|
486 | + return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]); |
|
487 | 487 | } else { |
488 | 488 | return $matches[0]; |
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | - public function replace_icon_callback( $matches ) |
|
492 | + public function replace_icon_callback($matches) |
|
493 | 493 | { |
494 | - if ( array_key_exists( '2', $matches ) ) { |
|
495 | - $sizes = explode( 'x', $matches[2] ); |
|
494 | + if (array_key_exists('2', $matches)) { |
|
495 | + $sizes = explode('x', $matches[2]); |
|
496 | 496 | $width = $sizes[0]; |
497 | 497 | $height = $sizes[1]; |
498 | 498 | } else { |
499 | 499 | $width = 180; |
500 | 500 | $height = 180; |
501 | 501 | } |
502 | - return $this->replace_img_callback( $matches, $width, $height ); |
|
502 | + return $this->replace_img_callback($matches, $width, $height); |
|
503 | 503 | } |
504 | 504 | |
505 | - public function filter_optimize_images( $in ) |
|
505 | + public function filter_optimize_images($in) |
|
506 | 506 | { |
507 | 507 | /* |
508 | 508 | * potential future functional improvements: |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $to_replace = array(); |
513 | 513 | |
514 | 514 | // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript). |
515 | - if ( $this->should_lazyload() ) { |
|
515 | + if ($this->should_lazyload()) { |
|
516 | 516 | $in = autoptimizeBase::replace_contents_with_marker_if_exists( |
517 | 517 | 'SCRIPT', |
518 | 518 | '<script', |
@@ -522,25 +522,25 @@ discard block |
||
522 | 522 | } |
523 | 523 | |
524 | 524 | // extract img tags. |
525 | - if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) { |
|
526 | - foreach ( $matches[0] as $tag ) { |
|
525 | + if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) { |
|
526 | + foreach ($matches[0] as $tag) { |
|
527 | 527 | $orig_tag = $tag; |
528 | 528 | $imgopt_w = ''; |
529 | 529 | $imgopt_h = ''; |
530 | 530 | |
531 | 531 | // first do (data-)srcsets. |
532 | - if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) { |
|
533 | - foreach ( $allsrcsets as $srcset ) { |
|
532 | + if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) { |
|
533 | + foreach ($allsrcsets as $srcset) { |
|
534 | 534 | $srcset = $srcset[2]; |
535 | - $srcsets = explode( ',', $srcset ); |
|
536 | - foreach ( $srcsets as $indiv_srcset ) { |
|
537 | - $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) ); |
|
538 | - if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) { |
|
539 | - $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' ); |
|
535 | + $srcsets = explode(',', $srcset); |
|
536 | + foreach ($srcsets as $indiv_srcset) { |
|
537 | + $indiv_srcset_parts = explode(' ', trim($indiv_srcset)); |
|
538 | + if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) { |
|
539 | + $imgopt_w = rtrim($indiv_srcset_parts[1], 'w'); |
|
540 | 540 | } |
541 | - if ( $this->can_optimize_image( $indiv_srcset_parts[0] ) ) { |
|
542 | - $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' ); |
|
543 | - $tag = str_replace( $indiv_srcset_parts[0], $imgopt_url, $tag ); |
|
541 | + if ($this->can_optimize_image($indiv_srcset_parts[0])) { |
|
542 | + $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, ''); |
|
543 | + $tag = str_replace($indiv_srcset_parts[0], $imgopt_url, $tag); |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | } |
@@ -548,133 +548,133 @@ discard block |
||
548 | 548 | |
549 | 549 | // proceed with img src. |
550 | 550 | // get width and height and add to $imgopt_size. |
551 | - $_get_size = $this->get_size_from_tag( $tag ); |
|
551 | + $_get_size = $this->get_size_from_tag($tag); |
|
552 | 552 | $imgopt_w = $_get_size['width']; |
553 | 553 | $imgopt_h = $_get_size['height']; |
554 | 554 | |
555 | 555 | // then start replacing images src. |
556 | - if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) { |
|
557 | - foreach ( $urls as $url ) { |
|
556 | + if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) { |
|
557 | + foreach ($urls as $url) { |
|
558 | 558 | $full_src_orig = $url[0]; |
559 | 559 | $url = $url[1]; |
560 | - if ( $this->can_optimize_image( $url ) ) { |
|
561 | - $imgopt_url = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h ); |
|
562 | - $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig ); |
|
563 | - $tag = str_replace( $full_src_orig, $full_imgopt_src, $tag ); |
|
560 | + if ($this->can_optimize_image($url)) { |
|
561 | + $imgopt_url = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h); |
|
562 | + $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig); |
|
563 | + $tag = str_replace($full_src_orig, $full_imgopt_src, $tag); |
|
564 | 564 | } |
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
568 | 568 | // do lazyload stuff. |
569 | - if ( $this->should_lazyload( $in ) && ! empty( $url ) ) { |
|
569 | + if ($this->should_lazyload($in) && !empty($url)) { |
|
570 | 570 | // first do lpiq placeholder logic. |
571 | - if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) { |
|
571 | + if (strpos($url, $this->get_imgopt_host()) === 0) { |
|
572 | 572 | // if all img src have been replaced during srcset, we have to extract the |
573 | 573 | // origin url from the imgopt one to be able to set a lqip placeholder. |
574 | - $_url = substr( $url, strpos( $url, '/http' ) + 1 ); |
|
574 | + $_url = substr($url, strpos($url, '/http') + 1); |
|
575 | 575 | } else { |
576 | 576 | $_url = $url; |
577 | 577 | } |
578 | 578 | |
579 | - $_url = $this->normalize_img_url( $_url ); |
|
579 | + $_url = $this->normalize_img_url($_url); |
|
580 | 580 | |
581 | 581 | $placeholder = ''; |
582 | - if ( $this->can_optimize_image( $_url ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) { |
|
582 | + if ($this->can_optimize_image($_url) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) { |
|
583 | 583 | $lqip_w = ''; |
584 | 584 | $lqip_h = ''; |
585 | - if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) { |
|
586 | - $lqip_w = ',w_' . $imgopt_w; |
|
585 | + if (isset($imgopt_w) && !empty($imgopt_w)) { |
|
586 | + $lqip_w = ',w_'.$imgopt_w; |
|
587 | 587 | } |
588 | - if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) { |
|
589 | - $lqip_h = ',h_' . $imgopt_h; |
|
588 | + if (isset($imgopt_h) && !empty($imgopt_h)) { |
|
589 | + $lqip_h = ',h_'.$imgopt_h; |
|
590 | 590 | } |
591 | - $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url; |
|
591 | + $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url; |
|
592 | 592 | } |
593 | 593 | // then call add_lazyload-function with lpiq placeholder if set. |
594 | - $tag = $this->add_lazyload( $tag, $placeholder ); |
|
594 | + $tag = $this->add_lazyload($tag, $placeholder); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | // and add tag to array for later replacement. |
598 | - if ( $tag !== $orig_tag ) { |
|
599 | - $to_replace[ $orig_tag ] = $tag; |
|
598 | + if ($tag !== $orig_tag) { |
|
599 | + $to_replace[$orig_tag] = $tag; |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | } |
603 | 603 | |
604 | 604 | // and replace all. |
605 | - $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in ); |
|
605 | + $out = str_replace(array_keys($to_replace), array_values($to_replace), $in); |
|
606 | 606 | |
607 | 607 | // img thumbnails in e.g. woocommerce. |
608 | - if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) { |
|
608 | + if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) { |
|
609 | 609 | $out = preg_replace_callback( |
610 | 610 | '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s', |
611 | - array( $this, 'replace_data_thumbs' ), |
|
611 | + array($this, 'replace_data_thumbs'), |
|
612 | 612 | $out |
613 | 613 | ); |
614 | 614 | } |
615 | 615 | |
616 | 616 | // background-image in inline style. |
617 | - if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) { |
|
617 | + if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) { |
|
618 | 618 | $out = preg_replace_callback( |
619 | 619 | '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/', |
620 | - array( $this, 'replace_img_callback' ), |
|
620 | + array($this, 'replace_img_callback'), |
|
621 | 621 | $out |
622 | 622 | ); |
623 | 623 | } |
624 | 624 | |
625 | 625 | // act on icon links. |
626 | - if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) { |
|
626 | + if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) { |
|
627 | 627 | $out = preg_replace_callback( |
628 | 628 | '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um', |
629 | - array( $this, 'replace_icon_callback' ), |
|
629 | + array($this, 'replace_icon_callback'), |
|
630 | 630 | $out |
631 | 631 | ); |
632 | 632 | } |
633 | 633 | |
634 | 634 | // lazyload: restore noscript tags + lazyload picture source tags and bgimage. |
635 | - if ( $this->should_lazyload() ) { |
|
635 | + if ($this->should_lazyload()) { |
|
636 | 636 | $out = autoptimizeBase::restore_marked_content( |
637 | 637 | 'SCRIPT', |
638 | 638 | $out |
639 | 639 | ); |
640 | 640 | |
641 | - $out = $this->process_picture_tag( $out, true, true ); |
|
642 | - $out = $this->process_bgimage( $out ); |
|
641 | + $out = $this->process_picture_tag($out, true, true); |
|
642 | + $out = $this->process_bgimage($out); |
|
643 | 643 | } else { |
644 | - $out = $this->process_picture_tag( $out, true, false ); |
|
644 | + $out = $this->process_picture_tag($out, true, false); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | return $out; |
648 | 648 | } |
649 | 649 | |
650 | - public function get_size_from_tag( $tag ) { |
|
650 | + public function get_size_from_tag($tag) { |
|
651 | 651 | // reusable function to extract widht and height from an image tag |
652 | 652 | // enforcing a filterable maximum width and height (default 4999X4999). |
653 | 653 | $width = ''; |
654 | 654 | $height = ''; |
655 | 655 | |
656 | - if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) { |
|
657 | - if ( strpos( $_width[2], '%' ) === false ) { |
|
656 | + if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) { |
|
657 | + if (strpos($_width[2], '%') === false) { |
|
658 | 658 | $width = (int) $_width[2]; |
659 | 659 | } |
660 | 660 | } |
661 | - if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) { |
|
662 | - if ( strpos( $_height[2], '%' ) === false ) { |
|
661 | + if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) { |
|
662 | + if (strpos($_height[2], '%') === false) { |
|
663 | 663 | $height = (int) $_height[2]; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | 667 | // check for and enforce (filterable) max sizes. |
668 | - $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 ); |
|
669 | - if ( $width > $_max_width ) { |
|
668 | + $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999); |
|
669 | + if ($width > $_max_width) { |
|
670 | 670 | $_width = $_max_width; |
671 | - $height = $_width / $width * $height; |
|
671 | + $height = $_width/$width*$height; |
|
672 | 672 | $width = $_width; |
673 | 673 | } |
674 | - $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 ); |
|
675 | - if ( $height > $_max_height ) { |
|
674 | + $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999); |
|
675 | + if ($height > $_max_height) { |
|
676 | 676 | $_height = $_max_height; |
677 | - $width = $_height / $height * $width; |
|
677 | + $width = $_height/$height*$width; |
|
678 | 678 | $height = $_height; |
679 | 679 | } |
680 | 680 | |
@@ -693,26 +693,26 @@ discard block |
||
693 | 693 | return $self->should_lazyload(); |
694 | 694 | } |
695 | 695 | |
696 | - public function should_lazyload( $context = '' ) { |
|
697 | - if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) { |
|
696 | + public function should_lazyload($context = '') { |
|
697 | + if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) { |
|
698 | 698 | $lazyload_return = true; |
699 | 699 | } else { |
700 | 700 | $lazyload_return = false; |
701 | 701 | } |
702 | - $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context ); |
|
702 | + $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context); |
|
703 | 703 | |
704 | 704 | return $lazyload_return; |
705 | 705 | } |
706 | 706 | |
707 | 707 | public function check_nolazy() { |
708 | - if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) { |
|
708 | + if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) { |
|
709 | 709 | return true; |
710 | 710 | } else { |
711 | 711 | return false; |
712 | 712 | } |
713 | 713 | } |
714 | 714 | |
715 | - public function filter_lazyload_images( $in ) |
|
715 | + public function filter_lazyload_images($in) |
|
716 | 716 | { |
717 | 717 | // only used is image optimization is NOT active but lazyload is. |
718 | 718 | $to_replace = array(); |
@@ -726,20 +726,20 @@ discard block |
||
726 | 726 | ); |
727 | 727 | |
728 | 728 | // extract img tags and add lazyload attribs. |
729 | - if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) { |
|
730 | - foreach ( $matches[0] as $tag ) { |
|
731 | - if ( $this->should_lazyload( $out ) ) { |
|
732 | - $to_replace[ $tag ] = $this->add_lazyload( $tag ); |
|
729 | + if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) { |
|
730 | + foreach ($matches[0] as $tag) { |
|
731 | + if ($this->should_lazyload($out)) { |
|
732 | + $to_replace[$tag] = $this->add_lazyload($tag); |
|
733 | 733 | } |
734 | 734 | } |
735 | - $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out ); |
|
735 | + $out = str_replace(array_keys($to_replace), array_values($to_replace), $out); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | // and also lazyload picture tag. |
739 | - $out = $this->process_picture_tag( $out, false, true ); |
|
739 | + $out = $this->process_picture_tag($out, false, true); |
|
740 | 740 | |
741 | 741 | // and inline style blocks with background-image. |
742 | - $out = $this->process_bgimage( $out ); |
|
742 | + $out = $this->process_bgimage($out); |
|
743 | 743 | |
744 | 744 | // restore noscript tags. |
745 | 745 | $out = autoptimizeBase::restore_marked_content( |
@@ -750,85 +750,85 @@ discard block |
||
750 | 750 | return $out; |
751 | 751 | } |
752 | 752 | |
753 | - public function add_lazyload( $tag, $placeholder = '' ) { |
|
753 | + public function add_lazyload($tag, $placeholder = '') { |
|
754 | 754 | // adds actual lazyload-attributes to an image node. |
755 | - if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) { |
|
756 | - $tag = $this->maybe_fix_missing_quotes( $tag ); |
|
755 | + if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) { |
|
756 | + $tag = $this->maybe_fix_missing_quotes($tag); |
|
757 | 757 | |
758 | 758 | // store original tag for use in noscript version. |
759 | - $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>'; |
|
759 | + $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'; |
|
760 | 760 | |
761 | - $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' ); |
|
761 | + $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload'); |
|
762 | 762 | |
763 | 763 | // insert lazyload class. |
764 | - $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " ); |
|
764 | + $tag = $this->inject_classes_in_tag($tag, "$lazyload_class "); |
|
765 | 765 | |
766 | - if ( ! $placeholder || empty( $placeholder ) ) { |
|
766 | + if (!$placeholder || empty($placeholder)) { |
|
767 | 767 | // get image width & heigth for placeholder fun (and to prevent content reflow). |
768 | - $_get_size = $this->get_size_from_tag( $tag ); |
|
768 | + $_get_size = $this->get_size_from_tag($tag); |
|
769 | 769 | $width = $_get_size['width']; |
770 | 770 | $height = $_get_size['height']; |
771 | - if ( false === $width || empty( $width ) ) { |
|
771 | + if (false === $width || empty($width)) { |
|
772 | 772 | $width = 210; // default width for SVG placeholder. |
773 | 773 | } |
774 | - if ( false === $height || empty( $height ) ) { |
|
775 | - $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio. |
|
774 | + if (false === $height || empty($height)) { |
|
775 | + $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio. |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | // insert the actual lazyload stuff. |
779 | 779 | // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's. |
780 | - $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) ); |
|
780 | + $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height)); |
|
781 | 781 | } |
782 | 782 | |
783 | - $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag ); |
|
784 | - $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag ); |
|
783 | + $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag); |
|
784 | + $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag); |
|
785 | 785 | |
786 | 786 | // move sizes to data-sizes unless filter says no. |
787 | - if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) { |
|
788 | - $tag = str_replace( ' sizes=', ' data-sizes=', $tag ); |
|
787 | + if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) { |
|
788 | + $tag = str_replace(' sizes=', ' data-sizes=', $tag); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | // add the noscript-tag from earlier. |
792 | - $tag = $noscript_tag . $tag; |
|
793 | - $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag ); |
|
792 | + $tag = $noscript_tag.$tag; |
|
793 | + $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | return $tag; |
797 | 797 | } |
798 | 798 | |
799 | 799 | public function add_lazyload_js_footer() { |
800 | - if ( false === autoptimizeMain::should_buffer() ) { |
|
800 | + if (false === autoptimizeMain::should_buffer()) { |
|
801 | 801 | return; |
802 | 802 | } |
803 | 803 | |
804 | 804 | // The JS will by default be excluded form autoptimization but this can be changed with a filter. |
805 | 805 | $noptimize_flag = ''; |
806 | - if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) { |
|
806 | + if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) { |
|
807 | 807 | $noptimize_flag = ' data-noptimize="1"'; |
808 | 808 | } |
809 | 809 | |
810 | - $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ ); |
|
810 | + $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__); |
|
811 | 811 | $cdn_url = $this->get_cdn_url(); |
812 | - if ( ! empty( $cdn_url ) ) { |
|
813 | - $cdn_url = rtrim( $cdn_url, '/' ); |
|
814 | - $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js ); |
|
812 | + if (!empty($cdn_url)) { |
|
813 | + $cdn_url = rtrim($cdn_url, '/'); |
|
814 | + $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | $type_js = ''; |
818 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
818 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
819 | 819 | $type_js = ' type="text/javascript"'; |
820 | 820 | } |
821 | 821 | |
822 | 822 | // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async). |
823 | - echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' ); |
|
824 | - echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' ); |
|
825 | - echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' ); |
|
823 | + echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>'); |
|
824 | + echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>'); |
|
825 | + echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>'); |
|
826 | 826 | |
827 | 827 | // And add webp detection and loading JS. |
828 | - if ( $this->should_webp() ) { |
|
828 | + if ($this->should_webp()) { |
|
829 | 829 | $_webp_detect = "function c_webp(A){var n=new Image;n.onload=function(){var e=0<n.width&&0<n.height;A(e)},n.onerror=function(){A(!1)},n.src='data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA=='}function s_webp(e){window.supportsWebP=e}c_webp(s_webp);"; |
830 | 830 | $_webp_load = "document.addEventListener('lazybeforeunveil',function({target:b}){window.supportsWebP&&['data-src','data-srcset'].forEach(function(c){attr=b.getAttribute(c),null!==attr&&-1==attr.indexOf('/client/to_webp')&&b.setAttribute(c,attr.replace(/\/client\//,'/client/to_webp,'))})});"; |
831 | - echo apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_webp_detect . $_webp_load . '</script>' ); |
|
831 | + echo apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_webp_detect.$_webp_load.'</script>'); |
|
832 | 832 | } |
833 | 833 | } |
834 | 834 | |
@@ -836,10 +836,10 @@ discard block |
||
836 | 836 | // getting CDN url here to avoid having to make bigger changes to autoptimizeBase. |
837 | 837 | static $cdn_url = null; |
838 | 838 | |
839 | - if ( null === $cdn_url ) { |
|
840 | - $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ); |
|
841 | - $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url ); |
|
842 | - $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url ); |
|
839 | + if (null === $cdn_url) { |
|
840 | + $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''); |
|
841 | + $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url); |
|
842 | + $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | return $cdn_url; |
@@ -849,47 +849,47 @@ discard block |
||
849 | 849 | // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded. |
850 | 850 | static $exclude_lazyload_array = null; |
851 | 851 | |
852 | - if ( null === $exclude_lazyload_array ) { |
|
852 | + if (null === $exclude_lazyload_array) { |
|
853 | 853 | $options = $this->options; |
854 | 854 | |
855 | 855 | // set default exclusions. |
856 | - $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' ); |
|
856 | + $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"'); |
|
857 | 857 | |
858 | 858 | // add from setting. |
859 | - if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) { |
|
859 | + if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) { |
|
860 | 860 | $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5']; |
861 | - if ( ! empty( $exclude_lazyload_option ) ) { |
|
862 | - $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) ); |
|
861 | + if (!empty($exclude_lazyload_option)) { |
|
862 | + $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5'])))); |
|
863 | 863 | } |
864 | 864 | } |
865 | 865 | |
866 | 866 | // and filter for developer-initiated changes. |
867 | - $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array ); |
|
867 | + $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | return $exclude_lazyload_array; |
871 | 871 | } |
872 | 872 | |
873 | - public function inject_classes_in_tag( $tag, $target_class ) { |
|
874 | - if ( strpos( $tag, 'class=' ) !== false ) { |
|
875 | - $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag ); |
|
873 | + public function inject_classes_in_tag($tag, $target_class) { |
|
874 | + if (strpos($tag, 'class=') !== false) { |
|
875 | + $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag); |
|
876 | 876 | } else { |
877 | - $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag ); |
|
877 | + $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | return $tag; |
881 | 881 | } |
882 | 882 | |
883 | - public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) { |
|
884 | - return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20' . $imgopt_w . '%20' . $imgopt_h . '%22%3E%3C/svg%3E'; |
|
883 | + public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) { |
|
884 | + return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20'.$imgopt_w.'%20'.$imgopt_h.'%22%3E%3C/svg%3E'; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | public function should_webp() { |
888 | 888 | static $webp_return = null; |
889 | 889 | |
890 | - if ( is_null( $webp_return ) ) { |
|
890 | + if (is_null($webp_return)) { |
|
891 | 891 | // webp only works if imgopt and lazyload are also active. |
892 | - if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) { |
|
892 | + if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) { |
|
893 | 893 | $webp_return = true; |
894 | 894 | } else { |
895 | 895 | $webp_return = false; |
@@ -899,9 +899,9 @@ discard block |
||
899 | 899 | return $webp_return; |
900 | 900 | } |
901 | 901 | |
902 | - public function process_picture_tag( $in, $imgopt = false, $lazy = false ) { |
|
902 | + public function process_picture_tag($in, $imgopt = false, $lazy = false) { |
|
903 | 903 | // check if "<picture" is present and if filter allows us to process <picture>. |
904 | - if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) { |
|
904 | + if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) { |
|
905 | 905 | return $in; |
906 | 906 | } |
907 | 907 | |
@@ -909,37 +909,37 @@ discard block |
||
909 | 909 | $to_replace_pict = array(); |
910 | 910 | |
911 | 911 | // extract and process each picture-node. |
912 | - preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER ); |
|
913 | - foreach ( $_pictures as $_picture ) { |
|
914 | - $_picture = $this->maybe_fix_missing_quotes( $_picture ); |
|
915 | - if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) { |
|
916 | - foreach ( $_sources as $_source ) { |
|
912 | + preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER); |
|
913 | + foreach ($_pictures as $_picture) { |
|
914 | + $_picture = $this->maybe_fix_missing_quotes($_picture); |
|
915 | + if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) { |
|
916 | + foreach ($_sources as $_source) { |
|
917 | 917 | $_picture_replacement = $_source[0]; |
918 | 918 | |
919 | 919 | // should we optimize the image? |
920 | - if ( $imgopt && $this->can_optimize_image( $_source[1] ) ) { |
|
921 | - $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement ); |
|
920 | + if ($imgopt && $this->can_optimize_image($_source[1])) { |
|
921 | + $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement); |
|
922 | 922 | } |
923 | 923 | // should we lazy-load? |
924 | - if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) { |
|
925 | - $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement ); |
|
924 | + if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) { |
|
925 | + $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement); |
|
926 | 926 | } |
927 | - $to_replace_pict[ $_source[0] ] = $_picture_replacement; |
|
927 | + $to_replace_pict[$_source[0]] = $_picture_replacement; |
|
928 | 928 | } |
929 | 929 | } |
930 | 930 | } |
931 | 931 | |
932 | 932 | // and return the fully procesed $in. |
933 | - $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in ); |
|
933 | + $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in); |
|
934 | 934 | |
935 | 935 | return $out; |
936 | 936 | } |
937 | 937 | |
938 | - public function process_bgimage( $in ) { |
|
939 | - if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) { |
|
938 | + public function process_bgimage($in) { |
|
939 | + if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) { |
|
940 | 940 | $out = preg_replace_callback( |
941 | 941 | '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/', |
942 | - array( $this, 'lazyload_bgimg_callback' ), |
|
942 | + array($this, 'lazyload_bgimg_callback'), |
|
943 | 943 | $in |
944 | 944 | ); |
945 | 945 | return $out; |
@@ -947,27 +947,27 @@ discard block |
||
947 | 947 | return $in; |
948 | 948 | } |
949 | 949 | |
950 | - public function lazyload_bgimg_callback( $matches ) { |
|
951 | - if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) { |
|
950 | + public function lazyload_bgimg_callback($matches) { |
|
951 | + if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) { |
|
952 | 952 | // get placeholder & lazyload class strings. |
953 | - $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) ); |
|
954 | - $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' ); |
|
953 | + $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300)); |
|
954 | + $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload'); |
|
955 | 955 | // replace background-image URL with SVG placeholder. |
956 | - $out = str_replace( $matches[2], $placeholder, $matches[0] ); |
|
956 | + $out = str_replace($matches[2], $placeholder, $matches[0]); |
|
957 | 957 | // add data-bg attribute with real background-image URL for lazyload to pick up. |
958 | - $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '"' ), '', $matches[2] ) ) . '"', $out ); |
|
958 | + $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '"'), '', $matches[2])).'"', $out); |
|
959 | 959 | // add lazyload class to tag. |
960 | - $out = $this->inject_classes_in_tag( $out, "$lazyload_class " ); |
|
960 | + $out = $this->inject_classes_in_tag($out, "$lazyload_class "); |
|
961 | 961 | return $out; |
962 | 962 | } |
963 | 963 | return $matches[0]; |
964 | 964 | } |
965 | 965 | |
966 | - public function maybe_fix_missing_quotes( $tag_in ) { |
|
966 | + public function maybe_fix_missing_quotes($tag_in) { |
|
967 | 967 | // W3TC's Minify_HTML class removes quotes around attribute value, this re-adds them for the class and width/height attributes so we can lazyload properly. |
968 | - if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) { |
|
969 | - $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in ); |
|
970 | - $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out ); |
|
968 | + if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) { |
|
969 | + $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in); |
|
970 | + $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out); |
|
971 | 971 | return $tag_out; |
972 | 972 | } else { |
973 | 973 | return $tag_in; |
@@ -980,23 +980,23 @@ discard block |
||
980 | 980 | public function imgopt_admin_menu() |
981 | 981 | { |
982 | 982 | // no acces if multisite and not network admin and no site config allowed. |
983 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
983 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
984 | 984 | add_submenu_page( |
985 | 985 | null, |
986 | 986 | 'autoptimize_imgopt', |
987 | 987 | 'autoptimize_imgopt', |
988 | 988 | 'manage_options', |
989 | 989 | 'autoptimize_imgopt', |
990 | - array( $this, 'imgopt_options_page' ) |
|
990 | + array($this, 'imgopt_options_page') |
|
991 | 991 | ); |
992 | 992 | } |
993 | - register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' ); |
|
993 | + register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings'); |
|
994 | 994 | } |
995 | 995 | |
996 | - public function add_imgopt_tab( $in ) |
|
996 | + public function add_imgopt_tab($in) |
|
997 | 997 | { |
998 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
999 | - $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) ); |
|
998 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
999 | + $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize'))); |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | return $in; |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | public function imgopt_options_page() |
1006 | 1006 | { |
1007 | 1007 | // Check querystring for "refreshCacheChecker" and call cachechecker if so. |
1008 | - if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) { |
|
1008 | + if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) { |
|
1009 | 1009 | $this->query_img_provider_stats(); |
1010 | 1010 | } |
1011 | 1011 | |
@@ -1017,47 +1017,47 @@ discard block |
||
1017 | 1017 | #ao_settings_form .form-table th {font-weight: normal;} |
1018 | 1018 | #autoptimize_imgopt_descr{font-size: 120%;} |
1019 | 1019 | </style> |
1020 | - <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script> |
|
1020 | + <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script> |
|
1021 | 1021 | <div class="wrap"> |
1022 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
1022 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
1023 | 1023 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
1024 | - <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?> |
|
1024 | + <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?> |
|
1025 | 1025 | <div class="notice-warning notice"><p> |
1026 | 1026 | <?php |
1027 | 1027 | // translators: "Autoptimize support forum" will appear in a "a href". |
1028 | - echo sprintf( __( 'The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize' ), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>' ); |
|
1028 | + echo sprintf(__('The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize'), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>'); |
|
1029 | 1029 | ?> |
1030 | 1030 | </p></div> |
1031 | 1031 | <?php } ?> |
1032 | 1032 | |
1033 | - <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?> |
|
1033 | + <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?> |
|
1034 | 1034 | <div class="notice-warning notice"><p> |
1035 | - <?php _e( 'The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize' ); ?> |
|
1035 | + <?php _e('The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize'); ?> |
|
1036 | 1036 | </p></div> |
1037 | 1037 | <?php } ?> |
1038 | 1038 | |
1039 | - <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?> |
|
1039 | + <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?> |
|
1040 | 1040 | <div class="notice-warning notice"><p> |
1041 | 1041 | <?php |
1042 | 1042 | // translators: "disable Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page. |
1043 | - echo sprintf( __( 'Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize' ), '<a href="admin.php?page=jetpack#/settings">', '</a>' ); |
|
1043 | + echo sprintf(__('Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize'), '<a href="admin.php?page=jetpack#/settings">', '</a>'); |
|
1044 | 1044 | ?> |
1045 | 1045 | </p></div> |
1046 | 1046 | <?php } ?> |
1047 | - <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'> |
|
1048 | - <?php settings_fields( 'autoptimize_imgopt_settings' ); ?> |
|
1049 | - <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2> |
|
1050 | - <span id='autoptimize_imgopt_descr'><?php _e( 'Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize' ); ?></span> |
|
1047 | + <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'> |
|
1048 | + <?php settings_fields('autoptimize_imgopt_settings'); ?> |
|
1049 | + <h2><?php _e('Image optimization', 'autoptimize'); ?></h2> |
|
1050 | + <span id='autoptimize_imgopt_descr'><?php _e('Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize'); ?></span> |
|
1051 | 1051 | <table class="form-table"> |
1052 | 1052 | <tr> |
1053 | - <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th> |
|
1053 | + <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th> |
|
1054 | 1054 | <td> |
1055 | - <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize' ); ?></label> |
|
1055 | + <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_1']) && '1' === $options['autoptimize_imgopt_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize'); ?></label> |
|
1056 | 1056 | <?php |
1057 | 1057 | // show shortpixel status. |
1058 | 1058 | $_notice = autoptimizeImages::instance()->get_imgopt_status_notice(); |
1059 | - if ( $_notice ) { |
|
1060 | - switch ( $_notice['status'] ) { |
|
1059 | + if ($_notice) { |
|
1060 | + switch ($_notice['status']) { |
|
1061 | 1061 | case 2: |
1062 | 1062 | $_notice_color = 'green'; |
1063 | 1063 | break; |
@@ -1072,29 +1072,29 @@ discard block |
||
1072 | 1072 | default: |
1073 | 1073 | $_notice_color = 'green'; |
1074 | 1074 | } |
1075 | - echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' ); |
|
1075 | + echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>'); |
|
1076 | 1076 | } else { |
1077 | 1077 | // translators: link points to shortpixel. |
1078 | - $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' ); |
|
1079 | - if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) { |
|
1080 | - $upsell_msg_2 = __( 'For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize' ); |
|
1078 | + $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>'); |
|
1079 | + if ('launch' === $options['availabilities']['extra_imgopt']['status']) { |
|
1080 | + $upsell_msg_2 = __('For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize'); |
|
1081 | 1081 | } else { |
1082 | 1082 | // translators: link points to shortpixel. |
1083 | - $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive a 1 000 bonus + 50% more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' ); |
|
1083 | + $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive a 1 000 bonus + 50% more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>'); |
|
1084 | 1084 | } |
1085 | - echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' ); |
|
1085 | + echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>'); |
|
1086 | 1086 | } |
1087 | 1087 | // translators: link points to shortpixel FAQ. |
1088 | - $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>' ); |
|
1089 | - $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' ); |
|
1088 | + $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>'); |
|
1089 | + $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize'); |
|
1090 | 1090 | // translators: links points to shortpixel TOS & Privacy Policy. |
1091 | - $toscopy = sprintf( __( 'Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize' ), '<a href="https://shortpixel.com/tos' . $sp_url_suffix . '" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp' . $sp_url_suffix . '" target="_blank">', '</a>' ); |
|
1092 | - echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' ); |
|
1091 | + $toscopy = sprintf(__('Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize'), '<a href="https://shortpixel.com/tos'.$sp_url_suffix.'" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp'.$sp_url_suffix.'" target="_blank">', '</a>'); |
|
1092 | + echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>'); |
|
1093 | 1093 | ?> |
1094 | 1094 | </td> |
1095 | 1095 | </tr> |
1096 | - <tr id='autoptimize_imgopt_quality' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>> |
|
1097 | - <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th> |
|
1096 | + <tr id='autoptimize_imgopt_quality' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>> |
|
1097 | + <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th> |
|
1098 | 1098 | <td> |
1099 | 1099 | <label> |
1100 | 1100 | <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'> |
@@ -1102,12 +1102,12 @@ discard block |
||
1102 | 1102 | $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array(); |
1103 | 1103 | $_imgopt_val = autoptimizeImages::instance()->get_img_quality_setting(); |
1104 | 1104 | |
1105 | - foreach ( $_imgopt_array as $key => $value ) { |
|
1106 | - echo '<option value="' . $key . '"'; |
|
1107 | - if ( $_imgopt_val == $key ) { |
|
1105 | + foreach ($_imgopt_array as $key => $value) { |
|
1106 | + echo '<option value="'.$key.'"'; |
|
1107 | + if ($_imgopt_val == $key) { |
|
1108 | 1108 | echo ' selected'; |
1109 | 1109 | } |
1110 | - echo '>' . ucfirst( $value ) . '</option>'; |
|
1110 | + echo '>'.ucfirst($value).'</option>'; |
|
1111 | 1111 | } |
1112 | 1112 | echo "\n"; |
1113 | 1113 | ?> |
@@ -1116,31 +1116,31 @@ discard block |
||
1116 | 1116 | <p> |
1117 | 1117 | <?php |
1118 | 1118 | // translators: link points to shortpixel image test page. |
1119 | - echo apply_filters( 'autoptimize_imgopt_imgopt_quality_copy', sprintf( __( 'You can %1$stest compression levels here%2$s.', 'autoptimize' ), '<a href="https://shortpixel.com/oic' . $sp_url_suffix . '" target="_blank">', '</a>' ) ); |
|
1119 | + echo apply_filters('autoptimize_imgopt_imgopt_quality_copy', sprintf(__('You can %1$stest compression levels here%2$s.', 'autoptimize'), '<a href="https://shortpixel.com/oic'.$sp_url_suffix.'" target="_blank">', '</a>')); |
|
1120 | 1120 | ?> |
1121 | 1121 | </p> |
1122 | 1122 | </td> |
1123 | 1123 | </tr> |
1124 | - <tr id='autoptimize_imgopt_webp' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>> |
|
1125 | - <th scope="row"><?php _e( 'Load WebP in supported browsers?', 'autoptimize' ); ?></th> |
|
1124 | + <tr id='autoptimize_imgopt_webp' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>> |
|
1125 | + <th scope="row"><?php _e('Load WebP in supported browsers?', 'autoptimize'); ?></th> |
|
1126 | 1126 | <td> |
1127 | - <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_4'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label> |
|
1127 | + <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_4']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label> |
|
1128 | 1128 | </td> |
1129 | 1129 | </tr> |
1130 | 1130 | <tr> |
1131 | - <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th> |
|
1131 | + <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th> |
|
1132 | 1132 | <td> |
1133 | - <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize' ); ?></label> |
|
1133 | + <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_3']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize'); ?></label> |
|
1134 | 1134 | </td> |
1135 | 1135 | </tr> |
1136 | - <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="hidden"'; } ?>> |
|
1137 | - <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th> |
|
1136 | + <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="hidden"'; } ?>> |
|
1137 | + <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th> |
|
1138 | 1138 | <td> |
1139 | - <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label> |
|
1139 | + <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label> |
|
1140 | 1140 | </td> |
1141 | 1141 | </tr> |
1142 | 1142 | </table> |
1143 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
1143 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
1144 | 1144 | </form> |
1145 | 1145 | <script> |
1146 | 1146 | jQuery(document).ready(function() { |
@@ -1176,50 +1176,50 @@ discard block |
||
1176 | 1176 | * Ïmg opt status as used on dashboard. |
1177 | 1177 | */ |
1178 | 1178 | public function get_imgopt_status_notice() { |
1179 | - if ( $this->imgopt_active() ) { |
|
1179 | + if ($this->imgopt_active()) { |
|
1180 | 1180 | $_imgopt_notice = ''; |
1181 | - $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' ); |
|
1181 | + $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', ''); |
|
1182 | 1182 | $_site_host = AUTOPTIMIZE_SITE_DOMAIN; |
1183 | - $_imgopt_upsell = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host; |
|
1183 | + $_imgopt_upsell = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host; |
|
1184 | 1184 | $_imgopt_assoc = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account'; |
1185 | 1185 | $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai'; |
1186 | 1186 | |
1187 | - if ( is_array( $_stat ) ) { |
|
1188 | - if ( 1 == $_stat['Status'] ) { |
|
1187 | + if (is_array($_stat)) { |
|
1188 | + if (1 == $_stat['Status']) { |
|
1189 | 1189 | // translators: "add more credits" will appear in a "a href". |
1190 | - $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' ); |
|
1190 | + $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>'); |
|
1191 | 1191 | } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) { |
1192 | 1192 | // translators: "add more credits" will appear in a "a href". |
1193 | - $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' ); |
|
1193 | + $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>'); |
|
1194 | 1194 | // translators: "associate your domain" will appear in a "a href". |
1195 | - $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '<a rel="noopener noreferrer" href="' . $_imgopt_assoc . '" target="_blank">', '</a>' ); |
|
1195 | + $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize'), '<a rel="noopener noreferrer" href="'.$_imgopt_assoc.'" target="_blank">', '</a>'); |
|
1196 | 1196 | } elseif ( -3 == $_stat['Status'] ) { |
1197 | 1197 | // translators: "check the documentation here" will appear in a "a href". |
1198 | - $_imgopt_notice = sprintf( __( 'It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize' ), '<a href="' . $_imgopt_unreach . '" target="_blank">', '</a>' ); |
|
1198 | + $_imgopt_notice = sprintf(__('It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize'), '<a href="'.$_imgopt_unreach.'" target="_blank">', '</a>'); |
|
1199 | 1199 | } else { |
1200 | 1200 | $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483'; |
1201 | 1201 | // translators: "log in to check your account" will appear in a "a href". |
1202 | - $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' ); |
|
1202 | + $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>'); |
|
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | // add info on freshness + refresh link if status is not 2 (good shape). |
1206 | - if ( 2 != $_stat['Status'] ) { |
|
1207 | - $_imgopt_stats_refresh_url = add_query_arg( array( |
|
1206 | + if (2 != $_stat['Status']) { |
|
1207 | + $_imgopt_stats_refresh_url = add_query_arg(array( |
|
1208 | 1208 | 'page' => 'autoptimize_imgopt', |
1209 | 1209 | 'refreshImgProvStats' => '1', |
1210 | - ), admin_url( 'options-general.php' ) ); |
|
1211 | - if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) { |
|
1212 | - $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] ); |
|
1210 | + ), admin_url('options-general.php')); |
|
1211 | + if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) { |
|
1212 | + $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']); |
|
1213 | 1213 | } else { |
1214 | - $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' ); |
|
1214 | + $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize'); |
|
1215 | 1215 | } |
1216 | - $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', '; |
|
1216 | + $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', '; |
|
1217 | 1217 | // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats. |
1218 | - $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' ); |
|
1218 | + $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).'); |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | // and make the full notice filterable. |
1222 | - $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice ); |
|
1222 | + $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice); |
|
1223 | 1223 | |
1224 | 1224 | return array( |
1225 | 1225 | 'status' => $_stat['Status'], |
@@ -1240,14 +1240,14 @@ discard block |
||
1240 | 1240 | * Get img provider stats (used to display notice). |
1241 | 1241 | */ |
1242 | 1242 | public function query_img_provider_stats() { |
1243 | - if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) { |
|
1243 | + if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) { |
|
1244 | 1244 | $url = ''; |
1245 | - $endpoint = $this->get_imgopt_host() . 'read-domain/'; |
|
1245 | + $endpoint = $this->get_imgopt_host().'read-domain/'; |
|
1246 | 1246 | $domain = AUTOPTIMIZE_SITE_DOMAIN; |
1247 | 1247 | |
1248 | 1248 | // make sure parse_url result makes sense, keeping $url empty if not. |
1249 | - if ( $domain && ! empty( $domain ) ) { |
|
1250 | - $url = $endpoint . $domain; |
|
1249 | + if ($domain && !empty($domain)) { |
|
1250 | + $url = $endpoint.$domain; |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | $url = apply_filters( |
@@ -1257,12 +1257,12 @@ discard block |
||
1257 | 1257 | |
1258 | 1258 | // only do the remote call if $url is not empty to make sure no parse_url |
1259 | 1259 | // weirdness results in useless calls. |
1260 | - if ( ! empty( $url ) ) { |
|
1261 | - $response = wp_remote_get( $url ); |
|
1262 | - if ( ! is_wp_error( $response ) ) { |
|
1263 | - if ( '200' == wp_remote_retrieve_response_code( $response ) ) { |
|
1264 | - $stats = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
1265 | - autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats ); |
|
1260 | + if (!empty($url)) { |
|
1261 | + $response = wp_remote_get($url); |
|
1262 | + if (!is_wp_error($response)) { |
|
1263 | + if ('200' == wp_remote_retrieve_response_code($response)) { |
|
1264 | + $stats = json_decode(wp_remote_retrieve_body($response), true); |
|
1265 | + autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats); |
|
1266 | 1266 | } |
1267 | 1267 | } |
1268 | 1268 | } |
@@ -1285,15 +1285,15 @@ discard block |
||
1285 | 1285 | { |
1286 | 1286 | static $launch_status = null; |
1287 | 1287 | |
1288 | - if ( null === $launch_status ) { |
|
1288 | + if (null === $launch_status) { |
|
1289 | 1289 | $avail_imgopt = $this->options['availabilities']['extra_imgopt']; |
1290 | - $magic_number = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 ); |
|
1291 | - $has_launched = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' ); |
|
1290 | + $magic_number = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16); |
|
1291 | + $has_launched = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', ''); |
|
1292 | 1292 | $launch_status = false; |
1293 | - if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) { |
|
1293 | + if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) { |
|
1294 | 1294 | $launch_status = true; |
1295 | - if ( ! $has_launched ) { |
|
1296 | - autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' ); |
|
1295 | + if (!$has_launched) { |
|
1296 | + autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on'); |
|
1297 | 1297 | } |
1298 | 1298 | } |
1299 | 1299 | } |
@@ -1310,16 +1310,16 @@ discard block |
||
1310 | 1310 | public function get_imgopt_provider_userstatus() { |
1311 | 1311 | static $_provider_userstatus = null; |
1312 | 1312 | |
1313 | - if ( is_null( $_provider_userstatus ) ) { |
|
1314 | - $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' ); |
|
1315 | - if ( is_array( $_stat ) ) { |
|
1316 | - if ( array_key_exists( 'Status', $_stat ) ) { |
|
1313 | + if (is_null($_provider_userstatus)) { |
|
1314 | + $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', ''); |
|
1315 | + if (is_array($_stat)) { |
|
1316 | + if (array_key_exists('Status', $_stat)) { |
|
1317 | 1317 | $_provider_userstatus['Status'] = $_stat['Status']; |
1318 | 1318 | } else { |
1319 | 1319 | // if no stats then we assume all is well. |
1320 | 1320 | $_provider_userstatus['Status'] = 2; |
1321 | 1321 | } |
1322 | - if ( array_key_exists( 'timestamp', $_stat ) ) { |
|
1322 | + if (array_key_exists('timestamp', $_stat)) { |
|
1323 | 1323 | $_provider_userstatus['timestamp'] = $_stat['timestamp']; |
1324 | 1324 | } else { |
1325 | 1325 | // if no timestamp then we return "". |
@@ -3,7 +3,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 . '&subset=' . $subset_string; |
|
279 | + if (!empty($subset_string)) { |
|
280 | + $subset_string = str_replace(',', '%2C', ltrim($subset_string, ',')); |
|
281 | + $fonts_string = $fonts_string.'&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', '&display=swap' ); |
|
286 | + if (strpos($fonts_string, 'display=') === false) { |
|
287 | + $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&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 |
||
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 |
||
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 |
||
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 | } |