Last active
October 31, 2024 00:50
-
-
Save FinalDestiny/cca603a238ed3bb3ecb0ce33c7b54075 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if ( ! function_exists( 'et_core_clear_wp_cache' ) ): | |
function et_core_clear_wp_cache( $post_id = '' ) { | |
if ( ! wp_doing_cron() && ! et_core_security_check_passed( 'edit_posts' ) ) { | |
return; | |
} | |
try { | |
// Cache Plugins | |
// Comet Cache | |
if ( is_callable( 'comet_cache::clear' ) ) { | |
comet_cache::clear(); | |
} | |
// WP Rocket | |
if ( function_exists( 'rocket_clean_post' ) ) { | |
if ( '' !== $post_id ) { | |
rocket_clean_post( $post_id ); | |
} else if ( function_exists( 'rocket_clean_domain' ) ) { | |
rocket_clean_domain(); | |
} | |
} | |
// W3 Total Cache | |
if ( has_action( 'w3tc_flush_post' ) ) { | |
'' !== $post_id ? do_action( 'w3tc_flush_post', $post_id ) : do_action( 'w3tc_flush_posts' ); | |
} | |
// WP Super Cache | |
if ( function_exists( 'wp_cache_debug' ) && defined( 'WPCACHEHOME' ) ) { | |
include_once WPCACHEHOME . 'wp-cache-phase1.php'; | |
include_once WPCACHEHOME . 'wp-cache-phase2.php'; | |
if ( '' !== $post_id && function_exists( 'clear_post_supercache' ) ) { | |
clear_post_supercache( $post_id ); | |
} else if ( '' === $post_id && function_exists( 'wp_cache_clear_cache_on_menu' ) ) { | |
wp_cache_clear_cache_on_menu(); | |
} | |
} | |
// WP Fastest Cache | |
if ( isset( $GLOBALS['wp_fastest_cache'] ) ) { | |
if ( '' !== $post_id && method_exists( $GLOBALS['wp_fastest_cache'], 'singleDeleteCache' ) ) { | |
$GLOBALS['wp_fastest_cache']->singleDeleteCache( $post_id ); | |
} else if ( '' === $post_id && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) { | |
$GLOBALS['wp_fastest_cache']->deleteCache(); | |
} | |
} | |
// WordPress Cache Enabler | |
if ( has_action( 'ce_clear_cache' ) ) { | |
'' !== $post_id ? do_action( 'ce_clear_post_cache', $post_id ) : do_action( 'ce_clear_cache' ); | |
} | |
// LiteSpeed Cache | |
if ( is_callable( 'LiteSpeed_Cache::get_instance' ) ) { | |
$litespeed = LiteSpeed_Cache::get_instance(); | |
if ( '' !== $post_id && method_exists( $litespeed, 'purge_post' ) ) { | |
$litespeed->purge_post( $post_id ); | |
} else if ( '' === $post_id && method_exists( $litespeed, 'purge_all' ) ) { | |
$litespeed->purge_all(); | |
} | |
} | |
// LiteSpeed Cache v1.1.3+ | |
if ( '' !== $post_id && function_exists( 'litespeed_purge_single_post' ) ) { | |
litespeed_purge_single_post( $post_id ); | |
} else if ( '' === $post_id && is_callable( 'LiteSpeed_Cache_API::purge_all' ) ) { | |
LiteSpeed_Cache_API::purge_all(); | |
} | |
// Hyper Cache | |
if ( class_exists( 'HyperCache' ) && isset( HyperCache::$instance ) ) { | |
if ( '' !== $post_id && method_exists( HyperCache::$instance, 'clean_post' ) ) { | |
HyperCache::$instance->clean_post( $post_id ); | |
} else if ( '' === $post_id && method_exists( HyperCache::$instance, 'clean' ) ) { | |
HyperCache::$instance->clean_post( $post_id ); | |
} | |
} | |
// Hosting Provider Caching | |
// Pantheon Advanced Page Cache | |
$pantheon_clear = 'pantheon_wp_clear_edge_keys'; | |
$pantheon_clear_all = 'pantheon_wp_clear_edge_all'; | |
if ( function_exists( $pantheon_clear ) || function_exists( $pantheon_clear_all ) ) { | |
if ( '' !== $post_id && function_exists( $pantheon_clear ) ) { | |
pantheon_wp_clear_edge_keys( array( "post-{$post_id}" ) ); | |
} else if ( '' === $post_id && function_exists( $pantheon_clear_all ) ) { | |
pantheon_wp_clear_edge_all(); | |
} | |
} | |
// Siteground | |
if ( isset( $GLOBALS['sg_cachepress_supercacher'] ) ) { | |
global $sg_cachepress_supercacher; | |
if ( is_object( $sg_cachepress_supercacher ) && method_exists( $sg_cachepress_supercacher, 'purge_cache' ) ) { | |
$sg_cachepress_supercacher->purge_cache( true ); | |
} | |
} | |
// WP Engine | |
if ( class_exists( 'WpeCommon' ) ) { | |
is_callable( 'WpeCommon::purge_memcached' ) ? WpeCommon::purge_memcached() : ''; | |
is_callable( 'WpeCommon::clear_maxcdn_cache' ) ? WpeCommon::clear_maxcdn_cache() : ''; | |
is_callable( 'WpeCommon::purge_varnish_cache' ) ? WpeCommon::purge_varnish_cache() : ''; | |
if ( is_callable( 'WpeCommon::instance' ) && $instance = WpeCommon::instance() ) { | |
method_exists( $instance, 'purge_object_cache' ) ? $instance->purge_object_cache() : ''; | |
} | |
} | |
// Bluehost | |
if ( class_exists( 'Endurance_Page_Cache' ) ) { | |
wp_doing_ajax() ? ET_Core_LIB_BluehostCache::get_instance()->clear( $post_id ) : do_action( 'epc_purge' ); | |
} | |
// Complimentary Performance Plugins | |
// Autoptimize | |
if ( is_callable( 'autoptimizeCache::clearall' ) ) { | |
autoptimizeCache::clearall(); | |
} | |
} catch( Exception $err ) { | |
ET_Core_Logger::error( 'An exception occurred while attempting to clear site cache.' ); | |
} | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment