WPIntell

Source evidence

WP Rocket clear cache with BunnyCDN

bunny.net – WordPress CDN Plugin · support · 2024-12-30T13:11:00+00:00

complaintsentiment
highseverity
0.98relevance
1replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

7 / 37 rows with source links

18.9% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

30 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
jessy86 unresolved
hi, I use Wp Rocket, and I add the BunnyCDN url directly into WP Rocket CDN section. Howevern when I clear the cache, BunnyCDN still servers some older versions. I do not want to install BunyyCDN on top of WP Rocket, as only WP Rocket offers the possibility to exclude certain pages and all css & js files completely from Bunny. So I would ask you: what is the functions.php code to clear the BunnyCDN cache after post uddate ? In this code, I put my API key & Pull zone. I know this code exists, I looked for days for it online, but nowhere to be found (only a broken “BunnyCDN cache purger for WordPress”. So can you please provide this basic code, to clear my enture Bunny cache after I change a wordpress post ? This would be a lifesaver… I honestly do not understand why this code is not on your support forum already, considering wordpress is the most used CMD in the world. But I am still very happy with the incredible performance increase thanks to Bunny CDN ! Happy Newy Year! Interesting question. Try this (Disclaimer: it's untested and I got it from Copilot AI) function purge_bunnycdn_cache($post_id) { // Your BunnyCDN API key and Pull Zone URL $api_key = 'YOUR_API_KEY'; $pull_zone_id = 'YOUR_PULL_ZONE_ID'; // Get the post URL $post_url = get_permalink($post_id); // BunnyCDN API endpoint $api_endpoint = "https://api.bunny.net/purge"; // Prepare the request $body = json_encode([ 'url' => $post_url ]); // Send the request to BunnyCDN $response = wp_remote_post($api_endpoint, [ 'method' => 'POST', 'body' => $body, 'headers' => [ 'Content-Type' => 'application/json', 'AccessKey' => $api_key ] ]); // Check for errors if (is_wp_error($response)) { error_log('BunnyCDN cache purge failed: ' . $response->get_error_message()); } else { error_log('BunnyCDN cache purged successfully for URL: ' . $post_url); } } // Hook into post update add_action('save_post', 'purge_bunnycdn_cache'); My related question is: does it matter which cache you clear first after doing an update? Clear WP Rocket (Clear and Preload Cache) then the Bunny.net CDN cache, the WP Rocket Cache again?

Comments

1 shown
oabrahim 2025-04-30T15:47:00+00:00

Interesting question. Try this (Disclaimer: it's untested and I got it from Copilot AI) function purge_bunnycdn_cache($post_id) { // Your BunnyCDN API key and Pull Zone URL $api_key = 'YOUR_API_KEY'; $pull_zone_id = 'YOUR_PULL_ZONE_ID'; // Get the post URL $post_url = get_permalink($post_id); // BunnyCDN API endpoint $api_endpoint = "https://api.bunny.net/purge"; // Prepare the request $body = json_encode([ 'url' => $post_url ]); // Send the request to BunnyCDN $response = wp_remote_post($api_endpoint, [ 'method' => 'POST', 'body' => $body, 'headers' => [ 'Content-Type' => 'application/json', 'AccessKey' => $api_key ] ]); // Check for errors if (is_wp_error($response)) { error_log('BunnyCDN cache purge failed: ' . $response->get_error_message()); } else { error_log('BunnyCDN cache purged successfully for URL: ' . $post_url); } } // Hook into post update add_action('save_post', 'purge_bunnycdn_cache'); My related question is: does it matter which cache you clear first after doing an update? Clear WP Rocket (Clear and Preload Cache) then the Bunny.net CDN cache, the WP Rocket Cache again?