@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | ); |
14 | 14 | |
15 | 15 | private $dontmove = array( |
16 | - 'document.write','html5.js','show_ads.js','google_ad','histats.com/js','statcounter.com/counter/counter.js', |
|
17 | - 'ws.amazon.com/widgets','media.fastclick.net','/ads/','comment-form-quicktags/quicktags.php','edToolbar', |
|
18 | - 'intensedebate.com','scripts.chitika.net/','_gaq.push','jotform.com/','admin-bar.min.js','GoogleAnalyticsObject', |
|
19 | - 'plupload.full.min.js','syntaxhighlighter','adsbygoogle','gist.github.com','_stq','nonce','post_id','data-noptimize' |
|
16 | + 'document.write', 'html5.js', 'show_ads.js', 'google_ad', 'histats.com/js', 'statcounter.com/counter/counter.js', |
|
17 | + 'ws.amazon.com/widgets', 'media.fastclick.net', '/ads/', 'comment-form-quicktags/quicktags.php', 'edToolbar', |
|
18 | + 'intensedebate.com', 'scripts.chitika.net/', '_gaq.push', 'jotform.com/', 'admin-bar.min.js', 'GoogleAnalyticsObject', |
|
19 | + 'plupload.full.min.js', 'syntaxhighlighter', 'adsbygoogle', 'gist.github.com', '_stq', 'nonce', 'post_id', 'data-noptimize' |
|
20 | 20 | ,'logHuman' |
21 | 21 | ); |
22 | 22 | private $domove = array( |
23 | - 'gaJsHost','load_cmc','jd.gallery.transitions.js','swfobject.embedSWF(','tiny_mce.js','tinyMCEPreInit.go' |
|
23 | + 'gaJsHost', 'load_cmc', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'tiny_mce.js', 'tinyMCEPreInit.go' |
|
24 | 24 | ); |
25 | 25 | private $domovelast = array( |
26 | - 'addthis.com','/afsonline/show_afs_search.js','disqus.js','networkedblogs.com/getnetworkwidget','infolinks.com/js/', |
|
27 | - 'jd.gallery.js.php','jd.gallery.transitions.js','swfobject.embedSWF(','linkwithin.com/widget.js','tiny_mce.js','tinyMCEPreInit.go' |
|
26 | + 'addthis.com', '/afsonline/show_afs_search.js', 'disqus.js', 'networkedblogs.com/getnetworkwidget', 'infolinks.com/js/', |
|
27 | + 'jd.gallery.js.php', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'linkwithin.com/widget.js', 'tiny_mce.js', 'tinyMCEPreInit.go' |
|
28 | 28 | ); |
29 | 29 | |
30 | 30 | private $aggregate = true; |
@@ -44,89 +44,89 @@ discard block |
||
44 | 44 | // Reads the page and collects script tags. |
45 | 45 | public function read($options) |
46 | 46 | { |
47 | - $noptimizeJS = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content ); |
|
48 | - if ( $noptimizeJS ) { |
|
47 | + $noptimizeJS = apply_filters('autoptimize_filter_js_noptimize', false, $this->content); |
|
48 | + if ($noptimizeJS) { |
|
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // only optimize known good JS? |
53 | - $whitelistJS = apply_filters( 'autoptimize_filter_js_whitelist', '', $this->content ); |
|
54 | - if ( ! empty( $whitelistJS ) ) { |
|
55 | - $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelistJS ) ) ); |
|
53 | + $whitelistJS = apply_filters('autoptimize_filter_js_whitelist', '', $this->content); |
|
54 | + if (!empty($whitelistJS)) { |
|
55 | + $this->whitelist = array_filter(array_map('trim', explode(',', $whitelistJS))); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // is there JS we should simply remove? |
59 | - $removableJS = apply_filters( 'autoptimize_filter_js_removables', '', $this->content ); |
|
59 | + $removableJS = apply_filters('autoptimize_filter_js_removables', '', $this->content); |
|
60 | 60 | if (!empty($removableJS)) { |
61 | - $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removableJS ) ) ); |
|
61 | + $this->jsremovables = array_filter(array_map('trim', explode(',', $removableJS))); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | // only header? |
65 | - if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) { |
|
66 | - $content = explode( '</head>', $this->content, 2 ); |
|
67 | - $this->content = $content[0] . '</head>'; |
|
65 | + if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) { |
|
66 | + $content = explode('</head>', $this->content, 2); |
|
67 | + $this->content = $content[0].'</head>'; |
|
68 | 68 | $this->restofcontent = $content[1]; |
69 | 69 | } |
70 | 70 | |
71 | 71 | // Determine whether we're doing JS-files aggregation or not. |
72 | - if ( ! $options['aggregate'] ) { |
|
72 | + if (!$options['aggregate']) { |
|
73 | 73 | $this->aggregate = false; |
74 | 74 | } |
75 | 75 | // Returning true for "dontaggregate" turns off aggregation. |
76 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) { |
|
76 | + if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) { |
|
77 | 77 | $this->aggregate = false; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // include inline? |
81 | - if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) { |
|
81 | + if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) { |
|
82 | 82 | $this->include_inline = true; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // filter to "late inject minified JS", default to true for now (it is faster). |
86 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true ); |
|
86 | + $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true); |
|
87 | 87 | |
88 | 88 | // filters to override hardcoded do(nt)move(last) array contents (array in, array out!). |
89 | - $this->dontmove = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove ); |
|
90 | - $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast ); |
|
91 | - $this->domove = apply_filters( 'autoptimize_filter_js_domove', $this->domove ); |
|
89 | + $this->dontmove = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove); |
|
90 | + $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast); |
|
91 | + $this->domove = apply_filters('autoptimize_filter_js_domove', $this->domove); |
|
92 | 92 | |
93 | 93 | // Determine whether excluded files should be minified if not yet so. |
94 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
94 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
95 | 95 | $this->minify_excluded = false; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // get extra exclusions settings or filter. |
99 | 99 | $excludeJS = $options['js_exclude']; |
100 | - $excludeJS = apply_filters( 'autoptimize_filter_js_exclude', $excludeJS, $this->content ); |
|
100 | + $excludeJS = apply_filters('autoptimize_filter_js_exclude', $excludeJS, $this->content); |
|
101 | 101 | |
102 | - if ( '' !== $excludeJS ) { |
|
103 | - if ( is_array( $excludeJS ) ) { |
|
104 | - if ( ( $removeKeys = array_keys( $excludeJS, 'remove' ) ) !== false ) { |
|
105 | - foreach ( $removeKeys as $removeKey ) { |
|
106 | - unset( $excludeJS[$removeKey] ); |
|
102 | + if ('' !== $excludeJS) { |
|
103 | + if (is_array($excludeJS)) { |
|
104 | + if (($removeKeys = array_keys($excludeJS, 'remove')) !== false) { |
|
105 | + foreach ($removeKeys as $removeKey) { |
|
106 | + unset($excludeJS[$removeKey]); |
|
107 | 107 | $this->jsremovables[] = $removeKey; |
108 | 108 | } |
109 | 109 | } |
110 | - $exclJSArr = array_keys( $excludeJS ); |
|
110 | + $exclJSArr = array_keys($excludeJS); |
|
111 | 111 | } else { |
112 | - $exclJSArr = array_filter( array_map( 'trim', explode( ',', $excludeJS ) ) ); |
|
112 | + $exclJSArr = array_filter(array_map('trim', explode(',', $excludeJS))); |
|
113 | 113 | } |
114 | - $this->dontmove = array_merge( $exclJSArr, $this->dontmove ); |
|
114 | + $this->dontmove = array_merge($exclJSArr, $this->dontmove); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | // Should we add try-catch? |
118 | - if ( $options['trycatch'] ) { |
|
118 | + if ($options['trycatch']) { |
|
119 | 119 | $this->trycatch = true; |
120 | 120 | } |
121 | 121 | |
122 | 122 | // force js in head? |
123 | - if ( $options['forcehead'] ) { |
|
123 | + if ($options['forcehead']) { |
|
124 | 124 | $this->forcehead = true; |
125 | 125 | } else { |
126 | 126 | $this->forcehead = false; |
127 | 127 | } |
128 | 128 | |
129 | - $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead ); |
|
129 | + $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead); |
|
130 | 130 | |
131 | 131 | // get cdn url. |
132 | 132 | $this->cdn_url = $options['cdn_url']; |
@@ -141,26 +141,26 @@ discard block |
||
141 | 141 | $this->content = $this->hide_comments($this->content); |
142 | 142 | |
143 | 143 | // Get script files. |
144 | - if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) { |
|
145 | - foreach( $matches[0] as $tag ) { |
|
144 | + if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) { |
|
145 | + foreach ($matches[0] as $tag) { |
|
146 | 146 | // only consider script aggregation for types whitelisted in should_aggregate-function. |
147 | 147 | $should_aggregate = $this->should_aggregate($tag); |
148 | - if ( ! $should_aggregate ) { |
|
148 | + if (!$should_aggregate) { |
|
149 | 149 | $tag = ''; |
150 | 150 | continue; |
151 | 151 | } |
152 | 152 | |
153 | - if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) { |
|
153 | + if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) { |
|
154 | 154 | // non-inline script. |
155 | - if ( $this->isremovable($tag, $this->jsremovables) ) { |
|
156 | - $this->content = str_replace( $tag, '', $this->content ); |
|
155 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
156 | + $this->content = str_replace($tag, '', $this->content); |
|
157 | 157 | continue; |
158 | 158 | } |
159 | 159 | |
160 | 160 | $origTag = null; |
161 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
161 | + $url = current(explode('?', $source[2], 2)); |
|
162 | 162 | $path = $this->getpath($url); |
163 | - if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable($tag) ) { |
|
163 | + if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) { |
|
164 | 164 | // ok to optimize, add to array. |
165 | 165 | $this->scripts[] = $path; |
166 | 166 | } else { |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | $newTag = $tag; |
169 | 169 | |
170 | 170 | // non-mergeable script (excluded or dynamic or external). |
171 | - if ( is_array( $excludeJS ) ) { |
|
171 | + if (is_array($excludeJS)) { |
|
172 | 172 | // should we add flags? |
173 | - foreach ( $excludeJS as $exclTag => $exclFlags) { |
|
174 | - if ( false !== strpos( $origTag, $exclTag ) && in_array( $exclFlags, array( 'async', 'defer' ) ) ) { |
|
175 | - $newTag = str_replace( '<script ', '<script ' . $exclFlags . ' ', $newTag ); |
|
173 | + foreach ($excludeJS as $exclTag => $exclFlags) { |
|
174 | + if (false !== strpos($origTag, $exclTag) && in_array($exclFlags, array('async', 'defer'))) { |
|
175 | + $newTag = str_replace('<script ', '<script '.$exclFlags.' ', $newTag); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | } |
@@ -180,28 +180,28 @@ discard block |
||
180 | 180 | // Should we minify the non-aggregated script? |
181 | 181 | // -> if aggregate is on and exclude minify is on |
182 | 182 | // -> if aggregate is off and the file is not in dontmove. |
183 | - if ( $path && ( $this->minify_excluded || apply_filters( 'autoptimize_filter_js_minify_excluded', false, $url ) ) ) { |
|
184 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
185 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
186 | - $minified_url = $this->minify_single( $path ); |
|
183 | + if ($path && ($this->minify_excluded || apply_filters('autoptimize_filter_js_minify_excluded', false, $url))) { |
|
184 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
185 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
186 | + $minified_url = $this->minify_single($path); |
|
187 | 187 | // replace orig URL with minified URL from cache if so. |
188 | - if ( ! empty( $minified_url ) ) { |
|
189 | - $newTag = str_replace( $url, $minified_url, $newTag ); |
|
188 | + if (!empty($minified_url)) { |
|
189 | + $newTag = str_replace($url, $minified_url, $newTag); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - if ( $this->ismovable($newTag) ) { |
|
194 | + if ($this->ismovable($newTag)) { |
|
195 | 195 | // can be moved, flags and all. |
196 | - if ( $this->movetolast($newTag) ) { |
|
196 | + if ($this->movetolast($newTag)) { |
|
197 | 197 | $this->move['last'][] = $newTag; |
198 | 198 | } else { |
199 | 199 | $this->move['first'][] = $newTag; |
200 | 200 | } |
201 | 201 | } else { |
202 | 202 | // cannot be moved, so if flag was added re-inject altered tag immediately. |
203 | - if ( $origTag !== $newTag ) { |
|
204 | - $this->content = str_replace( $origTag, $newTag, $this->content ); |
|
203 | + if ($origTag !== $newTag) { |
|
204 | + $this->content = str_replace($origTag, $newTag, $this->content); |
|
205 | 205 | $origTag = ''; |
206 | 206 | } |
207 | 207 | // and forget about the $tag (not to be touched any more). |
@@ -210,23 +210,23 @@ discard block |
||
210 | 210 | } |
211 | 211 | } else { |
212 | 212 | // Inline script. |
213 | - if ( $this->isremovable($tag, $this->jsremovables) ) { |
|
214 | - $this->content = str_replace( $tag, '', $this->content ); |
|
213 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
214 | + $this->content = str_replace($tag, '', $this->content); |
|
215 | 215 | continue; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // unhide comments, as javascript may be wrapped in comment-tags for old times' sake. |
219 | 219 | $tag = $this->restore_comments($tag); |
220 | - if ( $this->ismergeable($tag) && $this->include_inline ) { |
|
221 | - preg_match( '#<script.*>(.*)</script>#Usmi', $tag , $code ); |
|
222 | - $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] ); |
|
223 | - $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code ); |
|
224 | - $this->scripts[] = 'INLINE;' . $code; |
|
220 | + if ($this->ismergeable($tag) && $this->include_inline) { |
|
221 | + preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code); |
|
222 | + $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]); |
|
223 | + $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code); |
|
224 | + $this->scripts[] = 'INLINE;'.$code; |
|
225 | 225 | } else { |
226 | 226 | // Can we move this? |
227 | - $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag ); |
|
228 | - if ( $this->ismovable($tag) || '' !== $autoptimize_js_moveable ) { |
|
229 | - if ( $this->movetolast($tag) || 'last' === $autoptimize_js_moveable ) { |
|
227 | + $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag); |
|
228 | + if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) { |
|
229 | + if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) { |
|
230 | 230 | $this->move['last'][] = $tag; |
231 | 231 | } else { |
232 | 232 | $this->move['first'][] = $tag; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | //Remove the original script tag. |
244 | - $this->content = str_replace( $tag, '', $this->content ); |
|
244 | + $this->content = str_replace($tag, '', $this->content); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | return true; |
@@ -271,21 +271,21 @@ discard block |
||
271 | 271 | // We're only interested in the type attribute of the <script> tag itself, not any possible |
272 | 272 | // inline code that might just contain the 'type=' string... |
273 | 273 | $tag_parts = array(); |
274 | - preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts); |
|
274 | + preg_match('#<(script[^>]*)>#i', $tag, $tag_parts); |
|
275 | 275 | $tag_without_contents = null; |
276 | - if ( ! empty( $tag_parts[1] ) ) { |
|
276 | + if (!empty($tag_parts[1])) { |
|
277 | 277 | $tag_without_contents = $tag_parts[1]; |
278 | 278 | } |
279 | 279 | |
280 | - $has_type = ( strpos( $tag_without_contents, 'type' ) !== false ); |
|
280 | + $has_type = (strpos($tag_without_contents, 'type') !== false); |
|
281 | 281 | |
282 | 282 | $type_valid = false; |
283 | - if ( $has_type ) { |
|
284 | - $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents ); |
|
283 | + if ($has_type) { |
|
284 | + $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $should_aggregate = false; |
288 | - if ( ! $has_type || $type_valid ) { |
|
288 | + if (!$has_type || $type_valid) { |
|
289 | 289 | $should_aggregate = true; |
290 | 290 | } |
291 | 291 | |
@@ -295,40 +295,40 @@ discard block |
||
295 | 295 | //Joins and optimizes JS |
296 | 296 | public function minify() |
297 | 297 | { |
298 | - foreach ( $this->scripts as $script ) { |
|
298 | + foreach ($this->scripts as $script) { |
|
299 | 299 | // TODO/FIXME: some duplicate code here, can be reduced/simplified |
300 | - if ( preg_match( '#^INLINE;#', $script ) ) { |
|
300 | + if (preg_match('#^INLINE;#', $script)) { |
|
301 | 301 | // Inline script |
302 | - $script = preg_replace( '#^INLINE;#', '', $script ); |
|
303 | - $script = rtrim( $script, ";\n\t\r" ) . ';'; |
|
302 | + $script = preg_replace('#^INLINE;#', '', $script); |
|
303 | + $script = rtrim($script, ";\n\t\r").';'; |
|
304 | 304 | // Add try-catch? |
305 | - if ( $this->trycatch ) { |
|
306 | - $script = 'try{' . $script . '}catch(e){}'; |
|
305 | + if ($this->trycatch) { |
|
306 | + $script = 'try{'.$script.'}catch(e){}'; |
|
307 | 307 | } |
308 | - $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' ); |
|
309 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) { |
|
308 | + $tmpscript = apply_filters('autoptimize_js_individual_script', $script, ''); |
|
309 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) { |
|
310 | 310 | $script = $tmpscript; |
311 | 311 | $this->alreadyminified = true; |
312 | 312 | } |
313 | - $this->jscode .= "\n" . $script; |
|
313 | + $this->jscode .= "\n".$script; |
|
314 | 314 | } else { |
315 | 315 | // External script |
316 | - if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) { |
|
317 | - $scriptsrc = file_get_contents( $script ); |
|
318 | - $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc ); |
|
319 | - $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';'; |
|
316 | + if (false !== $script && file_exists($script) && is_readable($script)) { |
|
317 | + $scriptsrc = file_get_contents($script); |
|
318 | + $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc); |
|
319 | + $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';'; |
|
320 | 320 | // Add try-catch? |
321 | - if ( $this->trycatch ) { |
|
322 | - $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}'; |
|
321 | + if ($this->trycatch) { |
|
322 | + $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}'; |
|
323 | 323 | } |
324 | - $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script ); |
|
325 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) { |
|
324 | + $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script); |
|
325 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) { |
|
326 | 326 | $scriptsrc = $tmpscriptsrc; |
327 | 327 | $this->alreadyminified = true; |
328 | - } else if ( $this->can_inject_late($script) ) { |
|
328 | + } else if ($this->can_inject_late($script)) { |
|
329 | 329 | $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc)); |
330 | 330 | } |
331 | - $this->jscode .= "\n" . $scriptsrc; |
|
331 | + $this->jscode .= "\n".$scriptsrc; |
|
332 | 332 | }/*else{ |
333 | 333 | //Couldn't read JS. Maybe getpath isn't working? |
334 | 334 | }*/ |
@@ -336,32 +336,32 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | // Check for already-minified code |
339 | - $this->md5hash = md5( $this->jscode ); |
|
339 | + $this->md5hash = md5($this->jscode); |
|
340 | 340 | $ccheck = new autoptimizeCache($this->md5hash, 'js'); |
341 | - if ( $ccheck->check() ) { |
|
341 | + if ($ccheck->check()) { |
|
342 | 342 | $this->jscode = $ccheck->retrieve(); |
343 | 343 | return true; |
344 | 344 | } |
345 | - unset( $ccheck ); |
|
345 | + unset($ccheck); |
|
346 | 346 | |
347 | 347 | // $this->jscode has all the uncompressed code now. |
348 | - if ( true !== $this->alreadyminified ) { |
|
349 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
350 | - $tmp_jscode = trim( JSMin::minify( $this->jscode ) ); |
|
351 | - if ( ! empty( $tmp_jscode ) ) { |
|
348 | + if (true !== $this->alreadyminified) { |
|
349 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
350 | + $tmp_jscode = trim(JSMin::minify($this->jscode)); |
|
351 | + if (!empty($tmp_jscode)) { |
|
352 | 352 | $this->jscode = $tmp_jscode; |
353 | - unset( $tmp_jscode ); |
|
353 | + unset($tmp_jscode); |
|
354 | 354 | } |
355 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
356 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
355 | + $this->jscode = $this->inject_minified($this->jscode); |
|
356 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
357 | 357 | return true; |
358 | 358 | } else { |
359 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
359 | + $this->jscode = $this->inject_minified($this->jscode); |
|
360 | 360 | return false; |
361 | 361 | } |
362 | 362 | } |
363 | 363 | |
364 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
364 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
365 | 365 | return true; |
366 | 366 | } |
367 | 367 | |
@@ -369,11 +369,11 @@ discard block |
||
369 | 369 | public function cache() |
370 | 370 | { |
371 | 371 | $cache = new autoptimizeCache($this->md5hash, 'js'); |
372 | - if ( ! $cache->check() ) { |
|
372 | + if (!$cache->check()) { |
|
373 | 373 | // Cache our code |
374 | 374 | $cache->cache($this->jscode, 'text/javascript'); |
375 | 375 | } |
376 | - $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
376 | + $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
377 | 377 | $this->url = $this->url_replace_cdn($this->url); |
378 | 378 | } |
379 | 379 | |
@@ -381,43 +381,43 @@ discard block |
||
381 | 381 | public function getcontent() |
382 | 382 | { |
383 | 383 | // Restore the full content |
384 | - if ( ! empty( $this->restofcontent ) ) { |
|
384 | + if (!empty($this->restofcontent)) { |
|
385 | 385 | $this->content .= $this->restofcontent; |
386 | 386 | $this->restofcontent = ''; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // Add the scripts taking forcehead/ deferred (default) into account |
390 | - if ( $this->forcehead ) { |
|
391 | - $replaceTag = array( '</head>', 'before' ); |
|
390 | + if ($this->forcehead) { |
|
391 | + $replaceTag = array('</head>', 'before'); |
|
392 | 392 | $defer = ''; |
393 | 393 | } else { |
394 | - $replaceTag = array( '</body>', 'before' ); |
|
394 | + $replaceTag = array('</body>', 'before'); |
|
395 | 395 | $defer = 'defer '; |
396 | 396 | } |
397 | 397 | |
398 | - $defer = apply_filters( 'autoptimize_filter_js_defer', $defer ); |
|
398 | + $defer = apply_filters('autoptimize_filter_js_defer', $defer); |
|
399 | 399 | |
400 | - $bodyreplacementpayload = '<script type="text/javascript" ' . $defer . 'src="' . $this->url . '"></script>'; |
|
401 | - $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload ); |
|
400 | + $bodyreplacementpayload = '<script type="text/javascript" '.$defer.'src="'.$this->url.'"></script>'; |
|
401 | + $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload); |
|
402 | 402 | |
403 | - $bodyreplacement = implode( '', $this->move['first'] ); |
|
403 | + $bodyreplacement = implode('', $this->move['first']); |
|
404 | 404 | $bodyreplacement .= $bodyreplacementpayload; |
405 | - $bodyreplacement .= implode( '', $this->move['last'] ); |
|
405 | + $bodyreplacement .= implode('', $this->move['last']); |
|
406 | 406 | |
407 | - $replaceTag = apply_filters( 'autoptimize_filter_js_replacetag', $replaceTag ); |
|
407 | + $replaceTag = apply_filters('autoptimize_filter_js_replacetag', $replaceTag); |
|
408 | 408 | |
409 | - if ( strlen( $this->jscode ) > 0 ) { |
|
410 | - $this->inject_in_html( $bodyreplacement, $replaceTag ); |
|
409 | + if (strlen($this->jscode) > 0) { |
|
410 | + $this->inject_in_html($bodyreplacement, $replaceTag); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | // Restore comments. |
414 | - $this->content = $this->restore_comments( $this->content ); |
|
414 | + $this->content = $this->restore_comments($this->content); |
|
415 | 415 | |
416 | 416 | // Restore IE hacks. |
417 | - $this->content = $this->restore_iehacks( $this->content ); |
|
417 | + $this->content = $this->restore_iehacks($this->content); |
|
418 | 418 | |
419 | 419 | // Restore noptimize. |
420 | - $this->content = $this->restore_noptimize( $this->content ); |
|
420 | + $this->content = $this->restore_noptimize($this->content); |
|
421 | 421 | |
422 | 422 | // Return the modified HTML. |
423 | 423 | return $this->content; |
@@ -426,32 +426,32 @@ discard block |
||
426 | 426 | // Checks against the white- and blacklists |
427 | 427 | private function ismergeable($tag) |
428 | 428 | { |
429 | - if ( ! $this->aggregate ) { |
|
429 | + if (!$this->aggregate) { |
|
430 | 430 | return false; |
431 | 431 | } |
432 | 432 | |
433 | - if ( ! empty( $this->whitelist ) ) { |
|
434 | - foreach ( $this->whitelist as $match ) { |
|
435 | - if (false !== strpos( $tag, $match ) ) { |
|
433 | + if (!empty($this->whitelist)) { |
|
434 | + foreach ($this->whitelist as $match) { |
|
435 | + if (false !== strpos($tag, $match)) { |
|
436 | 436 | return true; |
437 | 437 | } |
438 | 438 | } |
439 | 439 | // no match with whitelist |
440 | 440 | return false; |
441 | 441 | } else { |
442 | - foreach($this->domove as $match) { |
|
443 | - if ( false !== strpos( $tag, $match ) ) { |
|
442 | + foreach ($this->domove as $match) { |
|
443 | + if (false !== strpos($tag, $match)) { |
|
444 | 444 | // Matched something |
445 | 445 | return false; |
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
449 | - if ( $this->movetolast($tag) ) { |
|
449 | + if ($this->movetolast($tag)) { |
|
450 | 450 | return false; |
451 | 451 | } |
452 | 452 | |
453 | - foreach( $this->dontmove as $match ) { |
|
454 | - if ( false !== strpos( $tag, $match ) ) { |
|
453 | + foreach ($this->dontmove as $match) { |
|
454 | + if (false !== strpos($tag, $match)) { |
|
455 | 455 | // Matched something |
456 | 456 | return false; |
457 | 457 | } |
@@ -465,23 +465,23 @@ discard block |
||
465 | 465 | // Checks agains the blacklist |
466 | 466 | private function ismovable($tag) |
467 | 467 | { |
468 | - if ( true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { |
|
468 | + if (true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) { |
|
469 | 469 | return false; |
470 | 470 | } |
471 | 471 | |
472 | - foreach ( $this->domove as $match ) { |
|
473 | - if ( false !== strpos( $tag, $match ) ) { |
|
472 | + foreach ($this->domove as $match) { |
|
473 | + if (false !== strpos($tag, $match)) { |
|
474 | 474 | // Matched something |
475 | 475 | return true; |
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
479 | - if ( $this->movetolast($tag) ) { |
|
479 | + if ($this->movetolast($tag)) { |
|
480 | 480 | return true; |
481 | 481 | } |
482 | 482 | |
483 | - foreach ( $this->dontmove as $match ) { |
|
484 | - if ( false !== strpos( $tag, $match ) ) { |
|
483 | + foreach ($this->dontmove as $match) { |
|
484 | + if (false !== strpos($tag, $match)) { |
|
485 | 485 | // Matched something |
486 | 486 | return false; |
487 | 487 | } |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | |
494 | 494 | private function movetolast($tag) |
495 | 495 | { |
496 | - foreach ( $this->domovelast as $match ) { |
|
497 | - if ( false !== strpos( $tag, $match ) ) { |
|
496 | + foreach ($this->domovelast as $match) { |
|
497 | + if (false !== strpos($tag, $match)) { |
|
498 | 498 | // Matched, return true |
499 | 499 | return true; |
500 | 500 | } |
@@ -515,11 +515,11 @@ discard block |
||
515 | 515 | * @return bool |
516 | 516 | */ |
517 | 517 | private function can_inject_late($jsPath) { |
518 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
519 | - if ( true !== $this->inject_min_late ) { |
|
518 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
519 | + if (true !== $this->inject_min_late) { |
|
520 | 520 | // late-inject turned off |
521 | 521 | return false; |
522 | - } else if ( ( false === strpos( $jsPath, 'min.js' ) ) && ( false === strpos( $jsPath, 'wp-includes/js/jquery/jquery.js' ) ) && ( str_replace( $consider_minified_array, '', $jsPath ) === $jsPath ) ) { |
|
522 | + } else if ((false === strpos($jsPath, 'min.js')) && (false === strpos($jsPath, 'wp-includes/js/jquery/jquery.js')) && (str_replace($consider_minified_array, '', $jsPath) === $jsPath)) { |
|
523 | 523 | // file not minified based on filename & filter |
524 | 524 | return false; |
525 | 525 | } else { |
@@ -546,26 +546,26 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @return bool|string Url pointing to the minified js file or false. |
548 | 548 | */ |
549 | - public function minify_single( $filepath, $cache_miss = false ) |
|
549 | + public function minify_single($filepath, $cache_miss = false) |
|
550 | 550 | { |
551 | - $contents = $this->prepare_minify_single( $filepath ); |
|
551 | + $contents = $this->prepare_minify_single($filepath); |
|
552 | 552 | |
553 | - if ( empty( $contents ) ) { |
|
553 | + if (empty($contents)) { |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | |
557 | 557 | // Check cache. |
558 | - $hash = 'single_' . md5( $contents ); |
|
559 | - $cache = new autoptimizeCache( $hash, 'js' ); |
|
558 | + $hash = 'single_'.md5($contents); |
|
559 | + $cache = new autoptimizeCache($hash, 'js'); |
|
560 | 560 | |
561 | 561 | // If not in cache already, minify... |
562 | - if ( ! $cache->check() || $cache_miss ) { |
|
563 | - $contents = trim( JSMin::minify( $contents ) ); |
|
562 | + if (!$cache->check() || $cache_miss) { |
|
563 | + $contents = trim(JSMin::minify($contents)); |
|
564 | 564 | // Store in cache. |
565 | - $cache->cache( $contents, 'text/javascript' ); |
|
565 | + $cache->cache($contents, 'text/javascript'); |
|
566 | 566 | } |
567 | 567 | |
568 | - $url = $this->build_minify_single_url( $cache ); |
|
568 | + $url = $this->build_minify_single_url($cache); |
|
569 | 569 | |
570 | 570 | return $url; |
571 | 571 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * Checks if cachesize is > 0.5GB (size is filterable), if so, an option is set which controls showing an admin notice. |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -25,51 +25,51 @@ discard block |
||
25 | 25 | |
26 | 26 | public function add_hooks() |
27 | 27 | { |
28 | - if ( is_admin() ) { |
|
29 | - add_action( 'plugins_loaded', array( $this, 'setup' ) ); |
|
28 | + if (is_admin()) { |
|
29 | + add_action('plugins_loaded', array($this, 'setup')); |
|
30 | 30 | } |
31 | - add_action( self::SCHEDULE_HOOK, array( $this, 'cronjob' ) ); |
|
32 | - add_action( 'admin_notices', array( $this, 'show_admin_notice' ) ); |
|
31 | + add_action(self::SCHEDULE_HOOK, array($this, 'cronjob')); |
|
32 | + add_action('admin_notices', array($this, 'show_admin_notice')); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public function setup() |
36 | 36 | { |
37 | - $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true ); |
|
38 | - $schedule = wp_get_schedule( self::SCHEDULE_HOOK ); |
|
39 | - $frequency = apply_filters( 'autoptimize_filter_cachecheck_frequency', 'twicedaily' ); |
|
40 | - if ( ! in_array( $frequency, array( 'hourly', 'twicedaily', 'daily', 'weekly', 'monthly' ) ) ) { |
|
37 | + $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
38 | + $schedule = wp_get_schedule(self::SCHEDULE_HOOK); |
|
39 | + $frequency = apply_filters('autoptimize_filter_cachecheck_frequency', 'twicedaily'); |
|
40 | + if (!in_array($frequency, array('hourly', 'twicedaily', 'daily', 'weekly', 'monthly'))) { |
|
41 | 41 | $frequency = 'twicedaily'; |
42 | 42 | } |
43 | - if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) { |
|
44 | - if ( $schedule ) { |
|
45 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
43 | + if ($do_cache_check && (!$schedule || $schedule !== $frequency)) { |
|
44 | + if ($schedule) { |
|
45 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
46 | 46 | } |
47 | - wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK ); |
|
48 | - } elseif ( $schedule && ! $do_cache_check ) { |
|
49 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
47 | + wp_schedule_event(time(), $frequency, self::SCHEDULE_HOOK); |
|
48 | + } elseif ($schedule && !$do_cache_check) { |
|
49 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | public function cronjob() |
54 | 54 | { |
55 | 55 | // Check cachesize and act accordingly. |
56 | - $max_size = (int) apply_filters( 'autoptimize_filter_cachecheck_maxsize', 536870912 ); |
|
57 | - $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true ); |
|
56 | + $max_size = (int) apply_filters('autoptimize_filter_cachecheck_maxsize', 536870912); |
|
57 | + $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
58 | 58 | $stat_array = autoptimizeCache::stats(); |
59 | - $cache_size = round( $stat_array[1] ); |
|
60 | - if ( ( $cache_size > $max_size ) && ( $do_cache_check ) ) { |
|
61 | - update_option( 'autoptimize_cachesize_notice', true ); |
|
62 | - if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) { |
|
63 | - $home_url = esc_url( home_url() ); |
|
64 | - $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', get_option( 'admin_email', '' ) ); |
|
65 | - |
|
66 | - $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $home_url . ')'; |
|
67 | - $ao_mailbody = __( 'Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize' ) . ' (site: ' . $home_url . ')'; |
|
68 | - |
|
69 | - if ( ! empty( $ao_mailto ) ) { |
|
70 | - $ao_mailresult = wp_mail( $ao_mailto, $ao_mailsubject, $ao_mailbody ); |
|
71 | - if ( ! $ao_mailresult ) { |
|
72 | - error_log( 'Autoptimize could not send cache size warning mail.' ); |
|
59 | + $cache_size = round($stat_array[1]); |
|
60 | + if (($cache_size > $max_size) && ($do_cache_check)) { |
|
61 | + update_option('autoptimize_cachesize_notice', true); |
|
62 | + if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) { |
|
63 | + $home_url = esc_url(home_url()); |
|
64 | + $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', '')); |
|
65 | + |
|
66 | + $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$home_url.')'; |
|
67 | + $ao_mailbody = __('Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize').' (site: '.$home_url.')'; |
|
68 | + |
|
69 | + if (!empty($ao_mailto)) { |
|
70 | + $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody); |
|
71 | + if (!$ao_mailresult) { |
|
72 | + error_log('Autoptimize could not send cache size warning mail.'); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | } |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | |
88 | 88 | public function show_admin_notice() |
89 | 89 | { |
90 | - if ( (bool) get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) { |
|
90 | + if ((bool) get_option('autoptimize_cachesize_notice', false) && current_user_can('manage_options')) { |
|
91 | 91 | echo '<div class="notice notice-warning"><p>'; |
92 | - _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' ); |
|
92 | + _e('<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize'); |
|
93 | 93 | echo '</p></div>'; |
94 | - update_option( 'autoptimize_cachesize_notice', false ); |
|
94 | + update_option('autoptimize_cachesize_notice', false); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Notice for image proxy usage. |
98 | 98 | $_imgopt_notice = autoptimizeImages::instance()->get_status_notice(); |
99 | - if ( current_user_can( 'manage_options' ) && is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1, -2 ) ) ) { |
|
99 | + if (current_user_can('manage_options') && is_array($_imgopt_notice) && array_key_exists('status', $_imgopt_notice) && in_array($_imgopt_notice['status'], array(1, -1, -2))) { |
|
100 | 100 | $_dismissible = 'ao-img-opt-notice-'; |
101 | 101 | $_hide_notice = '7'; |
102 | 102 | |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | $_hide_notice = '1'; |
105 | 105 | } |
106 | 106 | |
107 | - $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice ); |
|
107 | + $_imgopt_notice_dismissible = apply_filters('autoptimize_filter_imgopt_notice_dismissable', $_dismissible.$_hide_notice); |
|
108 | 108 | |
109 | - if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) { |
|
110 | - echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p>' . $_imgopt_notice['notice'] . '</p></div>'; |
|
109 | + if ($_imgopt_notice && PAnD::is_admin_notice_active($_imgopt_notice_dismissible)) { |
|
110 | + echo '<div class="notice notice-warning is-dismissible" data-dismissible="'.$_imgopt_notice_dismissible.'"><p>'.$_imgopt_notice['notice'].'</p></div>'; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param string $version Version. |
34 | 34 | * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks. |
35 | 35 | */ |
36 | - public function __construct( $version, $filepath ) |
|
36 | + public function __construct($version, $filepath) |
|
37 | 37 | { |
38 | 38 | $this->version = $version; |
39 | 39 | $this->filepath = $filepath; |
@@ -50,98 +50,98 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function add_hooks() |
52 | 52 | { |
53 | - if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) { |
|
54 | - define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' ); |
|
53 | + if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) { |
|
54 | + define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded'); |
|
55 | 55 | } |
56 | 56 | |
57 | - add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) ); |
|
58 | - add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) ); |
|
57 | + add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup')); |
|
58 | + add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge')); |
|
59 | 59 | |
60 | - add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) ); |
|
61 | - add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) ); |
|
62 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) ); |
|
63 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) ); |
|
60 | + add_action('autoptimize_setup_done', array($this, 'version_upgrades_check')); |
|
61 | + add_action('autoptimize_setup_done', array($this, 'check_cache_and_run')); |
|
62 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra')); |
|
63 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab')); |
|
64 | 64 | |
65 | - add_action( 'init', array( $this, 'load_textdomain' ) ); |
|
66 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); |
|
65 | + add_action('init', array($this, 'load_textdomain')); |
|
66 | + add_action('admin_init', array('PAnD', 'init')); |
|
67 | 67 | |
68 | - register_activation_hook( $this->filepath, array( $this, 'on_activate' ) ); |
|
68 | + register_activation_hook($this->filepath, array($this, 'on_activate')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | public function on_activate() |
72 | 72 | { |
73 | - register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' ); |
|
73 | + register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public function load_textdomain() |
77 | 77 | { |
78 | - load_plugin_textdomain( 'autoptimize' ); |
|
78 | + load_plugin_textdomain('autoptimize'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | public function setup() |
82 | 82 | { |
83 | 83 | // Do we gzip in php when caching or is the webserver doing it? |
84 | - define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option( 'autoptimize_cache_nogzip' ) ); |
|
84 | + define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip')); |
|
85 | 85 | |
86 | 86 | // These can be overridden by specifying them in wp-config.php or such. |
87 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) { |
|
88 | - define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) ); |
|
87 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { |
|
88 | + define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); |
|
89 | 89 | } |
90 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) { |
|
91 | - define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' ); |
|
90 | + if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { |
|
91 | + define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); |
|
92 | 92 | } |
93 | - if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) { |
|
94 | - define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' ); |
|
93 | + if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { |
|
94 | + define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); |
|
95 | 95 | } |
96 | 96 | // Note: trailing slash is not optional! |
97 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
98 | - define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() ); |
|
97 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
98 | + define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname()); |
|
99 | 99 | } |
100 | 100 | |
101 | - define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) ); |
|
101 | + define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
102 | 102 | |
103 | - if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) { |
|
104 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
105 | - define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) ); |
|
103 | + if (!defined('AUTOPTIMIZE_WP_SITE_URL')) { |
|
104 | + if (function_exists('domain_mapping_siteurl')) { |
|
105 | + define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id())); |
|
106 | 106 | } else { |
107 | - define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() ); |
|
107 | + define('AUTOPTIMIZE_WP_SITE_URL', site_url()); |
|
108 | 108 | } |
109 | 109 | } |
110 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) { |
|
111 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
112 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) ); |
|
110 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) { |
|
111 | + if (function_exists('domain_mapping_siteurl')) { |
|
112 | + define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url())); |
|
113 | 113 | } else { |
114 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() ); |
|
114 | + define('AUTOPTIMIZE_WP_CONTENT_URL', content_url()); |
|
115 | 115 | } |
116 | 116 | } |
117 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) { |
|
118 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
117 | + if (!defined('AUTOPTIMIZE_CACHE_URL')) { |
|
118 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
119 | 119 | $blog_id = get_current_blog_id(); |
120 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' ); |
|
120 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
121 | 121 | } else { |
122 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR ); |
|
122 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
123 | 123 | } |
124 | 124 | } |
125 | - if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) { |
|
126 | - define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) ); |
|
125 | + if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) { |
|
126 | + define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL)); |
|
127 | 127 | } |
128 | - if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) { |
|
129 | - define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) ); |
|
128 | + if (!defined('AUTOPTIMIZE_HASH')) { |
|
129 | + define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL)); |
|
130 | 130 | } |
131 | - if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) { |
|
132 | - define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ); |
|
131 | + if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) { |
|
132 | + define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | // Multibyte-capable string replacements are available with a filter. |
136 | 136 | // Also requires 'mbstring' extension. |
137 | - $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false ); |
|
138 | - if ( $with_mbstring ) { |
|
139 | - autoptimizeUtils::mbstring_available( \extensions_loaded( 'mbstring' ) ); |
|
137 | + $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false); |
|
138 | + if ($with_mbstring) { |
|
139 | + autoptimizeUtils::mbstring_available(\extensions_loaded('mbstring')); |
|
140 | 140 | } else { |
141 | - autoptimizeUtils::mbstring_available( false ); |
|
141 | + autoptimizeUtils::mbstring_available(false); |
|
142 | 142 | } |
143 | 143 | |
144 | - do_action( 'autoptimize_setup_done' ); |
|
144 | + do_action('autoptimize_setup_done'); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -151,59 +151,59 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function version_upgrades_check() |
153 | 153 | { |
154 | - autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version ); |
|
154 | + autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | public function check_cache_and_run() |
158 | 158 | { |
159 | - if ( autoptimizeCache::cacheavail() ) { |
|
159 | + if (autoptimizeCache::cacheavail()) { |
|
160 | 160 | $conf = autoptimizeConfig::instance(); |
161 | - if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) { |
|
161 | + if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) { |
|
162 | 162 | // Hook into WordPress frontend. |
163 | - if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) { |
|
163 | + if (defined('AUTOPTIMIZE_INIT_EARLIER')) { |
|
164 | 164 | add_action( |
165 | 165 | 'init', |
166 | - array( $this, 'start_buffering' ), |
|
166 | + array($this, 'start_buffering'), |
|
167 | 167 | self::INIT_EARLIER_PRIORITY |
168 | 168 | ); |
169 | 169 | } else { |
170 | - if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) { |
|
171 | - define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' ); |
|
170 | + if (!defined('AUTOPTIMIZE_HOOK_INTO')) { |
|
171 | + define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); |
|
172 | 172 | } |
173 | 173 | add_action( |
174 | - constant( 'AUTOPTIMIZE_HOOK_INTO' ), |
|
175 | - array( $this, 'start_buffering' ), |
|
174 | + constant('AUTOPTIMIZE_HOOK_INTO'), |
|
175 | + array($this, 'start_buffering'), |
|
176 | 176 | self::DEFAULT_HOOK_PRIORITY |
177 | 177 | ); |
178 | 178 | } |
179 | 179 | |
180 | 180 | // And disable Jetpack's site accelerator if JS or CSS opt. are active. |
181 | - if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) { |
|
182 | - add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' ); |
|
181 | + if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) { |
|
182 | + add_filter('jetpack_force_disable_site_accelerator', '__return_true'); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | } else { |
186 | - add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' ); |
|
186 | + add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable'); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | public function maybe_run_ao_extra() |
191 | 191 | { |
192 | - if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) { |
|
192 | + if (apply_filters('autoptimize_filter_extra_activate', true)) { |
|
193 | 193 | $ao_imgopt = new autoptimizeImages(); |
194 | 194 | $ao_imgopt->run(); |
195 | 195 | $ao_extra = new autoptimizeExtra(); |
196 | 196 | $ao_extra->run(); |
197 | 197 | |
198 | 198 | // And show the imgopt notice. |
199 | - add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' ); |
|
199 | + add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt'); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | 203 | public function maybe_run_partners_tab() |
204 | 204 | { |
205 | 205 | // Loads partners tab code if in admin (and not in admin-ajax.php)! |
206 | - if ( autoptimizeConfig::is_admin_and_not_ajax() ) { |
|
206 | + if (autoptimizeConfig::is_admin_and_not_ajax()) { |
|
207 | 207 | new autoptimizePartners(); |
208 | 208 | } |
209 | 209 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | public function hook_page_cache_purge() |
212 | 212 | { |
213 | 213 | // hook into a collection of page cache purge actions if filter allows. |
214 | - if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) { |
|
214 | + if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) { |
|
215 | 215 | $page_cache_purge_actions = array( |
216 | 216 | 'after_rocket_clean_domain', // exists. |
217 | 217 | 'hyper_cache_purged', // Stefano confirmed this will be added. |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | 'wpfc_delete_cache', // Emre confirmed this will be added this. |
224 | 224 | 'swift_performance_after_clear_all_cache', // swift perf. yeah! |
225 | 225 | ); |
226 | - $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions ); |
|
227 | - foreach ( $page_cache_purge_actions as $purge_action ) { |
|
228 | - add_action( $purge_action, 'autoptimizeCache::clearall_actionless' ); |
|
226 | + $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions); |
|
227 | + foreach ($page_cache_purge_actions as $purge_action) { |
|
228 | + add_action($purge_action, 'autoptimizeCache::clearall_actionless'); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | } |
@@ -237,38 +237,38 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public function start_buffering() |
239 | 239 | { |
240 | - if ( $this->should_buffer() ) { |
|
240 | + if ($this->should_buffer()) { |
|
241 | 241 | |
242 | 242 | // Load speedupper conditionally (true by default). |
243 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
243 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
244 | 244 | $ao_speedupper = new autoptimizeSpeedupper(); |
245 | 245 | } |
246 | 246 | |
247 | 247 | $conf = autoptimizeConfig::instance(); |
248 | 248 | |
249 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
250 | - if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) { |
|
251 | - define( 'CONCATENATE_SCRIPTS', false ); |
|
249 | + if ($conf->get('autoptimize_js')) { |
|
250 | + if (!defined('CONCATENATE_SCRIPTS')) { |
|
251 | + define('CONCATENATE_SCRIPTS', false); |
|
252 | 252 | } |
253 | - if ( ! defined( 'COMPRESS_SCRIPTS' ) ) { |
|
254 | - define( 'COMPRESS_SCRIPTS', false ); |
|
253 | + if (!defined('COMPRESS_SCRIPTS')) { |
|
254 | + define('COMPRESS_SCRIPTS', false); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
259 | - if ( ! defined( 'COMPRESS_CSS' ) ) { |
|
260 | - define( 'COMPRESS_CSS', false ); |
|
258 | + if ($conf->get('autoptimize_css')) { |
|
259 | + if (!defined('COMPRESS_CSS')) { |
|
260 | + define('COMPRESS_CSS', false); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | - if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) { |
|
265 | - while ( ob_get_level() > 0 ) { |
|
264 | + if (apply_filters('autoptimize_filter_obkiller', false)) { |
|
265 | + while (ob_get_level() > 0) { |
|
266 | 266 | ob_end_clean(); |
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | 270 | // Now, start the real thing! |
271 | - ob_start( array( $this, 'end_buffering' ) ); |
|
271 | + ob_start(array($this, 'end_buffering')); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
@@ -279,31 +279,31 @@ discard block |
||
279 | 279 | * deciding once per request (for use in tests). |
280 | 280 | * @return bool |
281 | 281 | */ |
282 | - public function should_buffer( $doing_tests = false ) |
|
282 | + public function should_buffer($doing_tests = false) |
|
283 | 283 | { |
284 | 284 | static $do_buffering = null; |
285 | 285 | |
286 | 286 | // Only check once in case we're called multiple times by others but |
287 | 287 | // still allows multiple calls when doing tests. |
288 | - if ( null === $do_buffering || $doing_tests ) { |
|
288 | + if (null === $do_buffering || $doing_tests) { |
|
289 | 289 | |
290 | 290 | $ao_noptimize = false; |
291 | 291 | |
292 | 292 | // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS. |
293 | - if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) { |
|
293 | + if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) { |
|
294 | 294 | $ao_noptimize = true; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Skip checking query strings if they're disabled. |
298 | - if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) { |
|
298 | + if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) { |
|
299 | 299 | // Check for `ao_noptimize` (and other) keys in the query string |
300 | 300 | // to get non-optimized page for debugging. |
301 | 301 | $keys = array( |
302 | 302 | 'ao_noptimize', |
303 | 303 | 'ao_noptirocket', |
304 | 304 | ); |
305 | - foreach ( $keys as $key ) { |
|
306 | - if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) { |
|
305 | + foreach ($keys as $key) { |
|
306 | + if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) { |
|
307 | 307 | $ao_noptimize = true; |
308 | 308 | break; |
309 | 309 | } |
@@ -311,15 +311,15 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | // If setting says not to optimize logged in user and user is logged in... |
314 | - if ( 'on' !== get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { |
|
314 | + if ('on' !== get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) { |
|
315 | 315 | $ao_noptimize = true; |
316 | 316 | } |
317 | 317 | |
318 | 318 | // If setting says not to optimize cart/checkout. |
319 | - if ( 'on' !== get_option( 'autoptimize_optimize_checkout', 'on' ) ) { |
|
319 | + if ('on' !== get_option('autoptimize_optimize_checkout', 'on')) { |
|
320 | 320 | // Checking for woocommerce, easy digital downloads and wp ecommerce... |
321 | - foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { |
|
322 | - if ( function_exists( $func ) && $func() ) { |
|
321 | + foreach (array('is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) { |
|
322 | + if (function_exists($func) && $func()) { |
|
323 | 323 | $ao_noptimize = true; |
324 | 324 | break; |
325 | 325 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | } |
328 | 328 | |
329 | 329 | // Allows blocking of autoptimization on your own terms regardless of above decisions. |
330 | - $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
|
330 | + $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize); |
|
331 | 331 | |
332 | 332 | // Check for site being previewed in the Customizer (available since WP 4.0). |
333 | 333 | $is_customize_preview = false; |
334 | - if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) { |
|
334 | + if (function_exists('is_customize_preview') && is_customize_preview()) { |
|
335 | 335 | $is_customize_preview = is_customize_preview(); |
336 | 336 | } |
337 | 337 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * while the main query hasn't been ran yet. Thats why we use |
343 | 343 | * AUTOPTIMIZE_INIT_EARLIER in tests. |
344 | 344 | */ |
345 | - $do_buffering = ( ! is_admin() && ! is_feed() && ! $ao_noptimize && ! $is_customize_preview ); |
|
345 | + $do_buffering = (!is_admin() && !is_feed() && !$ao_noptimize && !$is_customize_preview); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | return $do_buffering; |
@@ -355,24 +355,24 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return bool |
357 | 357 | */ |
358 | - public function is_valid_buffer( $content ) |
|
358 | + public function is_valid_buffer($content) |
|
359 | 359 | { |
360 | 360 | // Defaults to true. |
361 | 361 | $valid = true; |
362 | 362 | |
363 | - $has_no_html_tag = ( false === stripos( $content, '<html' ) ); |
|
364 | - $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) ); |
|
365 | - $has_html5_doctype = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 ); |
|
363 | + $has_no_html_tag = (false === stripos($content, '<html')); |
|
364 | + $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet')); |
|
365 | + $has_html5_doctype = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0); |
|
366 | 366 | |
367 | - if ( $has_no_html_tag ) { |
|
367 | + if ($has_no_html_tag) { |
|
368 | 368 | // Can't be valid amp markup without an html tag preceding it. |
369 | 369 | $is_amp_markup = false; |
370 | 370 | } else { |
371 | - $is_amp_markup = self::is_amp_markup( $content ); |
|
371 | + $is_amp_markup = self::is_amp_markup($content); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it. |
375 | - if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet ) { |
|
375 | + if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet) { |
|
376 | 376 | $valid = false; |
377 | 377 | } |
378 | 378 | |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @return bool |
389 | 389 | */ |
390 | - public static function is_amp_markup( $content ) |
|
390 | + public static function is_amp_markup($content) |
|
391 | 391 | { |
392 | 392 | // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page. |
393 | - if ( function_exists( 'is_amp_endpoint' ) ) { |
|
393 | + if (function_exists('is_amp_endpoint')) { |
|
394 | 394 | return is_amp_endpoint(); |
395 | 395 | } |
396 | 396 | |
397 | - $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content ); |
|
397 | + $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content); |
|
398 | 398 | |
399 | 399 | return (bool) $is_amp_markup; |
400 | 400 | } |
@@ -407,10 +407,10 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @return string |
409 | 409 | */ |
410 | - public function end_buffering( $content ) |
|
410 | + public function end_buffering($content) |
|
411 | 411 | { |
412 | 412 | // Bail early without modifying anything if we can't handle the content. |
413 | - if ( ! $this->is_valid_buffer( $content ) ) { |
|
413 | + if (!$this->is_valid_buffer($content)) { |
|
414 | 414 | return $content; |
415 | 415 | } |
416 | 416 | |
@@ -418,59 +418,59 @@ discard block |
||
418 | 418 | |
419 | 419 | // Determine what needs to be ran. |
420 | 420 | $classes = array(); |
421 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
421 | + if ($conf->get('autoptimize_js')) { |
|
422 | 422 | $classes[] = 'autoptimizeScripts'; |
423 | 423 | } |
424 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
424 | + if ($conf->get('autoptimize_css')) { |
|
425 | 425 | $classes[] = 'autoptimizeStyles'; |
426 | 426 | } |
427 | - if ( $conf->get( 'autoptimize_html' ) ) { |
|
427 | + if ($conf->get('autoptimize_html')) { |
|
428 | 428 | $classes[] = 'autoptimizeHTML'; |
429 | 429 | } |
430 | 430 | |
431 | 431 | $classoptions = array( |
432 | 432 | 'autoptimizeScripts' => array( |
433 | - 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), |
|
434 | - 'justhead' => $conf->get( 'autoptimize_js_justhead' ), |
|
435 | - 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), |
|
436 | - 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), |
|
437 | - 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), |
|
438 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
439 | - 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), |
|
440 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), |
|
433 | + 'aggregate' => $conf->get('autoptimize_js_aggregate'), |
|
434 | + 'justhead' => $conf->get('autoptimize_js_justhead'), |
|
435 | + 'forcehead' => $conf->get('autoptimize_js_forcehead'), |
|
436 | + 'trycatch' => $conf->get('autoptimize_js_trycatch'), |
|
437 | + 'js_exclude' => $conf->get('autoptimize_js_exclude'), |
|
438 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
439 | + 'include_inline' => $conf->get('autoptimize_js_include_inline'), |
|
440 | + 'minify_excluded' => $conf->get('autoptimize_minify_excluded'), |
|
441 | 441 | ), |
442 | 442 | 'autoptimizeStyles' => array( |
443 | - 'aggregate' => $conf->get( 'autoptimize_css_aggregate' ), |
|
444 | - 'justhead' => $conf->get( 'autoptimize_css_justhead' ), |
|
445 | - 'datauris' => $conf->get( 'autoptimize_css_datauris' ), |
|
446 | - 'defer' => $conf->get( 'autoptimize_css_defer' ), |
|
447 | - 'defer_inline' => $conf->get( 'autoptimize_css_defer_inline' ), |
|
448 | - 'inline' => $conf->get( 'autoptimize_css_inline' ), |
|
449 | - 'css_exclude' => $conf->get( 'autoptimize_css_exclude' ), |
|
450 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
451 | - 'include_inline' => $conf->get( 'autoptimize_css_include_inline' ), |
|
452 | - 'nogooglefont' => $conf->get( 'autoptimize_css_nogooglefont' ), |
|
453 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), |
|
443 | + 'aggregate' => $conf->get('autoptimize_css_aggregate'), |
|
444 | + 'justhead' => $conf->get('autoptimize_css_justhead'), |
|
445 | + 'datauris' => $conf->get('autoptimize_css_datauris'), |
|
446 | + 'defer' => $conf->get('autoptimize_css_defer'), |
|
447 | + 'defer_inline' => $conf->get('autoptimize_css_defer_inline'), |
|
448 | + 'inline' => $conf->get('autoptimize_css_inline'), |
|
449 | + 'css_exclude' => $conf->get('autoptimize_css_exclude'), |
|
450 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
451 | + 'include_inline' => $conf->get('autoptimize_css_include_inline'), |
|
452 | + 'nogooglefont' => $conf->get('autoptimize_css_nogooglefont'), |
|
453 | + 'minify_excluded' => $conf->get('autoptimize_minify_excluded'), |
|
454 | 454 | ), |
455 | 455 | 'autoptimizeHTML' => array( |
456 | - 'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ), |
|
456 | + 'keepcomments' => $conf->get('autoptimize_html_keepcomments'), |
|
457 | 457 | ), |
458 | 458 | ); |
459 | 459 | |
460 | - $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); |
|
460 | + $content = apply_filters('autoptimize_filter_html_before_minify', $content); |
|
461 | 461 | |
462 | 462 | // Run the classes! |
463 | - foreach ( $classes as $name ) { |
|
464 | - $instance = new $name( $content ); |
|
465 | - if ( $instance->read( $classoptions[ $name ] ) ) { |
|
463 | + foreach ($classes as $name) { |
|
464 | + $instance = new $name($content); |
|
465 | + if ($instance->read($classoptions[$name])) { |
|
466 | 466 | $instance->minify(); |
467 | 467 | $instance->cache(); |
468 | 468 | $content = $instance->getcontent(); |
469 | 469 | } |
470 | - unset( $instance ); |
|
470 | + unset($instance); |
|
471 | 471 | } |
472 | 472 | |
473 | - $content = apply_filters( 'autoptimize_html_after_minify', $content ); |
|
473 | + $content = apply_filters('autoptimize_html_after_minify', $content); |
|
474 | 474 | |
475 | 475 | return $content; |
476 | 476 | } |
@@ -514,25 +514,25 @@ discard block |
||
514 | 514 | 'autoptimize_minify_excluded', |
515 | 515 | ); |
516 | 516 | |
517 | - if ( ! is_multisite() ) { |
|
518 | - foreach ( $delete_options as $del_opt ) { |
|
519 | - delete_option( $del_opt ); |
|
517 | + if (!is_multisite()) { |
|
518 | + foreach ($delete_options as $del_opt) { |
|
519 | + delete_option($del_opt); |
|
520 | 520 | } |
521 | 521 | } else { |
522 | 522 | global $wpdb; |
523 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
523 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
524 | 524 | $original_blog_id = get_current_blog_id(); |
525 | - foreach ( $blog_ids as $blog_id ) { |
|
526 | - switch_to_blog( $blog_id ); |
|
527 | - foreach ( $delete_options as $del_opt ) { |
|
528 | - delete_option( $del_opt ); |
|
525 | + foreach ($blog_ids as $blog_id) { |
|
526 | + switch_to_blog($blog_id); |
|
527 | + foreach ($delete_options as $del_opt) { |
|
528 | + delete_option($del_opt); |
|
529 | 529 | } |
530 | 530 | } |
531 | - switch_to_blog( $original_blog_id ); |
|
531 | + switch_to_blog($original_blog_id); |
|
532 | 532 | } |
533 | 533 | |
534 | - if ( wp_get_schedule( 'ao_cachechecker' ) ) { |
|
535 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
534 | + if (wp_get_schedule('ao_cachechecker')) { |
|
535 | + wp_clear_scheduled_hook('ao_cachechecker'); |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
@@ -540,35 +540,35 @@ discard block |
||
540 | 540 | { |
541 | 541 | echo '<div class="error"><p>'; |
542 | 542 | // Translators: %s is the cache directory location. |
543 | - printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); |
|
543 | + printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR); |
|
544 | 544 | echo '</p></div>'; |
545 | 545 | } |
546 | 546 | |
547 | 547 | public static function notice_installed() |
548 | 548 | { |
549 | 549 | echo '<div class="updated"><p>'; |
550 | - _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); |
|
550 | + _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize'); |
|
551 | 551 | echo '</p></div>'; |
552 | 552 | } |
553 | 553 | |
554 | 554 | public static function notice_updated() |
555 | 555 | { |
556 | 556 | echo '<div class="updated"><p>'; |
557 | - _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' ); |
|
557 | + _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize'); |
|
558 | 558 | echo '</p></div>'; |
559 | 559 | } |
560 | 560 | |
561 | 561 | public static function notice_plug_imgopt() |
562 | 562 | { |
563 | 563 | // Translators: the URL added points to the Autopmize Extra settings. |
564 | - $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' ); |
|
565 | - $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); |
|
564 | + $_ao_imgopt_plug_notice = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>'); |
|
565 | + $_ao_imgopt_plug_notice = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice); |
|
566 | 566 | $_ao_imgopt_launch_ok = autoptimizeImages::launch_ok_wrapper(); |
567 | 567 | $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; |
568 | 568 | $_ao_imgopt_active = autoptimizeImages::imgopt_active(); |
569 | 569 | |
570 | - if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { |
|
571 | - echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>'; |
|
570 | + if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) { |
|
571 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>'; |
|
572 | 572 | echo $_ao_imgopt_plug_notice; |
573 | 573 | echo '</p></div>'; |
574 | 574 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles toolbar-related stuff. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -12,32 +12,32 @@ discard block |
||
12 | 12 | public function __construct() |
13 | 13 | { |
14 | 14 | // If Cache is not available we don't add the toolbar. |
15 | - if ( ! autoptimizeCache::cacheavail() ) { |
|
15 | + if (!autoptimizeCache::cacheavail()) { |
|
16 | 16 | return; |
17 | 17 | } |
18 | 18 | |
19 | 19 | // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated. |
20 | - add_action( 'wp_loaded', array( $this, 'load_toolbar' ) ); |
|
20 | + add_action('wp_loaded', array($this, 'load_toolbar')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function load_toolbar() |
24 | 24 | { |
25 | 25 | // Check permissions and that toolbar is not hidden via filter. |
26 | - if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) { |
|
26 | + if (current_user_can('manage_options') && apply_filters('autoptimize_filter_toolbar_show', true)) { |
|
27 | 27 | |
28 | 28 | // Create a handler for the AJAX toolbar requests. |
29 | - add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) ); |
|
29 | + add_action('wp_ajax_autoptimize_delete_cache', array($this, 'delete_cache')); |
|
30 | 30 | |
31 | 31 | // Load custom styles, scripts and menu only when needed. |
32 | - if ( is_admin_bar_showing() ) { |
|
33 | - if ( is_admin() ) { |
|
34 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
32 | + if (is_admin_bar_showing()) { |
|
33 | + if (is_admin()) { |
|
34 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
35 | 35 | } else { |
36 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
36 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // Add the Autoptimize Toolbar to the Admin bar. |
40 | - add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 ); |
|
40 | + add_action('admin_bar_menu', array($this, 'add_toolbar'), 100); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | $stats = autoptimizeCache::stats(); |
51 | 51 | |
52 | 52 | // Set the Max Size recommended for cache files. |
53 | - $max_size = apply_filters( 'autoptimize_filter_cachecheck_maxsize', 512 * 1024 * 1024 ); |
|
53 | + $max_size = apply_filters('autoptimize_filter_cachecheck_maxsize', 512*1024*1024); |
|
54 | 54 | |
55 | 55 | // Retrieve the current Total Files in cache. |
56 | 56 | $files = $stats[0]; |
57 | 57 | // Retrieve the current Total Size of the cache. |
58 | 58 | $bytes = $stats[1]; |
59 | - $size = $this->format_filesize( $bytes ); |
|
59 | + $size = $this->format_filesize($bytes); |
|
60 | 60 | |
61 | 61 | // Calculate the percentage of cache used. |
62 | - $percentage = ceil( $bytes / $max_size * 100 ); |
|
63 | - if ( $percentage > 100 ) { |
|
62 | + $percentage = ceil($bytes/$max_size*100); |
|
63 | + if ($percentage > 100) { |
|
64 | 64 | $percentage = 100; |
65 | 65 | } |
66 | 66 | |
@@ -70,82 +70,82 @@ discard block |
||
70 | 70 | * - "orange" if over 80%. |
71 | 71 | * - "red" if over 100%. |
72 | 72 | */ |
73 | - $color = ( 100 == $percentage ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' ); |
|
73 | + $color = (100 == $percentage) ? 'red' : (($percentage > 80) ? 'orange' : 'green'); |
|
74 | 74 | |
75 | 75 | // Create or add new items into the Admin Toolbar. |
76 | 76 | // Main "Autoptimize" node. |
77 | - $wp_admin_bar->add_node( array( |
|
77 | + $wp_admin_bar->add_node(array( |
|
78 | 78 | 'id' => 'autoptimize', |
79 | - 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Autoptimize', 'autoptimize' ) . '</span>', |
|
80 | - 'href' => admin_url( 'options-general.php?page=autoptimize' ), |
|
81 | - 'meta' => array( 'class' => 'bullet-' . $color ), |
|
79 | + 'title' => '<span class="ab-icon"></span><span class="ab-label">'.__('Autoptimize', 'autoptimize').'</span>', |
|
80 | + 'href' => admin_url('options-general.php?page=autoptimize'), |
|
81 | + 'meta' => array('class' => 'bullet-'.$color), |
|
82 | 82 | )); |
83 | 83 | |
84 | 84 | // "Cache Info" node. |
85 | - $wp_admin_bar->add_node( array( |
|
85 | + $wp_admin_bar->add_node(array( |
|
86 | 86 | 'id' => 'autoptimize-cache-info', |
87 | - 'title' => '<p>' . __( 'Cache Info', 'autoptimize' ) . '</p>' . |
|
88 | - '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . |
|
89 | - '<div class="autoptimize-circle">' . |
|
90 | - '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>' . |
|
91 | - '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>' . |
|
92 | - '<div class="shadow"></div>' . |
|
93 | - '</div>' . |
|
94 | - '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>' . |
|
95 | - '</div>' . |
|
96 | - '<table>' . |
|
97 | - '<tr><td>' . __( 'Size', 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . |
|
98 | - '<tr><td>' . __( 'Files', 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . |
|
87 | + 'title' => '<p>'.__('Cache Info', 'autoptimize').'</p>'. |
|
88 | + '<div class="autoptimize-radial-bar" percentage="'.$percentage.'">'. |
|
89 | + '<div class="autoptimize-circle">'. |
|
90 | + '<div class="mask full"><div class="fill bg-'.$color.'"></div></div>'. |
|
91 | + '<div class="mask half"><div class="fill bg-'.$color.'"></div></div>'. |
|
92 | + '<div class="shadow"></div>'. |
|
93 | + '</div>'. |
|
94 | + '<div class="inset"><div class="percentage"><div class="numbers '.$color.'">'.$percentage.'%</div></div></div>'. |
|
95 | + '</div>'. |
|
96 | + '<table>'. |
|
97 | + '<tr><td>'.__('Size', 'autoptimize').':</td><td class="size '.$color.'">'.$size.'</td></tr>'. |
|
98 | + '<tr><td>'.__('Files', 'autoptimize').':</td><td class="files white">'.$files.'</td></tr>'. |
|
99 | 99 | '</table>', |
100 | 100 | 'parent' => 'autoptimize', |
101 | 101 | )); |
102 | 102 | |
103 | 103 | // "Delete Cache" node. |
104 | - $wp_admin_bar->add_node( array( |
|
104 | + $wp_admin_bar->add_node(array( |
|
105 | 105 | 'id' => 'autoptimize-delete-cache', |
106 | - 'title' => __( 'Delete Cache', 'autoptimize' ), |
|
106 | + 'title' => __('Delete Cache', 'autoptimize'), |
|
107 | 107 | 'parent' => 'autoptimize', |
108 | 108 | )); |
109 | 109 | } |
110 | 110 | |
111 | 111 | public function delete_cache() |
112 | 112 | { |
113 | - check_ajax_referer( 'ao_delcache_nonce', 'nonce' ); |
|
113 | + check_ajax_referer('ao_delcache_nonce', 'nonce'); |
|
114 | 114 | |
115 | 115 | $result = false; |
116 | - if ( current_user_can( 'manage_options' ) ) { |
|
116 | + if (current_user_can('manage_options')) { |
|
117 | 117 | // We call the function for cleaning the Autoptimize cache. |
118 | 118 | $result = autoptimizeCache::clearall(); |
119 | 119 | } |
120 | 120 | |
121 | - wp_send_json( $result ); |
|
121 | + wp_send_json($result); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function enqueue_scripts() |
125 | 125 | { |
126 | 126 | // Autoptimize Toolbar Styles. |
127 | - wp_enqueue_style( 'autoptimize-toolbar', plugins_url( '/static/toolbar.css', __FILE__ ), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all' ); |
|
127 | + wp_enqueue_style('autoptimize-toolbar', plugins_url('/static/toolbar.css', __FILE__), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all'); |
|
128 | 128 | |
129 | 129 | // Autoptimize Toolbar Javascript. |
130 | - wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true ); |
|
130 | + wp_enqueue_script('autoptimize-toolbar', plugins_url('/static/toolbar.js', __FILE__), array('jquery'), AUTOPTIMIZE_PLUGIN_VERSION, true); |
|
131 | 131 | |
132 | 132 | // Localizes a registered script with data for a JavaScript variable. |
133 | 133 | // Needed for the AJAX to work properly on the frontend. |
134 | - wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
135 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
134 | + wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
135 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
136 | 136 | // translators: links to the Autoptimize settings page. |
137 | - 'error_msg' => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href="%s">Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ), |
|
138 | - 'dismiss_msg' => __( 'Dismiss this notice.' ), |
|
139 | - 'nonce' => wp_create_nonce( 'ao_delcache_nonce' ), |
|
140 | - ) ); |
|
137 | + 'error_msg' => sprintf(__('Your Autoptimize cache might not have been purged successfully, please check on the <a href="%s">Autoptimize settings page</a>.', 'autoptimize'), admin_url('options-general.php?page=autoptimize').' style="white-space:nowrap;"'), |
|
138 | + 'dismiss_msg' => __('Dismiss this notice.'), |
|
139 | + 'nonce' => wp_create_nonce('ao_delcache_nonce'), |
|
140 | + )); |
|
141 | 141 | } |
142 | 142 | |
143 | - public function format_filesize( $bytes, $decimals = 2 ) |
|
143 | + public function format_filesize($bytes, $decimals = 2) |
|
144 | 144 | { |
145 | - $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); |
|
145 | + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
146 | 146 | |
147 | - for ( $i = 0; ( $bytes / 1024) > 0.9; $i++, $bytes /= 1024 ) {} // @codingStandardsIgnoreLine |
|
147 | + for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {} // @codingStandardsIgnoreLine |
|
148 | 148 | |
149 | - return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[ $i ] ); |
|
149 | + return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]); |
|
150 | 150 | } |
151 | 151 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles autoptimizeExtra frontend features + admin options page |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param array $options Optional. Allows overriding options without having to specify them via admin options page. |
23 | 23 | */ |
24 | - public function __construct( $options = array() ) |
|
24 | + public function __construct($options = array()) |
|
25 | 25 | { |
26 | - if ( empty( $options ) ) { |
|
26 | + if (empty($options)) { |
|
27 | 27 | $options = self::fetch_options(); |
28 | 28 | } |
29 | 29 | |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | |
33 | 33 | public function run() |
34 | 34 | { |
35 | - if ( is_admin() ) { |
|
36 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
37 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) ); |
|
35 | + if (is_admin()) { |
|
36 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
37 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab')); |
|
38 | 38 | } else { |
39 | 39 | $this->run_on_frontend(); |
40 | 40 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | public static function fetch_options() |
44 | 44 | { |
45 | - $value = get_option( 'autoptimize_extra_settings' ); |
|
46 | - if ( empty( $value ) ) { |
|
45 | + $value = get_option('autoptimize_extra_settings'); |
|
46 | + if (empty($value)) { |
|
47 | 47 | // Fallback to returning defaults when no stored option exists yet. |
48 | 48 | $value = autoptimizeConfig::get_ao_extra_default_options(); |
49 | 49 | } |
@@ -54,55 +54,55 @@ discard block |
||
54 | 54 | public function disable_emojis() |
55 | 55 | { |
56 | 56 | // Removing all actions related to emojis! |
57 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
58 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
59 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
60 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
61 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
62 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
63 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
57 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
58 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
59 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
60 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
61 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
62 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
63 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
64 | 64 | |
65 | 65 | // Removes TinyMCE emojis. |
66 | - add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) ); |
|
66 | + add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce')); |
|
67 | 67 | |
68 | 68 | // Removes emoji dns-preftech. |
69 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 ); |
|
69 | + add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2); |
|
70 | 70 | } |
71 | 71 | |
72 | - public function filter_disable_emojis_tinymce( $plugins ) |
|
72 | + public function filter_disable_emojis_tinymce($plugins) |
|
73 | 73 | { |
74 | - if ( is_array( $plugins ) ) { |
|
75 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
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 | - public function filter_remove_qs( $src ) |
|
81 | + public function filter_remove_qs($src) |
|
82 | 82 | { |
83 | - if ( strpos( $src, '?ver=' ) ) { |
|
84 | - $src = remove_query_arg( 'ver', $src ); |
|
83 | + if (strpos($src, '?ver=')) { |
|
84 | + $src = remove_query_arg('ver', $src); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $src; |
88 | 88 | } |
89 | 89 | |
90 | - public function extra_async_js( $in ) |
|
90 | + public function extra_async_js($in) |
|
91 | 91 | { |
92 | 92 | $exclusions = array(); |
93 | - if ( ! empty( $in ) ) { |
|
94 | - $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' ); |
|
93 | + if (!empty($in)) { |
|
94 | + $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), ''); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $settings = $this->options['autoptimize_extra_text_field_3']; |
98 | - $async = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' ); |
|
99 | - $attr = apply_filters( 'autoptimize_filter_extra_async', 'async' ); |
|
100 | - foreach ( $async as $k => $v ) { |
|
101 | - $async[ $k ] = $attr; |
|
98 | + $async = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), ''); |
|
99 | + $attr = apply_filters('autoptimize_filter_extra_async', 'async'); |
|
100 | + foreach ($async as $k => $v) { |
|
101 | + $async[$k] = $attr; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Merge exclusions & asyncs in one array and return to AO API. |
105 | - $merged = array_merge( $exclusions, $async ); |
|
105 | + $merged = array_merge($exclusions, $async); |
|
106 | 106 | |
107 | 107 | return $merged; |
108 | 108 | } |
@@ -112,54 +112,54 @@ discard block |
||
112 | 112 | $options = $this->options; |
113 | 113 | |
114 | 114 | // Disable emojis if specified. |
115 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) { |
|
115 | + if (!empty($options['autoptimize_extra_checkbox_field_1'])) { |
|
116 | 116 | $this->disable_emojis(); |
117 | 117 | } |
118 | 118 | |
119 | 119 | // Remove version query parameters. |
120 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) { |
|
121 | - add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
122 | - add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
120 | + if (!empty($options['autoptimize_extra_checkbox_field_0'])) { |
|
121 | + add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
122 | + add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Avoiding conflicts of interest when async-javascript plugin is active! |
126 | - $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ); |
|
127 | - if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) { |
|
128 | - add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 ); |
|
126 | + $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php'); |
|
127 | + if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) { |
|
128 | + add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | // Optimize google fonts! |
132 | - if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) { |
|
133 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 ); |
|
134 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 ); |
|
135 | - add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 ); |
|
132 | + if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) { |
|
133 | + add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2); |
|
134 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1); |
|
135 | + add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Preconnect! |
139 | - if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) { |
|
140 | - add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 ); |
|
139 | + if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
140 | + add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - public function filter_remove_emoji_dns_prefetch( $urls, $relation_type ) |
|
144 | + public function filter_remove_emoji_dns_prefetch($urls, $relation_type) |
|
145 | 145 | { |
146 | - $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' ); |
|
146 | + $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/'); |
|
147 | 147 | |
148 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url ); |
|
148 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type ) |
|
151 | + public function filter_remove_gfonts_dnsprefetch($urls, $relation_type) |
|
152 | 152 | { |
153 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' ); |
|
153 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com'); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove ) |
|
156 | + public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove) |
|
157 | 157 | { |
158 | - if ( 'dns-prefetch' === $relation_type ) { |
|
158 | + if ('dns-prefetch' === $relation_type) { |
|
159 | 159 | $cnt = 0; |
160 | - foreach ( $urls as $url ) { |
|
161 | - if ( false !== strpos( $url, $url_to_remove ) ) { |
|
162 | - unset( $urls[ $cnt ] ); |
|
160 | + foreach ($urls as $url) { |
|
161 | + if (false !== strpos($url, $url_to_remove)) { |
|
162 | + unset($urls[$cnt]); |
|
163 | 163 | } |
164 | 164 | $cnt++; |
165 | 165 | } |
@@ -168,131 +168,131 @@ discard block |
||
168 | 168 | return $urls; |
169 | 169 | } |
170 | 170 | |
171 | - public function filter_optimize_google_fonts( $in ) |
|
171 | + public function filter_optimize_google_fonts($in) |
|
172 | 172 | { |
173 | 173 | // Extract fonts, partly based on wp rocket's extraction code. |
174 | - $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
175 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches ); |
|
174 | + $markup = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
175 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches); |
|
176 | 176 | |
177 | 177 | $fonts_collection = array(); |
178 | - if ( ! $matches[2] ) { |
|
178 | + if (!$matches[2]) { |
|
179 | 179 | return $in; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Store them in $fonts array. |
183 | 183 | $i = 0; |
184 | - foreach ( $matches[2] as $font ) { |
|
185 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
184 | + foreach ($matches[2] as $font) { |
|
185 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
186 | 186 | // Get fonts name. |
187 | - $font = str_replace( array( '%7C', '%7c' ), '|', $font ); |
|
188 | - $font = explode( 'family=', $font ); |
|
189 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
187 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
188 | + $font = explode('family=', $font); |
|
189 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
190 | 190 | // Add font to $fonts[$i] but make sure not to pollute with an empty family! |
191 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
192 | - if ( ! empty( $_thisfont ) ) { |
|
193 | - $fonts_collection[ $i ]['fonts'] = $_thisfont; |
|
191 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
192 | + if (!empty($_thisfont)) { |
|
193 | + $fonts_collection[$i]['fonts'] = $_thisfont; |
|
194 | 194 | // And add subset if any! |
195 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
196 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
197 | - $subset = str_replace( array( '%2C', '%2c' ), ',', $subset ); |
|
198 | - $subset = explode( 'subset=', $subset ); |
|
199 | - $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] ); |
|
195 | + $subset = (is_array($font)) ? end($font) : ''; |
|
196 | + if (false !== strpos($subset, 'subset=')) { |
|
197 | + $subset = str_replace(array('%2C', '%2c'), ',', $subset); |
|
198 | + $subset = explode('subset=', $subset); |
|
199 | + $fonts_collection[$i]['subsets'] = explode(',', $subset[1]); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | // And remove Google Fonts. |
203 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
203 | + $in = str_replace($matches[0][$i], '', $in); |
|
204 | 204 | } |
205 | 205 | $i++; |
206 | 206 | } |
207 | 207 | |
208 | 208 | $options = $this->options; |
209 | 209 | $fonts_markup = ''; |
210 | - if ( '2' === $options['autoptimize_extra_radio_field_4'] ) { |
|
210 | + if ('2' === $options['autoptimize_extra_radio_field_4']) { |
|
211 | 211 | // Remove Google Fonts. |
212 | - unset( $fonts_collection ); |
|
212 | + unset($fonts_collection); |
|
213 | 213 | return $in; |
214 | - } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
214 | + } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) { |
|
215 | 215 | // Aggregate & link! |
216 | 216 | $fonts_string = ''; |
217 | 217 | $subset_string = ''; |
218 | - foreach ( $fonts_collection as $font ) { |
|
219 | - $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' ); |
|
220 | - if ( ! empty( $font['subsets'] ) ) { |
|
221 | - $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' ); |
|
218 | + foreach ($fonts_collection as $font) { |
|
219 | + $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|'); |
|
220 | + if (!empty($font['subsets'])) { |
|
221 | + $subset_string .= ','.trim(implode(',', $font['subsets']), ','); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
225 | - if ( ! empty( $subset_string ) ) { |
|
226 | - $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) ); |
|
227 | - $fonts_string = $fonts_string . '&subset=' . $subset_string; |
|
225 | + if (!empty($subset_string)) { |
|
226 | + $subset_string = str_replace(',', '%2C', ltrim($subset_string, ',')); |
|
227 | + $fonts_string = $fonts_string.'&subset='.$subset_string; |
|
228 | 228 | } |
229 | 229 | |
230 | - $fonts_string = str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ); |
|
230 | + $fonts_string = str_replace('|', '%7C', ltrim($fonts_string, '|')); |
|
231 | 231 | |
232 | - if ( ! empty( $fonts_string ) ) { |
|
233 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
234 | - $rel_string = 'rel="preload" as="style" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"'; |
|
232 | + if (!empty($fonts_string)) { |
|
233 | + if ('5' === $options['autoptimize_extra_radio_field_4']) { |
|
234 | + $rel_string = 'rel="preload" as="style" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"'; |
|
235 | 235 | } else { |
236 | 236 | $rel_string = 'rel="stylesheet"'; |
237 | 237 | } |
238 | - $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />'; |
|
238 | + $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />'; |
|
239 | 239 | } |
240 | - } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) { |
|
240 | + } elseif ('4' === $options['autoptimize_extra_radio_field_4']) { |
|
241 | 241 | // Aggregate & load async (webfont.js impl.)! |
242 | 242 | $fonts_array = array(); |
243 | - foreach ( $fonts_collection as $_fonts ) { |
|
244 | - if ( ! empty( $_fonts['subsets'] ) ) { |
|
245 | - $_subset = implode( ',', $_fonts['subsets'] ); |
|
246 | - foreach ( $_fonts['fonts'] as $key => $_one_font ) { |
|
247 | - $_one_font = $_one_font . ':' . $_subset; |
|
248 | - $_fonts['fonts'][ $key ] = $_one_font; |
|
243 | + foreach ($fonts_collection as $_fonts) { |
|
244 | + if (!empty($_fonts['subsets'])) { |
|
245 | + $_subset = implode(',', $_fonts['subsets']); |
|
246 | + foreach ($_fonts['fonts'] as $key => $_one_font) { |
|
247 | + $_one_font = $_one_font.':'.$_subset; |
|
248 | + $_fonts['fonts'][$key] = $_one_font; |
|
249 | 249 | } |
250 | 250 | } |
251 | - $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] ); |
|
251 | + $fonts_array = array_merge($fonts_array, $_fonts['fonts']); |
|
252 | 252 | } |
253 | 253 | |
254 | - $fonts_array = array_map( 'urldecode', $fonts_array ); |
|
255 | - $fonts_markup = '<script data-cfasync="false" id="ao_optimized_gfonts_config" type="text/javascript">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>'; |
|
254 | + $fonts_array = array_map('urldecode', $fonts_array); |
|
255 | + $fonts_markup = '<script data-cfasync="false" id="ao_optimized_gfonts_config" type="text/javascript">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>'; |
|
256 | 256 | $fonts_library_markup = '<script data-cfasync="false" id="ao_optimized_gfonts_webfontloader" type="text/javascript">(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>'; |
257 | - $in = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) ); |
|
257 | + $in = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>')); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | // Replace back in markup. |
261 | - $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' ); |
|
262 | - $out = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) ); |
|
263 | - unset( $fonts_collection ); |
|
261 | + $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link'); |
|
262 | + $out = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point)); |
|
263 | + unset($fonts_collection); |
|
264 | 264 | |
265 | 265 | // and insert preload polyfill if "link preload" and if the polyfill isn't there yet (courtesy of inline&defer). |
266 | 266 | $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill(); |
267 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] && strpos( $out, $preload_polyfill ) === false ) { |
|
268 | - $out = str_replace( '</body>', $preload_polyfill . '</body>', $out ); |
|
267 | + if ('5' === $options['autoptimize_extra_radio_field_4'] && strpos($out, $preload_polyfill) === false) { |
|
268 | + $out = str_replace('</body>', $preload_polyfill.'</body>', $out); |
|
269 | 269 | } |
270 | 270 | return $out; |
271 | 271 | } |
272 | 272 | |
273 | - public function filter_preconnect( $hints, $relation_type ) |
|
273 | + public function filter_preconnect($hints, $relation_type) |
|
274 | 274 | { |
275 | 275 | $options = $this->options; |
276 | 276 | |
277 | 277 | // Get settings and store in array. |
278 | - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) ); |
|
279 | - $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns ); |
|
278 | + $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2']))); |
|
279 | + $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns); |
|
280 | 280 | |
281 | 281 | // Walk array, extract domain and add to new array with crossorigin attribute. |
282 | - foreach ( $preconns as $preconn ) { |
|
283 | - $parsed = parse_url( $preconn ); |
|
284 | - if ( is_array( $parsed ) && empty( $parsed['scheme'] ) ) { |
|
285 | - $domain = '//' . $parsed['host']; |
|
286 | - } elseif ( is_array( $parsed ) ) { |
|
287 | - $domain = $parsed['scheme'] . '://' . $parsed['host']; |
|
282 | + foreach ($preconns as $preconn) { |
|
283 | + $parsed = parse_url($preconn); |
|
284 | + if (is_array($parsed) && empty($parsed['scheme'])) { |
|
285 | + $domain = '//'.$parsed['host']; |
|
286 | + } elseif (is_array($parsed)) { |
|
287 | + $domain = $parsed['scheme'].'://'.$parsed['host']; |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $domain ) ) { |
|
291 | - $hint = array( 'href' => $domain ); |
|
290 | + if (!empty($domain)) { |
|
291 | + $hint = array('href' => $domain); |
|
292 | 292 | // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
293 | 293 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed. |
294 | - $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) ); |
|
295 | - if ( in_array( $domain, $crossorigins ) ) { |
|
294 | + $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
295 | + if (in_array($domain, $crossorigins)) { |
|
296 | 296 | $hint['crossorigin'] = 'anonymous'; |
297 | 297 | } |
298 | 298 | $new_hints[] = $hint; |
@@ -300,21 +300,21 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Merge in WP's preconnect hints. |
303 | - if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) { |
|
304 | - $hints = array_merge( $hints, $new_hints ); |
|
303 | + if ('preconnect' === $relation_type && !empty($new_hints)) { |
|
304 | + $hints = array_merge($hints, $new_hints); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | return $hints; |
308 | 308 | } |
309 | 309 | |
310 | - public function filter_preconnect_google_fonts( $in ) |
|
310 | + public function filter_preconnect_google_fonts($in) |
|
311 | 311 | { |
312 | - if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) { |
|
312 | + if ('2' !== $this->options['autoptimize_extra_radio_field_4']) { |
|
313 | 313 | // Preconnect to fonts.gstatic.com unless we remove gfonts. |
314 | 314 | $in[] = 'https://fonts.gstatic.com'; |
315 | 315 | } |
316 | 316 | |
317 | - if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) { |
|
317 | + if ('4' === $this->options['autoptimize_extra_radio_field_4']) { |
|
318 | 318 | // Preconnect even more hosts for webfont.js! |
319 | 319 | $in[] = 'https://ajax.googleapis.com'; |
320 | 320 | $in[] = 'https://fonts.googleapis.com'; |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | 'autoptimize_extra', |
332 | 332 | 'manage_options', |
333 | 333 | 'autoptimize_extra', |
334 | - array( $this, 'options_page' ) |
|
334 | + array($this, 'options_page') |
|
335 | 335 | ); |
336 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
336 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
337 | 337 | } |
338 | 338 | |
339 | - public function add_extra_tab( $in ) |
|
339 | + public function add_extra_tab($in) |
|
340 | 340 | { |
341 | - $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) ); |
|
341 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
342 | 342 | |
343 | 343 | return $in; |
344 | 344 | } |
@@ -358,87 +358,87 @@ discard block |
||
358 | 358 | #autoptimize_extra_descr{font-size: 120%;} |
359 | 359 | </style> |
360 | 360 | <div class="wrap"> |
361 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
361 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
362 | 362 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
363 | - <?php if ( 'on' !== get_option( 'autoptimize_js' ) && 'on' !== get_option( 'autoptimize_css' ) && 'on' !== get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?> |
|
363 | + <?php if ('on' !== get_option('autoptimize_js') && 'on' !== get_option('autoptimize_css') && 'on' !== get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?> |
|
364 | 364 | <div class="notice-warning notice"><p> |
365 | - <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?> |
|
365 | + <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?> |
|
366 | 366 | </p></div> |
367 | 367 | <?php } ?> |
368 | 368 | |
369 | 369 | <form id='ao_settings_form' action='options.php' method='post'> |
370 | - <?php settings_fields( 'autoptimize_extra_settings' ); ?> |
|
371 | - <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2> |
|
372 | - <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span> |
|
370 | + <?php settings_fields('autoptimize_extra_settings'); ?> |
|
371 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
372 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
373 | 373 | <table class="form-table"> |
374 | 374 | <tr> |
375 | - <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th> |
|
375 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
376 | 376 | <td> |
377 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/> |
|
378 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/> |
|
379 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php _e( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ); ?><br/> |
|
380 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php _e( 'Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize' ); ?><br/> |
|
381 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php _e( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ); ?><br/> |
|
377 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/> |
|
378 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/> |
|
379 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php _e('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize'); ?><br/> |
|
380 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php _e('Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize'); ?><br/> |
|
381 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize'); ?><br/> |
|
382 | 382 | </td> |
383 | 383 | </tr> |
384 | 384 | <tr> |
385 | - <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th> |
|
385 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
386 | 386 | <td> |
387 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label> |
|
387 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label> |
|
388 | 388 | </td> |
389 | 389 | </tr> |
390 | 390 | <tr> |
391 | - <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th> |
|
391 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
392 | 392 | <td> |
393 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label> |
|
393 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label> |
|
394 | 394 | </td> |
395 | 395 | </tr> |
396 | 396 | <tr> |
397 | - <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
397 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
398 | 398 | <td> |
399 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label> |
|
399 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label> |
|
400 | 400 | </td> |
401 | 401 | </tr> |
402 | 402 | <tr> |
403 | - <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
403 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
404 | 404 | <td> |
405 | 405 | <?php |
406 | - if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) { |
|
406 | + if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) { |
|
407 | 407 | // translators: link points Async Javascript settings page. |
408 | - printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' ); |
|
408 | + printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>'); |
|
409 | 409 | } else { |
410 | 410 | ?> |
411 | - <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'> |
|
411 | + <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'> |
|
412 | 412 | <br /> |
413 | 413 | <?php |
414 | - _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' ); |
|
414 | + _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'); |
|
415 | 415 | // translators: %s will be replaced by a link to the "async javascript" plugin. |
416 | - 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>"' ); |
|
417 | - $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
418 | - echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
416 | + 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>"'); |
|
417 | + $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
418 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
419 | 419 | } |
420 | 420 | ?> |
421 | 421 | </td> |
422 | 422 | </tr> |
423 | 423 | <tr> |
424 | - <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th> |
|
424 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
425 | 425 | <td> |
426 | 426 | <?php |
427 | - if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) { |
|
428 | - _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' ); |
|
427 | + if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
428 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
429 | 429 | $lyte_config_url = 'options-general.php?page=lyte_settings_page'; |
430 | - echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) ); |
|
430 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
431 | 431 | } else { |
432 | 432 | // translators: %s will be replaced by a link to "wp youtube lyte" plugin. |
433 | - 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>' ); |
|
434 | - $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term'; |
|
435 | - echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
433 | + 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>'); |
|
434 | + $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term'; |
|
435 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
436 | 436 | } |
437 | 437 | ?> |
438 | 438 | </td> |
439 | 439 | </tr> |
440 | 440 | </table> |
441 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
441 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
442 | 442 | </form> |
443 | 443 | <?php |
444 | 444 | } |
@@ -16,66 +16,66 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | |
19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
19 | +if (!defined('ABSPATH')) { |
|
20 | 20 | exit; |
21 | 21 | } |
22 | 22 | |
23 | -define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.5.0' ); |
|
23 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.5.0'); |
|
24 | 24 | |
25 | 25 | // plugin_dir_path() returns the trailing slash! |
26 | -define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
27 | -define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ ); |
|
26 | +define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
27 | +define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__); |
|
28 | 28 | |
29 | 29 | // Bail early if attempting to run on non-supported php versions. |
30 | -if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
|
30 | +if (version_compare(PHP_VERSION, '5.3', '<')) { |
|
31 | 31 | function autoptimize_incompatible_admin_notice() { |
32 | - echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.3 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>'; |
|
33 | - if ( isset( $_GET['activate'] ) ) { |
|
34 | - unset( $_GET['activate'] ); |
|
32 | + echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.3 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>'; |
|
33 | + if (isset($_GET['activate'])) { |
|
34 | + unset($_GET['activate']); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | function autoptimize_deactivate_self() { |
38 | - deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) ); |
|
38 | + deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE)); |
|
39 | 39 | } |
40 | - add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' ); |
|
41 | - add_action( 'admin_init', 'autoptimize_deactivate_self' ); |
|
40 | + add_action('admin_notices', 'autoptimize_incompatible_admin_notice'); |
|
41 | + add_action('admin_init', 'autoptimize_deactivate_self'); |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | -function autoptimize_autoload( $class_name ) { |
|
46 | - if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) { |
|
47 | - $file = strtolower( $class_name ); |
|
48 | - $file = str_replace( '_', '-', $file ); |
|
49 | - $path = dirname( __FILE__ ) . '/classes/external/php/'; |
|
50 | - $filepath = $path . $file . '.php'; |
|
51 | - } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) { |
|
52 | - $file = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name ); |
|
53 | - $path = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/'; |
|
54 | - $filepath = $path . $file . '.php'; |
|
55 | - } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) { |
|
45 | +function autoptimize_autoload($class_name) { |
|
46 | + if (in_array($class_name, array('Minify_HTML', 'JSMin'))) { |
|
47 | + $file = strtolower($class_name); |
|
48 | + $file = str_replace('_', '-', $file); |
|
49 | + $path = dirname(__FILE__).'/classes/external/php/'; |
|
50 | + $filepath = $path.$file.'.php'; |
|
51 | + } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) { |
|
52 | + $file = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name); |
|
53 | + $path = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/'; |
|
54 | + $filepath = $path.$file.'.php'; |
|
55 | + } elseif ('autoptimize' === substr($class_name, 0, 11)) { |
|
56 | 56 | // One of our "old" classes. |
57 | 57 | $file = $class_name; |
58 | - $path = dirname( __FILE__ ) . '/classes/'; |
|
59 | - $filepath = $path . $file . '.php'; |
|
60 | - } elseif ( 'PAnD' === $class_name ) { |
|
58 | + $path = dirname(__FILE__).'/classes/'; |
|
59 | + $filepath = $path.$file.'.php'; |
|
60 | + } elseif ('PAnD' === $class_name) { |
|
61 | 61 | $file = 'persist-admin-notices-dismissal'; |
62 | - $path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/'; |
|
63 | - $filepath = $path . $file . '.php'; |
|
62 | + $path = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/'; |
|
63 | + $filepath = $path.$file.'.php'; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // If we didn't match one of our rules, bail! |
67 | - if ( ! isset( $filepath ) ) { |
|
67 | + if (!isset($filepath)) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | require $filepath; |
72 | 72 | } |
73 | 73 | |
74 | -spl_autoload_register( 'autoptimize_autoload' ); |
|
74 | +spl_autoload_register('autoptimize_autoload'); |
|
75 | 75 | |
76 | 76 | // Load WP CLI command(s) on demand. |
77 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
78 | - require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
77 | +if (defined('WP_CLI') && WP_CLI) { |
|
78 | + require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php'; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | function autoptimize() { |
87 | 87 | static $plugin = null; |
88 | 88 | |
89 | - if ( null === $plugin ) { |
|
90 | - $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
89 | + if (null === $plugin) { |
|
90 | + $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $plugin; |