Last active
August 29, 2015 14:12
-
-
Save kasparsd/857860d56208ff85094a to your computer and use it in GitHub Desktop.
Invalidate widget output cache when updating posts, categories, terms, menus, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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