WPCOM_VIP_Cache_Manager::get_purge_urls_for_term PHP Method

get_purge_urls_for_term() protected method

Get all URLs to be purged for a given term
protected get_purge_urls_for_term ( object $term ) : array
$term object A WP term object
return array An array of URLs to be purged
    protected function get_purge_urls_for_term($term)
    {
        // Belt and braces: get the term object,
        // in case something sent us a term ID
        $term = get_term($term);
        if (is_wp_error($term) || empty($term)) {
            return array();
        }
        $term_purge_urls = array();
        /**
         * Allows you to customise the URL suffix used to specify a page for
         * paged term archives.
         *
         * Developers should hook this filter to provide a different page
         * endpoint if they have custom or translated rewrite rules for
         * paging in term archives:
         *
         * Standard:     example.com/category/news/page/2
         * Non-standard: example.com/category/news/p/2
         *
         * The string should be formatted as for `sprintf`, with a `%d` in place
         * of the page number.
         *
         * @param string sprintf formatted string, including `%d`
         * }
         */
        $paging_endpoint = apply_filters('wpcom_vip_cache_purge_urls_paging_endpoint', $GLOBALS['wp_rewrite']->pagination_base . '/%d/');
        /**
         * The maximum page to purge from each term archive when a post associated with
         * that term is published.
         *
         * e.g. if the value is 3, the following pagination URLs will be purged for the
         * news category archive:
         *
         * example.com/category/news/
         * example.com/category/news/page/2
         * example.com/category/news/page/3
         *
         * @access private Please do not hook this filter at the moment
         * @param int The maximum page to purge from each term archive
         * }
         */
        $max_pages = apply_filters('wpcom_vip_cache_purge_urls_max_pages', 2, $term);
        // Set some limits on max and min values for pages
        $max_pages = max(1, min(5, $max_pages));
        $taxonomy_name = $term->taxonomy;
        $maybe_purge_url = get_term_link($term, $taxonomy_name);
        if (is_wp_error($maybe_purge_url)) {
            return array();
        }
        if ($maybe_purge_url && is_string($maybe_purge_url)) {
            $term_purge_urls[] = $maybe_purge_url;
            // Now add the pages for the archive we're clearing
            for ($i = 2; $i <= $max_pages; $i++) {
                $maybe_purge_url_page = rtrim($maybe_purge_url, '/') . '/' . ltrim($paging_endpoint, '/');
                $maybe_purge_url_page = sprintf($maybe_purge_url_page, $i);
                $term_purge_urls[] = user_trailingslashit($maybe_purge_url_page, 'paged');
            }
        }
        $maybe_purge_feed_url = get_term_feed_link($term->term_id, $taxonomy_name);
        if (false !== $maybe_purge_feed_url) {
            $term_purge_urls[] = $maybe_purge_feed_url;
        }
        /**
         * Allows adding URLs to be PURGEd from cache when a given term_id is PURGEd
         *
         * Developers can hook this filter and check the term being purged in order
         * to also purge related URLs, e.g. feeds.
         *
         * 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  $term_id The ID of the term which is the primary reason for the purge
         */
        $term_purge_urls = apply_filters("wpcom_vip_cache_purge_{$taxonomy_name}_term_urls", $term_purge_urls, $term->term_id);
        return $term_purge_urls;
    }