wp-rocket-cache-invalidation
WP Rocket: cache invalidation from third-party code
For developers shipping a plugin or theme that mutates content WP Rocket has cached — saving a custom CPT, completing a WooCommerce order, importing data, processing a webhook, scheduling a bulk update. WP Rocket caches HTML to disk (NOT to the WP object cache); raw cache invalidation requires going through the plugin's public API, otherwise stale HTML stays served until the cache TTL or the next save.
WP Rocket is a paid plugin, not on Packagist, not in the WordPress.org plugin directory. Many sites have it; many don't. Every code path that touches
rocket_clean_*MUST be feature-detected first — otherwise your code fatals on installs without WP Rocket.
Misconception this skill corrects
"I'll call
wp_cache_flush()after my plugin saves data — that clears WP Rocket too."
It doesn't. wp_cache_flush() clears the WordPress object cache (transients, options, post meta caches in Redis / Memcached / WP_Cache_Object). WP Rocket is a page cache that writes static HTML files to disk under wp-content/cache/wp-rocket/.... The two are completely independent layers — you can flush the object cache 1000 times and the WP Rocket cached HTML stays untouched.
The right entry point: rocket_clean_post( $post_id ) if a specific post changed, or one of the more granular rocket_clean_* functions for other scenarios. Verified at wp-content/plugins/wp-rocket/inc/common/purge.php:167 and inc/functions/files.php.
Other AI-prone misconceptions:
- "I'll just
unlink()the WP Rocket cache files for this URL." Wrong direction — WP Rocket's filename layout is non-trivial: desktop / mobile / tablet variants, language variants (/cache/wp-rocket/example.com-en/...), query-string variants, gzipped variants, webp variants. Manual deletion misses some, leaves stale files, AND skips thebefore_/after_action hooks that other plugins (CDN purgers, Varnish, Cloudflare addons) listen for. - "
function_exists('rocket_clean_post')is paranoid; everyone has WP Rocket." No, WP Rocket is paid. ~30% of WP installs use SOME caching plugin; even of those, WP Rocket is one of many. Always feature-detect. - "
is_plugin_active('wp-rocket/wp-rocket.php')" is the right check." Half-true.is_plugin_active()requireswp-admin/includes/plugin.phpto be loaded — it's NOT available during early hooks likeplugins_loaded.defined('WP_ROCKET_VERSION')andfunction_exists('rocket_clean_post')work everywhere.