Subscriber.php
4.31 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace WP_Rocket\Engine\CriticalPath\Admin;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Subscriber implements Subscriber_Interface {
/**
* Instance of the CPCSS Settings handler.
*
* @var Settings
*/
private $settings;
/**
* Instance of the Post handler
*
* @var Post
*/
private $post;
/**
* Instance of the Admin handler
*
* @var Admin
*/
private $admin;
/**
* Creates an instance of the subscriber.
*
* @param Post $post Post instance.
* @param Settings $settings CPCSS Settings instance.
* @param Admin $admin Admin instance.
*/
public function __construct( Post $post, Settings $settings, Admin $admin ) {
$this->post = $post;
$this->settings = $settings;
$this->admin = $admin;
}
/**
* Events this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_after_options_metabox' => 'cpcss_section',
'rocket_metabox_cpcss_content' => 'cpcss_actions',
'rocket_first_install_options' => 'add_async_css_mobile_option',
'wp_rocket_upgrade' => [ 'set_async_css_mobile_default_value', 12, 2 ],
'rocket_hidden_settings_fields' => 'add_hidden_async_css_mobile',
'rocket_settings_tools_content' => 'display_cpcss_mobile_section',
'wp_ajax_rocket_enable_mobile_cpcss' => 'enable_mobile_cpcss',
'wp_ajax_rocket_cpcss_heartbeat' => 'cpcss_heartbeat',
'admin_enqueue_scripts' => [
[ 'enqueue_admin_edit_script' ],
[ 'enqueue_admin_cpcss_heartbeat_script' ],
],
'rocket_admin_bar_items' => 'add_regenerate_menu_item',
];
}
/**
* Enable CPCSS mobile.
*
* @since 3.6
*
* @return void
*/
public function enable_mobile_cpcss() {
$this->settings->enable_mobile_cpcss();
}
/**
* Display CPCSS mobile section tool admin view.
*
* @since 3.6
*
* @return void
*/
public function display_cpcss_mobile_section() {
$this->settings->display_cpcss_mobile_section();
}
/**
* Enqueue CPCSS generation / deletion script on edit.php page.
*
* @since 3.6
*
* @param string $page The current admin page.
*
* @return void
*/
public function enqueue_admin_edit_script( $page ) {
$this->post->enqueue_admin_edit_script( $page );
}
/**
* Displays the critical CSS block in WP Rocket options metabox.
*
* @since 3.6
*
* @return void
*/
public function cpcss_section() {
$this->post->cpcss_section();
}
/**
* Displays the content inside the critical CSS block.
*
* @since 3.6
*
* @return void
*/
public function cpcss_actions() {
$this->post->cpcss_actions();
}
/**
* Adds async_css_mobile option to WP Rocket options.
*
* @since 3.6
*
* @param array $options WP Rocket options array.
*
* @return array
*/
public function add_async_css_mobile_option( $options ) {
return $this->settings->add_async_css_mobile_option( $options );
}
/**
* Sets the default value of async_css_mobile to 0 when upgrading from < 3.6.
*
* @since 3.6
*
* @param string $new_version New WP Rocket version.
* @param string $old_version Previous WP Rocket version.
*/
public function set_async_css_mobile_default_value( $new_version, $old_version ) {
$this->settings->set_async_css_mobile_default_value( $new_version, $old_version );
}
/**
* Adds async_css_mobile to the hidden settings fields.
*
* @since 3.6
*
* @param array $hidden_settings_fields An array of hidden settings fields ID.
*
* @return array
*/
public function add_hidden_async_css_mobile( $hidden_settings_fields ) {
return $this->settings->add_hidden_async_css_mobile( $hidden_settings_fields );
}
/**
* Check the CPCSS heartbeat.
*
* @since 3.6
*/
public function cpcss_heartbeat() {
$this->admin->cpcss_heartbeat();
}
/**
* Enqueue CPCSS heartbeat script on all admin pages.
*
* @since 3.6
*/
public function enqueue_admin_cpcss_heartbeat_script() {
$this->admin->enqueue_admin_cpcss_heartbeat_script();
}
/**
* Add Regenerate Critical CSS link to WP Rocket admin bar item
*
* @since 3.6
*
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference.
* @return void
*/
public function add_regenerate_menu_item( $wp_admin_bar ) {
$this->admin->add_regenerate_menu_item( $wp_admin_bar );
}
}