25.02.2025, Technical documentation & snippets

How can WordPress editors clear the WP Rocket cache?

Problem:

WP Rocket (version 2025/2) does not offer editors access to the cache clearing and preloading functions via its settings. The action can be important under certain circumstances if the automatic registration via the caching system of WP Rocket fails, i.e. WP Rocket thinks that nothing has changed and shows old content.

Solution:

In the Init Hook (location e.g. in functions.php), grant a corresponding function with access roles:

<?php 

function wp_rocket_for_editor() {
	$role = get_role('editor');
        $role->add_cap('rocket_purge_cache', true);
	$role->add_cap('rocket_purge_posts', true);
        $role->add_cap('rocket_purge_terms', true);
}
add_action('init', 'wp_rocket_for_editor', 12);Code language: HTML, XML (xml)

From now on, an editor has access to the "Empty cache and preload" feature of WP-Rocket:

Further "capabilities" for WP-Rocket can be found here:

https://docs.wp-rocket.me/article/1280-customize-access-to-options-for-user-roles

See also