@@ -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