Skip to content

Purge All cache if menu is associated with any location else ignore #273

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
30 changes: 30 additions & 0 deletions admin/class-purger.php
Original file line number Diff line number Diff line change
@@ -1161,6 +1161,10 @@ public function purge_on_term_taxonomy_edited( $term_id, $tt_id, $taxon ) {

global $nginx_helper_admin;

if ( $taxon === 'nav_menu' ) {
return;
}

if ( ! $nginx_helper_admin->options['enable_purge'] ) {
return;
}
@@ -1217,6 +1221,32 @@ public function purge_on_check_ajax_referer( $action ) {

}

/**
* Purge All on Nav Menu Update.
* Only if the menu is associated with any display location.
*
* @param int $menu_id Menu ID
*
* @return void
*/
public function purge_on_nav_menu_update( $menu_id ) {

global $nginx_helper_admin;

if ( ! $nginx_helper_admin->options['enable_purge'] ) {
return;
}

$this->log( sprintf( __( 'Menu updated. Menu ID: %s', 'nginx-helper' ), $menu_id ) );

$menu_locations = get_nav_menu_locations();

if ( in_array( $menu_id, $menu_locations, true ) ) {

$this->purge_all();
}
}

/**
* Unlink file recursively.
* Source - http://stackoverflow.com/a/1360437/156336
1 change: 1 addition & 0 deletions includes/class-nginx-helper.php
Original file line number Diff line number Diff line change
@@ -223,6 +223,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( 'wp_update_nav_menu', $nginx_purger, 'purge_on_nav_menu_update', 20 );
$this->loader->add_action( 'admin_bar_init', $nginx_helper_admin, 'purge_all' );

// expose action to allow other plugins to purge the cache.