@@ -1,18 +1,18 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | // initialize |
5 | -if ( is_admin() ) { |
|
6 | - add_action( 'admin_menu', 'autoptimize_extra_admin' ); |
|
7 | - add_filter( 'autoptimize_filter_settingsscreen_tabs','add_autoptimize_extra_tab' ); |
|
5 | +if (is_admin()) { |
|
6 | + add_action('admin_menu', 'autoptimize_extra_admin'); |
|
7 | + add_filter('autoptimize_filter_settingsscreen_tabs', 'add_autoptimize_extra_tab'); |
|
8 | 8 | } else { |
9 | 9 | autoptimize_extra_init(); |
10 | 10 | } |
11 | 11 | |
12 | 12 | // get option |
13 | 13 | function autoptimize_extra_get_options() { |
14 | - $_default_val = array("autoptimize_extra_checkbox_field_1"=>"0","autoptimize_extra_checkbox_field_0"=>"0","autoptimize_extra_radio_field_4"=>"1","autoptimize_extra_text_field_2"=>"","autoptimize_extra_text_field_3"=>""); |
|
15 | - $_option_val = get_option( 'autoptimize_extra_settings' ); |
|
14 | + $_default_val = array("autoptimize_extra_checkbox_field_1"=>"0", "autoptimize_extra_checkbox_field_0"=>"0", "autoptimize_extra_radio_field_4"=>"1", "autoptimize_extra_text_field_2"=>"", "autoptimize_extra_text_field_3"=>""); |
|
15 | + $_option_val = get_option('autoptimize_extra_settings'); |
|
16 | 16 | if (empty($_option_val)) { |
17 | 17 | $_option_val = $_default_val; |
18 | 18 | } |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
25 | 25 | |
26 | 26 | /* disable emojis */ |
27 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) ) { |
|
27 | + if (!empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_1'])) { |
|
28 | 28 | autoptimize_extra_disable_emojis(); |
29 | 29 | } |
30 | 30 | |
31 | 31 | /* remove version from query string */ |
32 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) ) { |
|
33 | - add_filter( 'script_loader_src', 'autoptimize_extra_remove_qs', 15, 1 ); |
|
34 | - add_filter( 'style_loader_src', 'autoptimize_extra_remove_qs', 15, 1 ); |
|
32 | + if (!empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_0'])) { |
|
33 | + add_filter('script_loader_src', 'autoptimize_extra_remove_qs', 15, 1); |
|
34 | + add_filter('style_loader_src', 'autoptimize_extra_remove_qs', 15, 1); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /* |
@@ -41,68 +41,68 @@ discard block |
||
41 | 41 | * cfr. https://codex.wordpress.org/Function_Reference/is_plugin_active |
42 | 42 | * so we need to source in wp-admin/includes/plugin.php |
43 | 43 | */ |
44 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
44 | + include_once(ABSPATH.'wp-admin/includes/plugin.php'); |
|
45 | 45 | $_asyncJSactive = false; |
46 | - if ( function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php') ) { |
|
46 | + if (function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php')) { |
|
47 | 47 | $_asyncJSactive = true; |
48 | 48 | } |
49 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_text_field_3']) && $_asyncJSactive === false ) { |
|
50 | - add_filter('autoptimize_filter_js_exclude','autoptimize_extra_async_js',10,1); |
|
49 | + if (!empty($autoptimize_extra_options['autoptimize_extra_text_field_3']) && $_asyncJSactive === false) { |
|
50 | + add_filter('autoptimize_filter_js_exclude', 'autoptimize_extra_async_js', 10, 1); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /* optimize google fonts */ |
54 | - if ( !empty( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] ) && ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1" ) ) { |
|
55 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_gfonts_remove_dnsprefetch', 10, 2 ); |
|
56 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2" ) { |
|
57 | - add_filter('autoptimize_filter_css_removables','autoptimize_extra_remove_gfonts',10,1); |
|
54 | + if (!empty($autoptimize_extra_options['autoptimize_extra_radio_field_4']) && ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1")) { |
|
55 | + add_filter('wp_resource_hints', 'autoptimize_extra_gfonts_remove_dnsprefetch', 10, 2); |
|
56 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2") { |
|
57 | + add_filter('autoptimize_filter_css_removables', 'autoptimize_extra_remove_gfonts', 10, 1); |
|
58 | 58 | } else { |
59 | - add_filter('autoptimize_html_after_minify','autoptimize_extra_gfonts',10,1); |
|
60 | - add_filter('autoptimize_extra_filter_tobepreconn','autoptimize_extra_preconnectgooglefonts',10,1); |
|
59 | + add_filter('autoptimize_html_after_minify', 'autoptimize_extra_gfonts', 10, 1); |
|
60 | + add_filter('autoptimize_extra_filter_tobepreconn', 'autoptimize_extra_preconnectgooglefonts', 10, 1); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | /* preconnect */ |
65 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn') ) { |
|
66 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_preconnect', 10, 2 ); |
|
65 | + if (!empty($autoptimize_extra_options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
66 | + add_filter('wp_resource_hints', 'autoptimize_extra_preconnect', 10, 2); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | 70 | // disable emoji's functions |
71 | 71 | function autoptimize_extra_disable_emojis() { |
72 | 72 | // all actions related to emojis |
73 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
74 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
75 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
76 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
77 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
78 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
79 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
73 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
74 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
75 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
76 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
77 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
78 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
79 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
80 | 80 | |
81 | 81 | // filter to remove TinyMCE emojis |
82 | - add_filter( 'tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce' ); |
|
82 | + add_filter('tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce'); |
|
83 | 83 | |
84 | 84 | // and remove dns-prefetch for emoji |
85 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_emojis_remove_dns_prefetch', 10, 2 ); |
|
85 | + add_filter('wp_resource_hints', 'autoptimize_extra_emojis_remove_dns_prefetch', 10, 2); |
|
86 | 86 | } |
87 | 87 | |
88 | -function autoptimize_extra_disable_emojis_tinymce( $plugins ) { |
|
89 | - if ( is_array( $plugins ) ) { |
|
90 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
88 | +function autoptimize_extra_disable_emojis_tinymce($plugins) { |
|
89 | + if (is_array($plugins)) { |
|
90 | + return array_diff($plugins, array('wpemoji')); |
|
91 | 91 | } else { |
92 | 92 | return array(); |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | -function autoptimize_extra_emojis_remove_dns_prefetch( $urls, $relation_type ) { |
|
97 | - $_emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' ); |
|
96 | +function autoptimize_extra_emojis_remove_dns_prefetch($urls, $relation_type) { |
|
97 | + $_emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/'); |
|
98 | 98 | |
99 | - return autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_emoji_svg_url ); |
|
99 | + return autoptimize_extra_remove_dns_prefetch($urls, $relation_type, $_emoji_svg_url); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | // remove query string function |
103 | -function autoptimize_extra_remove_qs( $src ) { |
|
104 | - if ( strpos($src, '?ver=') ) { |
|
105 | - $src = remove_query_arg( 'ver', $src ); |
|
103 | +function autoptimize_extra_remove_qs($src) { |
|
104 | + if (strpos($src, '?ver=')) { |
|
105 | + $src = remove_query_arg('ver', $src); |
|
106 | 106 | } |
107 | 107 | return $src; |
108 | 108 | } |
@@ -114,19 +114,19 @@ discard block |
||
114 | 114 | // get exclusions |
115 | 115 | $AO_JSexclArrayIn = array(); |
116 | 116 | if (!empty($in)) { |
117 | - $AO_JSexclArrayIn = array_fill_keys(array_filter(array_map('trim',explode(",",$in))),""); |
|
117 | + $AO_JSexclArrayIn = array_fill_keys(array_filter(array_map('trim', explode(",", $in))), ""); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // get asyncs |
121 | 121 | $_fromSetting = $autoptimize_extra_options['autoptimize_extra_text_field_3']; |
122 | - $AO_asynced_JS = array_fill_keys(array_filter(array_map('trim',explode(",",$_fromSetting))),""); |
|
123 | - $AO_async_flag = apply_filters('autoptimize_filter_extra_async',"async"); |
|
122 | + $AO_asynced_JS = array_fill_keys(array_filter(array_map('trim', explode(",", $_fromSetting))), ""); |
|
123 | + $AO_async_flag = apply_filters('autoptimize_filter_extra_async', "async"); |
|
124 | 124 | foreach ($AO_asynced_JS as $JSkey => $JSvalue) { |
125 | 125 | $AO_asynced_JS[$JSkey] = $AO_async_flag; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // merge exclusions & asyncs in one array and return to AO API |
129 | - $AO_excl_w_async = array_merge( $AO_JSexclArrayIn, $AO_asynced_JS ); |
|
129 | + $AO_excl_w_async = array_merge($AO_JSexclArrayIn, $AO_asynced_JS); |
|
130 | 130 | return $AO_excl_w_async; |
131 | 131 | } |
132 | 132 | |
@@ -135,25 +135,25 @@ discard block |
||
135 | 135 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
136 | 136 | |
137 | 137 | // get setting and store in array |
138 | - $_to_be_preconnected = array_filter(array_map('trim',explode(",",$autoptimize_extra_options['autoptimize_extra_text_field_2']))); |
|
139 | - $_to_be_preconnected = apply_filters( 'autoptimize_extra_filter_tobepreconn', $_to_be_preconnected ); |
|
138 | + $_to_be_preconnected = array_filter(array_map('trim', explode(",", $autoptimize_extra_options['autoptimize_extra_text_field_2']))); |
|
139 | + $_to_be_preconnected = apply_filters('autoptimize_extra_filter_tobepreconn', $_to_be_preconnected); |
|
140 | 140 | |
141 | 141 | // walk array, extract domain and add to new array with crossorigin attribute |
142 | 142 | foreach ($_to_be_preconnected as $_preconn_single) { |
143 | 143 | $_preconn_parsed = parse_url($_preconn_single); |
144 | 144 | |
145 | - if ( is_array($_preconn_parsed) && empty($_preconn_parsed['scheme']) ) { |
|
145 | + if (is_array($_preconn_parsed) && empty($_preconn_parsed['scheme'])) { |
|
146 | 146 | $_preconn_domain = "//".$_preconn_parsed['host']; |
147 | - } else if ( is_array($_preconn_parsed) ) { |
|
147 | + } else if (is_array($_preconn_parsed)) { |
|
148 | 148 | $_preconn_domain = $_preconn_parsed['scheme']."://".$_preconn_parsed['host']; |
149 | 149 | } |
150 | 150 | |
151 | - if ( !empty($_preconn_domain) ) { |
|
151 | + if (!empty($_preconn_domain)) { |
|
152 | 152 | $_preconn_hint = array('href' => $_preconn_domain); |
153 | 153 | // fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
154 | 154 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed |
155 | - $_preconn_crossorigin = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com') ); |
|
156 | - if ( in_array( $_preconn_domain, $_preconn_crossorigin ) ) { |
|
155 | + $_preconn_crossorigin = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
156 | + if (in_array($_preconn_domain, $_preconn_crossorigin)) { |
|
157 | 157 | $_preconn_hint['crossorigin'] = 'anonymous'; |
158 | 158 | } |
159 | 159 | $_new_hints[] = $_preconn_hint; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | } |
162 | 162 | |
163 | 163 | // merge in wordpress' preconnect hints |
164 | - if ( 'preconnect' === $relation_type && !empty($_new_hints) ) { |
|
164 | + if ('preconnect' === $relation_type && !empty($_new_hints)) { |
|
165 | 165 | $hints = array_merge($hints, $_new_hints); |
166 | 166 | } |
167 | 167 | |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | // google font functions |
172 | -function autoptimize_extra_gfonts_remove_dnsprefetch ( $urls, $relation_type ) { |
|
172 | +function autoptimize_extra_gfonts_remove_dnsprefetch($urls, $relation_type) { |
|
173 | 173 | $_gfonts_url = "fonts.googleapis.com"; |
174 | 174 | |
175 | - return autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_gfonts_url ); |
|
175 | + return autoptimize_extra_remove_dns_prefetch($urls, $relation_type, $_gfonts_url); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | function autoptimize_extra_remove_gfonts($in) { |
@@ -184,48 +184,48 @@ discard block |
||
184 | 184 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
185 | 185 | |
186 | 186 | // extract fonts, partly based on wp rocket's extraction code |
187 | - $_without_comments = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
188 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $_without_comments, $matches ); |
|
187 | + $_without_comments = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
188 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $_without_comments, $matches); |
|
189 | 189 | |
190 | 190 | $i = 0; |
191 | 191 | $fontsCollection = array(); |
192 | - if ( ! $matches[2] ) { |
|
192 | + if (!$matches[2]) { |
|
193 | 193 | return $in; |
194 | 194 | } |
195 | 195 | |
196 | 196 | // store them in $fonts array |
197 | - foreach ( $matches[2] as $font ) { |
|
198 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
197 | + foreach ($matches[2] as $font) { |
|
198 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
199 | 199 | // Get fonts name. |
200 | - $font = str_replace( array( '%7C', '%7c' ) , '|', $font ); |
|
201 | - $font = explode( 'family=', $font ); |
|
202 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
200 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
201 | + $font = explode('family=', $font); |
|
202 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
203 | 203 | // Add font to $fonts[$i] but make sure not to pollute with an empty family |
204 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
205 | - if ( !empty($_thisfont) ) { |
|
204 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
205 | + if (!empty($_thisfont)) { |
|
206 | 206 | $fontsCollection[$i]["fonts"] = $_thisfont; |
207 | 207 | // And add subset if any |
208 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
209 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
210 | - $subset = explode( 'subset=', $subset ); |
|
211 | - $fontsCollection[$i]["subsets"] = explode( ',', $subset[1] ); |
|
208 | + $subset = (is_array($font)) ? end($font) : ''; |
|
209 | + if (false !== strpos($subset, 'subset=')) { |
|
210 | + $subset = explode('subset=', $subset); |
|
211 | + $fontsCollection[$i]["subsets"] = explode(',', $subset[1]); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | // And remove Google Fonts. |
215 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
215 | + $in = str_replace($matches[0][$i], '', $in); |
|
216 | 216 | } |
217 | 217 | $i++; |
218 | 218 | } |
219 | 219 | |
220 | - $_fontsOut=""; |
|
221 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "3" ) { |
|
220 | + $_fontsOut = ""; |
|
221 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "3") { |
|
222 | 222 | // aggregate & link |
223 | - $_fontsString=""; |
|
224 | - $_subsetString=""; |
|
223 | + $_fontsString = ""; |
|
224 | + $_subsetString = ""; |
|
225 | 225 | foreach ($fontsCollection as $font) { |
226 | - $_fontsString .= '|'.trim( implode( '|' , $font["fonts"] ), '|' ); |
|
227 | - if ( !empty( $font["subsets"] ) ) { |
|
228 | - $_subsetString .= implode( ',', $font["subsets"] ); |
|
226 | + $_fontsString .= '|'.trim(implode('|', $font["fonts"]), '|'); |
|
227 | + if (!empty($font["subsets"])) { |
|
228 | + $_subsetString .= implode(',', $font["subsets"]); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | $_fontsString = $_fontsString."#038;subset=".$_subsetString; |
234 | 234 | } |
235 | 235 | |
236 | - $_fontsString = str_replace( '|', '%7C', ltrim($_fontsString,'|') ); |
|
236 | + $_fontsString = str_replace('|', '%7C', ltrim($_fontsString, '|')); |
|
237 | 237 | |
238 | - if ( ! empty( $_fontsString ) ) { |
|
239 | - $_fontsOut = '<link rel="stylesheet" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $_fontsString . '" />'; |
|
238 | + if (!empty($_fontsString)) { |
|
239 | + $_fontsOut = '<link rel="stylesheet" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$_fontsString.'" />'; |
|
240 | 240 | } |
241 | - } else if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) { |
|
241 | + } else if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4") { |
|
242 | 242 | // aggregate & load async (webfont.js impl.) |
243 | 243 | $_fontsArray = array(); |
244 | 244 | foreach ($fontsCollection as $_fonts) { |
245 | - if ( !empty( $_fonts["subsets"] ) ) { |
|
246 | - $_subset = implode(",",$_fonts["subsets"]); |
|
245 | + if (!empty($_fonts["subsets"])) { |
|
246 | + $_subset = implode(",", $_fonts["subsets"]); |
|
247 | 247 | foreach ($_fonts["fonts"] as $key => $_one_font) { |
248 | 248 | $_one_font = $_one_font.":".$_subset; |
249 | 249 | $_fonts["fonts"][$key] = $_one_font; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | foreach ($_fontsArray as $_font) { |
257 | 257 | $_fontsOut .= $_font."','"; |
258 | 258 | } |
259 | - $_fontsOut = trim(trim($_fontsOut,"'"),","); |
|
259 | + $_fontsOut = trim(trim($_fontsOut, "'"), ","); |
|
260 | 260 | $_fontsOut .= '] },classes:false, events:false, timeout:1500};(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.defer=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
261 | 261 | } |
262 | 262 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | |
271 | 271 | // preconnect to fonts.gstatic.com speed up download of static font-files |
272 | 272 | $in[] = "https://fonts.gstatic.com"; |
273 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) { |
|
273 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4") { |
|
274 | 274 | // and more preconnects for webfont.js |
275 | 275 | $in[] = "https://ajax.googleapis.com"; |
276 | 276 | $in[] = "https://fonts.googleapis.com"; |
@@ -278,11 +278,11 @@ discard block |
||
278 | 278 | return $in; |
279 | 279 | } |
280 | 280 | |
281 | -function autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_remove_url ) { |
|
282 | - if ( 'dns-prefetch' == $relation_type ) { |
|
283 | - $_count=0; |
|
281 | +function autoptimize_extra_remove_dns_prefetch($urls, $relation_type, $_remove_url) { |
|
282 | + if ('dns-prefetch' == $relation_type) { |
|
283 | + $_count = 0; |
|
284 | 284 | foreach ($urls as $_url) { |
285 | - if ( strpos($_url, $_remove_url) !== false ) { |
|
285 | + if (strpos($_url, $_remove_url) !== false) { |
|
286 | 286 | unset($urls[$_count]); |
287 | 287 | } |
288 | 288 | $_count++; |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | |
295 | 295 | /* admin page functions */ |
296 | 296 | function autoptimize_extra_admin() { |
297 | - add_submenu_page( null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page' ); |
|
298 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
297 | + add_submenu_page(null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page'); |
|
298 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | function add_autoptimize_extra_tab($in) { |
302 | - $in=array_merge($in,array('autoptimize_extra' => __('Extra','autoptimize'))); |
|
302 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
303 | 303 | return $in; |
304 | 304 | } |
305 | 305 | |
@@ -313,74 +313,74 @@ discard block |
||
313 | 313 | #autoptimize_extra_descr{font-size: 120%;} |
314 | 314 | </style> |
315 | 315 | <div class="wrap"> |
316 | - <h1><?php _e('Autoptimize Settings','autoptimize'); ?></h1> |
|
316 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
317 | 317 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
318 | 318 | <form id='ao_settings_form' action='options.php' method='post'> |
319 | 319 | <?php settings_fields('autoptimize_extra_settings'); ?> |
320 | - <h2><?php _e('Extra Auto-Optimizations','autoptimize'); ?></h2> |
|
321 | - <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.','autoptimize'); ?></span> |
|
320 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
321 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
322 | 322 | <table class="form-table"> |
323 | 323 | <tr> |
324 | - <th scope="row"><?php _e('Remove emojis','autoptimize'); ?></th> |
|
324 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
325 | 325 | <td> |
326 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) && 1 == $autoptimize_extra_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> |
|
326 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) && 1 == $autoptimize_extra_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> |
|
327 | 327 | </td> |
328 | 328 | </tr> |
329 | 329 | <tr> |
330 | - <th scope="row"><?php _e('Remove query strings from static resources','autoptimize'); ?></th> |
|
330 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
331 | 331 | <td> |
332 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty( $autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) && 1 == $autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) echo 'checked="checked"'; ?> value='1'><?php _e('Removing query strings (or more specificaly the <code>ver</code> parameter) will not improve load time, but might improve performance scores.','autoptimize'); ?></label> |
|
332 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) && 1 == $autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) echo 'checked="checked"'; ?> value='1'><?php _e('Removing query strings (or more specificaly the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label> |
|
333 | 333 | </td> |
334 | 334 | </tr> |
335 | 335 | <tr> |
336 | - <th scope="row"><?php _e('Google Fonts','autoptimize'); ?></th> |
|
336 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
337 | 337 | <td> |
338 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($_googlef,array(2,3,4))) {echo "checked"; } ?> ><?php _e('Leave as is','autoptimize'); ?><br/> |
|
339 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $_googlef, true); ?> ><?php _e('Remove Google Fonts','autoptimize'); ?><br/> |
|
340 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $_googlef, true); ?> ><?php _e('Combine and link in head','autoptimize'); ?><br/> |
|
341 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $_googlef, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>','autoptimize'); ?><br/> |
|
338 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($_googlef, array(2, 3, 4))) {echo "checked"; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/> |
|
339 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $_googlef, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/> |
|
340 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $_googlef, true); ?> ><?php _e('Combine and link in head', 'autoptimize'); ?><br/> |
|
341 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $_googlef, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize'); ?><br/> |
|
342 | 342 | </td> |
343 | 343 | </tr> |
344 | 344 | <tr> |
345 | - <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>','autoptimize'); ?></th> |
|
345 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
346 | 346 | <td> |
347 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php echo $autoptimize_extra_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> |
|
347 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php echo $autoptimize_extra_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> |
|
348 | 348 | </td> |
349 | 349 | </tr> |
350 | 350 | <tr> |
351 | - <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>','autoptimize'); ?></th> |
|
351 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
352 | 352 | <td> |
353 | - <?php if ( function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php') ) { |
|
354 | - _e('You have "Async JavaScript" installed,','autoptimize'); |
|
355 | - $asj_config_url="options-general.php?page=async-javascript"; |
|
356 | - echo sprintf(' <a href="'.$asj_config_url.'">%s</a>', __('configuration of async javascript is best done there.','autoptimize')); |
|
353 | + <?php if (function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php')) { |
|
354 | + _e('You have "Async JavaScript" installed,', 'autoptimize'); |
|
355 | + $asj_config_url = "options-general.php?page=async-javascript"; |
|
356 | + echo sprintf(' <a href="'.$asj_config_url.'">%s</a>', __('configuration of async javascript is best done there.', 'autoptimize')); |
|
357 | 357 | } else { ?> |
358 | 358 | <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php echo $autoptimize_extra_options['autoptimize_extra_text_field_3']; ?>'> |
359 | 359 | <br /> |
360 | 360 | <?php |
361 | - _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'); |
|
362 | - 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>"'); |
|
363 | - $asj_install_url= network_admin_url()."plugin-install.php?s=async+javascript&tab=search&type=term"; |
|
364 | - echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.','autoptimize')); |
|
361 | + _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'); |
|
362 | + 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>"'); |
|
363 | + $asj_install_url = network_admin_url()."plugin-install.php?s=async+javascript&tab=search&type=term"; |
|
364 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
365 | 365 | } ?> |
366 | 366 | </td> |
367 | 367 | </tr> |
368 | 368 | <tr> |
369 | - <th scope="row"><?php _e('Optimize YouTube videos','autoptimize'); ?></th> |
|
369 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
370 | 370 | <td> |
371 | - <?php if ( function_exists('is_plugin_active') && is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php') ) { |
|
372 | - _e('Great, you have WP YouTube Lyte installed.','autoptimize'); |
|
373 | - $lyte_config_url="options-general.php?page=lyte_settings_page"; |
|
374 | - echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.','autoptimize')); |
|
371 | + <?php if (function_exists('is_plugin_active') && is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
372 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
373 | + $lyte_config_url = "options-general.php?page=lyte_settings_page"; |
|
374 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
375 | 375 | } else { |
376 | - 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>'); |
|
377 | - $lyte_install_url= network_admin_url()."plugin-install.php?s=lyte&tab=search&type=term"; |
|
378 | - echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.','autoptimize')); |
|
376 | + 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>'); |
|
377 | + $lyte_install_url = network_admin_url()."plugin-install.php?s=lyte&tab=search&type=term"; |
|
378 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
379 | 379 | } ?> |
380 | 380 | </td> |
381 | 381 | </tr> |
382 | 382 | </table> |
383 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes','autoptimize') ?>" /></p> |
|
383 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize') ?>" /></p> |
|
384 | 384 | </form> |
385 | 385 | <?php |
386 | 386 | } |