@@ -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 | } |
@@ -30,58 +30,58 @@ discard block |
||
30 | 30 | |
31 | 31 | /* remove version from query string */ |
32 | 32 | if ($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 ); |
|
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 | if (!empty($autoptimize_extra_options['autoptimize_extra_text_field_3'])) { |
39 | - add_filter('autoptimize_filter_js_exclude','autoptimize_extra_async_js',10,1); |
|
39 | + add_filter('autoptimize_filter_js_exclude', 'autoptimize_extra_async_js', 10, 1); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /* optimize google fonts */ |
43 | - if ( !empty( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] ) && ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1" ) ) { |
|
44 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2" ) { |
|
45 | - add_filter('autoptimize_filter_css_removables','autoptimize_extra_remove_gfonts',10,1); |
|
43 | + if (!empty($autoptimize_extra_options['autoptimize_extra_radio_field_4']) && ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1")) { |
|
44 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2") { |
|
45 | + add_filter('autoptimize_filter_css_removables', 'autoptimize_extra_remove_gfonts', 10, 1); |
|
46 | 46 | } else { |
47 | - add_filter('autoptimize_html_after_minify','autoptimize_extra_gfonts',10,1); |
|
48 | - add_filter('autoptimize_extra_filter_tobepreconn','autoptimize_extra_preconnectgooglefonts',10,1); |
|
47 | + add_filter('autoptimize_html_after_minify', 'autoptimize_extra_gfonts', 10, 1); |
|
48 | + add_filter('autoptimize_extra_filter_tobepreconn', 'autoptimize_extra_preconnectgooglefonts', 10, 1); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | 52 | /* preconnect */ |
53 | - if ( !empty($autoptimize_extra_options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn') ) { |
|
54 | - add_filter( 'wp_resource_hints', 'autoptimize_extra_preconnect', 10, 2 ); |
|
53 | + if (!empty($autoptimize_extra_options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
54 | + add_filter('wp_resource_hints', 'autoptimize_extra_preconnect', 10, 2); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | 58 | // disable emoji's functions |
59 | 59 | function autoptimize_extra_disable_emojis() { |
60 | 60 | // all actions related to emojis |
61 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
62 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
63 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
64 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
65 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
66 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
67 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
61 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
62 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
63 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
64 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
65 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
66 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
67 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
68 | 68 | |
69 | 69 | // filter to remove TinyMCE emojis |
70 | - add_filter( 'tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce' ); |
|
70 | + add_filter('tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce'); |
|
71 | 71 | } |
72 | 72 | |
73 | -function autoptimize_extra_disable_emojis_tinymce( $plugins ) { |
|
74 | - if ( is_array( $plugins ) ) { |
|
75 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
73 | +function autoptimize_extra_disable_emojis_tinymce($plugins) { |
|
74 | + if (is_array($plugins)) { |
|
75 | + return array_diff($plugins, array('wpemoji')); |
|
76 | 76 | } else { |
77 | 77 | return array(); |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | // remove query string function |
82 | -function autoptimize_extra_remove_qs( $src ) { |
|
83 | - if ( strpos($src, '?ver=') ) { |
|
84 | - $src = remove_query_arg( 'ver', $src ); |
|
82 | +function autoptimize_extra_remove_qs($src) { |
|
83 | + if (strpos($src, '?ver=')) { |
|
84 | + $src = remove_query_arg('ver', $src); |
|
85 | 85 | } |
86 | 86 | return $src; |
87 | 87 | } |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | // get exclusions |
94 | 94 | $AO_JSexclArrayIn = array(); |
95 | 95 | if (!empty($in)) { |
96 | - $AO_JSexclArrayIn = array_fill_keys(array_filter(array_map('trim',explode(",",$in))),""); |
|
96 | + $AO_JSexclArrayIn = array_fill_keys(array_filter(array_map('trim', explode(",", $in))), ""); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // get asyncs |
100 | 100 | $_fromSetting = $autoptimize_extra_options['autoptimize_extra_text_field_3']; |
101 | - $AO_asynced_JS = array_fill_keys(array_filter(array_map('trim',explode(",",$_fromSetting))),""); |
|
101 | + $AO_asynced_JS = array_fill_keys(array_filter(array_map('trim', explode(",", $_fromSetting))), ""); |
|
102 | 102 | foreach ($AO_asynced_JS as $JSkey => $JSvalue) { |
103 | 103 | $AO_asynced_JS[$JSkey] = "async"; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // merge exclusions & asyncs in one array and return to AO API |
107 | - $AO_excl_w_async = array_merge( $AO_JSexclArrayIn, $AO_asynced_JS ); |
|
107 | + $AO_excl_w_async = array_merge($AO_JSexclArrayIn, $AO_asynced_JS); |
|
108 | 108 | return $AO_excl_w_async; |
109 | 109 | } |
110 | 110 | |
@@ -113,25 +113,25 @@ discard block |
||
113 | 113 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
114 | 114 | |
115 | 115 | // get setting and store in array |
116 | - $_to_be_preconnected = array_filter(array_map('trim',explode(",",$autoptimize_extra_options['autoptimize_extra_text_field_2']))); |
|
117 | - $_to_be_preconnected = apply_filters( 'autoptimize_extra_filter_tobepreconn', $_to_be_preconnected ); |
|
116 | + $_to_be_preconnected = array_filter(array_map('trim', explode(",", $autoptimize_extra_options['autoptimize_extra_text_field_2']))); |
|
117 | + $_to_be_preconnected = apply_filters('autoptimize_extra_filter_tobepreconn', $_to_be_preconnected); |
|
118 | 118 | |
119 | 119 | // walk array, extract domain and add to new array with crossorigin attribute |
120 | 120 | foreach ($_to_be_preconnected as $_preconn_single) { |
121 | 121 | $_preconn_parsed = parse_url($_preconn_single); |
122 | 122 | |
123 | - if ( is_array($_preconn_parsed) && empty($_preconn_parsed['scheme']) ) { |
|
123 | + if (is_array($_preconn_parsed) && empty($_preconn_parsed['scheme'])) { |
|
124 | 124 | $_preconn_domain = "//".$_preconn_parsed['host']; |
125 | - } else if ( is_array($_preconn_parsed) ) { |
|
125 | + } else if (is_array($_preconn_parsed)) { |
|
126 | 126 | $_preconn_domain = $_preconn_parsed['scheme']."://".$_preconn_parsed['host']; |
127 | 127 | } |
128 | 128 | |
129 | - if ( !empty($_preconn_domain) ) { |
|
129 | + if (!empty($_preconn_domain)) { |
|
130 | 130 | $_preconn_hint = array('href' => $_preconn_domain); |
131 | 131 | // fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
132 | 132 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed |
133 | - $_preconn_crossorigin = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com') ); |
|
134 | - if ( in_array( $_preconn_domain, $_preconn_crossorigin ) ) { |
|
133 | + $_preconn_crossorigin = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
134 | + if (in_array($_preconn_domain, $_preconn_crossorigin)) { |
|
135 | 135 | $_preconn_hint['crossorigin'] = 'anonymous'; |
136 | 136 | } |
137 | 137 | $_new_hints[] = $_preconn_hint; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // merge in wordpress' preconnect hints |
142 | - if ( 'preconnect' === $relation_type && !empty($_new_hints) ) { |
|
142 | + if ('preconnect' === $relation_type && !empty($_new_hints)) { |
|
143 | 143 | $hints = array_merge($hints, $_new_hints); |
144 | 144 | } |
145 | 145 | |
@@ -156,48 +156,48 @@ discard block |
||
156 | 156 | $autoptimize_extra_options = autoptimize_extra_get_options(); |
157 | 157 | |
158 | 158 | // extract fonts, partly based on wp rocket's extraction code |
159 | - $_without_comments = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
160 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $_without_comments, $matches ); |
|
159 | + $_without_comments = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
160 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $_without_comments, $matches); |
|
161 | 161 | |
162 | 162 | $i = 0; |
163 | 163 | $fontsCollection = array(); |
164 | - if ( ! $matches[2] ) { |
|
164 | + if (!$matches[2]) { |
|
165 | 165 | return $in; |
166 | 166 | } |
167 | 167 | |
168 | 168 | // store them in $fonts array |
169 | - foreach ( $matches[2] as $font ) { |
|
170 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
169 | + foreach ($matches[2] as $font) { |
|
170 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
171 | 171 | // Get fonts name. |
172 | - $font = str_replace( array( '%7C', '%7c' ) , '|', $font ); |
|
173 | - $font = explode( 'family=', $font ); |
|
174 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
172 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
173 | + $font = explode('family=', $font); |
|
174 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
175 | 175 | // Add font to $fonts[$i] but make sure not to pollute with an empty family |
176 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
177 | - if ( !empty($_thisfont) ) { |
|
176 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
177 | + if (!empty($_thisfont)) { |
|
178 | 178 | $fontsCollection[$i]["fonts"] = $_thisfont; |
179 | 179 | // And add subset if any |
180 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
181 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
182 | - $subset = explode( 'subset=', $subset ); |
|
183 | - $fontsCollection[$i]["subsets"] = explode( ',', $subset[1] ); |
|
180 | + $subset = (is_array($font)) ? end($font) : ''; |
|
181 | + if (false !== strpos($subset, 'subset=')) { |
|
182 | + $subset = explode('subset=', $subset); |
|
183 | + $fontsCollection[$i]["subsets"] = explode(',', $subset[1]); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | // And remove Google Fonts. |
187 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
187 | + $in = str_replace($matches[0][$i], '', $in); |
|
188 | 188 | } |
189 | 189 | $i++; |
190 | 190 | } |
191 | 191 | |
192 | - $_fontsOut=""; |
|
193 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "3" ) { |
|
192 | + $_fontsOut = ""; |
|
193 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "3") { |
|
194 | 194 | // aggregate & link |
195 | - $_fontsString=""; |
|
196 | - $_subsetString=""; |
|
195 | + $_fontsString = ""; |
|
196 | + $_subsetString = ""; |
|
197 | 197 | foreach ($fontsCollection as $font) { |
198 | - $_fontsString .= '|'.trim( implode( '|' , $font["fonts"] ), '|' ); |
|
199 | - if ( !empty( $font["subsets"] ) ) { |
|
200 | - $_subsetString .= implode( ',', $font["subsets"] ); |
|
198 | + $_fontsString .= '|'.trim(implode('|', $font["fonts"]), '|'); |
|
199 | + if (!empty($font["subsets"])) { |
|
200 | + $_subsetString .= implode(',', $font["subsets"]); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
@@ -205,17 +205,17 @@ discard block |
||
205 | 205 | $_fontsString = $_fontsString."#038;subset=".$_subsetString; |
206 | 206 | } |
207 | 207 | |
208 | - $_fontsString = str_replace( '|', '%7C', ltrim($_fontsString,'|') ); |
|
208 | + $_fontsString = str_replace('|', '%7C', ltrim($_fontsString, '|')); |
|
209 | 209 | |
210 | - if ( ! empty( $_fontsString ) ) { |
|
211 | - $_fontsOut = '<link rel="stylesheet" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $_fontsString . '" />'; |
|
210 | + if (!empty($_fontsString)) { |
|
211 | + $_fontsOut = '<link rel="stylesheet" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$_fontsString.'" />'; |
|
212 | 212 | } |
213 | - } else if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) { |
|
213 | + } else if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4") { |
|
214 | 214 | // aggregate & load async (webfont.js impl.) |
215 | 215 | $_fontsArray = array(); |
216 | 216 | foreach ($fontsCollection as $_fonts) { |
217 | - if ( !empty( $_fonts["subsets"] ) ) { |
|
218 | - $_subset = implode(",",$_fonts["subsets"]); |
|
217 | + if (!empty($_fonts["subsets"])) { |
|
218 | + $_subset = implode(",", $_fonts["subsets"]); |
|
219 | 219 | foreach ($_fonts["fonts"] as $key => $_one_font) { |
220 | 220 | $_one_font = $_one_font.":".$_subset; |
221 | 221 | $_fonts["fonts"][$key] = $_one_font; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | foreach ($_fontsArray as $_font) { |
229 | 229 | $_fontsOut .= $_font."','"; |
230 | 230 | } |
231 | - $_fontsOut = trim(trim($_fontsOut,"'"),","); |
|
231 | + $_fontsOut = trim(trim($_fontsOut, "'"), ","); |
|
232 | 232 | $_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.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
233 | 233 | } |
234 | 234 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | // preconnect to fonts.gstatic.com speed up download of static font-files |
244 | 244 | $in[] = "https://fonts.gstatic.com"; |
245 | - if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) { |
|
245 | + if ($autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4") { |
|
246 | 246 | // and more preconnects for webfont.js |
247 | 247 | $in[] = "https://ajax.googleapis.com/"; |
248 | 248 | $in[] = "https://fonts.googleapis.com"; |
@@ -252,12 +252,12 @@ discard block |
||
252 | 252 | |
253 | 253 | /* admin page functions */ |
254 | 254 | function autoptimize_extra_admin() { |
255 | - add_submenu_page( null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page' ); |
|
256 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
255 | + add_submenu_page(null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page'); |
|
256 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | function add_autoptimize_extra_tab($in) { |
260 | - $in=array_merge($in,array('autoptimize_extra' => 'Extra')); |
|
260 | + $in = array_merge($in, array('autoptimize_extra' => 'Extra')); |
|
261 | 261 | return $in; |
262 | 262 | } |
263 | 263 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | #autoptimize_extra_descr{font-size: 120%;} |
272 | 272 | </style> |
273 | 273 | <div class="wrap"> |
274 | - <h1><?php _e('Autoptimize Settings','autoptimize'); ?></h1> |
|
274 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
275 | 275 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
276 | 276 | <form id='ao_settings_form' action='options.php' method='post'> |
277 | 277 | <?php settings_fields('autoptimize_extra_settings'); ?> |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | <tr> |
282 | 282 | <th scope="row">Remove emojis</th> |
283 | 283 | <td> |
284 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php checked( $autoptimize_extra_options['autoptimize_extra_checkbox_field_1'], 1 ); ?> value='1'>Removes WordPress' core emojis' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.</label> |
|
284 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php checked($autoptimize_extra_options['autoptimize_extra_checkbox_field_1'], 1); ?> value='1'>Removes WordPress' core emojis' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.</label> |
|
285 | 285 | </td> |
286 | 286 | </tr> |
287 | 287 | <tr> |
288 | 288 | <th scope="row">Remove query strings from static resources</th> |
289 | 289 | <td> |
290 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php checked( $autoptimize_extra_options['autoptimize_extra_checkbox_field_0'], 1 ); ?> value='1'>Removing query strings (or more specificaly the <code>ver</code> parameter) will not improve load time, but might improve performance scores.</label> |
|
290 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php checked($autoptimize_extra_options['autoptimize_extra_checkbox_field_0'], 1); ?> value='1'>Removing query strings (or more specificaly the <code>ver</code> parameter) will not improve load time, but might improve performance scores.</label> |
|
291 | 291 | </td> |
292 | 292 | </tr> |
293 | 293 | <tr> |
294 | 294 | <th scope="row">Google Fonts</th> |
295 | 295 | <td> |
296 | - <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"; } ?>>Leave as is<br/> |
|
296 | + <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"; } ?>>Leave as is<br/> |
|
297 | 297 | <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $_googlef, true); ?> >Remove Google Fonts<br/> |
298 | 298 | <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $_googlef, true); ?>>Combine and link in head<br/> |
299 | 299 | <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $_googlef, true); ?>>Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a><br/> |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | http://www.gnu.org/licenses/gpl.txt |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
15 | +if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|
16 | 16 | |
17 | -define('AUTOPTIMIZE_PLUGIN_DIR',plugin_dir_path(__FILE__)); |
|
17 | +define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
18 | 18 | |
19 | 19 | // Load config class |
20 | 20 | include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeConfig.php'); |
21 | 21 | |
22 | 22 | // Load toolbar class |
23 | -include( AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeToolbar.php' ); |
|
23 | +include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeToolbar.php'); |
|
24 | 24 | |
25 | 25 | // Load partners tab if admin |
26 | 26 | if (is_admin()) { |
@@ -28,29 +28,29 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | // Do we gzip when caching (needed early to load autoptimizeCache.php) |
31 | -define('AUTOPTIMIZE_CACHE_NOGZIP',(bool) get_option('autoptimize_cache_nogzip')); |
|
31 | +define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip')); |
|
32 | 32 | |
33 | 33 | // Load cache class |
34 | 34 | include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCache.php'); |
35 | 35 | |
36 | 36 | // wp-content dir name (automagically set, should not be needed), dirname of AO cache dir and AO-prefix can be overridden in wp-config.php |
37 | -if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { define('AUTOPTIMIZE_WP_CONTENT_NAME','/'.wp_basename( WP_CONTENT_DIR )); } |
|
38 | -if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { define('AUTOPTIMIZE_CACHE_CHILD_DIR','/cache/autoptimize/'); } |
|
37 | +if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); } |
|
38 | +if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); } |
|
39 | 39 | if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); } |
40 | 40 | |
41 | 41 | // Plugin dir constants (plugin url's defined later to accomodate domain mapped sites) |
42 | -if (is_multisite() && apply_filters( 'autoptimize_separate_blog_caches' , true )) { |
|
42 | +if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
43 | 43 | $blog_id = get_current_blog_id(); |
44 | - define('AUTOPTIMIZE_CACHE_DIR', WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/' ); |
|
44 | + define('AUTOPTIMIZE_CACHE_DIR', WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
45 | 45 | } else { |
46 | 46 | define('AUTOPTIMIZE_CACHE_DIR', WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR); |
47 | 47 | } |
48 | -define('AUTOPTIMIZE_CACHE_DELAY',true); |
|
49 | -define('WP_ROOT_DIR',substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR)-strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
48 | +define('AUTOPTIMIZE_CACHE_DELAY', true); |
|
49 | +define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
50 | 50 | |
51 | 51 | // WP CLI |
52 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
53 | - require_once AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
52 | +if (defined('WP_CLI') && WP_CLI) { |
|
53 | + require_once AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php'; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | // Initialize the cache at least once |
@@ -59,65 +59,65 @@ discard block |
||
59 | 59 | /* Check if we're updating, in which case we might need to do stuff and flush the cache |
60 | 60 | to avoid old versions of aggregated files lingering around */ |
61 | 61 | |
62 | -$autoptimize_version="2.2.0"; |
|
63 | -$autoptimize_db_version=get_option('autoptimize_version','none'); |
|
62 | +$autoptimize_version = "2.2.0"; |
|
63 | +$autoptimize_db_version = get_option('autoptimize_version', 'none'); |
|
64 | 64 | |
65 | 65 | if ($autoptimize_db_version !== $autoptimize_version) { |
66 | - if ($autoptimize_db_version==="none") { |
|
66 | + if ($autoptimize_db_version === "none") { |
|
67 | 67 | add_action('admin_notices', 'autoptimize_install_config_notice'); |
68 | 68 | } else { |
69 | 69 | // updating, include the update-code |
70 | 70 | include(AUTOPTIMIZE_PLUGIN_DIR.'classlesses/autoptimizeUpdateCode.php'); |
71 | 71 | } |
72 | 72 | |
73 | - update_option('autoptimize_version',$autoptimize_version); |
|
74 | - $autoptimize_db_version=$autoptimize_version; |
|
73 | + update_option('autoptimize_version', $autoptimize_version); |
|
74 | + $autoptimize_db_version = $autoptimize_version; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | // Load translations |
78 | 78 | function autoptimize_load_plugin_textdomain() { |
79 | - load_plugin_textdomain('autoptimize',false,plugin_basename(dirname( __FILE__ )).'/localization'); |
|
79 | + load_plugin_textdomain('autoptimize', false, plugin_basename(dirname(__FILE__)).'/localization'); |
|
80 | 80 | } |
81 | -add_action( 'init', 'autoptimize_load_plugin_textdomain' ); |
|
81 | +add_action('init', 'autoptimize_load_plugin_textdomain'); |
|
82 | 82 | |
83 | -function autoptimize_uninstall(){ |
|
83 | +function autoptimize_uninstall() { |
|
84 | 84 | autoptimizeCache::clearall(); |
85 | 85 | |
86 | - $delete_options=array("autoptimize_cache_clean", "autoptimize_cache_nogzip", "autoptimize_css", "autoptimize_css_datauris", "autoptimize_css_justhead", "autoptimize_css_defer", "autoptimize_css_defer_inline", "autoptimize_css_inline", "autoptimize_css_exclude", "autoptimize_html", "autoptimize_html_keepcomments", "autoptimize_js", "autoptimize_js_exclude", "autoptimize_js_forcehead", "autoptimize_js_justhead", "autoptimize_js_trycatch", "autoptimize_version", "autoptimize_show_adv", "autoptimize_cdn_url", "autoptimize_cachesize_notice","autoptimize_css_include_inline","autoptimize_js_include_inline","autoptimize_css_nogooglefont","autoptimize_optimize_logged","autoptimize_optimize_checkout","autoptimize_extra_settings"); |
|
86 | + $delete_options = array("autoptimize_cache_clean", "autoptimize_cache_nogzip", "autoptimize_css", "autoptimize_css_datauris", "autoptimize_css_justhead", "autoptimize_css_defer", "autoptimize_css_defer_inline", "autoptimize_css_inline", "autoptimize_css_exclude", "autoptimize_html", "autoptimize_html_keepcomments", "autoptimize_js", "autoptimize_js_exclude", "autoptimize_js_forcehead", "autoptimize_js_justhead", "autoptimize_js_trycatch", "autoptimize_version", "autoptimize_show_adv", "autoptimize_cdn_url", "autoptimize_cachesize_notice", "autoptimize_css_include_inline", "autoptimize_js_include_inline", "autoptimize_css_nogooglefont", "autoptimize_optimize_logged", "autoptimize_optimize_checkout", "autoptimize_extra_settings"); |
|
87 | 87 | |
88 | - if ( !is_multisite() ) { |
|
89 | - foreach ($delete_options as $del_opt) { delete_option( $del_opt ); } |
|
88 | + if (!is_multisite()) { |
|
89 | + foreach ($delete_options as $del_opt) { delete_option($del_opt); } |
|
90 | 90 | } else { |
91 | 91 | global $wpdb; |
92 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
92 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
93 | 93 | $original_blog_id = get_current_blog_id(); |
94 | - foreach ( $blog_ids as $blog_id ) { |
|
95 | - switch_to_blog( $blog_id ); |
|
96 | - foreach ($delete_options as $del_opt) { delete_option( $del_opt ); } |
|
94 | + foreach ($blog_ids as $blog_id) { |
|
95 | + switch_to_blog($blog_id); |
|
96 | + foreach ($delete_options as $del_opt) { delete_option($del_opt); } |
|
97 | 97 | } |
98 | - switch_to_blog( $original_blog_id ); |
|
98 | + switch_to_blog($original_blog_id); |
|
99 | 99 | } |
100 | 100 | |
101 | - if ( wp_get_schedule( 'ao_cachechecker' ) ) { |
|
102 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
101 | + if (wp_get_schedule('ao_cachechecker')) { |
|
102 | + wp_clear_scheduled_hook('ao_cachechecker'); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | 106 | function autoptimize_install_config_notice() { |
107 | 107 | echo '<div class="updated"><p>'; |
108 | - _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); |
|
108 | + _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize'); |
|
109 | 109 | echo '</p></div>'; |
110 | 110 | } |
111 | 111 | |
112 | 112 | function autoptimize_update_config_notice() { |
113 | 113 | echo '<div class="updated"><p>'; |
114 | - _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' ); |
|
114 | + _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize'); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | |
118 | 118 | function autoptimize_cache_unavailable_notice() { |
119 | 119 | echo '<div class="error"><p>'; |
120 | - printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); |
|
120 | + printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR); |
|
121 | 121 | echo '</p></div>'; |
122 | 122 | } |
123 | 123 | |
@@ -126,27 +126,27 @@ discard block |
||
126 | 126 | $ao_noptimize = false; |
127 | 127 | |
128 | 128 | // noptimize in qs to get non-optimized page for debugging |
129 | - if (array_key_exists("ao_noptimize",$_GET) || array_key_exists("ao_noptirocket",$_GET)) { |
|
130 | - if ( ( ($_GET["ao_noptimize"]==="1") || ($_GET["ao_noptirocket"]==="1") ) && (apply_filters('autoptimize_filter_honor_qs_noptimize',true)) ) { |
|
129 | + if (array_key_exists("ao_noptimize", $_GET) || array_key_exists("ao_noptirocket", $_GET)) { |
|
130 | + if ((($_GET["ao_noptimize"] === "1") || ($_GET["ao_noptirocket"] === "1")) && (apply_filters('autoptimize_filter_honor_qs_noptimize', true))) { |
|
131 | 131 | $ao_noptimize = true; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | // check for DONOTMINIFY constant as used by e.g. WooCommerce POS |
136 | - if (defined('DONOTMINIFY') && (constant('DONOTMINIFY')===true || constant('DONOTMINIFY')==="true")) { |
|
136 | + if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === "true")) { |
|
137 | 137 | $ao_noptimize = true; |
138 | 138 | } |
139 | 139 | |
140 | 140 | // if setting says not to optimize logged in user and user is logged in |
141 | - if ( get_option('autoptimize_optimize_logged','on') !== 'on' && is_user_logged_in() && current_user_can('edit_posts') ) { |
|
141 | + if (get_option('autoptimize_optimize_logged', 'on') !== 'on' && is_user_logged_in() && current_user_can('edit_posts')) { |
|
142 | 142 | $ao_noptimize = true; |
143 | 143 | } |
144 | 144 | |
145 | 145 | // if setting says not to optimize cart/ checkout |
146 | - if ( get_option('autoptimize_optimize_checkout','on') !== 'on' ) { |
|
146 | + if (get_option('autoptimize_optimize_checkout', 'on') !== 'on') { |
|
147 | 147 | // checking for woocommerce, easy digital downloads and wp ecommerce |
148 | - foreach ( array("is_checkout","is_cart","edd_is_checkout","wpsc_is_cart","wpsc_is_checkout") as $shopCond ) { |
|
149 | - if ( function_exists($shopCond) && $shopCond() ) { |
|
148 | + foreach (array("is_checkout", "is_cart", "edd_is_checkout", "wpsc_is_cart", "wpsc_is_checkout") as $shopCond) { |
|
149 | + if (function_exists($shopCond) && $shopCond()) { |
|
150 | 150 | $ao_noptimize = true; |
151 | 151 | break; |
152 | 152 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | // filter you can use to block autoptimization on your own terms |
157 | - $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
|
157 | + $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize); |
|
158 | 158 | |
159 | - if (!is_feed() && !$ao_noptimize && !is_admin() && ( !function_exists('is_customize_preview') || !is_customize_preview() ) ) { |
|
159 | + if (!is_feed() && !$ao_noptimize && !is_admin() && (!function_exists('is_customize_preview') || !is_customize_preview())) { |
|
160 | 160 | // load speedupper conditionally (true by default?) |
161 | - if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
161 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
162 | 162 | include(AUTOPTIMIZE_PLUGIN_DIR.'classlesses/autoptimizeSpeedupper.php'); |
163 | 163 | } |
164 | 164 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeBase.php'); |
170 | 170 | |
171 | 171 | // Load extra classes and set some vars |
172 | - if($conf->get('autoptimize_html')) { |
|
172 | + if ($conf->get('autoptimize_html')) { |
|
173 | 173 | include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeHTML.php'); |
174 | 174 | // BUG: new minify-html does not support keeping HTML comments, skipping for now |
175 | 175 | // if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | // } |
180 | 180 | } |
181 | 181 | |
182 | - if($conf->get('autoptimize_js')) { |
|
182 | + if ($conf->get('autoptimize_js')) { |
|
183 | 183 | include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeScripts.php'); |
184 | 184 | if (!class_exists('JSMin')) { |
185 | 185 | if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/minify-2.3.1-jsmin.php'); |
189 | 189 | } |
190 | 190 | } |
191 | - if ( ! defined( 'CONCATENATE_SCRIPTS' )) { |
|
192 | - define('CONCATENATE_SCRIPTS',false); |
|
191 | + if (!defined('CONCATENATE_SCRIPTS')) { |
|
192 | + define('CONCATENATE_SCRIPTS', false); |
|
193 | 193 | } |
194 | - if ( ! defined( 'COMPRESS_SCRIPTS' )) { |
|
195 | - define('COMPRESS_SCRIPTS',false); |
|
194 | + if (!defined('COMPRESS_SCRIPTS')) { |
|
195 | + define('COMPRESS_SCRIPTS', false); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | - if($conf->get('autoptimize_css')) { |
|
199 | + if ($conf->get('autoptimize_css')) { |
|
200 | 200 | include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeStyles.php'); |
201 | 201 | if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { |
202 | 202 | if (!class_exists('Minify_CSS_Compressor')) { |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/yui-php-cssmin-2.4.8-4_fgo.php'); |
208 | 208 | } |
209 | 209 | } |
210 | - if ( ! defined( 'COMPRESS_CSS' )) { |
|
211 | - define('COMPRESS_CSS',false); |
|
210 | + if (!defined('COMPRESS_CSS')) { |
|
211 | + define('COMPRESS_CSS', false); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | 215 | // filter to be used with care, kills all output buffers when true. use with extreme caution. you have been warned! |
216 | - if (apply_filters('autoptimize_filter_obkiller',false)) { |
|
216 | + if (apply_filters('autoptimize_filter_obkiller', false)) { |
|
217 | 217 | while (ob_get_level() > 0) { |
218 | 218 | ob_end_clean(); |
219 | 219 | } |
@@ -225,36 +225,36 @@ discard block |
||
225 | 225 | |
226 | 226 | // Action on end, this is where the magic happens |
227 | 227 | function autoptimize_end_buffering($content) { |
228 | - if ( ((stripos($content,"<html") === false) && (stripos($content,"<!DOCTYPE html") === false)) || preg_match('/<html[^>]*(?:amp|⚡)/',$content) === 1 || stripos($content,"<xsl:stylesheet") !== false ) { return $content; } |
|
228 | + if (((stripos($content, "<html") === false) && (stripos($content, "<!DOCTYPE html") === false)) || preg_match('/<html[^>]*(?:amp|⚡)/', $content) === 1 || stripos($content, "<xsl:stylesheet") !== false) { return $content; } |
|
229 | 229 | |
230 | 230 | // load URL constants as late as possible to allow domain mapper to kick in |
231 | 231 | if (function_exists("domain_mapping_siteurl")) { |
232 | - define('AUTOPTIMIZE_WP_SITE_URL',domain_mapping_siteurl(get_current_blog_id())); |
|
233 | - define('AUTOPTIMIZE_WP_CONTENT_URL',str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL),AUTOPTIMIZE_WP_SITE_URL,content_url())); |
|
232 | + define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id())); |
|
233 | + define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url())); |
|
234 | 234 | } else { |
235 | - define('AUTOPTIMIZE_WP_SITE_URL',site_url()); |
|
236 | - define('AUTOPTIMIZE_WP_CONTENT_URL',content_url()); |
|
235 | + define('AUTOPTIMIZE_WP_SITE_URL', site_url()); |
|
236 | + define('AUTOPTIMIZE_WP_CONTENT_URL', content_url()); |
|
237 | 237 | } |
238 | 238 | |
239 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches' , true ) ) { |
|
239 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
240 | 240 | $blog_id = get_current_blog_id(); |
241 | - define('AUTOPTIMIZE_CACHE_URL',AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/' ); |
|
241 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
242 | 242 | } else { |
243 | - define('AUTOPTIMIZE_CACHE_URL',AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
243 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
244 | 244 | } |
245 | - define('AUTOPTIMIZE_WP_ROOT_URL',str_replace(AUTOPTIMIZE_WP_CONTENT_NAME,'',AUTOPTIMIZE_WP_CONTENT_URL)); |
|
246 | - define('AUTOPTIMIZE_HASH',wp_hash(AUTOPTIMIZE_CACHE_DIR)); |
|
245 | + define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL)); |
|
246 | + define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_DIR)); |
|
247 | 247 | |
248 | 248 | // Config element |
249 | 249 | $conf = autoptimizeConfig::instance(); |
250 | 250 | |
251 | 251 | // Choose the classes |
252 | 252 | $classes = array(); |
253 | - if($conf->get('autoptimize_js')) |
|
253 | + if ($conf->get('autoptimize_js')) |
|
254 | 254 | $classes[] = 'autoptimizeScripts'; |
255 | - if($conf->get('autoptimize_css')) |
|
255 | + if ($conf->get('autoptimize_css')) |
|
256 | 256 | $classes[] = 'autoptimizeStyles'; |
257 | - if($conf->get('autoptimize_html')) |
|
257 | + if ($conf->get('autoptimize_html')) |
|
258 | 258 | $classes[] = 'autoptimizeHTML'; |
259 | 259 | |
260 | 260 | // Set some options |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | ) |
284 | 284 | ); |
285 | 285 | |
286 | - $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); |
|
286 | + $content = apply_filters('autoptimize_filter_html_before_minify', $content); |
|
287 | 287 | |
288 | 288 | // Run the classes |
289 | - foreach($classes as $name) { |
|
289 | + foreach ($classes as $name) { |
|
290 | 290 | $instance = new $name($content); |
291 | - if($instance->read($classoptions[$name])) { |
|
291 | + if ($instance->read($classoptions[$name])) { |
|
292 | 292 | $instance->minify(); |
293 | 293 | $instance->cache(); |
294 | 294 | $content = $instance->getcontent(); |
@@ -296,19 +296,19 @@ discard block |
||
296 | 296 | unset($instance); |
297 | 297 | } |
298 | 298 | |
299 | - $content = apply_filters( 'autoptimize_html_after_minify', $content ); |
|
299 | + $content = apply_filters('autoptimize_html_after_minify', $content); |
|
300 | 300 | return $content; |
301 | 301 | } |
302 | 302 | |
303 | -if ( autoptimizeCache::cacheavail() ) { |
|
303 | +if (autoptimizeCache::cacheavail()) { |
|
304 | 304 | $conf = autoptimizeConfig::instance(); |
305 | - if( $conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') ) { |
|
305 | + if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) { |
|
306 | 306 | // Hook to wordpress |
307 | 307 | if (defined('AUTOPTIMIZE_INIT_EARLIER')) { |
308 | - add_action('init','autoptimize_start_buffering',-1); |
|
308 | + add_action('init', 'autoptimize_start_buffering', -1); |
|
309 | 309 | } else { |
310 | 310 | if (!defined('AUTOPTIMIZE_HOOK_INTO')) { define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); } |
311 | - add_action(constant("AUTOPTIMIZE_HOOK_INTO"),'autoptimize_start_buffering',2); |
|
311 | + add_action(constant("AUTOPTIMIZE_HOOK_INTO"), 'autoptimize_start_buffering', 2); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } else { |
@@ -316,15 +316,15 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | function autoptimize_activate() { |
319 | - register_uninstall_hook( __FILE__, 'autoptimize_uninstall' ); |
|
319 | + register_uninstall_hook(__FILE__, 'autoptimize_uninstall'); |
|
320 | 320 | } |
321 | -register_activation_hook( __FILE__, 'autoptimize_activate' ); |
|
321 | +register_activation_hook(__FILE__, 'autoptimize_activate'); |
|
322 | 322 | |
323 | 323 | include_once('classlesses/autoptimizeCacheChecker.php'); |
324 | 324 | |
325 | -add_action('plugins_loaded','includeAutoptimizeExtra'); |
|
325 | +add_action('plugins_loaded', 'includeAutoptimizeExtra'); |
|
326 | 326 | function includeAutoptimizeExtra() { |
327 | - if ( apply_filters('autoptimize_filter_extra_activate',true) ) { |
|
327 | + if (apply_filters('autoptimize_filter_extra_activate', true)) { |
|
328 | 328 | include_once('classlesses/autoptimizeExtra.php'); |
329 | 329 | } |
330 | 330 | } |