Skip to content

Commit eb2dab9

Browse files
authored
Update purge notices to be more consistent (#1220)
* Update purge notice result handling to more consistently display results. Added a new notice to the top admin bar if on the frontend. * Update flush all except CDN to properly skip the configured CDNs. * Remove flush all except CDN, as it is added by the CDN separately. * Made the admin bar JS human-readable for the frontend. * Added missing translations.
1 parent 322d851 commit eb2dab9

13 files changed

+303
-105
lines changed

BrowserCache_Plugin.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,18 @@ public function w3tc_admin_bar_menu( $menu_items ) {
450450
);
451451

452452
if ( $browsercache_update_media_qs ) {
453+
$current_page = Util_Request::get_string( 'page', 'w3tc_dashboard' );
454+
453455
$menu_items['20190.browsercache'] = array(
454456
'id' => 'w3tc_flush_browsercache',
455457
'parent' => 'w3tc_flush',
456458
'title' => __( 'Browser Cache', 'w3-total-cache' ),
457-
'href' => wp_nonce_url( admin_url( 'admin.php?page=w3tc_dashboard&w3tc_flush_browser_cache' ), 'w3tc' ),
459+
'href' => wp_nonce_url(
460+
admin_url(
461+
'admin.php?page=' . $current_page . '&w3tc_flush_browser_cache'
462+
),
463+
'w3tc'
464+
),
458465
);
459466
}
460467

Cdn_Plugin.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,19 @@ public function w3tc_minify_http2_preload_url( $data ) {
850850
*/
851851
public function w3tc_admin_bar_menu( $menu_items ) {
852852
$cdn_engine = $this->_config->get_string( 'cdn.engine' );
853+
$current_page = Util_Request::get_string( 'page', 'w3tc_dashboard' );
853854

854855
if ( Cdn_Util::can_purge_all( $cdn_engine ) ) {
855856
$menu_items['20710.cdn'] = array(
856857
'id' => 'w3tc_cdn_flush_all',
857858
'parent' => 'w3tc_flush',
858859
'title' => __( 'CDN Cache', 'w3-total-cache' ),
859-
'href' => wp_nonce_url( admin_url( 'admin.php?page=w3tc_cdn&w3tc_flush_cdn' ), 'w3tc' ),
860+
'href' => wp_nonce_url(
861+
admin_url(
862+
'admin.php?page=' . $current_page . '&w3tc_flush_cdn'
863+
),
864+
'w3tc'
865+
),
860866
);
861867
}
862868

@@ -865,7 +871,12 @@ public function w3tc_admin_bar_menu( $menu_items ) {
865871
'id' => 'w3tc_cdn_flush',
866872
'parent' => 'w3tc_flush',
867873
'title' => __( 'CDN: Manual Purge', 'w3-total-cache' ),
868-
'href' => wp_nonce_url( admin_url( 'admin.php?page=w3tc_cdn&w3tc_cdn_purge' ), 'w3tc' ),
874+
'href' => wp_nonce_url(
875+
admin_url(
876+
'admin.php?page=' . $current_page . '&w3tc_cdn_purge'
877+
),
878+
'w3tc'
879+
),
869880
'meta' => array( 'onclick' => 'w3tc_popupadmin_bar(this.href); return false' ),
870881
);
871882
}

DbCache_Plugin.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ public function on_comment_status( $comment_id, $status ) {
256256
* @return array Modified admin bar menu items.
257257
*/
258258
public function w3tc_admin_bar_menu( $menu_items ) {
259+
$current_page = Util_Request::get_string( 'page', 'w3tc_dashboard' );
260+
259261
$menu_items['20310.dbcache'] = array(
260262
'id' => 'w3tc_flush_dbcache',
261263
'parent' => 'w3tc_flush',
262264
'title' => __( 'Database', 'w3-total-cache' ),
263265
'href' => wp_nonce_url(
264-
admin_url( 'admin.php?page=w3tc_dashboard&w3tc_flush_dbcache' ),
266+
admin_url(
267+
'admin.php?page=' . $current_page . '&w3tc_flush_dbcache'
268+
),
265269
'w3tc'
266270
),
267271
);

Extension_AlwaysCached_Plugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ public function init() {
115115
*/
116116
public function w3tc_admin_bar_menu( $menu_items ) {
117117
if ( ! is_admin() ) {
118+
$current_page = Util_Request::get_string( 'page', 'w3tc_dashboard' );
119+
118120
$menu_items['10025.always_cached'] = array(
119121
'id' => 'w3tc_flush_current_page',
120122
'parent' => 'w3tc',
121123
'title' => __( 'Regenerate Current Page', 'w3-total-cache' ),
122124
'href' => wp_nonce_url(
123-
admin_url( 'admin.php?page=w3tc_dashboard&w3tc_alwayscached_regenerate&post_id=' . Util_Environment::detect_post_id() ),
125+
admin_url(
126+
'admin.php?page=' . $current_page .
127+
'&w3tc_alwayscached_regenerate&post_id=' . Util_Environment::detect_post_id()
128+
),
124129
'w3tc'
125130
),
126131
);

Extension_CloudFlare_Plugin_Admin.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,18 @@ public function w3tc_admin_bar_menu( $menu_items ) {
209209
! empty( $this->_config->get_string( array( 'cloudflare', 'key' ) ) ) &&
210210
! empty( $this->_config->get_string( array( 'cloudflare', 'zone_id' ) ) )
211211
) {
212+
$current_page = Util_Request::get_string( 'page', 'w3tc_dashboard' );
213+
212214
$menu_items['20810.cloudflare'] = array(
213215
'id' => 'w3tc_flush_cloudflare',
214216
'parent' => 'w3tc_flush',
215217
'title' => __( 'Cloudflare', 'w3-total-cache' ),
216-
'href' => wp_nonce_url( admin_url( 'admin.php?page=w3tc_dashboard&w3tc_cloudflare_flush' ), 'w3tc' ),
218+
'href' => wp_nonce_url(
219+
admin_url(
220+
'admin.php?page=' . $current_page . '&w3tc_cloudflare_flush'
221+
),
222+
'w3tc'
223+
),
217224
);
218225
}
219226

Extension_FragmentCache_Plugin_Admin.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,18 @@ public function w3tc_admin_menu( $menu ) {
152152
*/
153153
public function w3tc_admin_bar_menu( $menu_items ) {
154154
if ( $this->_config->is_extension_active( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
155+
$current_page = Util_Request::get_string( 'page', 'w3tc_dashboard' );
156+
155157
$menu_items['20510.fragmentcache'] = array(
156158
'id' => 'w3tc_flush_fragmentcache',
157159
'parent' => 'w3tc_flush',
158160
'title' => __( 'Fragment Cache', 'w3-total-cache' ),
159-
'href' => wp_nonce_url( admin_url( 'admin.php?page=w3tc_dashboard&w3tc_flush_fragmentcache' ), 'w3tc' ),
161+
'href' => wp_nonce_url(
162+
admin_url(
163+
'admin.php?page=' . $current_page . '&w3tc_flush_fragmentcache'
164+
),
165+
'w3tc'
166+
),
160167
);
161168
}
162169

Generic_AdminActions_Flush.php

Lines changed: 37 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function w3tc_flush_all() {
4343
$state_note->set( 'common.show_note.flush_posts_needed', false );
4444
$state_note->set( 'common.show_note.plugins_updated', false );
4545

46-
$this->_redirect_after_flush( 'flush_all' );
46+
$this->_redirect_after_flush( 'flush_all', __( 'purge all caches', 'w3-total-cache' ) );
4747
}
4848

4949
/**
@@ -81,12 +81,7 @@ public function w3tc_flush_current_page() {
8181
public function w3tc_flush_memcached() {
8282
$this->flush_memcached();
8383

84-
Util_Admin::redirect(
85-
array(
86-
'w3tc_note' => 'flush_memcached',
87-
),
88-
true
89-
);
84+
$this->_redirect_after_flush( 'flush_memcached', __( 'purge Memcached cache', 'w3-total-cache' ) );
9085
}
9186

9287
/**
@@ -97,12 +92,7 @@ public function w3tc_flush_memcached() {
9792
public function w3tc_flush_opcode() {
9893
$this->flush_opcode();
9994

100-
Util_Admin::redirect(
101-
array(
102-
'w3tc_note' => 'flush_opcode',
103-
),
104-
true
105-
);
95+
$this->_redirect_after_flush( 'flush_opcode', __( 'purge Opcode cache', 'w3-total-cache' ) );
10696
}
10797

10898
/**
@@ -113,12 +103,7 @@ public function w3tc_flush_opcode() {
113103
public function w3tc_flush_file() {
114104
$this->flush_file();
115105

116-
Util_Admin::redirect(
117-
array(
118-
'w3tc_note' => 'flush_file',
119-
),
120-
true
121-
);
106+
$this->_redirect_after_flush( 'flush_file', __( 'purge all disk based caches', 'w3-total-cache' ) );
122107
}
123108

124109
/**
@@ -158,7 +143,7 @@ public function w3tc_flush_posts() {
158143
$state_note->set( 'common.show_note.flush_posts_needed', false );
159144
$state_note->set( 'common.show_note.plugins_updated', false );
160145

161-
$this->_redirect_after_flush( 'flush_pgcache' );
146+
$this->_redirect_after_flush( 'flush_pgcache', __( 'purge Page cache for posts', 'w3-total-cache' ) );
162147
}
163148

164149
/**
@@ -173,12 +158,7 @@ public function w3tc_flush_pgcache() {
173158
$state_note->set( 'common.show_note.flush_posts_needed', false );
174159
$state_note->set( 'common.show_note.plugins_updated', false );
175160

176-
Util_Admin::redirect(
177-
array(
178-
'w3tc_note' => 'flush_pgcache',
179-
),
180-
true
181-
);
161+
$this->_redirect_after_flush( 'flush_pgcache', __( 'purge Page cache', 'w3-total-cache' ) );
182162
}
183163

184164
/**
@@ -189,12 +169,7 @@ public function w3tc_flush_pgcache() {
189169
public function w3tc_flush_dbcache() {
190170
$this->flush_dbcache();
191171

192-
Util_Admin::redirect(
193-
array(
194-
'w3tc_note' => 'flush_dbcache',
195-
),
196-
true
197-
);
172+
$this->_redirect_after_flush( 'flush_dbcache', __( 'purge Database cache', 'w3-total-cache' ) );
198173
}
199174

200175
/**
@@ -208,12 +183,7 @@ public function w3tc_flush_objectcache() {
208183
$state_note = Dispatcher::config_state_note();
209184
$state_note->set( 'objectcache.show_note.flush_needed', false );
210185

211-
Util_Admin::redirect(
212-
array(
213-
'w3tc_note' => 'flush_objectcache',
214-
),
215-
true
216-
);
186+
$this->_redirect_after_flush( 'flush_objectcache', __( 'purge Object cache', 'w3-total-cache' ) );
217187
}
218188

219189
/**
@@ -227,12 +197,7 @@ public function w3tc_flush_fragmentcache() {
227197
$this->_config->set( 'notes.need_empty_fragmentcache', false );
228198
$this->_config->save();
229199

230-
Util_Admin::redirect(
231-
array(
232-
'w3tc_note' => 'flush_fragmentcache',
233-
),
234-
true
235-
);
200+
$this->_redirect_after_flush( 'flush_fragmentcache', __( 'purge Fragment cache', 'w3-total-cache' ) );
236201
}
237202

238203
/**
@@ -246,12 +211,7 @@ public function w3tc_flush_minify() {
246211
$state_note = Dispatcher::config_state_note();
247212
$state_note->set( 'minify.show_note.need_flush', false );
248213

249-
Util_Admin::redirect(
250-
array(
251-
'w3tc_note' => 'flush_minify',
252-
),
253-
true
254-
);
214+
$this->_redirect_after_flush( 'flush_minify', __( 'purge Minify cache', 'w3-total-cache' ) );
255215
}
256216

257217
/**
@@ -267,12 +227,7 @@ public function w3tc_flush_browser_cache() {
267227
$state_note->set( 'common.show_note.flush_statics_needed', false );
268228
$state_note->set( 'common.show_note.flush_posts_needed', true );
269229

270-
Util_Admin::redirect(
271-
array(
272-
'w3tc_note' => 'flush_browser_cache',
273-
),
274-
true
275-
);
230+
$this->_redirect_after_flush( 'flush_browser_cache', __( 'purge Browser cache', 'w3-total-cache' ) );
276231
}
277232

278233
/**
@@ -283,12 +238,7 @@ public function w3tc_flush_browser_cache() {
283238
public function w3tc_flush_varnish() {
284239
$this->flush_varnish();
285240

286-
Util_Admin::redirect(
287-
array(
288-
'w3tc_note' => 'flush_varnish',
289-
),
290-
true
291-
);
241+
$this->_redirect_after_flush( 'flush_varnish', __( 'purge Varnish cache', 'w3-total-cache' ) );
292242
}
293243

294244
/**
@@ -299,12 +249,7 @@ public function w3tc_flush_varnish() {
299249
public function w3tc_flush_cdn() {
300250
$this->flush_cdn( array( 'ui_action' => 'flush_button' ) );
301251

302-
Util_Admin::redirect(
303-
array(
304-
'w3tc_note' => 'flush_cdn',
305-
),
306-
true
307-
);
252+
$this->_redirect_after_flush( 'flush_cdn', __( 'purge CDN cache', 'w3-total-cache' ) );
308253
}
309254

310255
/**
@@ -316,12 +261,7 @@ public function w3tc_flush_post() {
316261
$post_id = Util_Request::get_integer( 'post_id' );
317262
w3tc_flush_post( $post_id, true, array( 'ui_action' => 'flush_button' ) );
318263

319-
Util_Admin::redirect(
320-
array(
321-
'w3tc_note' => 'pgcache_purge_post',
322-
),
323-
true
324-
);
264+
$this->_redirect_after_flush( 'pgcache_purge_post', __( 'purge Page cache for post', 'w3-total-cache' ) );
325265
}
326266

327267
/**
@@ -459,11 +399,12 @@ public function flush_cdn( $extras = array() ) {
459399
/**
460400
* Redirects after a successful flush operation and handles errors.
461401
*
462-
* @param string $success_note A note to indicate the success of the flush operation.
402+
* @param string $success_note A note to indicate the success of the flush operation.
403+
* @param string $error_context Description of what failed when an error occurs.
463404
*
464405
* @return void
465406
*/
466-
private function _redirect_after_flush( $success_note ) {
407+
private function _redirect_after_flush( $success_note, $error_context = '' ) {
467408
$flush = Dispatcher::component( 'CacheFlush' );
468409
$status = $flush->execute_delayed_operations();
469410

@@ -482,12 +423,29 @@ private function _redirect_after_flush( $success_note ) {
482423
true
483424
);
484425
} else {
485-
Util_Admin::redirect_with_custom_messages2(
426+
$message_id = uniqid();
427+
$error_context = empty( $error_context ) ? __( 'purge cache', 'w3-total-cache' ) : $error_context;
428+
429+
update_option(
430+
'w3tc_message',
486431
array(
487-
'errors' => array(
488-
'Failed to purge: ' . implode( ', ', $errors ),
432+
$message_id => array(
433+
'errors' => array(
434+
sprintf(
435+
'Failed to %1$s: %2$s',
436+
$error_context,
437+
implode( ', ', $errors )
438+
),
439+
),
489440
),
490441
),
442+
'yes'
443+
);
444+
445+
Util_Admin::redirect(
446+
array(
447+
'w3tc_message' => $message_id,
448+
),
491449
true
492450
);
493451
}

0 commit comments

Comments
 (0)