• Resolved wildoperation

    (@wildoperation)


    Hello,

    I was wondering if there is a way to trigger cache purging programmatically.

    The issue we’re running into is that cache purges when a page is updated, but not when something like a general options page is updated. So I’d like to write our own hooks than then call the Cloudflare plugin’s cache purge — rather than recreating an API call, storing credentials separately, etc.

    I searched through the plugin for something like save_post to see how you currently call the cache purge, but so far am coming up empty. Do you happen to have an example or can you point me in the right direction?

    Thanks,

    Tim

Viewing 1 replies (of 1 total)
  • Thread Starter wildoperation

    (@wildoperation)

    We found a solution for this. It seems like you can do this with both a hook-based approach or by calling the purge function directly. We didn’t test calling directly — only hooks — so I’ll share that here in case anyone else needs to do something similar.

    We found that adding these hooks to the theme functions didn’t work — they are registered too late. So we had to make a small plugin and add them there:

    /**
    * First add a custom action to the list of Cloudflare purge everything actions
    */
    add_filter(
    'cloudflare_purge_everything_actions',
    function ( $actions ) {
    $actions[] = 'ddi_cloudflare_purge_everything';
    return $actions;
    }
    );

    /**
    * Hook into the ACF options page save action, and call our custom action.
    * You can replace acf/options_page/save with any other action you're trying to intercept.
    */
    add_action(
    'acf/options_page/save',
    function ( $post_id, $menu_slug ) {
    if ( $menu_slug === 'acf-options-alert-message' || $menu_slug === 'site-general-settings' ) {
    do_action( 'ddi_cloudflare_purge_everything' );
    }
    },
    10,
    2
    );
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.