Title: Function/Hook to clear/reset AutOptimize?
Last modified: June 28, 2023

---

# Function/Hook to clear/reset AutOptimize?

 *  Resolved [codejp3](https://wordpress.org/support/users/codejp3/)
 * (@codejp3)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/function-hook-to-clear-reset-autoptimize/)
 * Frank,
 * I’m double-tapping and creating a topic here that I already tagged you in for
   the [bbP Style Pack](https://wordpress.org/plugins/bbp-style-pack/) plugin (see
   that topic here: [https://wordpress.org/support/topic/styling-subscribe-unsubscribe/](https://wordpress.org/support/topic/styling-subscribe-unsubscribe/))
 * Our plugin’s main purpose is to add styling options and feature enhancements 
   to bbPress (and BuddyPress). With that said, CSS and JS files are (re)generated
   almost every time a setting is changed. We’ve tried various tricks to force plugins
   and CDNs to re-cache/re-load those new files (such as enqueuing using the last
   generation timestamp as the version number) and have successfully taken care 
   of a majority of cases, but there are still cases where we get support topics
   stating that “it’s not working” and after clearing cache/resetting performance
   plugins, they “magically work”.
 * AutOptimize is one of those cases. Your plugin is a quality one for sure, but
   maybe it works a little too good. 🙂
 * I was wondering if you had a function or hook we can tap into to force a reset
   of minified/compressed/concatenated files handled by AutOptimize? Something like
   the built-in “wp_cache_flush()”. Either site-wide, or specific files would be
   suitable for this purpose.
 * I looked through API docs like this ([https://github.com/wp-plugins/autoptimize](https://github.com/wp-plugins/autoptimize))
   but didn’t see anything specifically addressing this capability.
 * We’d like to prevent users from having to reset AutOptimize every time after 
   they make a change with settings in our plugin, and automatically handle that
   for them. It’s far more convenient for them, and will save us on many “it’s not
   working” support topics at the same time.
 * If there is no suitable option in the plugin now, I’d like to request this feature
   in a future release. Thanks for your time!
 * John Patrick Hayden III
   – codejp3

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/function-hook-to-clear-reset-autoptimize/#post-16856518)
 * morning codejp3 ;
    Autoptimize _should_ detect updated CSS/ JS: it calculates
   an md5-hash of the CSS/ JS found and uses that hash to store the optimized version
   in AO’s cache, so if the content changes the hash changes and the cached version
   is not found to a new version is created in the cache.
 * Now when AO’s cache is cleared, it tries to also clear the page cache, so my 
   best guess is that it is the triggered clearing of the page cache that fixes 
   the problem and not the purging of AO’s cache itself.
 * That being said, yes you can programatically purge AO’s cache by calling `autoptimizeCache::
   clearall()` 🙂
 * hope this helps,
    frank
 *  Thread Starter [codejp3](https://wordpress.org/support/users/codejp3/)
 * (@codejp3)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/function-hook-to-clear-reset-autoptimize/#post-16862119)
 * Perfect!
 * I’ve added this to the next release of Style Pack. Any time we generate new files
   due to settings/value changes, we clear AutOptimze as well (if installed/activated).
 * In case anyone else wants to add this capability to their own plugin or custom
   code, here’s the final code snippet that has been tested and is working as expected:
 *     ```wp-block-code
       if ( class_exists( 'autoptimizeCache' ) ) autoptimizeCache::clearall();
       ```
   
 * Resolved 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Function/Hook to clear/reset AutOptimize?’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * 2 replies
 * 2 participants
 * Last reply from: [codejp3](https://wordpress.org/support/users/codejp3/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/function-hook-to-clear-reset-autoptimize/#post-16862119)
 * Status: resolved