Conversation
supporthi, 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?
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?