@@ -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,156 +218,156 @@ 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="preload" as="style" 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="preload" as="style" 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 | // and insert preload polyfill if "link preload" and if the polyfill isn't there yet (courtesy of inline&defer). |
337 | 337 | $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill(); |
338 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] && strpos( $out, $preload_polyfill ) === false ) { |
|
339 | - $out = str_replace( '</body>', $preload_polyfill . '</body>', $out ); |
|
338 | + if ('5' === $options['autoptimize_extra_radio_field_4'] && strpos($out, $preload_polyfill) === false) { |
|
339 | + $out = str_replace('</body>', $preload_polyfill.'</body>', $out); |
|
340 | 340 | } |
341 | 341 | return $out; |
342 | 342 | } |
343 | 343 | |
344 | - public function filter_preconnect( $hints, $relation_type ) |
|
344 | + public function filter_preconnect($hints, $relation_type) |
|
345 | 345 | { |
346 | 346 | $options = $this->options; |
347 | 347 | $preconns = array(); |
348 | 348 | |
349 | 349 | // Get settings and store in array. |
350 | - if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { |
|
351 | - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) ); |
|
350 | + if (array_key_exists('autoptimize_extra_text_field_2', $options)) { |
|
351 | + $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2']))); |
|
352 | 352 | } |
353 | - $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns ); |
|
353 | + $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns); |
|
354 | 354 | |
355 | 355 | // Walk array, extract domain and add to new array with crossorigin attribute. |
356 | - foreach ( $preconns as $preconn ) { |
|
356 | + foreach ($preconns as $preconn) { |
|
357 | 357 | $domain = ''; |
358 | - $parsed = parse_url( $preconn ); |
|
359 | - if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) { |
|
360 | - $domain = '//' . $parsed['host']; |
|
361 | - } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) { |
|
362 | - $domain = $parsed['scheme'] . '://' . $parsed['host']; |
|
358 | + $parsed = parse_url($preconn); |
|
359 | + if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) { |
|
360 | + $domain = '//'.$parsed['host']; |
|
361 | + } elseif (is_array($parsed) && !empty($parsed['host'])) { |
|
362 | + $domain = $parsed['scheme'].'://'.$parsed['host']; |
|
363 | 363 | } |
364 | 364 | |
365 | - if ( ! empty( $domain ) ) { |
|
366 | - $hint = array( 'href' => $domain ); |
|
365 | + if (!empty($domain)) { |
|
366 | + $hint = array('href' => $domain); |
|
367 | 367 | // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
368 | 368 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed. |
369 | - $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) ); |
|
370 | - if ( in_array( $domain, $crossorigins ) ) { |
|
369 | + $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
370 | + if (in_array($domain, $crossorigins)) { |
|
371 | 371 | $hint['crossorigin'] = 'anonymous'; |
372 | 372 | } |
373 | 373 | $new_hints[] = $hint; |
@@ -375,21 +375,21 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | // Merge in WP's preconnect hints. |
378 | - if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) { |
|
379 | - $hints = array_merge( $hints, $new_hints ); |
|
378 | + if ('preconnect' === $relation_type && !empty($new_hints)) { |
|
379 | + $hints = array_merge($hints, $new_hints); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | return $hints; |
383 | 383 | } |
384 | 384 | |
385 | - public function filter_preconnect_google_fonts( $in ) |
|
385 | + public function filter_preconnect_google_fonts($in) |
|
386 | 386 | { |
387 | - if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) { |
|
387 | + if ('2' !== $this->options['autoptimize_extra_radio_field_4']) { |
|
388 | 388 | // Preconnect to fonts.gstatic.com unless we remove gfonts. |
389 | 389 | $in[] = 'https://fonts.gstatic.com'; |
390 | 390 | } |
391 | 391 | |
392 | - if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) { |
|
392 | + if ('4' === $this->options['autoptimize_extra_radio_field_4']) { |
|
393 | 393 | // Preconnect even more hosts for webfont.js! |
394 | 394 | $in[] = 'https://ajax.googleapis.com'; |
395 | 395 | $in[] = 'https://fonts.googleapis.com'; |
@@ -398,76 +398,76 @@ discard block |
||
398 | 398 | return $in; |
399 | 399 | } |
400 | 400 | |
401 | - public function filter_preload( $in ) { |
|
401 | + public function filter_preload($in) { |
|
402 | 402 | // make array from comma separated list. |
403 | 403 | $options = $this->options; |
404 | 404 | $preloads = array(); |
405 | - if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { |
|
406 | - $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) ); |
|
405 | + if (array_key_exists('autoptimize_extra_text_field_7', $options)) { |
|
406 | + $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7']))); |
|
407 | 407 | } |
408 | - $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads ); |
|
408 | + $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads); |
|
409 | 409 | |
410 | 410 | // immediately return if nothing to be preloaded. |
411 | - if ( empty( $preloads ) ) { |
|
411 | + if (empty($preloads)) { |
|
412 | 412 | return $in; |
413 | 413 | } |
414 | 414 | |
415 | 415 | // iterate through array and add preload link to tmp string. |
416 | 416 | $preload_output = ''; |
417 | - foreach ( $preloads as $preload ) { |
|
417 | + foreach ($preloads as $preload) { |
|
418 | 418 | $crossorigin = ''; |
419 | 419 | $preload_as = ''; |
420 | 420 | $mime_type = ''; |
421 | - $_preload = strtok( $preload, '?' ); |
|
421 | + $_preload = strtok($preload, '?'); |
|
422 | 422 | |
423 | - if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) { |
|
423 | + if (autoptimizeUtils::str_ends_in($_preload, '.css')) { |
|
424 | 424 | $preload_as = 'style'; |
425 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) { |
|
425 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) { |
|
426 | 426 | $preload_as = 'script'; |
427 | - } 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' ) ) { |
|
427 | + } 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')) { |
|
428 | 428 | $preload_as = 'font'; |
429 | 429 | $crossorigin = ' crossorigin'; |
430 | - $mime_type = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"'; |
|
431 | - if ( ' type="font/eot"' === $mime_type ) { |
|
430 | + $mime_type = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"'; |
|
431 | + if (' type="font/eot"' === $mime_type) { |
|
432 | 432 | $mime_type = 'application/vnd.ms-fontobject'; |
433 | 433 | } |
434 | - } 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' ) ) { |
|
434 | + } 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')) { |
|
435 | 435 | $preload_as = 'image'; |
436 | 436 | } else { |
437 | 437 | $preload_as = 'other'; |
438 | 438 | } |
439 | 439 | |
440 | - $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>'; |
|
440 | + $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>'; |
|
441 | 441 | } |
442 | - $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output ); |
|
442 | + $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output); |
|
443 | 443 | |
444 | 444 | // add string to head (before first link node by default). |
445 | - $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' ); |
|
446 | - $position = autoptimizeUtils::strpos( $in, $preload_inject ); |
|
445 | + $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link'); |
|
446 | + $position = autoptimizeUtils::strpos($in, $preload_inject); |
|
447 | 447 | |
448 | - return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) ); |
|
448 | + return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject)); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | public function admin_menu() |
452 | 452 | { |
453 | 453 | // no acces if multisite and not network admin and no site config allowed. |
454 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
454 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
455 | 455 | add_submenu_page( |
456 | 456 | null, |
457 | 457 | 'autoptimize_extra', |
458 | 458 | 'autoptimize_extra', |
459 | 459 | 'manage_options', |
460 | 460 | 'autoptimize_extra', |
461 | - array( $this, 'options_page' ) |
|
461 | + array($this, 'options_page') |
|
462 | 462 | ); |
463 | 463 | } |
464 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
464 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
465 | 465 | } |
466 | 466 | |
467 | - public function add_extra_tab( $in ) |
|
467 | + public function add_extra_tab($in) |
|
468 | 468 | { |
469 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
470 | - $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) ); |
|
469 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
470 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | return $in; |
@@ -487,97 +487,97 @@ discard block |
||
487 | 487 | #ao_settings_form .form-table th {font-weight: normal;} |
488 | 488 | #autoptimize_extra_descr{font-size: 120%;} |
489 | 489 | </style> |
490 | - <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script> |
|
490 | + <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script> |
|
491 | 491 | <div class="wrap"> |
492 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
492 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
493 | 493 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
494 | - <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?> |
|
494 | + <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?> |
|
495 | 495 | <div class="notice-warning notice"><p> |
496 | - <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?> |
|
496 | + <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?> |
|
497 | 497 | </p></div> |
498 | 498 | <?php } ?> |
499 | 499 | |
500 | - <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'> |
|
501 | - <?php settings_fields( 'autoptimize_extra_settings' ); ?> |
|
502 | - <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2> |
|
503 | - <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span> |
|
500 | + <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'> |
|
501 | + <?php settings_fields('autoptimize_extra_settings'); ?> |
|
502 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
503 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
504 | 504 | <table class="form-table"> |
505 | 505 | <tr> |
506 | - <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th> |
|
506 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
507 | 507 | <td> |
508 | - <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/> |
|
509 | - <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/> |
|
508 | + <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/> |
|
509 | + <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/> |
|
510 | 510 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
511 | - <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/> |
|
511 | + <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/> |
|
512 | 512 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
513 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
514 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php _e( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ); ?><br/> |
|
513 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php echo __('Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
514 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize'); ?><br/> |
|
515 | 515 | </td> |
516 | 516 | </tr> |
517 | 517 | <tr> |
518 | - <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th> |
|
518 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
519 | 519 | <td> |
520 | - <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> |
|
520 | + <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> |
|
521 | 521 | </td> |
522 | 522 | </tr> |
523 | 523 | <tr> |
524 | - <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th> |
|
524 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
525 | 525 | <td> |
526 | - <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> |
|
526 | + <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> |
|
527 | 527 | </td> |
528 | 528 | </tr> |
529 | 529 | <tr> |
530 | - <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
530 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
531 | 531 | <td> |
532 | - <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> |
|
532 | + <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> |
|
533 | 533 | </td> |
534 | 534 | </tr> |
535 | 535 | <tr> |
536 | - <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
536 | + <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
537 | 537 | <td> |
538 | - <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> |
|
538 | + <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> |
|
539 | 539 | </td> |
540 | 540 | </tr> |
541 | 541 | <tr> |
542 | - <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
542 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
543 | 543 | <td> |
544 | 544 | <?php |
545 | - if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) { |
|
545 | + if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) { |
|
546 | 546 | // translators: link points Async Javascript settings page. |
547 | - 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>' ); |
|
547 | + 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>'); |
|
548 | 548 | } else { |
549 | 549 | ?> |
550 | - <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'] ); } ?>'> |
|
550 | + <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']); } ?>'> |
|
551 | 551 | <br /> |
552 | 552 | <?php |
553 | - _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' ); |
|
553 | + _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'); |
|
554 | 554 | // translators: %s will be replaced by a link to the "async javascript" plugin. |
555 | - 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>"' ); |
|
556 | - $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
557 | - echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
555 | + 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>"'); |
|
556 | + $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
557 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
558 | 558 | } |
559 | 559 | ?> |
560 | 560 | </td> |
561 | 561 | </tr> |
562 | 562 | <tr> |
563 | - <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th> |
|
563 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
564 | 564 | <td> |
565 | 565 | <?php |
566 | - if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) { |
|
567 | - _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' ); |
|
566 | + if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
567 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
568 | 568 | $lyte_config_url = 'options-general.php?page=lyte_settings_page'; |
569 | - echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) ); |
|
569 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
570 | 570 | } else { |
571 | 571 | // translators: %s will be replaced by a link to "wp youtube lyte" plugin. |
572 | - 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>' ); |
|
573 | - $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term'; |
|
574 | - echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
572 | + 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>'); |
|
573 | + $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term'; |
|
574 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
575 | 575 | } |
576 | 576 | ?> |
577 | 577 | </td> |
578 | 578 | </tr> |
579 | 579 | </table> |
580 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
580 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
581 | 581 | </form> |
582 | 582 | <?php |
583 | 583 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Critical CSS base file (initializes all ccss files). |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | public function __construct() |
20 | 20 | { |
21 | 21 | // define constant, but only once. |
22 | - if ( ! defined( 'AO_CCSS_DIR' ) ) { |
|
22 | + if (!defined('AO_CCSS_DIR')) { |
|
23 | 23 | // Define plugin version. |
24 | - define( 'AO_CCSS_VER', 'AO_' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
24 | + define('AO_CCSS_VER', 'AO_'.AUTOPTIMIZE_PLUGIN_VERSION); |
|
25 | 25 | |
26 | 26 | // Define a constant with the directory to store critical CSS in. |
27 | - if ( is_multisite() ) { |
|
27 | + if (is_multisite()) { |
|
28 | 28 | $blog_id = get_current_blog_id(); |
29 | - define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' . $blog_id . '/' ); |
|
29 | + define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'.$blog_id.'/'); |
|
30 | 30 | } else { |
31 | - define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' ); |
|
31 | + define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Define support files locations. |
35 | - define( 'AO_CCSS_LOCK', AO_CCSS_DIR . 'queue.lock' ); |
|
36 | - define( 'AO_CCSS_LOG', AO_CCSS_DIR . 'queuelog.html' ); |
|
37 | - define( 'AO_CCSS_DEBUG', AO_CCSS_DIR . 'queue.json' ); |
|
35 | + define('AO_CCSS_LOCK', AO_CCSS_DIR.'queue.lock'); |
|
36 | + define('AO_CCSS_LOG', AO_CCSS_DIR.'queuelog.html'); |
|
37 | + define('AO_CCSS_DEBUG', AO_CCSS_DIR.'queue.json'); |
|
38 | 38 | |
39 | 39 | // Define constants for criticalcss.com base path and API endpoints. |
40 | 40 | // fixme: AO_CCSS_URL should be read from the autoptimize availability json stored as option. |
41 | - define( 'AO_CCSS_URL', 'https://criticalcss.com' ); |
|
42 | - define( 'AO_CCSS_API', AO_CCSS_URL . '/api/premium/' ); |
|
43 | - define( 'AO_CCSS_SLEEP', 10 ); |
|
41 | + define('AO_CCSS_URL', 'https://criticalcss.com'); |
|
42 | + define('AO_CCSS_API', AO_CCSS_URL.'/api/premium/'); |
|
43 | + define('AO_CCSS_SLEEP', 10); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $this->filepath = __FILE__; |
@@ -53,19 +53,19 @@ discard block |
||
53 | 53 | { |
54 | 54 | // get all options. |
55 | 55 | $all_options = $this->fetch_options(); |
56 | - foreach ( $all_options as $option => $value ) { |
|
56 | + foreach ($all_options as $option => $value) { |
|
57 | 57 | ${$option} = $value; |
58 | 58 | } |
59 | 59 | |
60 | 60 | // make sure the 10 minutes cron schedule is added. |
61 | - add_filter( 'cron_schedules', array( $this, 'ao_ccss_interval' ) ); |
|
61 | + add_filter('cron_schedules', array($this, 'ao_ccss_interval')); |
|
62 | 62 | |
63 | 63 | // check if we need to upgrade. |
64 | 64 | $this->check_upgrade(); |
65 | 65 | |
66 | 66 | // make sure ao_ccss_queue is scheduled OK if an API key is set. |
67 | - if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) { |
|
68 | - wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' ); |
|
67 | + if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) { |
|
68 | + wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue'); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | // Required libs, core is always needed. |
74 | 74 | $criticalcss_core = new autoptimizeCriticalCSSCore(); |
75 | 75 | |
76 | - if ( defined( 'DOING_CRON' ) || is_admin() ) { |
|
76 | + if (defined('DOING_CRON') || is_admin()) { |
|
77 | 77 | // TODO: also include if overridden somehow to force queue processing to be executed? |
78 | 78 | $criticalcss_cron = new autoptimizeCriticalCSSCron(); |
79 | 79 | } |
80 | 80 | |
81 | - if ( is_admin() ) { |
|
81 | + if (is_admin()) { |
|
82 | 82 | $criticalcss_settings = new autoptimizeCriticalCSSSettings(); |
83 | 83 | } else { |
84 | 84 | // enqueuing only done when not wp-admin. |
@@ -89,50 +89,50 @@ discard block |
||
89 | 89 | public static function fetch_options() { |
90 | 90 | static $autoptimize_ccss_options = null; |
91 | 91 | |
92 | - if ( null === $autoptimize_ccss_options ) { |
|
92 | + if (null === $autoptimize_ccss_options) { |
|
93 | 93 | // not cached yet, fetching from WordPress options. |
94 | - $autoptimize_ccss_options['ao_css_defer'] = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ); |
|
95 | - $autoptimize_ccss_options['ao_css_defer_inline'] = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); |
|
96 | - $autoptimize_ccss_options['ao_ccss_rules_raw'] = get_option( 'autoptimize_ccss_rules', false ); |
|
97 | - $autoptimize_ccss_options['ao_ccss_additional'] = get_option( 'autoptimize_ccss_additional' ); |
|
98 | - $autoptimize_ccss_options['ao_ccss_queue_raw'] = get_option( 'autoptimize_ccss_queue', false ); |
|
99 | - $autoptimize_ccss_options['ao_ccss_viewport'] = get_option( 'autoptimize_ccss_viewport', false ); |
|
100 | - $autoptimize_ccss_options['ao_ccss_finclude'] = get_option( 'autoptimize_ccss_finclude', false ); |
|
101 | - $autoptimize_ccss_options['ao_ccss_rlimit'] = get_option( 'autoptimize_ccss_rlimit', '5' ); |
|
102 | - $autoptimize_ccss_options['ao_ccss_noptimize'] = get_option( 'autoptimize_ccss_noptimize', false ); |
|
103 | - $autoptimize_ccss_options['ao_ccss_debug'] = get_option( 'autoptimize_ccss_debug', false ); |
|
104 | - $autoptimize_ccss_options['ao_ccss_key'] = get_option( 'autoptimize_ccss_key' ); |
|
105 | - $autoptimize_ccss_options['ao_ccss_keyst'] = get_option( 'autoptimize_ccss_keyst' ); |
|
106 | - $autoptimize_ccss_options['ao_ccss_loggedin'] = get_option( 'autoptimize_ccss_loggedin', '1' ); |
|
107 | - $autoptimize_ccss_options['ao_ccss_forcepath'] = get_option( 'autoptimize_ccss_forcepath', '1' ); |
|
108 | - $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' ); |
|
109 | - $autoptimize_ccss_options['ao_ccss_deferjquery'] = get_option( 'autoptimize_ccss_deferjquery', false ); |
|
110 | - $autoptimize_ccss_options['ao_ccss_domain'] = get_option( 'autoptimize_ccss_domain' ); |
|
111 | - |
|
112 | - if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) { |
|
113 | - $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ); |
|
114 | - } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) { |
|
94 | + $autoptimize_ccss_options['ao_css_defer'] = autoptimizeOptionWrapper::get_option('autoptimize_css_defer'); |
|
95 | + $autoptimize_ccss_options['ao_css_defer_inline'] = autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); |
|
96 | + $autoptimize_ccss_options['ao_ccss_rules_raw'] = get_option('autoptimize_ccss_rules', false); |
|
97 | + $autoptimize_ccss_options['ao_ccss_additional'] = get_option('autoptimize_ccss_additional'); |
|
98 | + $autoptimize_ccss_options['ao_ccss_queue_raw'] = get_option('autoptimize_ccss_queue', false); |
|
99 | + $autoptimize_ccss_options['ao_ccss_viewport'] = get_option('autoptimize_ccss_viewport', false); |
|
100 | + $autoptimize_ccss_options['ao_ccss_finclude'] = get_option('autoptimize_ccss_finclude', false); |
|
101 | + $autoptimize_ccss_options['ao_ccss_rlimit'] = get_option('autoptimize_ccss_rlimit', '5'); |
|
102 | + $autoptimize_ccss_options['ao_ccss_noptimize'] = get_option('autoptimize_ccss_noptimize', false); |
|
103 | + $autoptimize_ccss_options['ao_ccss_debug'] = get_option('autoptimize_ccss_debug', false); |
|
104 | + $autoptimize_ccss_options['ao_ccss_key'] = get_option('autoptimize_ccss_key'); |
|
105 | + $autoptimize_ccss_options['ao_ccss_keyst'] = get_option('autoptimize_ccss_keyst'); |
|
106 | + $autoptimize_ccss_options['ao_ccss_loggedin'] = get_option('autoptimize_ccss_loggedin', '1'); |
|
107 | + $autoptimize_ccss_options['ao_ccss_forcepath'] = get_option('autoptimize_ccss_forcepath', '1'); |
|
108 | + $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option('autoptimize_service_availablity'); |
|
109 | + $autoptimize_ccss_options['ao_ccss_deferjquery'] = get_option('autoptimize_ccss_deferjquery', false); |
|
110 | + $autoptimize_ccss_options['ao_ccss_domain'] = get_option('autoptimize_ccss_domain'); |
|
111 | + |
|
112 | + if (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') === false && strpos($autoptimize_ccss_options['ao_ccss_domain'], 'uggc') === 0) { |
|
113 | + $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13($autoptimize_ccss_options['ao_ccss_domain']); |
|
114 | + } elseif (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') !== false) { |
|
115 | 115 | // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain). |
116 | - update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) ); |
|
116 | + update_option('autoptimize_ccss_domain', str_rot13($autoptimize_ccss_options['ao_ccss_domain'])); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Setup the rules array. |
120 | - if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) { |
|
120 | + if (empty($autoptimize_ccss_options['ao_ccss_rules_raw'])) { |
|
121 | 121 | $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array(); |
122 | 122 | $autoptimize_ccss_options['ao_ccss_rules']['types'] = array(); |
123 | 123 | } else { |
124 | - $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true ); |
|
124 | + $autoptimize_ccss_options['ao_ccss_rules'] = json_decode($autoptimize_ccss_options['ao_ccss_rules_raw'], true); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // Setup the queue array. |
128 | - if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) { |
|
128 | + if (empty($autoptimize_ccss_options['ao_ccss_queue_raw'])) { |
|
129 | 129 | $autoptimize_ccss_options['ao_ccss_queue'] = array(); |
130 | 130 | } else { |
131 | - $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true ); |
|
131 | + $autoptimize_ccss_options['ao_ccss_queue'] = json_decode($autoptimize_ccss_options['ao_ccss_queue_raw'], true); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Override API key if constant is defined. |
135 | - if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) { |
|
135 | + if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) { |
|
136 | 136 | $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY; |
137 | 137 | } |
138 | 138 | } |
@@ -144,49 +144,49 @@ discard block |
||
144 | 144 | global $ao_ccss_key; |
145 | 145 | |
146 | 146 | // Create the cache directory if it doesn't exist already. |
147 | - if ( ! file_exists( AO_CCSS_DIR ) ) { |
|
148 | - mkdir( AO_CCSS_DIR, 0755, true ); |
|
147 | + if (!file_exists(AO_CCSS_DIR)) { |
|
148 | + mkdir(AO_CCSS_DIR, 0755, true); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // Create a scheduled event for the queue. |
152 | - if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) { |
|
153 | - wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' ); |
|
152 | + if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) { |
|
153 | + wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // Create a scheduled event for log maintenance. |
157 | - if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) { |
|
158 | - wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' ); |
|
157 | + if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_maintenance')) { |
|
158 | + wp_schedule_event(time(), 'twicedaily', 'ao_ccss_maintenance'); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | 162 | public function check_upgrade() { |
163 | - $db_version = get_option( 'autoptimize_ccss_version', '' ); |
|
164 | - if ( AO_CCSS_VER !== $db_version ) { |
|
163 | + $db_version = get_option('autoptimize_ccss_version', ''); |
|
164 | + if (AO_CCSS_VER !== $db_version) { |
|
165 | 165 | // check schedules & re-schedule if needed. |
166 | 166 | $this->on_upgrade(); |
167 | 167 | // and update db_version. |
168 | - update_option( 'autoptimize_ccss_version', AO_CCSS_VER ); |
|
168 | + update_option('autoptimize_ccss_version', AO_CCSS_VER); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - public function ao_ccss_interval( $schedules ) { |
|
172 | + public function ao_ccss_interval($schedules) { |
|
173 | 173 | // Let interval be configurable. |
174 | - if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) { |
|
174 | + if (!defined('AO_CCSS_DEBUG_INTERVAL')) { |
|
175 | 175 | $intsec = 600; |
176 | 176 | } else { |
177 | 177 | $intsec = AO_CCSS_DEBUG_INTERVAL; |
178 | - if ( $intsec >= 120 ) { |
|
179 | - $inttxt = $intsec / 60 . ' minutes'; |
|
178 | + if ($intsec >= 120) { |
|
179 | + $inttxt = $intsec/60.' minutes'; |
|
180 | 180 | } else { |
181 | - $inttxt = $intsec . ' second(s)'; |
|
181 | + $inttxt = $intsec.' second(s)'; |
|
182 | 182 | } |
183 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 ); |
|
183 | + autoptimizeCriticalCSSCore::ao_ccss_log('Using custom WP-Cron interval of '.$inttxt, 3); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Attach interval to schedule. |
187 | 187 | $schedules['ao_ccss'] = array( |
188 | 188 | 'interval' => $intsec, |
189 | - 'display' => __( 'Autoptimize CriticalCSS' ), |
|
189 | + 'display' => __('Autoptimize CriticalCSS'), |
|
190 | 190 | ); |
191 | 191 | return $schedules; |
192 | 192 | } |
@@ -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>"; |