public function clear_cache() { if (function_exists('wp_cache_clean_cache')) { global $file_prefix; wp_cache_clean_cache($file_prefix); } }
/** * Clear cache */ public function clear_pagecache() { global $file_prefix; if (function_exists('wp_cache_clean_cache')) { wp_cache_clean_cache($file_prefix, true); } }
/** * Clear the caches! */ function ccfm_clear_cache_for_me($source) { global $wp_fastest_cache; do_action('ccfm_clear_cache_for_me_before', $source); // if W3 Total Cache is being used, clear the cache if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); } else { if (function_exists('wp_cache_clean_cache')) { global $file_prefix, $supercachedir; if (empty($supercachedir) && function_exists('get_supercache_dir')) { $supercachedir = get_supercache_dir(); } wp_cache_clean_cache($file_prefix); } else { if (class_exists('WpeCommon')) { //be extra careful, just in case 3rd party changes things on us if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); } if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::clear_maxcdn_cache(); } if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_varnish_cache(); } } else { if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) { $wp_fastest_cache->deleteCache(); } } } } do_action('ccfm_clear_cache_for_me', $source); }
function ajax_refresh_static_posts() { check_ajax_referer('refreshstaticposts'); if (isset($_POST['number'])) { $number = absint($_POST['number']); $action = sanitize_text_field($_POST['action']); $name = sanitize_text_field($_POST['name']); //Get the SRP widgets $settings = get_option($name); $widget = $settings[$number]; //Get the new post IDs $widget = $this->build_posts(intval($widget['postlimit']), $widget); $post_ids = $widget['posts']; //Save the settings $settings[$number] = $widget; //Only save if user is admin if (is_user_logged_in() && current_user_can('administrator')) { update_option($name, $settings); //Let's clean up the cache //Update WP Super Cache if available if (function_exists("wp_cache_clean_cache")) { @wp_cache_clean_cache('wp-cache-'); } } //Build and send the response die($this->print_posts($post_ids, false)); } exit; }
function reset_caches() { global $cache_path, $file_prefix; if (function_exists('prune_super_cache')) { prune_super_cache($cache_path, true); } if (function_exists('wp_cache_clean_cache')) { wp_cache_clean_cache($file_prefix); } }
public static function mt_clear_cache() { global $file_prefix; if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); } if (function_exists('wp_cache_clean_cache')) { wp_cache_clean_cache($file_prefix, true); } }
/** * Clear something from the cache. * * @synopsis [--post_id=<post-id>] [--permalink=<permalink>] */ function flush($args = array(), $assoc_args = array()) { if (isset($assoc_args['post_id'])) { if (is_numeric($assoc_args['post_id'])) { wp_cache_post_change($assoc_args['post_id']); } else { WP_CLI::error('This is not a valid post id.'); } wp_cache_post_change($assoc_args['post_id']); } elseif (isset($assoc_args['permalink'])) { $id = url_to_postid($assoc_args['permalink']); if (is_numeric($id)) { wp_cache_post_change($id); } else { WP_CLI::error('There is no post with this permalink.'); } } else { global $file_prefix; wp_cache_clean_cache($file_prefix, true); WP_CLI::success('Cache cleared.'); } }
function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression; if ('/' != substr($cache_path, -1)) { $cache_path .= '/'; } if ($valid_nonce) { if (isset($_REQUEST['wp_delete_cache'])) { wp_cache_clean_cache($file_prefix); } if (isset($_REQUEST['wp_delete_expired'])) { wp_cache_clean_expired($file_prefix); } } echo "<a name='listfiles'></a>"; echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __('Cache Contents', 'wp-super-cache') . '</h3>'; $list_files = false; // it doesn't list supercached files, and removing single pages is buggy $count = 0; $expired = 0; $now = time(); if ($handle = @opendir($blog_cache_dir . 'meta/')) { if ($list_files) { echo "<table cellspacing=\"0\" cellpadding=\"5\">"; } $wp_cache_fsize = 0; if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletewpcache') { $deleteuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri']))))); $deleteuri = str_replace('\\', '', $deleteuri); } else { $deleteuri = ''; } if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletesupercache') { $supercacheuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri']))))); $supercacheuri = trailingslashit(str_replace('\\', '', $supercacheuri)); printf(__("Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache'), $supercacheuri); @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html'); @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html.gz'); prune_super_cache($cache_path . 'supercache/' . $supercacheuri . 'page', true); @rmdir($cache_path . 'supercache/' . $supercacheuri); } while (false !== ($file = readdir($handle))) { if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) { $content_file = preg_replace("/meta\$/", "html", $file); $mtime = filemtime($blog_cache_dir . 'meta/' . $file); if (!($fsize = @filesize($blog_cache_dir . $content_file))) { continue; } // .meta does not exists $age = $now - $mtime; if ($valid_nonce && $_GET['listfiles']) { $meta = unserialize(file_get_contents($blog_cache_dir . 'meta/' . $file)); if ($deleteuri != '' && $meta['uri'] == $deleteuri) { printf(__("Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache'), $deleteuri); @unlink($blog_cache_dir . 'meta/' . $file); @unlink($blog_cache_dir . $content_file); continue; } $meta['age'] = $age; if ($age > $cache_max_time) { $expired_list[$age][] = $meta; } else { $cached_list[$age][] = $meta; } } if ($age > $cache_max_time) { $expired++; } else { $count++; } $wp_cache_fsize += $fsize; $fsize = intval($fsize / 1024); } } closedir($handle); if ($list_files) { echo "</table>"; } } if ($wp_cache_fsize != 0) { $wp_cache_fsize = $wp_cache_fsize / 1024; } else { $wp_cache_fsize = 0; } if ($wp_cache_fsize > 1024) { $wp_cache_fsize = number_format($wp_cache_fsize / 1024, 2) . "MB"; } elseif ($wp_cache_fsize != 0) { $wp_cache_fsize = number_format($wp_cache_fsize, 2) . "KB"; } else { $wp_cache_fsize = '0KB'; } if ($cache_enabled == true && $super_cache_enabled == true) { $now = time(); $sizes = array('expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0); if (is_dir($supercachedir)) { if ($dh = opendir($supercachedir)) { while (($entry = readdir($dh)) !== false) { if ($entry != '.' && $entry != '..') { $sizes = wpsc_dirsize(trailingslashit($supercachedir) . $entry, $sizes); } } closedir($dh); } } else { $filem = @filemtime($supercachedir); if (is_file($supercachedir) && $filem + $cache_max_time <= $now) { $sizes['expired']++; if ($valid_nonce && $_GET['listfiles']) { $sizes['expired_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem; } } else { if ($valid_nonce && $_GET['listfiles'] && $filem) { $sizes['cached_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem; } } } $sizes['ts'] = time(); } echo "<p><strong>" . __('WP-Cache', 'wp-super-cache') . " ({$wp_cache_fsize})</strong></p>"; echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), $count) . "</li>"; echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), $expired) . "</li></ul>"; if ($cache_enabled == true && $super_cache_enabled == true) { $fsize = $sizes['fsize'] / 1024; if ($fsize > 1024) { $fsize = number_format($fsize / 1024, 2) . "MB"; } elseif ($fsize != 0) { $fsize = number_format($fsize, 2) . "KB"; } else { $fsize = "0KB"; } $divisor = $cache_compression == 1 ? 2 : 1; echo "<p><strong>" . __('WP-Super-Cache', 'wp-super-cache') . " ({$fsize})</strong></p>"; echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), intval($sizes['cached'] / $divisor)) . "</li>"; $age = intval(($now - $sizes['ts']) / 60); echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), intval($sizes['expired'] / $divisor)) . "</li></ul>"; } if ($valid_nonce && $_GET['listfiles']) { echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 70%; overflow: auto'>"; if (is_array($cached_list) && !empty($cached_list)) { echo "<h4>" . __('Fresh WP-Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($cached_list); foreach ($cached_list as $age => $d) { foreach ($d as $details) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } if (is_array($expired_list) && !empty($expired_list)) { echo "<h4>" . __('Stale WP-Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($expired_list); foreach ($expired_list as $age => $d) { foreach ($d as $details) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } if (is_array($sizes['cached_list']) & !empty($sizes['cached_list'])) { echo "<h4>" . __('Fresh Super Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($sizes['cached_list']); foreach ($sizes['cached_list'] as $age => $d) { foreach ($d as $uri => $n) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } if (is_array($sizes['expired_list']) && !empty($sizes['expired_list'])) { echo "<h4>" . __('Stale Super Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($sizes['expired_list']); foreach ($sizes['expired_list'] as $age => $d) { foreach ($d as $uri => $n) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } echo "</div>"; echo "<p><a href='?page=wpsupercache#top'>" . __('Hide file list', 'wp-super-cache') . "</a></p>"; } else { echo "<p><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'listfiles' => '1')), 'wp-cache') . "#listfiles'>" . __('List all cached files', 'wp-super-cache') . "</a></p>"; } $last_gc = get_option("wpsupercache_gc_time"); if ($last_gc) { $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600; $next_gc_mins = time() - $last_gc; echo "<p>" . sprintf(__('<strong>Garbage Collection</strong><br />Last GC was <strong>%s</strong> minutes ago<br />', 'wp-super-cache'), date('i:s', $next_gc_mins)); printf(__("Next GC in <strong>%s</strong> minutes", 'wp-super-cache'), date('i:s', $next_gc - $next_gc_mins)) . "</p>"; } echo "<p>" . sprintf(__('Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache'), $cache_max_time) . "</p>"; echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">'; echo '<input type="hidden" name="wp_delete_expired" />'; echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="' . __('Delete Expired', 'wp-super-cache') . ' »" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">'; echo '<input type="hidden" name="wp_delete_cache" />'; echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __('Delete Cache', 'wp-super-cache') . ' »" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '</fieldset>'; }
function manage_options() { if (isset($_GET['download'])) { if ($_GET['download'] == 'site') { check_admin_referer('thesis-download-site'); #wp header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: text/plain"); header('Content-Disposition: attachment; filename="thesis-site-options-' . date("Ymd") . '.dat"'); $site_options = new thesis_site_options(); $site_options->get_options(); echo serialize($site_options); exit; } elseif ($_GET['download'] == 'design') { check_admin_referer('thesis-download-design'); #wp header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: text/plain"); header('Content-Disposition: attachment; filename="thesis-design-options-' . date("Ymd") . '.dat"'); $design_options = new thesis_design_options(); $design_options->get_options(); echo serialize($design_options); exit; } elseif ($_GET['download'] == 'all') { check_admin_referer('thesis-download-all'); #wp header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: text/plain"); header('Content-Disposition: attachment; filename="thesis-all-options-' . date("Ymd") . '.dat"'); $site_options = new thesis_site_options(); $site_options->get_options(); $design_options = new thesis_design_options(); $design_options->get_options(); echo serialize(array('site_options' => $site_options, 'design_options' => $design_options)); exit; } } elseif (isset($_GET['restore'])) { if ($_GET['restore'] == 'site') { check_admin_referer('thesis-restore-site'); #wp $default_site_options = new thesis_site_options(); $default_site_options->default_options(); update_option('thesis_options', $default_site_options); #wp wp_redirect(admin_url('admin.php?page=options-manager&restored=true&type=Site')); #wp } elseif ($_GET['restore'] == 'design') { check_admin_referer('thesis-restore-design'); #wp $default_design_options = new thesis_design_options(); $default_design_options->default_options(); update_option('thesis_design_options', $default_design_options); #wp thesis_generate_css(); wp_redirect(admin_url('admin.php?page=options-manager&restored=true&type=Design')); #wp } elseif ($_GET['restore'] == 'all') { check_admin_referer('thesis-restore-all'); #wp $default_site_options = new thesis_site_options(); $default_site_options->default_options(); $default_design_options = new thesis_design_options(); $default_design_options->default_options(); update_option('thesis_options', $default_site_options); #wp update_option('thesis_design_options', $default_design_options); #wp thesis_generate_css(); wp_redirect(admin_url('admin.php?page=options-manager&restored=true&type=All')); #wp } } elseif (isset($_POST['upload'])) { global $thesis_site; if ($_POST['upload'] == 'site') { check_admin_referer('thesis-upload-site', '_wpnonce-thesis-upload-site'); #wp if (strpos($_FILES['file']['name'], 'thesis-site-options') === false) { wp_redirect(admin_url('admin.php?page=options-manager&type=Site&error=wrongfile')); } elseif ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=options-manager&type=Site&error=file')); } else { $raw_options = file_get_contents($_FILES['file']['tmp_name']); $site_options = new thesis_site_options(); $site_options = unserialize($raw_options); if (function_exists('wp_cache_clean_cache')) { #wp global $file_prefix; wp_cache_clean_cache($file_prefix); } if (is_object($site_options) && version_compare($thesis_site->version, $site_options->version, '==')) { update_option('thesis_options', $site_options); #wp wp_redirect(admin_url('admin.php?page=options-manager&imported=true&type=Site')); #wp } else { wp_redirect(admin_url("admin.php?page=options-manager&type=Site&error=version&tried={$site_options->version}")); } #wp } } elseif ($_POST['upload'] == 'design') { check_admin_referer('thesis-upload-design', '_wpnonce-thesis-upload-design'); #wp if (strpos($_FILES['file']['name'], 'thesis-design-options') === false) { wp_redirect(admin_url('admin.php?page=options-manager&type=Design&error=wrongfile')); } elseif ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=options-manager&type=Design&error=file')); } else { $raw_options = file_get_contents($_FILES['file']['tmp_name']); $design_options = new thesis_design_options(); $design_options = unserialize($raw_options); if (function_exists('wp_cache_clean_cache')) { #wp global $file_prefix; wp_cache_clean_cache($file_prefix); } if (is_object($design_options) && version_compare($thesis_site->version, $design_options->version, '==')) { update_option('thesis_design_options', $design_options); #wp thesis_generate_css(); wp_redirect(admin_url('admin.php?page=options-manager&imported=true&type=Design')); #wp } else { wp_redirect(admin_url('admin.php?page=options-manager&type=Design&error=version-unknown')); } #wp } } elseif ($_POST['upload'] == 'all') { check_admin_referer('thesis-upload-all', '_wpnonce-thesis-upload-all'); #wp if (strpos($_FILES['file']['name'], 'thesis-all-options') === false) { wp_redirect(admin_url('admin.php?page=options-manager&type=All&error=wrongfile')); } elseif ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=options-manager&type=All&error=file')); } else { $raw_options = file_get_contents($_FILES['file']['tmp_name']); $all_options = unserialize($raw_options); $site_options = new thesis_site_options(); $design_options = new thesis_design_options(); $site_options = $all_options['site_options']; $design_options = $all_options['design_options']; if (function_exists('wp_cache_clean_cache')) { #wp global $file_prefix; wp_cache_clean_cache($file_prefix); #wp } if (is_object($site_options) && version_compare($thesis_site->version, $site_options->version, '==') && is_object($design_options) && version_compare($thesis_site->version, $design_options->version, '==')) { update_option('thesis_options', $site_options); #wp update_option('thesis_design_options', $design_options); #wp thesis_generate_css(); wp_redirect(admin_url('admin.php?page=options-manager&imported=true&type=All')); #wp } else { wp_redirect(admin_url("admin.php?page=options-manager&type=All&error=version&tried={$site_options->version}")); } #wp } } } }
/** * * @TODO do * */ function pagelines_import_export() { if (isset($_POST['form_submitted']) && $_POST['form_submitted'] == 'export_settings_form') { $pagelines_settings = (array) get_option(PAGELINES_SETTINGS); $pagelines_template_map = (array) get_option(PAGELINES_TEMPLATE_MAP); $pagelines_templates = (array) get_option(PAGELINES_TEMPLATES); $pagelines_special = (array) get_option(PAGELINES_SPECIAL); $options['pagelines_templates'] = $pagelines_templates; $options['pagelines_template_map'] = $pagelines_template_map; $options['pagelines_settings'] = $pagelines_settings; $options['pagelines_special'] = $pagelines_special; if (isset($options) && is_array($options)) { header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="' . PL_THEMENAME . '-Settings-' . date('Ymd') . '.dat"'); echo json_encode($options); exit; } } if (isset($_POST['form_submitted']) && $_POST['form_submitted'] == 'import_settings_form') { if (strpos($_FILES['file']['name'], 'Settings') === false && strpos($_FILES['file']['name'], 'settings') === false) { wp_redirect(admin_url(PL_IMPORT_EXPORT_URL . '&pageaction=import&error=wrongfile')); } elseif ($_FILES['file']['error'] > 0) { $error_type = $_FILES['file']['error']; wp_redirect(admin_url(PL_IMPORT_EXPORT_URL . '&pageaction=import&error=file&' . $error_type)); } else { $raw_options = pl_file_get_contents($_FILES['file']['tmp_name']); $all_options = json_decode(json_encode(json_decode($raw_options)), true); if (!isset($_POST['pagelines_layout']) && is_array($all_options) && isset($all_options['pagelines_settings']) && is_array($all_options['pagelines_settings'])) { unset($all_options['pagelines_settings']['layout']); } if (isset($_POST['pagelines_settings']) && is_array($all_options) && isset($all_options['pagelines_settings']) && is_array($all_options['pagelines_settings'])) { update_option(PAGELINES_SETTINGS, array_merge(get_option(PAGELINES_SETTINGS), $all_options['pagelines_settings'])); $done = 1; } if (isset($_POST['pagelines_special']) && is_array($all_options) && isset($all_options['pagelines_special']) && is_array($all_options['pagelines_special'])) { $special = (array) get_option(PAGELINES_SPECIAL); update_option(PAGELINES_SPECIAL, array_merge($special, $all_options['pagelines_special'])); $done = 1; } if (isset($_POST['pagelines_templates']) && is_array($all_options) && isset($all_options['pagelines_template_map']) && is_array($all_options['pagelines_template_map'])) { $template_map = (array) get_option(PAGELINES_TEMPLATE_MAP); $template_settings = (array) get_option(PAGELINES_TEMPLATES); $template_settings_new = isset($all_options['pagelines_templates']) && is_array($all_options['pagelines_templates']) ? $all_options['pagelines_templates'] : array(); $template_map_new = isset($all_options['pagelines_template_map']) && is_array($all_options['pagelines_template_map']) ? $all_options['pagelines_template_map'] : array(); update_option(PAGELINES_TEMPLATE_MAP, array_merge($template_map, $template_map_new)); update_option(PAGELINES_TEMPLATES, array_merge($template_settings, $template_settings_new)); $done = 1; } if (function_exists('wp_cache_clean_cache')) { global $file_prefix; wp_cache_clean_cache($file_prefix); } if (isset($done)) { wp_redirect(admin_url(PL_IMPORT_EXPORT_URL . '&pageaction=import&imported=true')); } else { wp_redirect(admin_url(PL_IMPORT_EXPORT_URL . '&pageaction=import&error=wrongfile')); } } } }
private function clear_cache_plugins() { /* Not implemented yet - still testing */ /*** * Automatically clears page caches after plugin install or upgrade * Called from upgrade_check() * Added 1.9.6.2 ***/ global $wpss_cache_check, $wp_fastest_cache; if (empty($wpss_cache_check)) { $wpss_cache_check = rs_wpss_check_cache_status(); } if ($wpss_cache_check['cache_check_status'] === 'ACTIVE') { if (rs_wpss_is_plugin_active('w3-total-cache/w3-total-cache.php') && function_exists('w3tc_pgcache_flush')) { /* W3 Total Cache */ w3tc_pgcache_flush(); } if (rs_wpss_is_plugin_active('wp-super-cache/wp-cache.php') && function_exists('wp_cache_clean_cache')) { /* WP Super Cache */ global $file_prefix; wp_cache_clean_cache($file_prefix); } if (rs_wpss_is_plugin_active('wp-fastest-cache/wpFastestCache.php') && !empty($wp_fastest_cache) && method_exists('WpFastestCache', 'deleteCache')) { /* WP Fastest Cache */ $wp_fastest_cache->deleteCache(); } if (class_exists('WPE_API', FALSE) && class_exists('WpeCommon')) { /* WP Engine Hosting */ if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); } if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { WpeCommon::clear_maxcdn_cache(); } if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); } } } }
/** * Clear cache from: * - W3TC, * - WordPress Total Cache * - WPEngine * - Varnish */ public function clear_cache() { // if W3 Total Cache is being used, clear the cache if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); } else { if (function_exists('wp_cache_clean_cache')) { global $file_prefix; wp_cache_clean_cache($file_prefix); } else { if (class_exists('WpeCommon')) { WpeCommon::purge_memcached(); WpeCommon::clear_maxcdn_cache(); WpeCommon::purge_varnish_cache(); } } } // Clear Varnish caches if (Avada()->settings->get('dynamic_css_compiler') && Avada()->settings->get('cache_server_ip')) { $this->clear_varnish_cache(self::file('url')); } }
function pagelines_import_export() { if (isset($_GET['download']) && $_GET['download'] == 'settings') { header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: text/plain"); header('Content-Disposition: attachment; filename="PageLines-' . THEMENAME . '-Settings-' . date("Ymd") . '.dat"'); $pagelines_settings = get_option(PAGELINES_SETTINGS); $pagelines_template = get_option('pagelines_template_map'); echo serialize(array('pagelines_settings' => $pagelines_settings, 'pagelines_template' => $pagelines_template)); exit; } if (isset($_POST['settings_upload']) && $_POST['settings_upload'] == 'settings') { if (strpos($_FILES['file']['name'], 'Settings') === false) { wp_redirect(admin_url('admin.php?page=pagelines&pageaction=import&error=wrongfile')); } elseif ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=pagelines&pageaction=import&error=file')); } else { $raw_options = file_get_contents($_FILES['file']['tmp_name']); $all_options = unserialize($raw_options); if (isset($all_options['pagelines_settings']) && isset($all_options['pagelines_template'])) { $pagelines_settings = $all_options['pagelines_settings']; $pagelines_template = $all_options['pagelines_template']; if (is_array($pagelines_settings)) { update_option(PAGELINES_SETTINGS, $pagelines_settings); } if (is_array($pagelines_template)) { update_option('pagelines_template_map', $pagelines_template); } } if (function_exists('wp_cache_clean_cache')) { global $file_prefix; wp_cache_clean_cache($file_prefix); } pagelines_build_dynamic_css(); wp_redirect(admin_url('admin.php?page=pagelines&pageaction=import&imported=true')); } } }
function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce; if ('/' != substr($cache_path, -1)) { $cache_path .= '/'; } if ($valid_nonce) { if (isset($_REQUEST['wp_delete_cache'])) { wp_cache_clean_cache($file_prefix); } if (isset($_REQUEST['wp_delete_cache_file'])) { wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); } if (isset($_REQUEST['wp_delete_expired'])) { wp_cache_clean_expired($file_prefix); } } if (isset($_REQUEST['wp_list_cache'])) { $list_files = true; $list_mess = "Update list"; } else { $list_mess = "List files"; } echo '<a name="list"></a><fieldset class="options"><legend>Cache contents</legend>'; echo '<form name="wp_cache_content_list" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<div class="submit"><input type="submit" value="' . $list_mess . '" /></div>'; echo "</form>\n"; $count = 0; $expired = 0; $now = time(); if ($handle = opendir($cache_path)) { if ($list_files) { echo "<table cellspacing=\"0\" cellpadding=\"5\">"; } while (false !== ($file = readdir($handle))) { if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) { $this_expired = false; $content_file = preg_replace("/meta\$/", "html", $file); $mtime = filemtime($cache_path . $file); if (!($fsize = @filesize($cache_path . $content_file))) { continue; } // .meta does not exists $fsize = intval($fsize / 1024); $age = $now - $mtime; if ($age > $cache_max_time) { $expired++; $this_expired = true; } $count++; if ($list_files) { $meta = new CacheMeta(); $meta = unserialize(file_get_contents($cache_path . $file)); echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>'; $flip = !$flip; echo '<td><a href="http://' . $meta->uri . '" target="_blank" >'; echo $meta->uri . "</a></td>"; if ($this_expired) { echo "<td><span style='color:red'>{$age} secs</span></td>"; } else { echo "<td>{$age} secs</td>"; } echo "<td>{$fsize} KB</td>"; echo '<td><form name="wp_delete_cache_file" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<input type="hidden" name="wp_delete_cache_file" value="' . preg_replace("/^(.*)\\.meta\$/", "\$1", $file) . '" />'; echo '<div class="submit"><input id="deletepost" type="submit" value="Remove" /></div>'; wp_nonce_field('wp-cache'); echo "</form></td></tr>\n"; } } } closedir($handle); if ($list_files) { echo "</table>"; } } echo "<P><b>{$count} cached pages</b></p>"; echo "<P><b>{$expired} expired pages</b></p>"; echo '<form name="wp_cache_content_expired" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_delete_expired" />'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<div class="submit"><input type="submit" value="Delete expired" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '<form name="wp_cache_content_delete" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_delete_cache" />'; echo '<div class="submit"><input id="deletepost" type="submit" value="Delete cache" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '</fieldset>'; }
foreach ($items as $widget) { $w = explode('X|X', $widget); $options[$col][$i]['id'] = $w[0]; $options[$col][$i]['number'] = $w[1]; $options[$col][$i]['id_base'] = $w[2]; $i++; } } } $theOptions[$canvas_id]['widgets'] = $options; update_option('eletro_widgets', $theOptions); break; case 'apply': $canvas_id = $_POST['canvas_id']; $adminOptions = get_option('eletro_widgets'); $publicOptions = get_option('eletro_widgets_public'); $publicOptions[$canvas_id] = $adminOptions[$canvas_id]; update_option('eletro_widgets_public', $publicOptions); // if using wp-super-cache, clean the cache if (function_exists('wp_cache_clean_cache')) { wp_cache_clean_cache('wp-cache'); } break; case 'restore': $canvas_id = $_POST['canvas_id']; $adminOptions = get_option('eletro_widgets'); $publicOptions = get_option('eletro_widgets_public'); $adminOptions[$canvas_id] = $publicOptions[$canvas_id]; update_option('eletro_widgets', $adminOptions); break; }
function manage_options() { global $bizzthemes_site, $wpdb, $themeid, $frameversion, $opt, $optd; if (isset($_POST['upload'])) { if ($_POST['upload'] == 'all') { check_admin_referer('bizzthemes-upload-all', '_wpnonce-bizzthemes-upload-all'); #wp // DEFAULT OPTIONS $def_theme_id = $themeid; $def_frame_version = $frameversion; // UPLOADED OPTIONS $new_options = file_get_contents($_FILES['file']['tmp_name']); // remove BOM $new_options = mb_convert_encoding($new_options, 'UTF-8', 'ASCII,UTF-8,ISO-8859-1'); if (substr($new_options, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $new_options = substr($new_options, 3); } // decode $new_options = json_decode($new_options, true); $new_theme_id = $new_options['theme_id']; $new_frame_version = $new_options['frame_version']; $new_options_id = $new_options['options_id']; if (function_exists('wp_cache_clean_cache')) { #wp global $file_prefix; wp_cache_clean_cache($file_prefix); #wp } // wrong file $files_array = array('bizzthemes-layouts', 'bizzthemes-settings', 'bizzthemes-design'); $wrongfile = true; foreach ($files_array as $needle) { if (strpos($_FILES['file']['name'], $needle) !== false) { $wrongfile = false; } } if ($wrongfile) { wp_redirect(admin_url('admin.php?page=bizz-tools&type=Layouts&error=wrongfile')); } #wp // file error if ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=bizz-tools&type=All&error=file')); } else { // all fine if ($new_options['options_id'] == 'layouts') { if (version_compare($def_frame_version, $new_frame_version, '!=')) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Layouts&error=version&tried={$new_frame_version}&yours={$def_frame_version}")); } elseif ($def_theme_id != $new_theme_id) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Layouts&error=theme&tried={$new_theme_id}&yours={$def_theme_id}")); } else { // read options $new_all_widgets = $new_options['options_value']['all_widgets']; $new_sidebars_widgets = $new_options['options_value']['sidebars_widgets']; // $new_sidebars_widgets = $new_options['options_value']['sidebars_widgets'][0]['option_value']; $new_widget_posts = isset($new_options['options_value']['widget_posts']) ? $new_options['options_value']['widget_posts'] : array(); $new_grid_posts = isset($new_options['options_value']['grid_posts']) ? $new_options['options_value']['grid_posts'] : array(); // reset old grids $query = "DELETE FROM {$wpdb->posts} WHERE post_type LIKE 'bizz_grid' OR post_type LIKE 'bizz_widget' AND post_content_filtered = '{$themeid}' "; $wpdb->query($query); // reset backed up widgets delete_option($themeid . '_sidebars_widgets'); // update defaults option update_option('bizz_defaults_' . $themeid, true); // update widgets // bizz_update_widgets($new_sidebars_widgets, $new_all_widgets); // update posts bizzthemes_update_options('set_new', $new_all_widgets); bizzthemes_update_options('set_new', $new_sidebars_widgets); bizzthemes_insert_posts('set_new', array_merge($new_widget_posts, $new_grid_posts)); // redirect wp_redirect(admin_url('admin.php?page=bizz-tools&imported=true&type=Layouts')); #wp } } elseif ($new_options['options_id'] == 'settings') { if (version_compare($def_frame_version, $new_frame_version, '!=')) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Settings&error=version&tried={$new_frame_version}&yours={$def_frame_version}")); } else { // read options $new_options = $new_options['options_value']; // insert data update_option('bizzthemes_options', $new_options); // redirect wp_redirect(admin_url('admin.php?page=bizz-tools&imported=true&type=Settings')); #wp } } elseif ($new_options['options_id'] == 'design') { if (version_compare($def_frame_version, $new_frame_version, '!=')) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Design&error=version&tried={$new_frame_version}&yours={$def_frame_version}")); } elseif ($def_theme_id != $new_theme_id) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Design&error=theme&tried={$new_theme_id}&yours={$def_theme_id}")); } else { // read options $new_options = $new_options['options_value']; // insert data update_option('bizzthemes_design', $new_options); // reset custom designs bizz_generate_css(); // redirect wp_redirect(admin_url('admin.php?page=bizz-tools&imported=true&type=Design')); #wp } } } } } elseif (isset($_GET['download'])) { if ($_GET['download'] == 'layouts') { $widgets_array = bizz_get_active_widgets(); $bizz_get_widget_posts = bizz_get_widget_posts(); $bizz_get_grid_posts = bizz_get_grid_posts(); $sidebars_widgets = get_option('sidebars_widgets'); check_admin_referer('bizzthemes-download-layouts'); #wp header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="bizzthemes-layouts-' . date("Y-m-d") . '.json"'); $json_string = json_encode(array('theme_id' => $themeid, 'frame_version' => $frameversion, 'options_id' => 'layouts', 'options_value' => array('all_widgets' => $widgets_array, 'widget_posts' => $bizz_get_widget_posts, 'grid_posts' => $bizz_get_grid_posts, 'sidebars_widgets' => array('0' => array('option_name' => 'sidebars_widgets', 'option_value' => $sidebars_widgets, 'type' => 'sidebars_widgets'))))); echo str_replace("'", "\\'", $json_string); exit; } elseif ($_GET['download'] == 'settings') { check_admin_referer('bizzthemes-download-settings'); #wp header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="bizzthemes-settings-' . date("Y-m-d") . '.json"'); echo json_encode(array('theme_id' => $themeid, 'frame_version' => $frameversion, 'options_id' => 'settings', 'options_value' => $opt)); exit; } elseif ($_GET['download'] == 'design') { check_admin_referer('bizzthemes-download-design'); #wp header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="bizzthemes-design-' . date("Y-m-d") . '.json"'); echo json_encode(array('theme_id' => $themeid, 'frame_version' => $frameversion, 'options_id' => 'design', 'options_value' => $optd)); exit; } } elseif (isset($_GET['restore'])) { if ($_GET['restore'] == 'layouts') { check_admin_referer('bizzthemes-restore-layouts'); #wp // fire the engine $default_action = 'set_defaults'; bizzthemes_default_layouts($default_action); wp_redirect(admin_url('admin.php?page=bizz-tools&restored=true&type=Layouts')); #wp } if ($_GET['restore'] == 'layouts-blank') { check_admin_referer('bizzthemes-restore-layouts'); #wp // fire the engine $default_action = 'reset'; bizzthemes_default_layouts($default_action); wp_redirect(admin_url('admin.php?page=bizz-tools&blank=true&type=Layouts')); #wp } elseif ($_GET['restore'] == 'settings') { check_admin_referer('bizzthemes-restore-settings'); #wp $query = "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'bizzthemes_options' OR option_name LIKE '%pag_exclude%' OR option_name LIKE '%pst_exclude%' "; $wpdb->query($query); wp_redirect(admin_url('admin.php?page=bizz-tools&restored=true&type=Settings')); #wp } elseif ($_GET['restore'] == 'design') { check_admin_referer('bizzthemes-restore-design'); #wp $query = "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'bizzthemes_design' "; $wpdb->query($query); bizz_generate_css(); wp_redirect(admin_url('admin.php?page=bizz-tools&restored=true&type=Design')); #wp } } }
function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir; if ('/' != substr($cache_path, -1)) { $cache_path .= '/'; } if ($valid_nonce) { if (isset($_REQUEST['wp_delete_cache'])) { wp_cache_clean_cache($file_prefix); } if (isset($_REQUEST['wp_delete_cache_file'])) { wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); } if (isset($_REQUEST['wp_delete_expired'])) { wp_cache_clean_expired($file_prefix); } } if (isset($_REQUEST['wp_list_cache'])) { $list_files = true; $list_mess = "Update list"; } else { $list_mess = "List files"; } echo '<fieldset class="options" id="show-this-fieldset"><h3>Cache Contents</h3>'; /* echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '" method="post">'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' »" /></div>'; echo "</form>\n"; */ $list_files = false; // it doesn't list supercached files, and removing single pages is buggy $count = 0; $expired = 0; $now = time(); if ($handle = @opendir($blog_cache_dir . 'meta/')) { if ($list_files) { echo "<table cellspacing=\"0\" cellpadding=\"5\">"; } while (false !== ($file = readdir($handle))) { if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) { $this_expired = false; $content_file = preg_replace("/meta\$/", "html", $file); $mtime = filemtime($blog_cache_dir . 'meta/' . $file); if (!($fsize = @filesize($blog_cache_dir . $content_file))) { continue; } // .meta does not exists $fsize = intval($fsize / 1024); $age = $now - $mtime; if ($age > $cache_max_time) { $expired++; $this_expired = true; } $count++; /* if ($list_files) { $meta = new CacheMeta; $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file)); echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>'; $flip = !$flip; echo '<td><a href="http://' . $meta->uri . '" target="_blank" >'; echo $meta->uri . "</a></td>"; if ($this_expired) echo "<td><span style='color:red'>$age secs</span></td>"; else echo "<td>$age secs</td>"; echo "<td>$fsize KB</td>"; echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '" method="post">'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />'; echo '<div class="submit"><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>'; wp_nonce_field('wp-cache'); echo "</form></td></tr>\n"; } */ } } closedir($handle); if ($list_files) { echo "</table>"; } } if ($cache_enabled == true && $super_cache_enabled == true) { $now = time(); $sizes = array('expired' => 0, 'cached' => 0, 'ts' => 0); if (is_dir($supercachedir)) { if ($dh = opendir($supercachedir)) { while (($entry = readdir($dh)) !== false) { if ($entry != '.' && $entry != '..') { $sizes = wpsc_dirsize(trailingslashit($supercachedir) . $entry, $sizes); } } closedir($dh); } } else { if (is_file($supercachedir) && filemtime($supercachedir) + $cache_max_time <= $now) { $sizes['expired']++; } } $sizes['ts'] = time(); } echo "<p><strong>WP-Cache</strong></p>"; echo "<ul><li>{$count} Cached Pages</li>"; echo "<li>{$expired} Expired Pages</li></ul>"; if ($cache_enabled == true && $super_cache_enabled == true) { echo "<p><strong>WP-Super-Cache</strong></p>"; echo "<ul><li>" . intval($sizes['cached'] / 2) . " Cached Pages</li>"; $age = intval(($now - $sizes['ts']) / 60); echo "<li>" . intval($sizes['expired'] / 2) . " Expired Pages</li></ul>"; } $last_gc = get_option("wpsupercache_gc_time"); if ($last_gc) { $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600; echo "<p><strong>Garbage Collection</strong><br />Last: " . date("Y-m-d H:i:s", $last_gc + get_option('gmt_offset') * 3600) . "<br />"; echo "Next: " . date("Y-m-d H:i:s", $next_gc + $last_gc + get_option('gmt_offset') * 3600) . "</p>"; } echo "<p>Expired files are files older than {$cache_max_time} seconds. They are still used by the plugin and are deleted periodically.</p>"; echo '<form name="wp_cache_content_expired" action="' . $_SERVER["REQUEST_URI"] . '" method="post">'; echo '<input type="hidden" name="wp_delete_expired" />'; echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="Delete Expired »" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '<form name="wp_cache_content_delete" action="' . $_SERVER["REQUEST_URI"] . '" method="post">'; echo '<input type="hidden" name="wp_delete_cache" />'; echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete Cache »" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '</fieldset>'; }
function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression; global $wp_cache_object_cache, $wp_cache_preload_on; if ('/' != substr($cache_path, -1)) { $cache_path .= '/'; } if ($valid_nonce) { if (isset($_REQUEST['wp_delete_cache'])) { wp_cache_clean_cache($file_prefix); $_GET['action'] = 'regenerate_cache_stats'; } if (isset($_REQUEST['wp_delete_all_cache'])) { wp_cache_clean_cache($file_prefix, true); $_GET['action'] = 'regenerate_cache_stats'; } if (isset($_REQUEST['wp_delete_expired'])) { wp_cache_clean_expired($file_prefix); $_GET['action'] = 'regenerate_cache_stats'; } } echo "<a name='listfiles'></a>"; echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __('Cache Contents', 'wp-super-cache') . '</h3>'; if ($wp_cache_object_cache) { echo "<p>" . __("Object cache in use. No cache listing available.", 'wp-super-cache') . "</p>"; wp_cache_delete_buttons(); echo "</fieldset>"; return false; } $cache_stats = get_option('supercache_stats'); if (!is_array($cache_stats) || isset($_GET['listfiles']) || $valid_nonce && array_key_exists('action', $_GET) && $_GET['action'] == 'regenerate_cache_stats') { $list_files = false; // it doesn't list supercached files, and removing single pages is buggy $count = 0; $expired = 0; $now = time(); if ($handle = @opendir($blog_cache_dir . 'meta/')) { $wp_cache_fsize = 0; if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletewpcache') { $deleteuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri']))))); $deleteuri = str_replace('\\', '', $deleteuri); } else { $deleteuri = ''; } if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletesupercache') { $supercacheuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri']))))); $supercacheuri = trailingslashit(str_replace('\\', '', $supercacheuri)); printf(__("Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache'), $supercacheuri); @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html'); @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html.gz'); prune_super_cache($cache_path . 'supercache/' . $supercacheuri . 'page', true); @rmdir($cache_path . 'supercache/' . $supercacheuri); } while (false !== ($file = readdir($handle))) { if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) { $content_file = preg_replace("/meta\$/", "html", $file); $mtime = filemtime($blog_cache_dir . 'meta/' . $file); if (!($fsize = @filesize($blog_cache_dir . $content_file))) { continue; } // .meta does not exists $age = $now - $mtime; if ($valid_nonce && $_GET['listfiles']) { $meta = unserialize(file_get_contents($blog_cache_dir . 'meta/' . $file)); if ($deleteuri != '' && $meta['uri'] == $deleteuri) { printf(__("Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache'), $deleteuri); @unlink($blog_cache_dir . 'meta/' . $file); @unlink($blog_cache_dir . $content_file); continue; } $meta['age'] = $age; if ($cache_max_time > 0 && $age > $cache_max_time) { $expired_list[$age][] = $meta; } else { $cached_list[$age][] = $meta; } } if ($cache_max_time > 0 && $age > $cache_max_time) { $expired++; } else { $count++; } $wp_cache_fsize += $fsize; $fsize = intval($fsize / 1024); } } closedir($handle); } if ($wp_cache_fsize != 0) { $wp_cache_fsize = $wp_cache_fsize / 1024; } else { $wp_cache_fsize = 0; } if ($wp_cache_fsize > 1024) { $wp_cache_fsize = number_format($wp_cache_fsize / 1024, 2) . "MB"; } elseif ($wp_cache_fsize != 0) { $wp_cache_fsize = number_format($wp_cache_fsize, 2) . "KB"; } else { $wp_cache_fsize = '0KB'; } // Supercache files $now = time(); $sizes = array('expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0); if (is_dir($supercachedir)) { if ($dh = opendir($supercachedir)) { while (($entry = readdir($dh)) !== false) { if ($entry != '.' && $entry != '..') { $sizes = wpsc_dirsize(trailingslashit($supercachedir) . $entry, $sizes); } } closedir($dh); } } else { $filem = @filemtime($supercachedir); if (false == $wp_cache_preload_on && is_file($supercachedir) && $cache_max_time > 0 && $filem + $cache_max_time <= $now) { $sizes['expired']++; if ($valid_nonce && $_GET['listfiles']) { $sizes['expired_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem; } } else { if ($valid_nonce && $_GET['listfiles'] && $filem) { $sizes['cached_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem; } } } $sizes['ts'] = time(); $cache_stats = array('generated' => time(), 'supercache' => $sizes, 'wpcache' => array('cached' => $count, 'expired' => $expired, 'fsize' => $wp_cache_fsize)); update_option('supercache_stats', $cache_stats); } else { echo "<p>" . __('Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache') . "</p>"; echo "<a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats')), 'wp-cache') . "'>" . __('Regenerate cache stats', 'wp-super-cache') . "</a>"; if (is_array($cache_stats)) { echo "<p>" . sprintf(__('Cache stats last generated: %s minutes ago.', 'wp-super-cache'), number_format((time() - $cache_stats['generated']) / 60)) . "</p>"; } $cache_stats = get_option('supercache_stats'); } // regerate stats cache if (is_array($cache_stats)) { echo "<p><strong>" . __('WP-Cache', 'wp-super-cache') . " ({$cache_stats['wpcache']['fsize']})</strong></p>"; echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), $cache_stats['wpcache']['cached']) . "</li>"; echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), $cache_stats['wpcache']['expired']) . "</li></ul>"; $divisor = $cache_compression == 1 ? 2 : 1; if (array_key_exists('fsize', (array) $cache_stats['supercache'])) { $fsize = $cache_stats['supercache']['fsize'] / 1024; } else { $fsize = 0; } if ($fsize > 1024) { $fsize = number_format($fsize / 1024, 2) . "MB"; } elseif ($fsize != 0) { $fsize = number_format($fsize, 2) . "KB"; } else { $fsize = "0KB"; } echo "<p><strong>" . __('WP-Super-Cache', 'wp-super-cache') . " ({$fsize})</strong></p>"; echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), intval($cache_stats['supercache']['cached'] / $divisor)) . "</li>"; if (isset($now) && isset($sizes)) { $age = intval(($now - $sizes['ts']) / 60); } else { $age = 0; } echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), intval($cache_stats['supercache']['expired'] / $divisor)) . "</li></ul>"; if ($valid_nonce && array_key_exists('listfiles', $_GET) && $_GET['listfiles']) { echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>"; if (is_array($cached_list) && !empty($cached_list)) { echo "<h4>" . __('Fresh WP-Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($cached_list); foreach ($cached_list as $age => $d) { foreach ($d as $details) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } if (is_array($expired_list) && !empty($expired_list)) { echo "<h4>" . __('Stale WP-Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($expired_list); foreach ($expired_list as $age => $d) { foreach ($d as $details) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } if (is_array($sizes['cached_list']) & !empty($sizes['cached_list'])) { echo "<h4>" . __('Fresh Super Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($sizes['cached_list']); foreach ($sizes['cached_list'] as $age => $d) { foreach ($d as $uri => $n) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } if (is_array($sizes['expired_list']) && !empty($sizes['expired_list'])) { echo "<h4>" . __('Stale Super Cached Files', 'wp-super-cache') . "</h4>"; echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>"; $c = 1; $flip = 1; ksort($sizes['expired_list']); foreach ($sizes['expired_list'] as $age => $d) { foreach ($d as $uri => $n) { $bg = $flip ? 'style="background: #EAEAEA;"' : ''; echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n"; $flip = !$flip; $c++; } } echo "</table>"; } echo "</div>"; echo "<p><a href='?page=wpsupercache&tab=contents#top'>" . __('Hide file list', 'wp-super-cache') . "</a></p>"; } elseif ($cache_stats['supercache']['cached'] > 300 || $cache_stats['supercache']['expired'] > 300 || $cache_stats['wpcache']['cached'] / $divisor > 300 || $cache_stats['wpcache']['expired'] / $divisor > 300) { echo "<p><em>" . __('Too many cached files, no listing possible.', 'wp-super-cache') . "</em></p>"; } else { echo "<p><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'listfiles' => '1')), 'wp-cache') . "#listfiles'>" . __('List all cached files', 'wp-super-cache') . "</a></p>"; } $last_gc = get_option("wpsupercache_gc_time"); if ($cache_max_time > 0 && $last_gc) { $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600; $next_gc_mins = time() - $last_gc; echo "<p>" . sprintf(__('<strong>Garbage Collection</strong><br />Last GC was <strong>%s</strong> minutes ago<br />', 'wp-super-cache'), date('i:s', $next_gc_mins)); printf(__("Next GC in <strong>%s</strong> minutes", 'wp-super-cache'), date('i:s', $next_gc - $next_gc_mins)) . "</p>"; } if ($cache_max_time > 0) { echo "<p>" . sprintf(__('Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache'), $cache_max_time) . "</p>"; } } // cache_stats wp_cache_delete_buttons(); echo '</fieldset>'; }
function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled; if ('/' != substr($cache_path, -1)) { $cache_path .= '/'; } if ($valid_nonce) { if (isset($_REQUEST['wp_delete_cache'])) { wp_cache_clean_cache($file_prefix); } if (isset($_REQUEST['wp_delete_cache_file'])) { wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); } if (isset($_REQUEST['wp_delete_expired'])) { wp_cache_clean_expired($file_prefix); } } if (isset($_REQUEST['wp_list_cache'])) { $list_files = true; $list_mess = "Update list"; } else { $list_mess = "List files"; } echo '<br /><a name="list"></a><fieldset class="options"><h3>Cache Contents</h3>'; /* echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' »" /></div>'; echo "</form>\n"; */ $list_files = false; // it doesn't list supercached files, and removing single pages is buggy $count = 0; $expired = 0; $now = time(); if ($handle = @opendir($cache_path . 'meta/')) { if ($list_files) { echo "<table cellspacing=\"0\" cellpadding=\"5\">"; } while (false !== ($file = readdir($handle))) { if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) { $this_expired = false; $content_file = preg_replace("/meta\$/", "html", $file); $mtime = filemtime($cache_path . 'meta/' . $file); if (!($fsize = @filesize($cache_path . $content_file))) { continue; } // .meta does not exists $fsize = intval($fsize / 1024); $age = $now - $mtime; if ($age > $cache_max_time) { $expired++; $this_expired = true; } $count++; if ($list_files) { $meta = new CacheMeta(); $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file)); echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>'; $flip = !$flip; echo '<td><a href="http://' . $meta->uri . '" target="_blank" >'; echo $meta->uri . "</a></td>"; if ($this_expired) { echo "<td><span style='color:red'>{$age} secs</span></td>"; } else { echo "<td>{$age} secs</td>"; } echo "<td>{$fsize} KB</td>"; echo '<td><form name="wp_delete_cache_file" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_list_cache" />'; echo '<input type="hidden" name="wp_delete_cache_file" value="' . preg_replace("/^(.*)\\.meta\$/", "\$1", $file) . '" />'; echo '<div><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>'; wp_nonce_field('wp-cache'); echo "</form></td></tr>\n"; } } } closedir($handle); if ($list_files) { echo "</table>"; } } if ($cache_enabled == true && $super_cache_enabled == true) { $now = time(); $sizes = array('expired' => 0, 'cached' => 0, 'ts' => 0); if (is_dir($supercachedir)) { $entries = glob($supercachedir . '/*'); foreach ((array) $entries as $entry) { if ($entry != '.' && $entry != '..') { $sizes = wpsc_dirsize($entry, $sizes); } } } else { if (is_file($supercachedir) && filemtime($supercachedir) + $cache_max_time <= $now) { $sizes['expired']++; } } $sizes['ts'] = time(); } echo "<p><h4>WP-Cache</h4></p>"; echo "<ul><li>{$count} cached pages</li>"; echo "<li>{$expired} expired pages</li></ul>"; if ($cache_enabled == true && $super_cache_enabled == true) { echo "<p><h4>WP-Super-Cache</h4></p>"; echo "<ul><li>" . intval($sizes['cached'] / 2) . " cached pages</li>"; $age = intval(($now - $sizes['ts']) / 60); echo "<li>" . intval($sizes['expired'] / 2) . " expired pages.</li></ul>"; } echo '<form name="wp_cache_content_expired" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_delete_expired" />'; echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Delete expired »" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '<form name="wp_cache_content_delete" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">'; echo '<input type="hidden" name="wp_delete_cache" />'; echo '<div><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete cache »" /></div>'; wp_nonce_field('wp-cache'); echo "</form>\n"; echo '</fieldset>'; }
private function clear_cache_plugins() { /* Not fully implemented yet - still testing */ /** * Automatically clears page caches after plugin install or upgraded * Called from upgrade_check() * Added 1.9.6.2, Modified 1.9.7.5 */ global $wpss_cache_check, $wp_fastest_cache, $file_prefix, $supercachedir; /* Flush Memcache(d) */ $flush_memcache = wp_cache_flush(); return; /* Temp - 1.9.7.5 */ /* Check if cache plugins or server-side caching active */ if (empty($wpss_cache_check)) { $wpss_cache_check = rs_wpss_check_cache_status(); } if ($wpss_cache_check['cache_check_status'] === 'ACTIVE') { if (WPSS_Compatibility::is_plugin_active('w3-total-cache/w3-total-cache.php') && function_exists('w3tc_pgcache_flush')) { /* W3 Total Cache */ w3tc_pgcache_flush(); } if (WPSS_Compatibility::is_plugin_active('wp-super-cache/wp-cache.php') && function_exists('wp_cache_clean_cache')) { /* WP Super Cache */ if (empty($supercachedir) && function_exists('get_supercache_dir')) { $supercachedir = get_supercache_dir(); } wp_cache_clean_cache($file_prefix); } if (WPSS_Compatibility::is_plugin_active('wp-fastest-cache/wpFastestCache.php') && method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) { /* WP Fastest Cache */ $wp_fastest_cache->deleteCache(); } if (class_exists('WPE_API', FALSE) && class_exists('WpeCommon')) { /* WP Engine Hosting */ if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); } if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { WpeCommon::clear_maxcdn_cache(); } if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); } } /* Add Autoptimize & other Cache Plugins... */ } }
/** * Clear cache from: * - W3TC, * - WordPress Total Cache * - WPEngine * - Varnish */ public function clear_cache() { /** * if W3 Total Cache is being used, clear the cache */ if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); } else { if (function_exists('wp_cache_clean_cache')) { global $file_prefix; wp_cache_clean_cache($file_prefix); } else { if (class_exists('WpeCommon')) { WpeCommon::purge_memcached(); WpeCommon::clear_maxcdn_cache(); WpeCommon::purge_varnish_cache(); } } } /** * Clear Varnish caches */ if ('file' == $this->mode() && Avada()->settings->get('cache_server_ip')) { $this->clear_varnish_cache($this->file('url')); } }
function nukeCachedPage() { if (function_exists('wp_cache_clean_cache') && function_exists('wp_cache_get_cookies_values')) { global $blogcacheid, $wp_cache_gzip_encoding; // copied from wp-cache-phase1.php $hashprefix = $blogcacheid . md5(aleph_get_user_profile_url($this->user_ID) . $wp_cache_gzip_encoding . wp_cache_get_cookies_values()); // hashprefix should now resemble that used for a given warrior url // e.g., http://racecharities.org/warrior/ereusser/ wp_cache_clean_cache($hashprefix); } }