20
20
* Class Admin
21
21
*
22
22
* Manages the admin bar integration for object cache operations.
23
- *
23
+ *
24
24
* @phpstan-type NoticeArray array{
25
25
* type: 'success'|'error',
26
26
* message: string
@@ -95,7 +95,7 @@ public function add_admin_bar_menu( $wp_admin_bar ): void {
95
95
return ;
96
96
}
97
97
98
- $ is_enabled = wp_using_ext_object_cache () && $ wp_object_cache instanceof Object_Cache_Annihilator;
98
+ $ is_enabled = wp_using_ext_object_cache () && class_exists ( Object_Cache_Annihilator::class ) && $ wp_object_cache instanceof Object_Cache_Annihilator;
99
99
$ action = $ is_enabled ? 'disable ' : 'enable ' ;
100
100
$ title = $ is_enabled ? __ ( 'Die 🔫 ' , 'object-cache-annihilator ' ) : __ ( 'Resurrect 👻 ' , 'object-cache-annihilator ' );
101
101
@@ -135,23 +135,15 @@ public function add_admin_bar_menu( $wp_admin_bar ): void {
135
135
* @since 0.1.0
136
136
*
137
137
* @global WP_Object_Cache|Object_Cache_Annihilator $wp_object_cache
138
- *
139
- * @return never
138
+ *
139
+ * @return never|void
140
140
*/
141
141
public function handle_actions () {
142
142
global $ wp_object_cache ;
143
143
144
- if ( ! current_user_can ( 'manage_options ' ) ) {
145
- $ this ->set_notice ( 'error ' , __ ( 'You do not have sufficient permissions to access this page. ' , 'object-cache-annihilator ' ) );
146
- wp_safe_redirect ( admin_url () );
147
- exit ;
148
- }
149
-
150
- $ action = isset ( $ _GET ['action ' ] ) ? $ _GET ['action ' ] : '' ;
144
+ $ action = isset ( $ _GET ['action ' ] ) ? sanitize_text_field ( $ _GET ['action ' ] ) : '' ;
151
145
if ( ! in_array ( $ action , [ 'object_cache_enable ' , 'object_cache_disable ' , 'object_cache_flush ' ], true ) ) {
152
- $ this ->set_notice ( 'error ' , __ ( 'Invalid action. ' , 'object-cache-annihilator ' ) );
153
- wp_safe_redirect ( admin_url () );
154
- exit ;
146
+ return ;
155
147
}
156
148
157
149
check_admin_referer ( $ action );
@@ -160,9 +152,18 @@ public function handle_actions() {
160
152
$ notice_type = 'success ' ;
161
153
$ notice_message = '' ;
162
154
155
+ if ( ! current_user_can ( 'manage_options ' ) ) {
156
+ $ this ->set_notice ( 'error ' , __ ( 'You do not have sufficient permissions to access this page. ' , 'object-cache-annihilator ' ) );
157
+ wp_safe_redirect ( admin_url (), 302 , 'X-Redirect-By: Object Cache Annihilator ' );
158
+ exit ;
159
+ }
160
+
163
161
switch ( $ action ) {
164
162
case 'object_cache_enable ' :
165
163
$ this ->dropper ->drop ();
164
+ if ( ! class_exists ( Object_Cache_Annihilator::class ) ) {
165
+ require_once \OBJECT_CACHE_ANNIHILATOR_DIR . '/drop-in.php ' ;
166
+ }
166
167
Object_Cache_Annihilator::instance ()->resurrect ();
167
168
if ( $ wp_object_cache instanceof Object_Cache_Annihilator ) {
168
169
$ notice_message = __ ( 'Object cache enabled successfully. ' , 'object-cache-annihilator ' );
@@ -201,7 +202,7 @@ public function handle_actions() {
201
202
$ this ->set_notice ( $ notice_type , $ notice_message );
202
203
}
203
204
204
- wp_safe_redirect ( $ redirect_url );
205
+ wp_safe_redirect ( $ redirect_url, 302 , ' X-Redirect-By: Object Cache Annihilator ' );
205
206
exit ;
206
207
}
207
208
@@ -224,7 +225,7 @@ public function display_notice(): void {
224
225
if ( ! is_array ( $ notice ) || ! isset ( $ notice ['type ' ] ) || ! isset ( $ notice ['message ' ] ) ) {
225
226
return ;
226
227
}
227
-
228
+
228
229
$ class = 'notice notice- ' . esc_attr ( $ notice ['type ' ] );
229
230
$ message = wp_kses ( $ notice ['message ' ], [] );
230
231
0 commit comments