¿Cómo limpiar todo el caché en WordPress?

Cuando necesitamos eliminar todo el caché en wordpress y no sabemos que plugin el cliente usará, te dejamos este script que trabaja con los más populares plugins de caché y te será de gran ayuda.

Hicimos este script para un cliente en particular mientras se guardaba un post personalizado (CPT).

Usamos el ganchosave_post  para hacer el script, pero eso también funciona con con gancho init .

<?php
if( ! function_exists('letsgo_clear_cache') ) {
  function letsgo_clear_cache() {
    
    // WP Rocket
    if ( function_exists( 'rocket_clean_domain' ) ) {
      rocket_clean_domain();
    }
    // W3 Total Cache : w3tc
    if ( function_exists( 'w3tc_pgcache_flush' ) ) {
      w3tc_pgcache_flush();
    }
    // WP Super Cache : wp-super-cache
    if ( function_exists( 'wp_cache_clear_cache' ) ) {
      wp_cache_clear_cache();
    }
    // WP Fastest Cache
    if( function_exists('wpfc_clear_all_cache') ) {
      wpfc_clear_all_cache(true);
    }
    // WPEngine
    if ( class_exists( 'WpeCommon' ) && method_exists( 'WpeCommon', 'purge_memcached' ) ) {
      WpeCommon::purge_memcached();
      WpeCommon::purge_varnish_cache();
    }
    // SG Optimizer by Siteground
    if ( function_exists( 'sg_cachepress_purge_cache' ) ) {
      sg_cachepress_purge_cache();
    }
    // LiteSpeed
    if( class_exists('LiteSpeed_Cache_API') && method_exists('LiteSpeed_Cache_API', 'purge_all') ) {
      LiteSpeed_Cache_API::purge_all();
    }
    // Cache Enabler
    if( class_exists('Cache_Enabler') && method_exists('Cache_Enabler', 'clear_total_cache') ) {
      Cache_Enabler::clear_total_cache();
    }
    // Pagely
    if ( class_exists('PagelyCachePurge') && method_exists('PagelyCachePurge','purgeAll') ) {
      PagelyCachePurge::purgeAll();
    }
    // Autoptimize
    if( class_exists('autoptimizeCache') && method_exists( 'autoptimizeCache', 'clearall') ) {
      autoptimizeCache::clearall();
    }
    // Comet cache
    if( class_exists('comet_cache') && method_exists('comet_cache', 'clear') ) {
      comet_cache::clear();
    }
    // Hummingbird Cache
    if( class_exists('\Hummingbird\WP_Hummingbird') &&
      method_exists('\Hummingbird\WP_Hummingbird', 'flush_cache')
    ) {
      \Hummingbird\WP_Hummingbird::flush_cache();
    }
  }
  add_action( 'save_post', 'letsgo_clear_cache' );
}

Úsalo sabiamente 🙂

0 0 votes
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Chile Vapo

Que gran aporte, muchas gracias.

Para complementar sería genial algo similar pero que limpie Post_id.

Saludos!

Back to Top
2
0
Would love your thoughts, please comment.x
()
x