[WP Super Cache] Here's how to REFRESH PAGES when a new post is added/deleted
-
Unless I’ve misconfigured supercache on our installs, I’ve noticed that it does not delete additional pages (off the front page) when a new post is published or deleted.
This means the pages are out of sync until the next cache purge for non-logged-in users.
Here’s some code to hook a post being published or deleted and purge the pages so they are regenerated on the next viewing.
add_action('transition_post_status', 'supercache_purge_paged', 10, 3); function supercache_purge_paged($new_status, $old_status, $post) { if ($post->post_type!='post' || !($new_status=='publish' || $old_status=='publish')) {return;} global $cache_path; if (empty($cache_path)) {return;} exec('find '.$cache_path.'supercache/*/page/ -maxdepth 0 -type d -exec rm -rf {} \;'); }
WARNING: if
exec
is disabled on your PHP install, this code will fail, also if you aren’t on a linux system or it’sFIND
is very outdated. In theory the “find” shell exec could be replaced with some much more complex PHP code to walk the directories and delete the pages but I’m not writing it, too slow.Because of the HTTP_HOST bug (I’ve reported elsewhere) it also has to use a wildcard to find all the various bad hostnames, which means if you have a strange rare install that uses multiple WP installs and one supercache area, all of the paged frontpages will be purged for all the installs.
- The topic ‘[WP Super Cache] Here's how to REFRESH PAGES when a new post is added/deleted’ is closed to new replies.