Skip to content

Commit b2c2cbe

Browse files
committed
Purge current page cache on front end
Change hook from 'admin_init' to 'admin_bar_init' so that purge_all() is called when purge button is clicked on both admin dashboard and front end admin bar. Check if the user is on front end when set the call purge_url() and purge the current page cache on case basis.
1 parent 66c2f5b commit b2c2cbe

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

admin/class-nginx-helper-admin.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public function update_new_blog_options( $blog_id ) {
655655
*/
656656
public function purge_all() {
657657

658-
global $nginx_purger;
658+
global $nginx_purger, $wp;
659659

660660
$method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING );
661661

@@ -682,13 +682,26 @@ public function purge_all() {
682682
}
683683

684684
check_admin_referer( 'nginx_helper-purge_all' );
685+
686+
$current_url = esc_url_raw( user_trailingslashit( home_url( $wp->request ) ) );
687+
688+
if ( ! is_admin() ) {
689+
$action = 'purge_single_page';
690+
$redirect_url = $current_url;
691+
} else {
692+
$redirect_url = add_query_arg( array( 'nginx_helper_action' => 'done' ) );
693+
}
694+
685695
switch ( $action ) {
686696
case 'purge':
687697
$nginx_purger->purge_all();
688698
break;
699+
case 'purge_single_page':
700+
$nginx_purger->purge_url( $current_url );
701+
break;
689702
}
690703

691-
wp_redirect( esc_url_raw( add_query_arg( array( 'nginx_helper_action' => 'done' ) ) ) );
704+
wp_redirect( esc_url_raw( $redirect_url ) );
692705
exit();
693706

694707
}

includes/class-nginx-helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function define_admin_hooks() {
221221
$this->loader->add_action( 'edit_term', $nginx_purger, 'purge_on_term_taxonomy_edited', 20, 3 );
222222
$this->loader->add_action( 'delete_term', $nginx_purger, 'purge_on_term_taxonomy_edited', 20, 3 );
223223
$this->loader->add_action( 'check_ajax_referer', $nginx_purger, 'purge_on_check_ajax_referer', 20 );
224-
$this->loader->add_action( 'admin_init', $nginx_helper_admin, 'purge_all' );
224+
$this->loader->add_action( 'admin_bar_init', $nginx_helper_admin, 'purge_all' );
225225

226226
// expose action to allow other plugins to purge the cache.
227227
$this->loader->add_action( 'rt_nginx_helper_purge_all', $nginx_purger, 'purge_all' );

0 commit comments

Comments
 (0)