Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvdsteege/08cf9f545e39c492d75b6081808f7cf0 to your computer and use it in GitHub Desktop.
Save rvdsteege/08cf9f545e39c492d75b6081808f7cf0 to your computer and use it in GitHub Desktop.
Fix timeout when menus are saved when Automatic Cache Purging of SG Optimizer plugin is enabled. Add code to `functions.php` of your WordPress theme.
<?php
/**
* Prevent timeout when menus are saved when Automatic Cache Purging of SG Optimizer plugin is enabled.
*/
add_action( 'save_post_nav_menu_item', 'sg_cachepress_remove_purge_all_post_cache' );
function sg_cachepress_remove_purge_all_post_cache() {
global $wp_filter;
foreach ( $wp_filter['save_post'] as $actions ) {
foreach ( $actions as $action ) {
// Check callback function.
if ( ! array_key_exists( 'function', $action ) ) {
continue;
}
$function = $action['function'];
// Check `purge_all_post_cache` callback function.
if ( ! is_array( $function ) || 'purge_all_post_cache' !== $function[1] ) {
continue;
}
// Remove actions.
remove_action( 'save_post', $function, 10 );
remove_action( 'save_post_nav_menu_item', 'sg_cachepress_remove_purge_all_post_cache' );
return;
}
}
}
add_action( 'wp_update_nav_menu', 'sg_cachepress_purge_everything');
function sg_cachepress_purge_everything() {
// Check SG Optimizer Supercacher.
if ( ! function_exists( 'sg_cachepress_purge_everything' ) ) {
return;
}
// Purge everything on shutdown.
add_action( 'shutdown', function() {
sg_cachepress_purge_everything();
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment