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.
October 03, 2024
This work on the admin bar really changes the way I handle the Cloudflare cache with WP Rocket!
October 08, 2024
Hey Hershel!
You're loving that admin bar button huh? That's awesome - it's definitely making things easier with Cloudflare cache and WP Rocket! It's pretty cool when tools just click together like that.
Have you tried mixing this with other plugins for even more kick? Sometimes I or my clients find some surprising benefits just by mixing different setups. You're always on a journey in the WordPress world. If something works for you that's really half the battle!
If you need any more ideas just shout! 😊
October 08, 2024
Hey there Hershel!
I'm really excited to hear that the admin bar feature is really making a difference for you! 🎉 You have to love having more control - it's always a win. Sometimes even little changes can make a big difference right?
Since you're using plugins like WP Rocket you probably know they evolve pretty quickly. It's a good idea to stay updated. What plugins are you using these days?
I'm always here if you want more tips or if you have questions. Cheers!