Subscriber.php
4.81 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
namespace WP_Rocket\Engine\Admin\Settings;
use Imagify_Partner;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* WP Rocket settings page subscriber.
*
* @since 3.5.5 Moves into the new architecture.
* @since 3.3
*/
class Subscriber implements Subscriber_Interface {
/**
* Page instance
*
* @var Page
*/
private $page;
/**
* Creates an instance of the object.
*
* @param Page $page Page instance.
*/
public function __construct( Page $page ) {
$this->page = $page;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_menu' => 'add_admin_page',
'admin_init' => 'configure',
'wp_ajax_rocket_refresh_customer_data' => 'refresh_customer_data',
'wp_ajax_rocket_toggle_option' => 'toggle_option',
'rocket_settings_menu_navigation' => [
[ 'add_menu_tools_page' ],
[ 'add_imagify_page', 9 ],
[ 'add_tutorials_page', 11 ],
],
'admin_enqueue_scripts' => 'enqueue_rocket_scripts',
'script_loader_tag' => [ 'async_wistia_script', 10, 2 ],
'rocket_after_settings_radio_options' => [ 'display_radio_options_sub_fields', 11 ],
];
}
/**
* Enqueues WP Rocket scripts on the settings page
*
* @since 3.6
*
* @param string $hook The current admin page.
*
* @return void
*/
public function enqueue_rocket_scripts( $hook ) {
$this->page->enqueue_rocket_scripts( $hook );
}
/**
* Adds the async attribute to the Wistia script
*
* @param string $tag The <script> tag for the enqueued script.
* @param string $handle The script's registered handle.
*
* @return string
*/
public function async_wistia_script( $tag, $handle ) {
return $this->page->async_wistia_script( $tag, $handle );
}
/**
* Adds plugin page to the Settings menu.
*
* @since 3.0
*/
public function add_admin_page() {
add_options_page(
$this->page->get_title(),
/**
* Filters the menu title to display in the Settings sub-menu
*
* @since 3.7.4
*
* @param string $menu_title The text to be used for the menu.
*/
apply_filters( 'rocket_menu_title', $this->page->get_title() ),
$this->page->get_capability(),
$this->page->get_slug(),
[ $this->page, 'render_page' ]
);
}
/**
* Registers the settings, page sections, fields sections and fields.
*
* @since 3.0
*/
public function configure() {
$this->page->configure();
}
/**
* Gets customer data to refresh it on the dashboard with AJAX.
*
* @since 3.0
*
* @return string
*/
public function refresh_customer_data() {
check_ajax_referer( 'rocket-ajax' );
if ( ! current_user_can( 'rocket_manage_options' ) ) {
wp_die();
}
delete_transient( 'wp_rocket_customer_data' );
return wp_send_json_success( $this->page->customer_data() );
}
/**
* Toggle sliding checkboxes option value.
*
* @since 3.0
*/
public function toggle_option() {
$this->page->toggle_option();
}
/**
* Add Tools section to navigation.
*
* @since 3.0
*
* @param array $navigation Array of menu items.
* @return array
*/
public function add_menu_tools_page( $navigation ) {
$navigation['tools'] = [
'id' => 'tools',
'title' => __( 'Tools', 'rocket' ),
'menu_description' => __( 'Import, Export, Rollback', 'rocket' ),
];
return $navigation;
}
/**
* Add Imagify section to navigation.
*
* @since 3.2
*
* @param array $navigation Array of menu items.
* @return array
*/
public function add_imagify_page( $navigation ) {
if (
rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT' )
||
Imagify_Partner::has_imagify_api_key()
) {
return $navigation;
}
$navigation['imagify'] = [
'id' => 'imagify',
'title' => __( 'Image Optimization', 'rocket' ),
'menu_description' => __( 'Compress your images', 'rocket' ),
];
return $navigation;
}
/**
* Add Tutorials section to navigation.
*
* @since 3.4
*
* @param array $navigation Array of menu items.
* @return array
*/
public function add_tutorials_page( $navigation ) {
$navigation['tutorials'] = [
'id' => 'tutorials',
'title' => __( 'Tutorials', 'rocket' ),
'menu_description' => __( 'Getting started and how to videos', 'rocket' ),
];
return $navigation;
}
/**
* Displays the radio option sub fields
*
* @since 3.10
*
* @param array $option_data array of option_id and sub_fields of the option.
*
* @return void
*/
public function display_radio_options_sub_fields( $option_data ) {
if ( empty( $option_data['sub_fields'] ) ) {
return;
}
$this->page->display_radio_options_sub_fields( $option_data['sub_fields'] );
}
}