• janvitos

    (@janvitos)


    Hi,

    I was using the function xmlsf_nginx_helper_purge_urls to fetch the list of URLs sent to the nginx helper plugin so I could feed it to Cloudflare for cache purge purposes. But since version 5.4.9, that function has been removed and it broke my cache purge script.

    Is there any other way to fetch the list of URLs that should be purged by caches?

    Thanks!

    • This topic was modified 1 month ago by janvitos.
Viewing 1 replies (of 1 total)
  • Plugin Author Rolf Allard van Hagen

    (@ravanh)

    Hi @janvitos sorry to have broken your purge script. The function xmlsf_nginx_helper_purge_urls() has actually been replaced by a hook. It could be used like this to recover the array of URLs that you wish to purge from Cloudflare:

    function wporg_cloudlfare_purge_urls( $urls ) {
    // Replace these with environment variables or WP options
    $api_token = CLOUDFLARE_API_TOKEN;
    $zone_id = CLOUDFLARE_ZONE_ID;

    if (!$api_token || !$zone_id) {
    error_log('Cloudflare API credentials are not set.');
    return;
    }

    $data = json_encode(array("files" => $urls));

    $response = wp_remote_post("https://api.cloudflare.com/client/v4/zones/$zone_id/purge_cache", array(
    'method' => 'POST',
    'headers' => array(
    'Content-Type' => 'application/json',
    'Authorization' => 'Bearer ' . $api_token,
    ),
    'body' => $data,
    ));
    }

    add_action( 'xmlsf_nginx_helper_purge_urls', 'wporg_cloudlfare_purge_urls' );

    Hope that helps ??

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.