• Resolved asafm7

    (@asafm7)


    Hello.

    Can an API hook to purge Cloudflare cache be considered? (similar to do_action('litespeed_purge_all'))

    As the LiteSpeed and Cloudflare plugins are not recommended to be installed together, there isn’t a good progromatic way to purge Cloudflare cache.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support qtwrk

    (@qtwrk)

    I will forward this as feature reuqest

    as a temp solution ,add this to your theme’s functions.php

    function lscwp_cf_purge_function() {
      $url = "https://api.cloudflare.com/client/v4/zones/ZONE_ID/purge_cache";
    
      $curl = curl_init($url);
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    
      $headers = array(
         "Authorization: Bearer API_TOKEN",
         "Content-Type: application/json",
      );
      curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
      $data = '{"purge_everything":true}';
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
      curl_exec($curl);
      curl_close($curl);
    }
    
    add_action('lscwp_cf_purge', 'lscwp_cf_purge_function');

    replace ZONE_ID and API_TOKEN to actual on , then you can call it as

    do_action('lscwp_cf_purge');

    for example

    add_action('litespeed_purged_all', 'cloudflare_purge_all');
    function cloudflare_purge_all() {
        do_action('lscwp_cf_purge');
    }

    to fire when LSCWP purge all

    Thread Starter asafm7

    (@asafm7)

    Thanks, @qtwrk.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Consider adding an API hook to purge Cloudflare cache’ is closed to new replies.