Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Purge Cache menu caching issue in the front-end #173

Merged
merged 5 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions admin/class-nginx-helper-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,18 @@ public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
return;
}

if ( is_admin() ) {
$nginx_helper_urls = 'all';
$link_title = __( 'Purge Cache', 'nginx-helper' );
} else {
$nginx_helper_urls = 'current-url';
$link_title = __( 'Purge Current Page', 'nginx-helper' );
}

$purge_url = add_query_arg(
array(
'nginx_helper_action' => 'purge',
'nginx_helper_urls' => 'all',
'nginx_helper_urls' => $nginx_helper_urls,
)
);

Expand All @@ -213,9 +221,9 @@ public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
$wp_admin_bar->add_menu(
array(
'id' => 'nginx-helper-purge-all',
'title' => __( 'Purge Cache', 'nginx-helper' ),
'title' => $link_title,
'href' => $nonced_url,
'meta' => array( 'title' => __( 'Purge Cache', 'nginx-helper' ) ),
'meta' => array( 'title' => array( 'title' => $link_title ) ),
chandrapatel marked this conversation as resolved.
Show resolved Hide resolved
)
);

Expand Down Expand Up @@ -642,12 +650,14 @@ public function update_new_blog_options( $blog_id ) {

/**
* Purge all urls.
* Purge current page cache when purging is requested from front
* and all urls when requested from admin dashboard.
*
* @global object $nginx_purger
*/
public function purge_all() {

global $nginx_purger;
global $nginx_purger, $wp;

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

Expand All @@ -674,13 +684,26 @@ public function purge_all() {
}

check_admin_referer( 'nginx_helper-purge_all' );

$current_url = esc_url_raw( user_trailingslashit( home_url( $wp->request ) ) );
chandrapatel marked this conversation as resolved.
Show resolved Hide resolved

if ( ! is_admin() ) {
$action = 'purge_current_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_current_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();

}
Expand Down
2 changes: 1 addition & 1 deletion includes/class-nginx-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down