@@ -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,78 +24,78 @@ 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 | /* async JS */ |
38 | 38 | $_asyncJSactive = false; |
39 | - if ( function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php') ) { |
|
39 | + if (function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php')) { |
|
40 | 40 | $_asyncJSactive = true; |
41 | 41 | } |
42 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_text_field_3']) && $_asyncJSactive === false ) { |
|
43 | - add_filter('autoptimize_filter_js_exclude','autoptimize_extra_async_js',10,1); |
|
42 | + if (!empty($autoptimize_extra_options['autoptimize_extra_text_field_3']) && $_asyncJSactive === false) { |
|
43 | + add_filter('autoptimize_filter_js_exclude', 'autoptimize_extra_async_js', 10, 1); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /* optimize google fonts */ |
47 | - if ( !empty( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] ) && ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1" ) ) { |
|
48 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_gfonts_remove_dnsprefetch', 10, 2 ); |
|
49 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2" ) { |
|
50 | - add_filter('autoptimize_filter_css_removables','autoptimize_extra_remove_gfonts',10,1); |
|
47 | + if (!empty($autoptimize_extra_options['autoptimize_extra_radio_field_4']) && ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1")) { |
|
48 | + add_filter('wp_resource_hints', 'autoptimize_extra_gfonts_remove_dnsprefetch', 10, 2); |
|
49 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2") { |
|
50 | + add_filter('autoptimize_filter_css_removables', 'autoptimize_extra_remove_gfonts', 10, 1); |
|
51 | 51 | } else { |
52 | - add_filter('autoptimize_html_after_minify','autoptimize_extra_gfonts',10,1); |
|
53 | - add_filter('autoptimize_extra_filter_tobepreconn','autoptimize_extra_preconnectgooglefonts',10,1); |
|
52 | + add_filter('autoptimize_html_after_minify', 'autoptimize_extra_gfonts', 10, 1); |
|
53 | + add_filter('autoptimize_extra_filter_tobepreconn', 'autoptimize_extra_preconnectgooglefonts', 10, 1); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | 57 | /* preconnect */ |
58 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn') ) { |
|
59 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_preconnect', 10, 2 ); |
|
58 | + if (!empty($autoptimize_extra_options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
59 | + add_filter('wp_resource_hints', 'autoptimize_extra_preconnect', 10, 2); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | 63 | // disable emoji's functions |
64 | 64 | function autoptimize_extra_disable_emojis() { |
65 | 65 | // all actions related to emojis |
66 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
67 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
68 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
69 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
70 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
71 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
72 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
66 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
67 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
68 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
69 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
70 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
71 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
72 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
73 | 73 | |
74 | 74 | // filter to remove TinyMCE emojis |
75 | - add_filter( 'tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce' ); |
|
75 | + add_filter('tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce'); |
|
76 | 76 | |
77 | 77 | // and remove dns-prefetch for emoji |
78 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_emojis_remove_dns_prefetch', 10, 2 ); |
|
78 | + add_filter('wp_resource_hints', 'autoptimize_extra_emojis_remove_dns_prefetch', 10, 2); |
|
79 | 79 | } |
80 | 80 | |
81 | -function autoptimize_extra_disable_emojis_tinymce( $plugins ) { |
|
82 | - if ( is_array( $plugins ) ) { |
|
83 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
81 | +function autoptimize_extra_disable_emojis_tinymce($plugins) { |
|
82 | + if (is_array($plugins)) { |
|
83 | + return array_diff($plugins, array('wpemoji')); |
|
84 | 84 | } else { |
85 | 85 | return array(); |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | -function autoptimize_extra_emojis_remove_dns_prefetch( $urls, $relation_type ) { |
|
90 | - $_emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' ); |
|
89 | +function autoptimize_extra_emojis_remove_dns_prefetch($urls, $relation_type) { |
|
90 | + $_emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/'); |
|
91 | 91 | |
92 | - return autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_emoji_svg_url ); |
|
92 | + return autoptimize_extra_remove_dns_prefetch($urls, $relation_type, $_emoji_svg_url); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // remove query string function |
96 | -function autoptimize_extra_remove_qs( $src ) { |
|
97 | - if ( strpos($src, '?ver=') ) { |
|
98 | - $src = remove_query_arg( 'ver', $src ); |
|
96 | +function autoptimize_extra_remove_qs($src) { |
|
97 | + if (strpos($src, '?ver=')) { |
|
98 | + $src = remove_query_arg('ver', $src); |
|
99 | 99 | } |
100 | 100 | return $src; |
101 | 101 | } |
@@ -107,19 +107,19 @@ discard block |
||
107 | 107 | // get exclusions |
108 | 108 | $AO_JSexclArrayIn = array(); |
109 | 109 | if (!empty($in)) { |
110 | - $AO_JSexclArrayIn = array_fill_keys(array_filter(array_map('trim',explode(",",$in))),""); |
|
110 | + $AO_JSexclArrayIn = array_fill_keys(array_filter(array_map('trim', explode(",", $in))), ""); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | // get asyncs |
114 | 114 | $_fromSetting = $autoptimize_extra_options['autoptimize_extra_text_field_3']; |
115 | - $AO_asynced_JS = array_fill_keys(array_filter(array_map('trim',explode(",",$_fromSetting))),""); |
|
116 | - $AO_async_flag = apply_filters('autoptimize_filter_extra_async',"async"); |
|
115 | + $AO_asynced_JS = array_fill_keys(array_filter(array_map('trim', explode(",", $_fromSetting))), ""); |
|
116 | + $AO_async_flag = apply_filters('autoptimize_filter_extra_async', "async"); |
|
117 | 117 | foreach ($AO_asynced_JS as $JSkey => $JSvalue) { |
118 | 118 | $AO_asynced_JS[$JSkey] = $AO_async_flag; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // merge exclusions & asyncs in one array and return to AO API |
122 | - $AO_excl_w_async = array_merge( $AO_JSexclArrayIn, $AO_asynced_JS ); |
|
122 | + $AO_excl_w_async = array_merge($AO_JSexclArrayIn, $AO_asynced_JS); |
|
123 | 123 | return $AO_excl_w_async; |
124 | 124 | } |
125 | 125 | |
@@ -128,25 +128,25 @@ discard block |
||
128 | 128 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
129 | 129 | |
130 | 130 | // get setting and store in array |
131 | - $_to_be_preconnected = array_filter(array_map('trim',explode(",",$autoptimize_extra_options['autoptimize_extra_text_field_2']))); |
|
132 | - $_to_be_preconnected = apply_filters( 'autoptimize_extra_filter_tobepreconn', $_to_be_preconnected ); |
|
131 | + $_to_be_preconnected = array_filter(array_map('trim', explode(",", $autoptimize_extra_options['autoptimize_extra_text_field_2']))); |
|
132 | + $_to_be_preconnected = apply_filters('autoptimize_extra_filter_tobepreconn', $_to_be_preconnected); |
|
133 | 133 | |
134 | 134 | // walk array, extract domain and add to new array with crossorigin attribute |
135 | 135 | foreach ($_to_be_preconnected as $_preconn_single) { |
136 | 136 | $_preconn_parsed = parse_url($_preconn_single); |
137 | 137 | |
138 | - if ( is_array($_preconn_parsed) && empty($_preconn_parsed['scheme']) ) { |
|
138 | + if (is_array($_preconn_parsed) && empty($_preconn_parsed['scheme'])) { |
|
139 | 139 | $_preconn_domain = "//".$_preconn_parsed['host']; |
140 | - } else if ( is_array($_preconn_parsed) ) { |
|
140 | + } else if (is_array($_preconn_parsed)) { |
|
141 | 141 | $_preconn_domain = $_preconn_parsed['scheme']."://".$_preconn_parsed['host']; |
142 | 142 | } |
143 | 143 | |
144 | - if ( !empty($_preconn_domain) ) { |
|
144 | + if (!empty($_preconn_domain)) { |
|
145 | 145 | $_preconn_hint = array('href' => $_preconn_domain); |
146 | 146 | // fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
147 | 147 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed |
148 | - $_preconn_crossorigin = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com') ); |
|
149 | - if ( in_array( $_preconn_domain, $_preconn_crossorigin ) ) { |
|
148 | + $_preconn_crossorigin = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
149 | + if (in_array($_preconn_domain, $_preconn_crossorigin)) { |
|
150 | 150 | $_preconn_hint['crossorigin'] = 'anonymous'; |
151 | 151 | } |
152 | 152 | $_new_hints[] = $_preconn_hint; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | // merge in wordpress' preconnect hints |
157 | - if ( 'preconnect' === $relation_type && !empty($_new_hints) ) { |
|
157 | + if ('preconnect' === $relation_type && !empty($_new_hints)) { |
|
158 | 158 | $hints = array_merge($hints, $_new_hints); |
159 | 159 | } |
160 | 160 | |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | // google font functions |
165 | -function autoptimize_extra_gfonts_remove_dnsprefetch ( $urls, $relation_type ) { |
|
165 | +function autoptimize_extra_gfonts_remove_dnsprefetch($urls, $relation_type) { |
|
166 | 166 | $_gfonts_url = "fonts.googleapis.com"; |
167 | 167 | |
168 | - return autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_gfonts_url ); |
|
168 | + return autoptimize_extra_remove_dns_prefetch($urls, $relation_type, $_gfonts_url); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | function autoptimize_extra_remove_gfonts($in) { |
@@ -177,48 +177,48 @@ discard block |
||
177 | 177 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
178 | 178 | |
179 | 179 | // extract fonts, partly based on wp rocket's extraction code |
180 | - $_without_comments = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
181 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $_without_comments, $matches ); |
|
180 | + $_without_comments = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
181 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $_without_comments, $matches); |
|
182 | 182 | |
183 | 183 | $i = 0; |
184 | 184 | $fontsCollection = array(); |
185 | - if ( ! $matches[2] ) { |
|
185 | + if (!$matches[2]) { |
|
186 | 186 | return $in; |
187 | 187 | } |
188 | 188 | |
189 | 189 | // store them in $fonts array |
190 | - foreach ( $matches[2] as $font ) { |
|
191 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
190 | + foreach ($matches[2] as $font) { |
|
191 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
192 | 192 | // Get fonts name. |
193 | - $font = str_replace( array( '%7C', '%7c' ) , '|', $font ); |
|
194 | - $font = explode( 'family=', $font ); |
|
195 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
193 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
194 | + $font = explode('family=', $font); |
|
195 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
196 | 196 | // Add font to $fonts[$i] but make sure not to pollute with an empty family |
197 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
198 | - if ( !empty($_thisfont) ) { |
|
197 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
198 | + if (!empty($_thisfont)) { |
|
199 | 199 | $fontsCollection[$i]["fonts"] = $_thisfont; |
200 | 200 | // And add subset if any |
201 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
202 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
203 | - $subset = explode( 'subset=', $subset ); |
|
204 | - $fontsCollection[$i]["subsets"] = explode( ',', $subset[1] ); |
|
201 | + $subset = (is_array($font)) ? end($font) : ''; |
|
202 | + if (false !== strpos($subset, 'subset=')) { |
|
203 | + $subset = explode('subset=', $subset); |
|
204 | + $fontsCollection[$i]["subsets"] = explode(',', $subset[1]); |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | // And remove Google Fonts. |
208 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
208 | + $in = str_replace($matches[0][$i], '', $in); |
|
209 | 209 | } |
210 | 210 | $i++; |
211 | 211 | } |
212 | 212 | |
213 | - $_fontsOut=""; |
|
214 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "3" ) { |
|
213 | + $_fontsOut = ""; |
|
214 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "3") { |
|
215 | 215 | // aggregate & link |
216 | - $_fontsString=""; |
|
217 | - $_subsetString=""; |
|
216 | + $_fontsString = ""; |
|
217 | + $_subsetString = ""; |
|
218 | 218 | foreach ($fontsCollection as $font) { |
219 | - $_fontsString .= '|'.trim( implode( '|' , $font["fonts"] ), '|' ); |
|
220 | - if ( !empty( $font["subsets"] ) ) { |
|
221 | - $_subsetString .= implode( ',', $font["subsets"] ); |
|
219 | + $_fontsString .= '|'.trim(implode('|', $font["fonts"]), '|'); |
|
220 | + if (!empty($font["subsets"])) { |
|
221 | + $_subsetString .= implode(',', $font["subsets"]); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
@@ -226,17 +226,17 @@ discard block |
||
226 | 226 | $_fontsString = $_fontsString."#038;subset=".$_subsetString; |
227 | 227 | } |
228 | 228 | |
229 | - $_fontsString = str_replace( '|', '%7C', ltrim($_fontsString,'|') ); |
|
229 | + $_fontsString = str_replace('|', '%7C', ltrim($_fontsString, '|')); |
|
230 | 230 | |
231 | - if ( ! empty( $_fontsString ) ) { |
|
232 | - $_fontsOut = '<link rel="stylesheet" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $_fontsString . '" />'; |
|
231 | + if (!empty($_fontsString)) { |
|
232 | + $_fontsOut = '<link rel="stylesheet" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$_fontsString.'" />'; |
|
233 | 233 | } |
234 | - } else if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) { |
|
234 | + } else if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4") { |
|
235 | 235 | // aggregate & load async (webfont.js impl.) |
236 | 236 | $_fontsArray = array(); |
237 | 237 | foreach ($fontsCollection as $_fonts) { |
238 | - if ( !empty( $_fonts["subsets"] ) ) { |
|
239 | - $_subset = implode(",",$_fonts["subsets"]); |
|
238 | + if (!empty($_fonts["subsets"])) { |
|
239 | + $_subset = implode(",", $_fonts["subsets"]); |
|
240 | 240 | foreach ($_fonts["fonts"] as $key => $_one_font) { |
241 | 241 | $_one_font = $_one_font.":".$_subset; |
242 | 242 | $_fonts["fonts"][$key] = $_one_font; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | foreach ($_fontsArray as $_font) { |
250 | 250 | $_fontsOut .= $_font."','"; |
251 | 251 | } |
252 | - $_fontsOut = trim(trim($_fontsOut,"'"),","); |
|
252 | + $_fontsOut = trim(trim($_fontsOut, "'"), ","); |
|
253 | 253 | $_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>'; |
254 | 254 | } |
255 | 255 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | |
264 | 264 | // preconnect to fonts.gstatic.com speed up download of static font-files |
265 | 265 | $in[] = "https://fonts.gstatic.com"; |
266 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) { |
|
266 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4") { |
|
267 | 267 | // and more preconnects for webfont.js |
268 | 268 | $in[] = "https://ajax.googleapis.com"; |
269 | 269 | $in[] = "https://fonts.googleapis.com"; |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | return $in; |
272 | 272 | } |
273 | 273 | |
274 | -function autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_remove_url ) { |
|
275 | - if ( 'dns-prefetch' == $relation_type ) { |
|
276 | - $_count=0; |
|
274 | +function autoptimize_extra_remove_dns_prefetch($urls, $relation_type, $_remove_url) { |
|
275 | + if ('dns-prefetch' == $relation_type) { |
|
276 | + $_count = 0; |
|
277 | 277 | foreach ($urls as $_url) { |
278 | - if ( strpos($_url, $_remove_url) !== false ) { |
|
278 | + if (strpos($_url, $_remove_url) !== false) { |
|
279 | 279 | unset($urls[$_count]); |
280 | 280 | } |
281 | 281 | $_count++; |
@@ -287,12 +287,12 @@ discard block |
||
287 | 287 | |
288 | 288 | /* admin page functions */ |
289 | 289 | function autoptimize_extra_admin() { |
290 | - add_submenu_page( null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page' ); |
|
291 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
290 | + add_submenu_page(null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page'); |
|
291 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | function add_autoptimize_extra_tab($in) { |
295 | - $in=array_merge($in,array('autoptimize_extra' => __('Extra','autoptimize'))); |
|
295 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
296 | 296 | return $in; |
297 | 297 | } |
298 | 298 | |
@@ -306,74 +306,74 @@ discard block |
||
306 | 306 | #autoptimize_extra_descr{font-size: 120%;} |
307 | 307 | </style> |
308 | 308 | <div class="wrap"> |
309 | - <h1><?php _e('Autoptimize Settings','autoptimize'); ?></h1> |
|
309 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
310 | 310 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
311 | 311 | <form id='ao_settings_form' action='options.php' method='post'> |
312 | 312 | <?php settings_fields('autoptimize_extra_settings'); ?> |
313 | - <h2><?php _e('Extra Auto-Optimizations','autoptimize'); ?></h2> |
|
314 | - <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.','autoptimize'); ?></span> |
|
313 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
314 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
315 | 315 | <table class="form-table"> |
316 | 316 | <tr> |
317 | - <th scope="row"><?php _e('Remove emojis','autoptimize'); ?></th> |
|
317 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
318 | 318 | <td> |
319 | - <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> |
|
319 | + <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> |
|
320 | 320 | </td> |
321 | 321 | </tr> |
322 | 322 | <tr> |
323 | - <th scope="row"><?php _e('Remove query strings from static resources','autoptimize'); ?></th> |
|
323 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
324 | 324 | <td> |
325 | - <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> |
|
325 | + <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> |
|
326 | 326 | </td> |
327 | 327 | </tr> |
328 | 328 | <tr> |
329 | - <th scope="row"><?php _e('Google Fonts','autoptimize'); ?></th> |
|
329 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
330 | 330 | <td> |
331 | - <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/> |
|
332 | - <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/> |
|
333 | - <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/> |
|
334 | - <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/> |
|
331 | + <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/> |
|
332 | + <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/> |
|
333 | + <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/> |
|
334 | + <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/> |
|
335 | 335 | </td> |
336 | 336 | </tr> |
337 | 337 | <tr> |
338 | - <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>','autoptimize'); ?></th> |
|
338 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
339 | 339 | <td> |
340 | - <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> |
|
340 | + <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> |
|
341 | 341 | </td> |
342 | 342 | </tr> |
343 | 343 | <tr> |
344 | - <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>','autoptimize'); ?></th> |
|
344 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
345 | 345 | <td> |
346 | - <?php if ( function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php') ) { |
|
347 | - _e('You have "Async JavaScript" installed,','autoptimize'); |
|
348 | - $asj_config_url="options-general.php?page=async-javascript"; |
|
349 | - echo sprintf(' <a href="'.$asj_config_url.'">%s</a>', __('configuration of async javascript is best done there.','autoptimize')); |
|
346 | + <?php if (function_exists('is_plugin_active') && is_plugin_active('async-javascript/async-javascript.php')) { |
|
347 | + _e('You have "Async JavaScript" installed,', 'autoptimize'); |
|
348 | + $asj_config_url = "options-general.php?page=async-javascript"; |
|
349 | + echo sprintf(' <a href="'.$asj_config_url.'">%s</a>', __('configuration of async javascript is best done there.', 'autoptimize')); |
|
350 | 350 | } else { ?> |
351 | 351 | <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']; ?>'> |
352 | 352 | <br /> |
353 | 353 | <?php |
354 | - _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'); |
|
355 | - 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>"'); |
|
356 | - $asj_install_url= network_admin_url()."plugin-install.php?s=async+javascript&tab=search&type=term"; |
|
357 | - echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.','autoptimize')); |
|
354 | + _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'); |
|
355 | + 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>"'); |
|
356 | + $asj_install_url = network_admin_url()."plugin-install.php?s=async+javascript&tab=search&type=term"; |
|
357 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
358 | 358 | } ?> |
359 | 359 | </td> |
360 | 360 | </tr> |
361 | 361 | <tr> |
362 | - <th scope="row"><?php _e('Optimize YouTube videos','autoptimize'); ?></th> |
|
362 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
363 | 363 | <td> |
364 | - <?php if ( function_exists('is_plugin_active') && is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php') ) { |
|
365 | - _e('Great, you have WP YouTube Lyte installed.','autoptimize'); |
|
366 | - $lyte_config_url="options-general.php?page=lyte_settings_page"; |
|
367 | - echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.','autoptimize')); |
|
364 | + <?php if (function_exists('is_plugin_active') && is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
365 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
366 | + $lyte_config_url = "options-general.php?page=lyte_settings_page"; |
|
367 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
368 | 368 | } else { |
369 | - 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>'); |
|
370 | - $lyte_install_url= network_admin_url()."plugin-install.php?s=lyte&tab=search&type=term"; |
|
371 | - echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.','autoptimize')); |
|
369 | + 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>'); |
|
370 | + $lyte_install_url = network_admin_url()."plugin-install.php?s=lyte&tab=search&type=term"; |
|
371 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
372 | 372 | } ?> |
373 | 373 | </td> |
374 | 374 | </tr> |
375 | 375 | </table> |
376 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes','autoptimize') ?>" /></p> |
|
376 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize') ?>" /></p> |
|
377 | 377 | </form> |
378 | 378 | <?php |
379 | 379 | } |