Add a "Flush Cloudflare Cache" Button to Your WordPress Admin
Note: This is only for users of the WP Rocket caching plugin.
This is a handy one. When purging cache, most plugins add the ability to do so right at the top of your admin. For instance, in WP Rocket, you hover your mouse up and click "Purge Cache".
But, if you have the Cloudflare integration, you have to dig deep in the settings to clear it:
- Settings
- WP Rocket
- Add-ons
- Modify Options
- Clear all Cloudflare cache files
- Modify Options
- Add-ons
- WP Rocket
This is a much easier way. Add this to your functions.php file in your WordPress theme:
/*
* Add "Flush Cloudflare Cache" button to top wp-admin bar
*/
function add_purge_cloudflare_to_admin_bar($wp_admin_bar) {
if (!is_admin_bar_showing()) {
return;
}
if (!current_user_can('rocket_purge_cloudflare_cache')) {
return;
}
$purge_url = wp_nonce_url(
admin_url('admin-post.php?action=rocket_purge_cloudflare'),
'rocket_purge_cloudflare'
);
$args = array(
'id' => 'purge_cloudflare',
'title' => 'Flush Cloudflare Cache',
'href' => $purge_url,
'meta' => array('class' => 'cloudflare-purge')
);
$wp_admin_bar - > add_node($args);
}
add_action('admin_bar_menu', 'add_purge_cloudflare_to_admin_bar', 100);
Now you have a handy button up next to your other cache plugins.
The "Flush PHP OPcache" plugin can be found here.
Comments