Skip to content

Instantly share code, notes, and snippets.

@mircobabini
Created October 23, 2023 07:27
Show Gist options
  • Save mircobabini/dc140ef7f0e46dbe51aae235de83f1b1 to your computer and use it in GitHub Desktop.
Save mircobabini/dc140ef7f0e46dbe51aae235de83f1b1 to your computer and use it in GitHub Desktop.
<?php
// these are the hooks sg-cachepress uses
add_action( 'upgrader_process_complete', 'clean_cache_after_critical_action' );
add_action( 'automatic_updates_complete', 'clean_cache_after_critical_action' );
add_action( '_core_updated_successfully', 'clean_cache_after_critical_action' );
// this has been found in litespeed-cache
add_action( 'admin_action_do-plugin-upgrade', 'clean_cache_after_critical_action' );
function clean_cache_after_critical_action() {
// wp-rocket is more specific in rocket_reset_opcache()
// wp does it using opcache_invalidate to delete only updated files
// @see https://github.com/WordPress/WordPress/commit/dd11076dc7867c985ab683462051929990105fbc
// but: it failed on 2021-04 updating WordPress SEO
if ( function_exists( 'opcache_reset' ) && ini_get( 'opcache.enable' ) ) {
opcache_reset();
}
// $ wp cache flush
// it's probably already done somewhere
// but: it failed on 2021-03 updating to WP 5.7
if ( function_exists( 'wp_cache_flush' ) ) {
wp_cache_flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment