/** * Admin bar menu * * @return void */ function admin_bar_menu() { global $wp_admin_bar; if (current_user_can('manage_options')) { /** * @var $modules W3_ModuleStatus */ $modules = w3_instance('W3_ModuleStatus'); $can_empty_memcache = $modules->can_empty_memcache(); $can_empty_opcode = $modules->can_empty_opcode(); $can_empty_file = $modules->can_empty_file(); $can_empty_varnish = $modules->can_empty_varnish(); $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace'); //$cdn_enabled = $modules->is_enabled('cdn'); $cdn_engine = $modules->get_module_engine('cdn'); $cdn_mirror = w3_is_cdn_mirror($cdn_engine); $menu_items = array(array('id' => 'w3tc', 'title' => __('Performance', 'w3-total-cache'), 'href' => admin_url('admin.php?page=w3tc_dashboard'))); if ($modules->is_enabled('pgcache') && w3_detect_post_id() && (!defined('DOING_AJAX') || !DOING_AJAX)) { $menu_items[] = array('id' => 'w3tc-pgcache-purge-post', 'parent' => 'w3tc', 'title' => __('Purge From Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_pgcache_purge_post&post_id=' . w3_detect_post_id()), 'w3tc')); } if ($can_empty_file && ($can_empty_opcode || $can_empty_memcache)) { $menu_items[] = array('id' => 'w3tc-flush-file', 'parent' => 'w3tc-empty-caches', 'title' => __('Empty Disc Cache(s)', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_file'), 'w3tc')); } if ($can_empty_opcode && ($can_empty_file || $can_empty_memcache)) { $menu_items[] = array('id' => 'w3tc-flush-opcode', 'parent' => 'w3tc-empty-caches', 'title' => __('Empty Opcode Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_opcode'), 'w3tc')); } if ($can_empty_memcache && ($can_empty_file || $can_empty_opcode)) { $menu_items[] = array('id' => 'w3tc-flush-memcached', 'parent' => 'w3tc-empty-caches', 'title' => __('Empty Memcached Cache(s)', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_memcached'), 'w3tc')); } if ($modules->is_enabled('browsercache') && $browsercache_update_media_qs) { $menu_items[] = array('id' => 'w3tc-update-media-qs', 'parent' => 'w3tc', 'title' => __('Update Media Query String', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_browser_cache'), 'w3tc')); } if ($modules->plugin_is_enabled()) { $menu_items[] = array('id' => 'w3tc-empty-caches', 'parent' => 'w3tc', 'title' => __('Empty All Caches', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_all'), 'w3tc')); $menu_items[] = array('id' => 'w3tc-modules', 'parent' => 'w3tc', 'title' => __('Empty Modules', 'w3-total-cache')); } if ($modules->is_enabled('pgcache')) { $menu_items[] = array('id' => 'w3tc-flush-pgcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Page Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_pgcache'), 'w3tc')); } if ($modules->is_enabled('minify')) { $menu_items[] = array('id' => 'w3tc-flush-minify', 'parent' => 'w3tc-modules', 'title' => __('Empty Minify Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_minify'), 'w3tc')); } if ($modules->is_enabled('dbcache')) { $menu_items[] = array('id' => 'w3tc-flush-dbcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Database Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_dbcache'), 'w3tc')); } if ($modules->is_enabled('objectcache')) { $menu_items[] = array('id' => 'w3tc-flush-objectcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Object Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_objectcache'), 'w3tc')); } if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { if ($modules->is_enabled('fragmentcache')) { $menu_items[] = array('id' => 'w3tc-flush-fragmentcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Fragment Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_fragmentcache'), 'w3tc')); } } if ($modules->is_enabled('varnish')) { $menu_items[] = array('id' => 'w3tc-flush-varnish', 'parent' => 'w3tc-modules', 'title' => __('Purge Varnish Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_varnish'), 'w3tc')); } if ($modules->is_enabled('cdn')) { if (w3_can_cdn_purge($cdn_engine)) { $menu_items[] = array('id' => 'w3tc-cdn-purge', 'parent' => 'w3tc', 'title' => __('Purge CDN', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&w3tc_cdn_purge'), 'w3tc'), 'meta' => array('onclick' => "w3tc_popupadmin_bar(this.href); return false")); } if (w3_cdn_can_purge_all($cdn_engine)) { $menu_items[] = array('id' => 'w3tc-cdn-purge-full', 'parent' => 'w3tc', 'title' => __('Purge CDN Completely', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&w3tc_flush_cdn'), 'w3tc')); } if (!$cdn_mirror) { $menu_items[] = array('id' => 'w3tc-cdn-queue', 'parent' => 'w3tc', 'title' => __('Unsuccessful file transfers', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&w3tc_cdn_queue'), 'w3tc'), 'meta' => array('onclick' => "w3tc_popupadmin_bar(this.href); return false")); } } $menu_items = array_merge($menu_items, array(array('id' => 'w3tc-faq', 'parent' => 'w3tc', 'title' => __('FAQ', 'w3-total-cache'), 'href' => admin_url('admin.php?page=w3tc_faq')), array('id' => 'w3tc-support', 'parent' => 'w3tc', 'title' => __('<span style="color: red; background: none;">Support</span>', 'w3-total-cache'), 'href' => admin_url('admin.php?page=w3tc_support')))); foreach ($menu_items as $menu_item) { $wp_admin_bar->add_menu($menu_item); } } }
/** * Purges cdn mirror post cache * * @param integer $post_id * @return boolean */ function purge_post($post_id) { if (!$post_id) { $post_id = w3_detect_post_id(); } if ($post_id) { $full_urls = array(); $global_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); } /** * @var $purge_urls W3_SharedPageUrls */ $purge_urls = w3_instance('W3_SharedPageUrls'); 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')) { $global_urls = array_merge($global_urls, $purge_urls->get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $global_urls = array_merge($global_urls, $purge_urls->get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author') && $post) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->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, $purge_urls->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, $purge_urls->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, $purge_urls->get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { $global_urls = array_merge($global_urls, $purge_urls->get_feed_urls($feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_comments_urls($post_id, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_author_urls($post->post_author, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, $purge_urls->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'); $global_urls = array_merge($global_urls, $purge_urls->get_pages_urls($pages)); } if ($this->_do_flush_global_urls()) { $full_urls = array_merge($global_urls, $full_urls); } elseif ($this->_flushes == 0) { $this->_repeated_urls = $global_urls; } /** * Flush cache */ if (count($full_urls)) { $this->_flushes++; $w3_plugin_cdncommon = w3_instance('W3_Plugin_CdnCommon'); $results = array(); $files = array(); foreach ($full_urls as $url) { if (!in_array($url, $this->_repeated_urls) && !in_array($url, $this->_flushed_urls)) { $parsed = parse_url($url); $local_site_path = isset($parsed['path']) ? ltrim($parsed['path'], '/') : ''; $remote_path = $w3_plugin_cdncommon->uri_to_cdn_uri($local_site_path); $files[] = $w3_plugin_cdncommon->build_file_descriptor($local_site_path, $remote_path); $this->_flushed_urls[] = $url; } elseif (!in_array($url, $this->_repeated_urls)) { $this->_repeated_urls[] = $url; } } return $w3_plugin_cdncommon->purge($files, false, $results); } } return false; }
/** * Flushes post cache * * @param integer $post_id * @return boolean */ function flush_post($post_id = null) { if (!$post_id) { $post_id = w3_detect_post_id(); } if ($post_id) { $full_urls = array(); $global_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); } /** * @var $purge_urls W3_SharedPageUrls */ $purge_urls = w3_instance('W3_SharedPageUrls'); $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')) { $global_urls = array_merge($global_urls, $purge_urls->get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $global_urls = array_merge($global_urls, $purge_urls->get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author')) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->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, $purge_urls->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, $purge_urls->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, $purge_urls->get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { $global_urls = array_merge($global_urls, $purge_urls->get_feed_urls($feeds, $post_type)); } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_comments_urls($post_id, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.author')) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_author_urls($post->post_author, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, $purge_urls->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'); $global_urls = array_merge($global_urls, $purge_urls->get_pages_urls($pages)); } /** * Purge sitemaps if a sitemap option has a regex */ if ($this->_config->get_string('pgcache.purge.sitemap_regex')) { $cache = $this->_get_cache(); $cache->flush('sitemaps'); } if ($this->_do_flush_global_urls()) { $full_urls = array_merge($global_urls, $full_urls); } elseif ($this->_flushes == 0) { $this->_repeated_urls = $global_urls; } /** * Flush cache */ if (count($full_urls)) { $this->_flushes++; $cache = $this->_get_cache(); $mobile_groups = $this->_get_mobile_groups(); $referrer_groups = $this->_get_referrer_groups(); $encryptions = $this->_get_encryptions(); $compressions = $this->_get_compressions(); foreach ($full_urls as $url) { if (!in_array($url, $this->_repeated_urls) && !in_array($url, $this->_flushed_urls)) { $this->_flushed_urls[] = $url; $this->flush_url($url, $cache, $mobile_groups, $referrer_groups, $encryptions, $compressions); } elseif (!in_array($url, $this->_repeated_urls)) { $this->_repeated_urls[] = $url; } } } return true; } return false; }
/** * Flushes varnish post cache * * @param integer $post_id * @return boolean */ function flush_post($post_id) { if (!$post_id) { $post_id = w3_detect_post_id(); } if ($post_id) { $full_urls = array(); $global_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); } $purge_urls = w3_instance('W3_PageUrls'); 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')) { $global_urls = array_merge($global_urls, $purge_urls->get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $global_urls = array_merge($global_urls, $purge_urls->get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author') && $post) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->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, $purge_urls->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, $purge_urls->get_montly_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, $purge_urls->get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { $global_urls = array_merge($global_urls, $purge_urls->get_feed_urls($feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_comments_urls($post_id, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_author_urls($post->post_author, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, $purge_urls->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, $purge_urls->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[] = w3_get_domain_url() . '/' . trim($sitemap_regex, "^\$"); } if ($this->_do_flush_global_urls()) { $full_urls = array_merge($global_urls, $full_urls); } elseif ($this->_flushes == 0) { $this->_repeated_urls = $global_urls; } /** * Flush cache */ if (count($full_urls)) { $this->_flushes++; foreach ($full_urls as $url) { if (!in_array($url, $this->_repeated_urls) && !in_array($url, $this->_flushed_urls)) { $this->_flushed_urls[] = $url; $this->flush_url($url); } elseif (!in_array($url, $this->_repeated_urls)) { $this->_repeated_urls[] = $url; } } } return true; } return false; }