Skip to content
Permalink
Browse files

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.
  • Loading branch information...
imranhsayed committed Feb 12, 2019
1 parent 66c2f5b commit b2c2cbef0f496ea974e8555f62aecdd8f3bce063
Showing with 16 additions and 3 deletions.
  1. +15 −2 admin/class-nginx-helper-admin.php
  2. +1 −1 includes/class-nginx-helper.php
@@ -655,7 +655,7 @@ public function update_new_blog_options( $blog_id ) {
*/
public function purge_all() {
global $nginx_purger;
global $nginx_purger, $wp;
$method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING );
@@ -682,13 +682,26 @@ public function purge_all() {
}
check_admin_referer( 'nginx_helper-purge_all' );
$current_url = esc_url_raw( user_trailingslashit( home_url( $wp->request ) ) );
if ( ! is_admin() ) {
$action = 'purge_single_page';
$redirect_url = $current_url;
} else {
$redirect_url = add_query_arg( array( 'nginx_helper_action' => 'done' ) );
}
switch ( $action ) {
case 'purge':
$nginx_purger->purge_all();
break;
case 'purge_single_page':
$nginx_purger->purge_url( $current_url );
break;
}
wp_redirect( esc_url_raw( add_query_arg( array( 'nginx_helper_action' => 'done' ) ) ) );
wp_redirect( esc_url_raw( $redirect_url ) );
exit();
}
@@ -221,7 +221,7 @@ private function define_admin_hooks() {
$this->loader->add_action( 'edit_term', $nginx_purger, 'purge_on_term_taxonomy_edited', 20, 3 );
$this->loader->add_action( 'delete_term', $nginx_purger, 'purge_on_term_taxonomy_edited', 20, 3 );
$this->loader->add_action( 'check_ajax_referer', $nginx_purger, 'purge_on_check_ajax_referer', 20 );
$this->loader->add_action( 'admin_init', $nginx_helper_admin, 'purge_all' );
$this->loader->add_action( 'admin_bar_init', $nginx_helper_admin, 'purge_all' );
// expose action to allow other plugins to purge the cache.
$this->loader->add_action( 'rt_nginx_helper_purge_all', $nginx_purger, 'purge_all' );

0 comments on commit b2c2cbe

Please sign in to comment.
You can’t perform that action at this time.