Skip to content

Instantly share code, notes, and snippets.

@sanzeeb3
Last active May 16, 2019 08:57
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 sanzeeb3/ed94371d1f053fdc3e12fc47d052b210 to your computer and use it in GitHub Desktop.
Save sanzeeb3/ed94371d1f053fdc3e12fc47d052b210 to your computer and use it in GitHub Desktop.
<?php
/**
* Flush cache created by some popular WordPress plugins in a specific page.
*
* @return void.
*/
function sa_flush_cache() {
$post_id = get_the_ID();
// Flush already set cache by w3total cache plugin.
if ( function_exists( 'w3tc_pgcache_flush' ) ) {
w3tc_pgcache_flush_post( $post_id );
}
// Flush already set cache by wp super cache plugin
if ( function_exists( 'wpsc_delete_post_cache' ) ) {
wpsc_delete_post_cache( $post_id );
}
// Flush already set cache by wp rocket cache plugin
if ( function_exists( 'rocket_clean_post' ) ) {
$post_id = get_the_ID();
rocket_clean_post( $post_id );
}
}
add_action( 'init', 'sa_flush_cache' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment