Subscriber.php
4.01 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\Optimization\DynamicLists;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Subscriber implements Subscriber_Interface {
/**
* DynamicLists instance
*
* @var DynamicLists
*/
private $dynamic_lists;
/**
* Instantiate the class
*
* @param DynamicLists $dynamic_lists DynamicLists instance.
*/
public function __construct( DynamicLists $dynamic_lists ) {
$this->dynamic_lists = $dynamic_lists;
}
/**
* Events this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rest_api_init' => 'register_rest_route',
'rocket_localize_admin_script' => [ 'add_dynamic_lists_script', 11 ],
'init' => 'schedule_lists_update',
'rocket_update_dynamic_lists' => 'update_lists',
'rocket_deactivation' => 'clear_schedule_lists_update',
'rocket_settings_tools_content' => 'display_update_lists_section',
'rocket_cache_ignored_parameters' => 'add_cache_ignored_parameters',
'rocket_minify_excluded_external_js' => 'add_minify_excluded_external_js',
'rocket_move_after_combine_js' => 'add_move_after_combine_js',
'rocket_excluded_inline_js_content' => 'add_combine_js_excluded_inline',
];
}
/**
* Registers the REST dynamic lists update route
*
* @return void
*/
public function register_rest_route() {
$this->dynamic_lists->register_rest_route();
}
/**
* Add REST data to our localize script data.
*
* @param array $data Localize script data.
* @return array
*/
public function add_dynamic_lists_script( $data ) {
$data['rest_url'] = rest_url( 'wp-rocket/v1/dynamic_lists/update/' );
$data['rest_nonce'] = wp_create_nonce( 'wp_rest' );
return $data;
}
/**
* Scheduling the dynamic lists update cron event.
*/
public function schedule_lists_update() {
$this->dynamic_lists->schedule_lists_update();
}
/**
* Clear the dynamic lists update cron event.
*
* @return void
*/
public function clear_schedule_lists_update() {
$this->dynamic_lists->clear_schedule_lists_update();
}
/**
* Update dynamic lists from API.
*
* * @return void
*/
public function update_lists() {
$this->dynamic_lists->update_lists_from_remote();
}
/**
* Displays the dynamic lists update section on tools tab
*
* @return void
*/
public function display_update_lists_section() {
$this->dynamic_lists->display_update_lists_section();
}
/**
* Add the cached ignored parameters to the array
*
* @param string $params Array of ignored parameters.
*
* @return array
*/
public function add_cache_ignored_parameters( $params = [] ): array {
if ( ! is_array( $params ) ) {
$params = (array) $params;
}
return array_merge( $params, $this->dynamic_lists->get_cache_ignored_parameters() );
}
/**
* Add the excluded external JS patterns to the array
*
* @param string $excluded Array of excluded patterns.
*
* @return array
*/
public function add_minify_excluded_external_js( $excluded = [] ): array {
if ( ! is_array( $excluded ) ) {
$excluded = (array) $excluded;
}
return array_merge( $excluded, $this->dynamic_lists->get_js_minify_excluded_external() );
}
/**
* Add the JS patterns to move after the combine JS file to the array
*
* @param string $excluded Array of patterns to move.
*
* @return array
*/
public function add_move_after_combine_js( $excluded = [] ): array {
if ( ! is_array( $excluded ) ) {
$excluded = (array) $excluded;
}
return array_merge( $excluded, $this->dynamic_lists->get_js_move_after_combine() );
}
/**
* Add the excluded inline JS patterns to the array
*
* @param string $excluded Array of excluded patterns.
*
* @return array
*/
public function add_combine_js_excluded_inline( $excluded = [] ): array {
if ( ! is_array( $excluded ) ) {
$excluded = (array) $excluded;
}
return array_merge( $excluded, $this->dynamic_lists->get_combine_js_excluded_inline() );
}
}