In with the new and out with the old. Strap in we are in for a big change. This will completely replace the old cache clearing structure for post actions, like publishing, updating, and trashing any post types.
Add a new pagination clear type to Cache_Enabler_Disk::delete_asset() to allow the pagination page(s) to be cleared. The pagination base path is currently obtained by using $GLOBALS['wp_rewrite']->pagination_base (this will get the updated value if it has been set to something other than the default page).
Add Cache_Enabler::clear_cache_on_post_save() to clear the page(s) cache when any published post type is created or updated.
Add Cache_Enabler::clear_associated_cache() to clear the page(s) cache associated with any published or updated post type. Currently this includes the following:
Post type archives page with Cache_Enabler::clear_post_type_archives_cache(). This takes the post type and finds the archives URL to that post type. For example, for the post post type this could be the home page or a defined posts page (e.g. https://www.example.com/blog/). For the product post type this could be the shop page (e.g. https://www.example.com/shop/). It is possible for a post type to not have an archives page (e.g. page post type or if there is no defined posts page).
Taxonomy archives pages with Cache_Enabler::clear_taxonomies_archives_cache_by_post_id(). This takes all of the taxonomies, whether that is the default like category or post_tag, or even a custom taxonomy, and finds the archives URL to any term attached to the created or updated post. For example, if the default tag and category bases were used, and a post had the perf tag and was in the development category, both https://www.example.com/tag/perf/ and https://www.example.com/category/development/ would be cleared.
Author archives pages with Cache_Enabler::clear_author_archives_cache_by_user_id(). This takes the author base path and combines it with the post author username. For example, if the default author base was used and a post with the John Doe (jdoe) author was created or updated then https://www.example.com/author/jdoe/ would be cleared. The author base path is currently obtained by using $GLOBALS['wp_rewrite']->author_base. home_url( '/' ) is used in case the retrieved $author_base is empty. This is currently only called if the created or updated post type is post.
Date archives pages with Cache_Enabler::clear_date_archives_cache_by_post_id(). This takes the post date and finds all of the possible date archives for the year, month, and day. For example, if a post was published on 2020-09-13 then https://www.example.com/2020/, https://www.example.com/2020/09/, and https://www.example.com/2020/09/13/ would be cleared. This is currently only called if the created or updated post type is post.
...and the pagination pages of all the above.
Add Cache_Enabler::on_save_post() to be called whenever the save_post hook is fired. This will update how the cache is cleared when any post type is published or updated. This should expand compatibility with other plugins, like other ecommerce solutions beyond WooCommerce, because the save_post hook will be fired whenever a post or page is created or updated (in any way that it was saved, like through the edit form in the WordPress admin or even an API). The default cache clearing behavior should clear the page cache whenever any post type is updated in any way. Not using the $update parameter because it returns true on new posts in some cases, like when the status changes from inherit to publish (in two separate save_hook fires). Still checking $post->post_date_gmt and $post->post_modified_gmt values are the same for a new post. Added checking if $post->post_date_gmt is also greater than $post->post_modified_gmt for scheduled posts (because scheduled posts are modified before they are published).
Add Cache_Enabler::on_post_updated() to be called whenever the post_updated hook is fired. This checks if the post author has changed. If it has changed then the authors archive cache is cleared for the last author. This is required to ensure both the new and old authors archives pages are cleared.
Add Cache_Enabler::on_transition_post_status() to clear the page cache by default if a published post status is updated to future, draft, pending, or private. The complete or associated cache can be cleared if the new setting below is enabled. This method has been added instead of using Cache_Enabler::on_save_post() because it has the old and new status, whereas the other method would only have the updated status. It will ensure cache clearing is only performed when a published post status has changed.
Add Cache_Enabler::_convert_settings() to change the old settings to the new settings. This is required to ensure the settings are retained on an update. The settings names were changed for improved understanding on what they are for and because we are moving towards better naming conventions. This will also make it easier when configuring Cache Enabler programmatically (like in the future when creating a new configure related subcommand for WP-CLI).
Add CSS for settings page to avoid inline CSS. No preprocessors used at this time to keep it simple as there is minimal required CSS.
Add rel="nofollow noopener" attribute to outbound href elements.
Update caching behavior to ignore query strings by default and deliver the cached page if any query string is present. Previously all query strings would bypass the cache unless included. This change was made because in most cases the cache should not be bypassed if a query string is present. A regular expression matching query strings can be set to bypass the cache (e.g. /.+/ could be set to bypass all query strings).
Update Cache_Enabler::create_advcache_settings() to handle creating and updating the advanced cache settings file (instead of getting the settings from the database and sending them to Cache_Enabler::validate_settings()).
Update Cache_Enabler::validate_settings() to update the advanced cache settings file after the settings have been validated. This fixes the issue where unvalidated settings would be saved to the advanced cache settings file as they were being recorded before being validated (#128). Validate the passed parameter as an array instead of checking if it is empty. Use empty() instead to check if the complete cache needs to be cleared as we just need to check if the item has been set and has a value. This would be the button value, which is currently Save Changes and Clear Cache or its translation.
Update Cache_Enabler::validate_regex() to use empty() instead of checking if it is an empty string. This fixes the edge case where // would be returned if the regular expression being checked was null (like if the database option was deleted).
Update Cache_Enabler::on_trash_post() to only clear the page and associated cache by default (like when any post type is published). Previously the entire cache was cleared when any post type was cleared. This is not done in Cache_Enabler::on_transition_post_status() because the wp_trash_post hook fires before the post is trashed, which we need to get the correct URL to clear (instead of https://www.example.com/hello-word__trashed).
Update Cache_Enabler::clear_page_cache_by_url() to not validate the string as this will be handled when validating the URL.
Update some get_home_url() functions to home_url() instead because we are calling the current site anyway.
Update variable naming to use "settings" instead of "options" to use the same naming across the entire code base.
Update settings page:
Update layout for improved usability. All cache behavior related settings are now together.
Update the setting for published posts to clear the associated cache by default instead of only the home page.
Add a new setting that allows the associated or complete cache to be cleared if any published post type is updated. This means the cache clearing publishing action is no longer required and has been removed. I have not found a good reason worth having this be defined on a per user level with the new changes.
Add a new setting to match query strings (not only query parameters) with a regular expression that will bypass the cache.
Remove WooCommerce stock update setting that was added in PR #88 because this is now all handled when any post type is updated. If the product stock is updated the save_post hook is fired. The product page cache will be cleared by default and the new option added above for updated posts can be enabled for further cache clearing. For example, now if the associated cache is cleared when a product is updated the product post type archive page (e.g. https://www.example.com/shop/) will be cleared in addition to any product categories or tags.
Remove cache inclusions setting for URL query parameters because query strings will now no longer bypass the cache by default.
Remove Cache_Enabler::check_future_posts() because cache timeouts for future posts are no longer required because the save_post hook will be fired when the post is published (the post status goes from future to publish). This will prevent unnecessarily calling Cache_Enabler_Disk::delete_advcache_settings() every time the save_post hook is fired and there is not scheduled post. It will also prevent undefined index errors when using a client that does not have a $_SERVER['HTTP_HOST'] header, like using WP-CLI to create new posts (#68).
Remove Cache_Enabler::clear_home_page_cache() because this can now be done with Cache_Enabler::clear_page_cache_by_url() because of the recently added clear types for strict cache clearing.
Remove legacy database option rename (from cache to cache-enabler). This was added in version 1.2.1 in May 2017 (744625d). Only 5% of installs are still on version 1.2, which could be version 1.2.0, 1.2.1, 1.2.2, or 1.2.3. This means if a plugin updates from <= 1.2.0 will need to define the settings again (and would have an orphaned cache option in the database).
Remove cache minification constants because they are no longer required with the updated minification setting.
Fix Cache_Enabler::_minify_cache() issue that was introduced in version 1.4.0 during the refactoring of the code base (PR #84). This caused only the script tag to be ignored if minifying the inline JavaScript was disabled.
In with the new and out with the old. Strap in we are in for a big change. This will completely replace the old cache clearing structure for post actions, like publishing, updating, and trashing any post types.
Add a new
pagination
clear type toCache_Enabler_Disk::delete_asset()
to allow the pagination page(s) to be cleared. The pagination base path is currently obtained by using$GLOBALS['wp_rewrite']->pagination_base
(this will get the updated value if it has been set to something other than the defaultpage
).Add
Cache_Enabler::clear_cache_on_post_save()
to clear the page(s) cache when any published post type is created or updated.Add
Cache_Enabler::clear_associated_cache()
to clear the page(s) cache associated with any published or updated post type. Currently this includes the following:Post type archives page with
Cache_Enabler::clear_post_type_archives_cache()
. This takes the post type and finds the archives URL to that post type. For example, for thepost
post type this could be the home page or a defined posts page (e.g.https://www.example.com/blog/
). For theproduct
post type this could be the shop page (e.g.https://www.example.com/shop/
). It is possible for a post type to not have an archives page (e.g.page
post type or if there is no defined posts page).Taxonomy archives pages with
Cache_Enabler::clear_taxonomies_archives_cache_by_post_id()
. This takes all of the taxonomies, whether that is the default likecategory
orpost_tag
, or even a custom taxonomy, and finds the archives URL to any term attached to the created or updated post. For example, if the default tag and category bases were used, and a post had theperf
tag and was in thedevelopment
category, bothhttps://www.example.com/tag/perf/
andhttps://www.example.com/category/development/
would be cleared.Author archives pages with
Cache_Enabler::clear_author_archives_cache_by_user_id()
. This takes the author base path and combines it with the post author username. For example, if the default author base was used and a post with the John Doe (jdoe) author was created or updated thenhttps://www.example.com/author/jdoe/
would be cleared. The author base path is currently obtained by using$GLOBALS['wp_rewrite']->author_base
.home_url( '/' )
is used in case the retrieved$author_base
is empty. This is currently only called if the created or updated post type ispost
.Date archives pages with
Cache_Enabler::clear_date_archives_cache_by_post_id()
. This takes the post date and finds all of the possible date archives for the year, month, and day. For example, if a post was published on 2020-09-13 thenhttps://www.example.com/2020/
,https://www.example.com/2020/09/
, andhttps://www.example.com/2020/09/13/
would be cleared. This is currently only called if the created or updated post type ispost
....and the pagination pages of all the above.
Add
Cache_Enabler::on_save_post()
to be called whenever thesave_post
hook is fired. This will update how the cache is cleared when any post type is published or updated. This should expand compatibility with other plugins, like other ecommerce solutions beyond WooCommerce, because thesave_post
hook will be fired whenever a post or page is created or updated (in any way that it was saved, like through the edit form in the WordPress admin or even an API). The default cache clearing behavior should clear the page cache whenever any post type is updated in any way. Not using the$update
parameter because it returns true on new posts in some cases, like when the status changes frominherit
topublish
(in two separatesave_hook
fires). Still checking$post->post_date_gmt
and$post->post_modified_gmt
values are the same for a new post. Added checking if$post->post_date_gmt
is also greater than$post->post_modified_gmt
for scheduled posts (because scheduled posts are modified before they are published).Add
Cache_Enabler::on_post_updated()
to be called whenever thepost_updated
hook is fired. This checks if the post author has changed. If it has changed then the authors archive cache is cleared for the last author. This is required to ensure both the new and old authors archives pages are cleared.Add
Cache_Enabler::on_transition_post_status()
to clear the page cache by default if a published post status is updated tofuture
,draft
,pending
, orprivate
. The complete or associated cache can be cleared if the new setting below is enabled. This method has been added instead of usingCache_Enabler::on_save_post()
because it has the old and new status, whereas the other method would only have the updated status. It will ensure cache clearing is only performed when a published post status has changed.Add
Cache_Enabler::_convert_settings()
to change the old settings to the new settings. This is required to ensure the settings are retained on an update. The settings names were changed for improved understanding on what they are for and because we are moving towards better naming conventions. This will also make it easier when configuring Cache Enabler programmatically (like in the future when creating a new configure related subcommand for WP-CLI).Add CSS for settings page to avoid inline CSS. No preprocessors used at this time to keep it simple as there is minimal required CSS.
Add
rel="nofollow noopener"
attribute to outboundhref
elements.Update caching behavior to ignore query strings by default and deliver the cached page if any query string is present. Previously all query strings would bypass the cache unless included. This change was made because in most cases the cache should not be bypassed if a query string is present. A regular expression matching query strings can be set to bypass the cache (e.g.
/.+/
could be set to bypass all query strings).Update
Cache_Enabler::create_advcache_settings()
to handle creating and updating the advanced cache settings file (instead of getting the settings from the database and sending them toCache_Enabler::validate_settings()
).Update
Cache_Enabler::validate_settings()
to update the advanced cache settings file after the settings have been validated. This fixes the issue where unvalidated settings would be saved to the advanced cache settings file as they were being recorded before being validated (#128). Validate the passed parameter as an array instead of checking if it is empty. Useempty()
instead to check if the complete cache needs to be cleared as we just need to check if the item has been set and has a value. This would be the button value, which is currentlySave Changes and Clear Cache
or its translation.Update
Cache_Enabler::validate_regex()
to useempty()
instead of checking if it is an empty string. This fixes the edge case where//
would be returned if the regular expression being checked was null (like if the database option was deleted).Update
Cache_Enabler::on_trash_post()
to only clear the page and associated cache by default (like when any post type is published). Previously the entire cache was cleared when any post type was cleared. This is not done inCache_Enabler::on_transition_post_status()
because thewp_trash_post
hook fires before the post is trashed, which we need to get the correct URL to clear (instead ofhttps://www.example.com/hello-word__trashed
).Update
Cache_Enabler::clear_page_cache_by_url()
to not validate the string as this will be handled when validating the URL.Update some
get_home_url()
functions tohome_url()
instead because we are calling the current site anyway.Update variable naming to use "settings" instead of "options" to use the same naming across the entire code base.
Update settings page:
Update layout for improved usability. All cache behavior related settings are now together.
Update the setting for published posts to clear the associated cache by default instead of only the home page.
Add a new setting that allows the associated or complete cache to be cleared if any published post type is updated. This means the cache clearing publishing action is no longer required and has been removed. I have not found a good reason worth having this be defined on a per user level with the new changes.
Add a new setting to match query strings (not only query parameters) with a regular expression that will bypass the cache.
Remove WooCommerce stock update setting that was added in PR #88 because this is now all handled when any post type is updated. If the product stock is updated the
save_post
hook is fired. The product page cache will be cleared by default and the new option added above for updated posts can be enabled for further cache clearing. For example, now if the associated cache is cleared when a product is updated theproduct
post type archive page (e.g.https://www.example.com/shop/
) will be cleared in addition to any product categories or tags.Remove cache inclusions setting for URL query parameters because query strings will now no longer bypass the cache by default.
Remove
Cache_Enabler::check_future_posts()
because cache timeouts for future posts are no longer required because thesave_post
hook will be fired when the post is published (the post status goes fromfuture
topublish
). This will prevent unnecessarily callingCache_Enabler_Disk::delete_advcache_settings()
every time thesave_post
hook is fired and there is not scheduled post. It will also prevent undefined index errors when using a client that does not have a$_SERVER['HTTP_HOST']
header, like using WP-CLI to create new posts (#68).Remove
Cache_Enabler::clear_home_page_cache()
because this can now be done withCache_Enabler::clear_page_cache_by_url()
because of the recently added clear types for strict cache clearing.Remove legacy database option rename (from
cache
tocache-enabler
). This was added in version 1.2.1 in May 2017 (744625d). Only 5% of installs are still on version 1.2, which could be version 1.2.0, 1.2.1, 1.2.2, or 1.2.3. This means if a plugin updates from <= 1.2.0 will need to define the settings again (and would have an orphanedcache
option in the database).Remove cache minification constants because they are no longer required with the updated minification setting.
Fix
Cache_Enabler::_minify_cache()
issue that was introduced in version 1.4.0 during the refactoring of the code base (PR #84). This caused only thescript
tag to be ignored if minifying the inline JavaScript was disabled.Closes #112 and fixes #128