{"id":9554,"date":"2018-04-18T09:56:11","date_gmt":"2018-04-18T13:56:11","guid":{"rendered":"https:\/\/blog.litespeedtech.com\/?p=9554"},"modified":"2018-04-18T09:56:11","modified_gmt":"2018-04-18T13:56:11","slug":"purging-litespeed-cache-via-wordpress-hooks","status":"publish","type":"post","link":"https:\/\/lswp.store\/index.php\/2018\/04\/18\/purging-litespeed-cache-via-wordpress-hooks\/","title":{"rendered":"WpW: The Purge All Hooks Setting"},"content":{"rendered":"<p><a href=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-10.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-9556\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-10.png\" alt=\"WordPress Wednesday: Purging LiteSpeed Cache via WordPress Hooks\" width=\"640\" height=\"320\" srcset=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-10.png 640w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-10-300x150.png 300w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-10-600x300.png 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Welcome to another installment of <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\">WordPress Wednesday<\/a>!<br \/>\nToday\u2019s topic is: <strong>Purging LiteSpeed Cache via WordPress Hooks<\/strong><\/p>\n<p><em><strong>Disclaimer<\/strong>: The information contained in this post is accurate for LSCWP v2.2.2 [<a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/#developers\">release log<\/a>]. If you are using a newer version of the plugin, some details may have changed. Please<a href=\"https:\/\/www.litespeedtech.com\/support\/wiki\/doku.php\/litespeed_wiki:cache:lscwp\"> refer to our wiki<\/a> for the latest!<\/em><\/p>\n<p>&#8212;<br \/>\nToday we\u2019re 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\u2019s great, too. Here\u2019s <a href=\"https:\/\/docs.presscustomizr.com\/article\/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers\">a really nice primer on the subject<\/a>. You might also want to brush up on <a href=\"https:\/\/lswp.store\/2017\/07\/19\/wpw-litespeed-caching-101\/\">LiteSpeed Cache and how purging works<\/a>.<br \/>\n&#8212;<\/p>\n<h2>Purging LiteSpeed Cache via WordPress Hooks<\/h2>\n<p>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 <code>switch_theme<\/code> hook), or every time you create a new category or tag (the <code>create_term<\/code> hook), a <code>purge_all<\/code> action is triggered.<\/p>\n<p>By default, LiteSpeed runs a <code>purge_all<\/code> action any time any of the following WordPress hooks occur:<\/p>\n<pre>switch_theme\nwp_create_nav_menu\nwp_update_nav_menu\nwp_delete_nav_menu\ncreate_term\nedit_terms\ndelete_term\nadd_link\nedit_link\ndelete_link\n<\/pre>\n<p>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.<\/p>\n<h2>Purge All Hooks<\/h2>\n<p><a href=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-6.jpeg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-9558\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-6.jpeg\" alt=\"Purging LiteSpeed Cache via WordPress Hooks: Polka Dot Cottage Crochet Hooks in a Row\" width=\"1000\" height=\"667\" srcset=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-6.jpeg 1000w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-6-300x200.jpeg 300w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-6-768x512.jpeg 768w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-6-600x400.jpeg 600w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>From the WordPress Dashboard, navigate to <strong>LiteSpeed Cache &gt; Settings &gt; Advanced<\/strong>. Scroll down to <strong>Purge All Hooks<\/strong>, and you will see the list of hooks that currently trigger <code>purge_all<\/code> actions for your site, entered one per line.<\/p>\n<p>You are free to edit this list. Remove hooks if you don\u2019t want the cache purged, and add hooks if you want to automate more purges.<\/p>\n<h3>Removing a Hook<\/h3>\n<p>Let\u2019s say you don\u2019t want to purge the cache every time you create a new category.<\/p>\n<p>Remove the <code>create_term<\/code> hook from the list, and press the <strong>Save Changes<\/strong> button.<\/p>\n<p>(That was easy.)<\/p>\n<h3>Adding a WordPress Hook<\/h3>\n<p>This one is slightly more complicated, but only because you need to know the name of the hook you want to add.<\/p>\n<p>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 <code>comment_post<\/code>.<\/p>\n<p>Once you are aware of the name of the correct hook, you can insert it into the list on its own line.<\/p>\n<p><a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/\">The WordPress Code Reference<\/a> provides a list of available hooks. There\u2019s a handy search function on the page, too, in case you don\u2019t want to go through the list alphabetically.<\/p>\n<h3>Adding a Plugin Hook<\/h3>\n<p>Plugins can provide hooks, too, and there may be a situation where you want to hang a <code>purge_all<\/code> onto a plugin hook. Again, you\u2019ll need to do a little research to find the name of the hook, but once you do, it\u2019s a simple matter of adding it to the <strong>Purge All Hooks<\/strong> list.<\/p>\n<p>Let\u2019s 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\u2019ve changed those settings. Well, if changing the configuration is something you do frequently, why not automate that Purge All?<\/p>\n<p>For example, <strong>LiteSpeed Cache &gt; Settings &gt; Optimize<\/strong> warns \u201cAfter changing Minify\/Combine settings, please do a Purge All action.\u201d All we need to do is find the hook that runs when you <strong>Save Changes<\/strong> on the <strong>Optimization<\/strong> page, and add that hook to the <strong>Purge All Hooks<\/strong> list.<\/p>\n<p>There is no hook specific to the <strong>Optimize<\/strong> page, but there is one that relates to nearly all of the <code>ON<\/code>\/<code>OFF<\/code> switches on any of the <strong>Settings<\/strong> tabs: <code>update_option_litespeed-cache-conf<\/code>.<\/p>\n<p>Add that hook to the list, and a Purge All will occur any time you enable or disable a setting.<\/p>\n<p><a href=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-7.jpeg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-9560\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-7.jpeg\" alt=\"Purging LiteSpeed Cache via WordPress Hooks: Polka Dot Cottage Crochet Hooks in a Jar\" width=\"1000\" height=\"667\" srcset=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-7.jpeg 1000w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-7-300x200.jpeg 300w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-7-768x512.jpeg 768w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-7-600x400.jpeg 600w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>Finding a plugin\u2019s hooks may not be easy. You can hope that they\u2019ve 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\u2019s open source).<\/p>\n<p>Here are some handy LiteSpeed plugin hooks. Most of these occur when individual settings (those not included in <code>update_option_litespeed-cache-conf<\/code>) are changed:<\/p>\n<pre>update_option_litespeed-cache-vary-group\nupdate_option_litespeed-cache-exclude-optimization-roles\nupdate_option_litespeed-cache-exclude-cache-roles\nupdate_option_litespeed-optm-css\nupdate_option_litespeed-optm-js-defer-excludes\nupdate_option_litespeed-media-lazy-img-excludes\nupdate_option_litespeed-media-need-pull\nupdate_option_litespeed-env-ref\nupdate_option_litespeed-cache-drop_qs\nupdate_option_litespeed-cache-cdn_mapping\nupdate_option_litespeed-cache-dns_prefetch\nupdate_option_litespeed-cache-cloudflare_status\nupdate_option_litespeed-log_ignore_filters\nupdate_option_litespeed-log_ignore_part_filters\nupdate_option_litespeed-object_global_groups\nupdate_option_litespeed-object_non_persistent_groups\nupdate_option_litespeed-crawler-as-uids\nupdate_option_litespeed-adv-purge_all_hooks\nupdate_option_litespeed-cdn-ori_dir\nupdate_option_litespeed-media-webp_attribute\n<\/pre>\n<p><em>Please be sure that you understand fully what any hook means before adding it to <strong>Purge All Hooks<\/strong>.<\/em> After all, <code>purge_all<\/code> is a drastic step. It wipes out the entire cache. You don\u2019t want to automate that task unless the hook truly warrants it!<\/p>\n<h2>Changing Your Mind<\/h2>\n<p>If you\u2019ve added some hooks, and you don\u2019t like the results, you can go back to the default configuration. Copy the list of hooks from the \u201cRecommended Value\u201d box into the <strong>Purge All Hooks<\/strong> setting and press the <strong>Save Changes<\/strong>. Everything should go back to normal.<\/p>\n<p>&#8212;<\/p>\n<p>Have some of your own ideas for future <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\">WordPress Wednesday<\/a> topics? Leave us a comment!<\/p>\n<p>Don\u2019t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:<\/p>\n<ul>\n<li>Subscribe to the <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\/feed\/\">WordPress Wednesday RSS feed<\/a><\/li>\n<li>Download <a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/\">LiteSpeed Cache for WordPress plugin<\/a><\/li>\n<li>Learn more about the plugin <a href=\"https:\/\/www.litespeedtech.com\/products\/cache-plugins\/wordpress-acceleration\">on our website<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>We automatically purge everything from the cache when certain WP hooks are run. Now you can add or remove hooks from that list.<\/p>\n","protected":false},"author":1,"featured_media":9556,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[316,317],"class_list":["post-9554","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cache","tag-wordpress","tag-wordpress-wednesday"],"jetpack_featured_media_url":"https:\/\/lswp.store\/wp-content\/uploads\/2018\/04\/null-10.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/9554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/comments?post=9554"}],"version-history":[{"count":0,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/9554\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media\/9556"}],"wp:attachment":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media?parent=9554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/categories?post=9554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/tags?post=9554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}