ManageWP: how to clear and preload WP Rocket cache

You can clear and preload WP Rocket cache from your  ManageWP control panel.

To do it, you can use the following snippet. 

<?php 
 
// Load WordPress environment.
require 'wp-load.php';

// Define some constants.
if ( ! defined( 'COOKIEHASH' ) ) {
	$siteurl = get_site_option( 'siteurl' );
	if ( $siteurl ) {
		define( 'COOKIEHASH', md5( $siteurl ) );
	} else {
		define( 'COOKIEHASH', '' );
	}
}
if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
	define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
}

// Instatiate the WP_Rewrite class and store it in $wp_rewrite.
$GLOBALS['wp_rewrite'] = new WP_Rewrite();

// Load WP Rocket environment.
require 'wp-content/plugins/wp-rocket/wp-rocket.php';
require 'wp-content/plugins/wp-rocket/inc/functions/i18n.php';
require 'wp-content/plugins/wp-rocket/inc/functions/formatting.php';
require 'wp-content/plugins/wp-rocket/inc/functions/options.php';
require 'wp-content/plugins/wp-rocket/inc/API/preload.php';
require 'wp-content/plugins/wp-rocket/inc/3rd-party/3rd-party.php';

// Clear the cache.
if ( function_exists( 'rocket_clean_domain' ) ) {
	rocket_clean_domain();
	echo 'Cache cleared';
}
 
// Check if sitemap preload is enabled.
if ( function_exists( 'get_rocket_option' ) ) { 
    $sitemap_preload = get_rocket_option( 'sitemap_preload');
}

// Preload the cache.
if( 1 == $sitemap_preload ) { 
	// run sitemap preload.
	if ( function_exists( 'run_rocket_sitemap_preload' ) ) { 
	   run_rocket_sitemap_preload(); 
	   echo ' - Sitemap Preload started';
	}
}

It has to be added to ManageWP’s Code Snippet feature.

This snippet will also check if you have  Sitemap Preload enabled, and it will trigger the preload if that's the case. 

For Sitemap preloading to work you'll need to:

  1. Uncheck the automatically detected sitemap, e.g. Yoast's, if that's active.
  2. Insert the sitemap's URL in the Sitemaps for preloading text area:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.