Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Last active August 29, 2015 14:12
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 kasparsd/857860d56208ff85094a to your computer and use it in GitHub Desktop.
Save kasparsd/857860d56208ff85094a to your computer and use it in GitHub Desktop.
Invalidate widget output cache when updating posts, categories, terms, menus, etc.
<?php
add_action( 'init', 'widget_cache_register_bump' );
function widget_cache_register_bump() {
// Invalidate widget cache during these action calls
$purge_actions = array(
'clean_post_cache',
'edit_term',
'publish_post',
'comment_post',
'delete_comment',
'edit_comment',
'delete_post',
'edit_post',
'wp_update_nav_menu',
'activated_plugin',
'deactivated_plugin',
'wp_maybe_auto_update'
);
foreach ( $purge_actions as $action ) {
add_action( $action, 'widget_cache_do_bump' );
}
}
function widget_cache_do_bump() {
update_option( 'cache-widgets-version', time() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment