RemoveSubscriber.php
1.74 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace WP_Rocket\Engine\Optimization\QueryString;
use WP_Rocket\deprecated\DeprecatedClassTrait;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Hooks into WordPress to remove query strings for static files.
*
* @since 3.1
* @since 3.6 Deprecated.
* @author Remy Perona
* @deprecated
*/
class RemoveSubscriber implements Subscriber_Interface {
use DeprecatedClassTrait;
/**
* Remove Query String instance.
*
* @since 3.1
* @author Remy Perona
*
* @var Remove
*/
protected $remove_query_string;
/**
* Constructor
*
* @since 3.1
* @author Remy Perona
*
* @param Remove $remove_query_string Remove Query String instance.
*/
public function __construct( Remove $remove_query_string ) {
self::deprecated_class( '3.6' );
$this->remove_query_string = $remove_query_string;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.1
* @author Remy Perona
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_buffer' => [ 'process', 30 ],
];
}
/**
* Filters the HTML to fetch static files with a query string and remove it
*
* @since 3.1
* @author Remy Perona
*
* @param string $html HTML content.
* @return string
*/
public function process( $html ) {
if ( ! $this->is_allowed() ) {
return $html;
}
$html = $this->remove_query_string->remove_query_strings_css( $html );
$html = $this->remove_query_string->remove_query_strings_js( $html );
return $html;
}
/**
* Checks if is allowed to remove query strings for static files.
*
* @since 3.1
* @author Remy Perona
*
* @return bool
*/
protected function is_allowed() {
return $this->remove_query_string->is_allowed();
}
}