@@ -201,10 +201,18 @@ public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
201201 return ;
202202 }
203203
204+ if ( is_admin () ) {
205+ $ nginx_helper_urls = 'all ' ;
206+ $ link_title = __ ( 'Purge Cache ' , 'nginx-helper ' );
207+ } else {
208+ $ nginx_helper_urls = 'current-url ' ;
209+ $ link_title = __ ( 'Purge Current Page ' , 'nginx-helper ' );
210+ }
211+
204212 $ purge_url = add_query_arg (
205213 array (
206214 'nginx_helper_action ' => 'purge ' ,
207- 'nginx_helper_urls ' => ' all ' ,
215+ 'nginx_helper_urls ' => $ nginx_helper_urls ,
208216 )
209217 );
210218
@@ -213,9 +221,9 @@ public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
213221 $ wp_admin_bar ->add_menu (
214222 array (
215223 'id ' => 'nginx-helper-purge-all ' ,
216- 'title ' => __ ( ' Purge Cache ' , ' nginx-helper ' ) ,
224+ 'title ' => $ link_title ,
217225 'href ' => $ nonced_url ,
218- 'meta ' => array ( 'title ' => __ ( ' Purge Cache ' , ' nginx-helper ' ) ),
226+ 'meta ' => array ( 'title ' => $ link_title ),
219227 )
220228 );
221229
@@ -642,12 +650,14 @@ public function update_new_blog_options( $blog_id ) {
642650
643651 /**
644652 * Purge all urls.
653+ * Purge current page cache when purging is requested from front
654+ * and all urls when requested from admin dashboard.
645655 *
646656 * @global object $nginx_purger
647657 */
648658 public function purge_all () {
649659
650- global $ nginx_purger ;
660+ global $ nginx_purger, $ wp ;
651661
652662 $ method = filter_input ( INPUT_SERVER , 'REQUEST_METHOD ' , FILTER_SANITIZE_STRING );
653663
@@ -674,13 +684,26 @@ public function purge_all() {
674684 }
675685
676686 check_admin_referer ( 'nginx_helper-purge_all ' );
687+
688+ $ current_url = user_trailingslashit ( home_url ( $ wp ->request ) );
689+
690+ if ( ! is_admin () ) {
691+ $ action = 'purge_current_page ' ;
692+ $ redirect_url = $ current_url ;
693+ } else {
694+ $ redirect_url = add_query_arg ( array ( 'nginx_helper_action ' => 'done ' ) );
695+ }
696+
677697 switch ( $ action ) {
678698 case 'purge ' :
679699 $ nginx_purger ->purge_all ();
680700 break ;
701+ case 'purge_current_page ' :
702+ $ nginx_purger ->purge_url ( $ current_url );
703+ break ;
681704 }
682705
683- wp_redirect ( esc_url_raw ( add_query_arg ( array ( ' nginx_helper_action ' => ' done ' ) ) ) );
706+ wp_redirect ( esc_url_raw ( $ redirect_url ) );
684707 exit ();
685708
686709 }
0 commit comments