WpW: The Purge All Hooks Setting

April 18th, 2018 by LSCache 16 Comments

WordPress Wednesday: Purging LiteSpeed Cache via WordPress Hooks

Welcome to another installment of WordPress Wednesday!
Today’s topic is: Purging LiteSpeed Cache via WordPress Hooks

Disclaimer: The information contained in this post is accurate for LSCWP v2.2.2 [release log]. If you are using a newer version of the plugin, some details may have changed. Please refer to our wiki for the latest!

Today we’re going to talk about a more advanced topic than usual. If you are unfamiliar with the concept of WordPress hooks and actions, then this may not be for you. If you want to learn more and then come back, that’s great, too. Here’s a really nice primer on the subject. You might also want to brush up on LiteSpeed Cache and how purging works.

Purging LiteSpeed Cache via WordPress Hooks

LiteSpeed Cache for WordPress is configured to automatically purge everything from the cache when certain WordPress hooks are run. For example: every time you change your theme (the switch_theme hook), or every time you create a new category or tag (the create_term hook), a purge_all action is triggered.

By default, LiteSpeed runs a purge_all action any time any of the following WordPress hooks occur:


For most installations, this list of hooks is sufficient. Owners of highly-customized sites, however, may have reason to make changes to the list. We recently added a new setting that will allow you to do just that.

Purge All Hooks

Purging LiteSpeed Cache via WordPress Hooks: Polka Dot Cottage Crochet Hooks in a Row

From the WordPress Dashboard, navigate to LiteSpeed Cache > Settings > Advanced. Scroll down to Purge All Hooks, and you will see the list of hooks that currently trigger purge_all actions for your site, entered one per line.

You are free to edit this list. Remove hooks if you don’t want the cache purged, and add hooks if you want to automate more purges.

Removing a Hook

Let’s say you don’t want to purge the cache every time you create a new category.

Remove the create_term hook from the list, and press the Save Changes button.

(That was easy.)

Adding a WordPress Hook

This one is slightly more complicated, but only because you need to know the name of the hook you want to add.

For example, if you want to purge the cache any time a new comment is posted, then you need to know that the WordPress hook for posting a comment is comment_post.

Once you are aware of the name of the correct hook, you can insert it into the list on its own line.

The WordPress Code Reference provides a list of available hooks. There’s a handy search function on the page, too, in case you don’t want to go through the list alphabetically.

Adding a Plugin Hook

Plugins can provide hooks, too, and there may be a situation where you want to hang a purge_all onto a plugin hook. Again, you’ll need to do a little research to find the name of the hook, but once you do, it’s a simple matter of adding it to the Purge All Hooks list.

Let’s look at an example from our own plugin. You may have noticed that there are some tabs in the LiteSpeed Settings pages that suggest you should run a Purge All after you’ve changed those settings. Well, if changing the configuration is something you do frequently, why not automate that Purge All?

For example, LiteSpeed Cache > Settings > Optimize warns “After changing Minify/Combine settings, please do a Purge All action.” All we need to do is find the hook that runs when you Save Changes on the Optimization page, and add that hook to the Purge All Hooks list.

There is no hook specific to the Optimize page, but there is one that relates to nearly all of the ON/OFF switches on any of the Settings tabs: update_option_litespeed-cache-conf.

Add that hook to the list, and a Purge All will occur any time you enable or disable a setting.

Purging LiteSpeed Cache via WordPress Hooks: Polka Dot Cottage Crochet Hooks in a Jar

Finding a plugin’s hooks may not be easy. You can hope that they’ve provided a complete list as part of their documentation (which is rare), you can ask in their support forum (if they have one), or you can pore through their source code and try to find them (if it’s open source).

Here are some handy LiteSpeed plugin hooks. Most of these occur when individual settings (those not included in update_option_litespeed-cache-conf) are changed:


Please be sure that you understand fully what any hook means before adding it to Purge All Hooks. After all, purge_all is a drastic step. It wipes out the entire cache. You don’t want to automate that task unless the hook truly warrants it!

Changing Your Mind

If you’ve added some hooks, and you don’t like the results, you can go back to the default configuration. Copy the list of hooks from the “Recommended Value” box into the Purge All Hooks setting and press the Save Changes. Everything should go back to normal.

Have some of your own ideas for future WordPress Wednesday topics? Leave us a comment!

Don’t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:


Related Posts