public function w3tc_admin_bar_menu($menu_items) { $menu_items['20110.pagecache'] = array('id' => 'w3tc_flush_pgcache', 'parent' => 'w3tc_flush', 'title' => __('Page Cache: All', 'w3-total-cache'), 'href' => wp_nonce_url(network_admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_pgcache'), 'w3tc')); if (Util_Environment::detect_post_id() && (!defined('DOING_AJAX') || !DOING_AJAX)) { $menu_items['20120.pagecache'] = array('id' => 'w3tc_pgcache_flush_post', 'parent' => 'w3tc_flush', 'title' => __('Page Cache: Current Page', 'w3-total-cache'), 'href' => wp_nonce_url(network_admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_post&post_id=' . Util_Environment::detect_post_id()), 'w3tc')); } return $menu_items; }
/** * Flushes varnish post cache * * @param integer $post_id * @return boolean */ function flush_post($post_id) { if (!$post_id) { $post_id = Util_Environment::detect_post_id(); } if ($post_id) { $full_urls = array(); $post = null; $terms = array(); $feeds = $this->_config->get_array('pgcache.purge.feed.types'); $limit_post_pages = $this->_config->get_integer('pgcache.purge.postpages_limit'); if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('varnish.pgcache.feed.terms')) { $taxonomies = get_post_taxonomies($post_id); $terms = wp_get_post_terms($post_id, $taxonomies); } switch (true) { case $this->_config->get_boolean('pgcache.purge.author'): case $this->_config->get_boolean('pgcache.purge.archive.daily'): case $this->_config->get_boolean('pgcache.purge.archive.monthly'): case $this->_config->get_boolean('pgcache.purge.archive.yearly'): case $this->_config->get_boolean('pgcache.purge.feed.author'): $post = get_post($post_id); } $front_page = get_option('show_on_front'); /** * Home (Frontpage) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $this->_config->get_boolean('pgcache.purge.front_page')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $full_urls = array_merge($full_urls, Util_PageUrls::get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_urls($post_id)); } /** * Post comments URLs */ if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_author_urls($post->post_author, $limit_post_pages)); } /** * Post terms URLs */ if ($this->_config->get_boolean('pgcache.purge.terms')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_terms_urls($terms, $limit_post_pages)); } /** * Daily archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_daily_archive_urls($post, $limit_post_pages)); } /** * Monthly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_monthly_archive_urls($post, $limit_post_pages)); } /** * Yearly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_urls($feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_comments_urls($post_id, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_author_urls($post->post_author, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_terms_urls($terms, $feeds)); } /** * Purge selected pages */ if ($this->_config->get_array('pgcache.purge.pages')) { $pages = $this->_config->get_array('pgcache.purge.pages'); $full_urls = array_merge($full_urls, Util_PageUrls::get_pages_urls($pages)); } if ($this->_config->get_string('pgcache.purge.sitemap_regex')) { $sitemap_regex = $this->_config->get_string('pgcache.purge.sitemap_regex'); $full_urls[] = Util_Environment::home_domain_root_url() . '/' . trim($sitemap_regex, "^\$"); } /** * Queue flush */ if (count($full_urls)) { foreach ($full_urls as $url) { $this->queued_urls[$url] = '*'; } // add mirror urls $this->queued_urls = Util_PageUrls::complement_with_mirror_urls($this->queued_urls); } return true; } return false; }
/** * Purges cdn's post cache * * @param integer $post_id * @return boolean */ public static function w3tc_flush_post($post_id) { if (!$post_id) { $post_id = Util_Environment::detect_post_id(); } if (!$post_id) { return false; } $config = Dispatcher::config(); $full_urls = array(); $post = null; $terms = array(); $feeds = $config->get_array('pgcache.purge.feed.types'); $limit_post_pages = $config->get_integer('pgcache.purge.postpages_limit'); if ($config->get_boolean('pgcache.purge.terms') || $config->get_boolean('varnish.pgcache.feed.terms')) { $taxonomies = get_post_taxonomies($post_id); $terms = wp_get_post_terms($post_id, $taxonomies); } switch (true) { case $config->get_boolean('pgcache.purge.author'): case $config->get_boolean('pgcache.purge.archive.daily'): case $config->get_boolean('pgcache.purge.archive.monthly'): case $config->get_boolean('pgcache.purge.archive.yearly'): case $config->get_boolean('pgcache.purge.feed.author'): $post = get_post($post_id); } $front_page = get_option('show_on_front'); /** * Home (Frontpage) URL */ if ($config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $config->get_boolean('pgcache.purge.front_page')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $full_urls = array_merge($full_urls, Util_PageUrls::get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_urls($post_id)); } /** * Post comments URLs */ if ($config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($config->get_boolean('pgcache.purge.author') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_author_urls($post->post_author, $limit_post_pages)); } /** * Post terms URLs */ if ($config->get_boolean('pgcache.purge.terms')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_terms_urls($terms, $limit_post_pages)); } /** * Daily archive URLs */ if ($config->get_boolean('pgcache.purge.archive.daily') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_daily_archive_urls($post, $limit_post_pages)); } /** * Monthly archive URLs */ if ($config->get_boolean('pgcache.purge.archive.monthly') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_monthly_archive_urls($post, $limit_post_pages)); } /** * Yearly archive URLs */ if ($config->get_boolean('pgcache.purge.archive.yearly') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($config->get_boolean('pgcache.purge.feed.blog')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_urls($feeds)); } if ($config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_comments_urls($post_id, $feeds)); } if ($config->get_boolean('pgcache.purge.feed.author') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_author_urls($post->post_author, $feeds)); } if ($config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_terms_urls($terms, $feeds)); } /** * Purge selected pages */ if ($config->get_array('pgcache.purge.pages')) { $pages = $config->get_array('pgcache.purge.pages'); $full_urls = array_merge($full_urls, Util_PageUrls::get_pages_urls($pages)); } /** * Queue flush */ if (count($full_urls)) { $o = Dispatcher::component('Cdn_Fsd_CacheFlush'); foreach ($full_urls as $url) { $o->queued_urls[$url] = '*'; } } return true; }
/** * Flushes post cache * * @param integer $post_id * @return boolean */ function flush_post($post_id = null) { if (!$post_id) { $post_id = Util_Environment::detect_post_id(); } if (!$post_id) { return false; } $full_urls = array(); $post = null; $terms = array(); $feeds = $this->_config->get_array('pgcache.purge.feed.types'); $limit_post_pages = $this->_config->get_integer('pgcache.purge.postpages_limit'); if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('pgcache.purge.feed.terms')) { $taxonomies = get_post_taxonomies($post_id); $terms = wp_get_post_terms($post_id, $taxonomies); $terms = $this->_append_parent_terms($terms, $terms); } $post = get_post($post_id); $post_type = in_array($post->post_type, array('post', 'page', 'attachment', 'revision')) ? null : $post->post_type; $front_page = get_option('show_on_front'); /** * Home (Frontpage) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $this->_config->get_boolean('pgcache.purge.front_page')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $full_urls = array_merge($full_urls, Util_PageUrls::get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_urls($post_id)); } /** * Post comments URLs */ if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_author_urls($post->post_author, $limit_post_pages)); } /** * Post terms URLs */ if ($this->_config->get_boolean('pgcache.purge.terms')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_post_terms_urls($terms, $limit_post_pages)); } /** * Daily archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_daily_archive_urls($post, $limit_post_pages)); } /** * Monthly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_monthly_archive_urls($post, $limit_post_pages)); } /** * Yearly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) { $full_urls = array_merge($full_urls, Util_PageUrls::get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_urls($feeds, $post_type)); } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_comments_urls($post_id, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.author')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_author_urls($post->post_author, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_terms_urls($terms, $feeds)); } /** * Purge selected pages */ if ($this->_config->get_array('pgcache.purge.pages')) { $pages = $this->_config->get_array('pgcache.purge.pages'); $full_urls = array_merge($full_urls, Util_PageUrls::get_pages_urls($pages)); } /** * Queue flush */ if (count($full_urls)) { foreach ($full_urls as $url) { $this->queued_urls[$url] = '*'; } } // add mirror urls $this->queued_urls = Util_PageUrls::complement_with_mirror_urls($this->queued_urls); return true; }