/
Extension_Amp_Plugin.php
executable file
·63 lines (42 loc) · 1.21 KB
/
Extension_Amp_Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace W3TC;
class Extension_Amp_Plugin {
function __construct() {
$is_amp_endpoint = null;
}
public function run() {
add_filter( 'w3tc_minify_js_enable',
array( $this, 'w3tc_minify_jscss_enable' ) );
add_filter( 'w3tc_minify_css_enable',
array( $this, 'w3tc_minify_jscss_enable' ) );
add_filter( 'w3tc_footer_comment',
array( $this, 'w3tc_footer_comment' ) );
}
private function is_amp_endpoint() {
if ( is_null( $is_amp_endpoint ) && function_exists('is_amp_endpoint') ) {
$is_amp_endpoint = is_amp_endpoint();
}
return $is_amp_endpoint;
}
public function w3tc_minify_jscss_enable( $enabled ) {
$is_amp_endpoint = $this->is_amp_endpoint();
if ( !is_null( $is_amp_endpoint ) && $is_amp_endpoint ) {
// amp has own rules for CSS and JS files, don't touch them by default
return false;
}
return $enabled;
}
public function w3tc_footer_comment( $strings ) {
$is_amp_endpoint = $this->is_amp_endpoint();
if ( !is_null( $is_amp_endpoint ) && $is_amp_endpoint ) {
$strings[] = 'AMP page, minification is limited';
}
return $strings;
}
}
$p = new Extension_Amp_Plugin();
$p->run();
if ( is_admin() ) {
$p = new Extension_Amp_Plugin_Admin();
$p->run();
}