udx / wp-stateless

WP-Stateless is a WordPress plugin that uploads and serves your WordPress media from Google Cloud Storage.
https://stateless.udx.io
MIT License
260 stars 62 forks source link

Cache-Busting issue with ACF Local JSON #730

Closed dlevesque-rationalit closed 6 months ago

dlevesque-rationalit commented 6 months ago

With cache-busting enabled, every time I update an ACF field group, a new json file with a random prefix is created under the acf-json directory. It seems to be related to the sanitize_file_name filter, which adds a random prefix to the ACF json file before saving.

I'm using the Ephemeral mode, so I think cache-busting is mandatory. Is there a way to disable the sanitize_file_name filter for all ACF Local JSON files?

Thanks

balexey88 commented 6 months ago

Hello @dlevesque-rationalit,

You can solve your issue with the following code:

add_filter('stateless_skip_cache_busting', function($null, $filename) {
  $actions_to_skip = array(
    'acf/update_field_group',
    'acf/untrash_field_group',
    'acf/update_post_type',
    'acf/untrash_post_type',
    'acf/update_taxonomy',
    'acf/untrash_taxonomy',
    'acf/update_ui_options_page',
    'acf/untrash_ui_options_page',
  );

  foreach ( $actions_to_skip as $action ) {
    if ( doing_action( $action ) ) {
      return $filename;
    }
  }

  return $null;
}, 10, 2);

I hope this helps and please let us know if this works for you.

Currently we don't see enough demand but in the future we can create a separate Addon for ACF so that other users can resolve such issues as well.

Thank you, Have a nice day!

dlevesque-rationalit commented 6 months ago

Hi @balexey88,

Thanks for the quick response, really appreciated. The code works perfectly, my issue is fixed.