Clear on ACF Options Save
-
I would like to add a feature request to clear cache on ACF Options page saves
https://www.advancedcustomfields.com/resources/acf-save_post/
-
I have created my own snippet to help me here with ACF and Breeze cache, but I think it would be a worthy addition to the plugin as well:
add_action(‘acf/save_post’, ‘acf_clear_cache’);
function acf_clear_cache( $post_id ) {
do_action( ‘breeze_clear_all_cache’ );
}Awesome! Thanks for the suggestion. I use ACF all the time too. I’ll add it soon.
It seems that acf/save_post will get called whenever WordPress’ save_post gets called and caching systems will normally already clear the cache when that happens.
When do you notice acf/save_post not clearing the cache? This might be a little too specific to your case.
Can you confirm that after updating an acf options page it clears cache? Because I its doesn’t for me across multiple hosting environments.
Ok I think I got what you mean. You want to clear the cache when editing the fields in ACF.
Clearing cache by updating the Settings page is handled by this plugin already, clearing cache (for the specific post) when a post is updated is handled by the caching system. I’ll add cache clearing when a field in ACF is updated.
please try the latest version, 1.7
@webheadllc Yes, v1.7 works 🤙🏻 Thanks for the update!
Example use case for anyone in the future seeing this: I have a notification banner that can be controlled by an ACF Options page that contains a True/False checkbox to enable/disable it and a text field to edit the content. If the checkbox is checked and the options page is Updated (saved) the banner is displayed – and removed when unchecked and saved.
With v1.7, when you click Update, your cache will clear to show the banner since it was cached with/without the banner before saving the options page.
-
This reply was modified 4 years, 4 months ago by
Zack Pyle.
great! 🤙🏻 thanks for the use case example.
@webheadllc Any ideas on clearing Cloudflare cache? I’m running into the same issue with the ACF options page, and the Cloudflare plugin isn’t recognizing it as a change causing it not to clear cache. It only recognizes:
- deleted_post
- edit_post
- delete_attachment
- autoptimize_action_cachepurged (for compatibility with the Autoptimize WordPress plugin)
- switch_theme
- customize_save_after
-
This reply was modified 4 years, 2 months ago by
Zack Pyle.
(PS: I’m reaching out to CF to see if they add that action to their plugin)
@webheadllc If you want to add it, here is the filter for the CF plugin to purge CF cache: https://wordpress.org/support/topic/clear-cf-on-acf-options-page-save/#post-15215429
add_filter( 'cloudflare_purge_everything_actions' , function( $actions) { return array_merge( $actions, [ 'acf/save_post' ]); }, 10,1);awesome! thank you for that. I’ll look into that and see if i can add it in the core plugin in the upcoming months.
Thanks again!
@webheadllc Cool. Btw, if you were thinking of it as another feature, no need to clear the CF cache at any other time, as CF plugin handles that on these 6 hooks (and does so on a page/url basis as not to clear the whole cache, I believe) – https://support.cloudflare.com/hc/en-us/articles/115002708027-Cloudflare-WordPress-Plugin-Automatic-Cache-Management-
But the acf/save_post hook isn’t covered under that. So that’s why this filter hooks into their plugin to also clear CF on acf/save_post 👍🏻
-
This reply was modified 4 years, 4 months ago by
The topic ‘Clear on ACF Options Save’ is closed to new replies.