Comment faire pour refresh le cache wp-rocket tout en excluant les cas de figure de mise en brouillon ou autre ?

Hook sur save_post

function purge_wp_rocket_cache_on_publish($ID, $post) {
    // Vérifiez si l'article est en train d'être publié (pas mis à jour)
    if ($post->post_status === 'publish' && $post->post_status !== 'draft' && $post->post_status !== 'pending') {
        // Purge Rocket cache
        if ( function_exists( 'rocket_clean_domain' ) ) {
            rocket_clean_domain();
        }
        // Clear minified CSS and JavaScript files Rocket
        if ( function_exists( 'rocket_clean_minify' ) ) {
            rocket_clean_minify();
        }
        // Preload cache Rocket
        if ( function_exists( 'run_rocket_sitemap_preload' ) ) {
            run_rocket_sitemap_preload();
        }
        // End rocket

        // wp-super-cache
        if ( function_exists( 'wp_cache_clear_cache' ) ) {
            wp_cache_clear_cache();
        }

        // WPEngine
        if ( class_exists( 'WpeCommon' ) ) {
            WpeCommon::purge_memcached();
            WpeCommon::clear_maxcdn_cache();
            WpeCommon::purge_varnish_cache();
        }

        // w3 total cash
        if ( function_exists( 'w3tc_pgcache_flush' ) ) {
            w3tc_pgcache_flush();
        }

        // siteground
        if ( function_exists( 'sg_cachepress_purge_cache' ) ) {
            sg_cachepress_purge_cache();
        }
    }
}

add_action('save_post', 'purge_wp_rocket_cache_on_publish', 10, 2);
0 0 votes
Article Rating
S’abonner
Notification pour
guest
0 Commentaires
Commentaires en ligne
Afficher tous les commentaires