public function queue_post_purge($post_id)
{
if ($this->site_cache_purged) {
return false;
}
if (defined('WP_IMPORTING')) {
$this->purge_site_cache();
return false;
}
$post = get_post($post_id);
if (empty($post) || 'revision' === $post->post_type || !in_array(get_post_status($post_id), array('publish', 'inherit', 'trash'), true)) {
return false;
}
if (!is_post_type_viewable($post->post_type)) {
return;
}
$post_purge_urls = array();
$post_purge_urls[] = get_permalink($post_id);
$post_purge_urls[] = home_url('/');
// Don't just purge the attachment page, but also include the file itself
if ('attachment' === $post->post_type) {
$this->purge_urls[] = wp_get_attachment_url($post_id);
}
$taxonomies = get_object_taxonomies($post, 'object');
foreach ($taxonomies as $taxonomy) {
if (true !== $taxonomy->public) {
continue;
}
$taxonomy_name = $taxonomy->name;
$terms = get_the_terms($post_id, $taxonomy_name);
if (false === $terms) {
continue;
}
foreach ($terms as $term) {
$post_purge_urls = array_merge($post_purge_urls, $this->get_purge_urls_for_term($term));
}
}
// Purge the standard site feeds
// @TODO Do we need to PURGE the comment feeds if the post_status is publish?
$site_feeds = array(get_bloginfo('rdf_url'), get_bloginfo('rss_url'), get_bloginfo('rss2_url'), get_bloginfo('atom_url'), get_bloginfo('comments_atom_url'), get_bloginfo('comments_rss2_url'), get_post_comments_feed_link($post_id));
$post_purge_urls = array_merge($post_purge_urls, $site_feeds);
/**
* Allows adding URLs to be PURGEd from cache when a given post ID is PURGEd
*
* Developers can hook this filter and check the post being purged in order
* to also purge related URLs, e.g. feeds.
*
* Related category archives, tag archives, generic feeds, etc, are already
* included to be purged (see code above).
*
* PLEASE NOTE: Your site benefits from the performance that our HTTP
* Reverse Proxy Caching provides, and purging URLs from that cache
* should be done cautiously. VIP may push back on use of this filter
* during initial code review and pre-deployment review where we
* see issues.
*
* @deprecated 1.1 Use `wpcom_vip_cache_purge_{post_type}_urls` instead
* @param array $this->purge_urls {
* An array of URLs for you to add to
* }
* @param type $post_id The ID of the post which is the primary reason for the purge
*/
$post_purge_urls = apply_filters('wpcom_vip_cache_purge_urls', $post_purge_urls, $post_id);
$this->purge_urls = array_merge($this->purge_urls, $post_purge_urls);
/**
* Allows adding URLs to be PURGEd from cache when a given post ID is PURGEd
*
* Developers can hook this filter and check the post being purged in order
* to also purge related URLs, e.g. feeds.
*
* Related category archives, tag archives, generic feeds, etc, are already
* included to be purged (see code above).
*
* PLEASE NOTE: Your site benefits from the performance that our HTTP
* Reverse Proxy Caching provides, and purging URLs from that cache
* should be done cautiously. VIP may push back on use of this filter
* during initial code review and pre-deployment review where we
* see issues.
*
* @param array $this->purge_urls {
* An array of URLs for you to add to
* }
* @param type $post_id The ID of the post which is the primary reason for the purge
*/
$this->purge_urls = apply_filters("wpcom_vip_cache_purge_{$post->post_type}_post_urls", $this->purge_urls, $post_id);
$this->purge_urls = array_unique($this->purge_urls);
return true;
}