本文整理汇总了PHP中get_supercache_dir函数的典型用法代码示例。如果您正苦于以下问题:PHP get_supercache_dir函数的具体用法?PHP get_supercache_dir怎么用?PHP get_supercache_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_supercache_dir函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ccfm_clear_cache_for_me
/**
* 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);
}
示例2: clearCache
public function clearCache()
{
if (SAM_WPSC) {
global $blog_cache_dir, $wp_cache_object_cache;
if ($wp_cache_object_cache) {
reset_oc_version();
} else {
prune_super_cache($blog_cache_dir, true);
prune_super_cache(get_supercache_dir(), true);
}
return __('Cache of WP Super Cache plugin is flushed.', SAM_DOMAIN);
} elseif (SAM_W3TC) {
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
}
if (function_exists('w3tc_dbcache_flush')) {
w3tc_dbcache_flush();
}
return __('Cache of W3 Total Cache plugin is flushed.', SAM_DOMAIN);
} else {
return '';
}
}
示例3: autoptimize_flush_pagecache
function autoptimize_flush_pagecache($nothing)
{
if (function_exists('wp_cache_clear_cache')) {
if (is_multisite()) {
$blog_id = get_current_blog_id();
wp_cache_clear_cache($blog_id);
} else {
wp_cache_clear_cache();
}
} else {
if (has_action('cachify_flush_cache')) {
do_action('cachify_flush_cache');
} else {
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
// w3 total cache
} else {
if (function_exists('hyper_cache_invalidate')) {
hyper_cache_invalidate();
// hypercache
} else {
if (function_exists('wp_fast_cache_bulk_delete_all')) {
wp_fast_cache_bulk_delete_all();
// wp fast cache
} else {
if (class_exists("WpFastestCache")) {
$wpfc = new WpFastestCache();
// wp fastest cache
$wpfc->deleteCache();
} else {
if (class_exists("c_ws_plugin__qcache_purging_routines")) {
c_ws_plugin__qcache_purging_routines::purge_cache_dir();
// quick cache
} else {
if (file_exists(WP_CONTENT_DIR . '/wp-cache-config.php') && function_exists('prune_super_cache')) {
// fallback for WP-Super-Cache
global $cache_path;
if (is_multisite()) {
$blog_id = get_current_blog_id();
prune_super_cache(get_supercache_dir($blog_id), true);
prune_super_cache($cache_path . 'blogs/', true);
} else {
prune_super_cache($cache_path . 'supercache/', true);
prune_super_cache($cache_path, true);
}
}
}
}
}
}
}
}
}
}
示例4: clear_cache_plugins
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... */
}
}
示例5: wp_cron_preload_cache
function wp_cron_preload_cache()
{
global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path;
if (get_option('preload_cache_stop')) {
delete_option('preload_cache_stop');
return true;
}
$mutex = $cache_path . "preload_mutex.tmp";
sleep(3 + mt_rand(1, 5));
if (@file_exists($mutex)) {
if (@filemtime($mutex) > time() - 600) {
return true;
} else {
@unlink($mutex);
}
}
$fp = @fopen($mutex, 'w');
@fclose($fp);
$counter = get_option('preload_cache_counter');
if (is_array($counter) == false) {
$counter = array('c' => 0, 't' => time());
update_option('preload_cache_counter', $counter);
}
$c = $counter['c'];
if ($wp_cache_preload_email_me && $c == 0) {
wp_mail(get_option('admin_email'), sprintf(__('[%1$s] Cache Preload Started', 'wp-super-cache'), site_url(), ''), ' ');
}
$taxonomies = apply_filters('wp_cache_preload_taxonomies', array('post_tag' => 'tag', 'category' => 'category'));
$finished = false;
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
foreach ($taxonomies as $taxonomy => $path) {
$taxonomy_filename = $cache_path . "taxonomy_" . $taxonomy . ".txt";
if ($c == 0) {
@unlink($taxonomy_filename);
}
if (false == @file_exists($taxonomy_filename)) {
$out = '';
$records = get_terms($taxonomy);
foreach ($records as $term) {
$out .= site_url($path . "/" . $term->slug . "/") . "\n";
}
$fp = fopen($taxonomy_filename, 'w');
if ($fp) {
fwrite($fp, $out);
fclose($fp);
}
$details = explode("\n", $out);
} else {
$details = explode("\n", file_get_contents($taxonomy_filename));
}
if (count($details) != 1 && $details[0] != '') {
$rows = array_splice($details, 0, 50);
if ($wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many') {
wp_mail(get_option('admin_email'), sprintf(__('[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache'), site_url(), $taxonomy, $c, $c + 100), 'Refreshing: ' . print_r($rows, 1));
}
foreach ((array) $rows as $url) {
set_time_limit(60);
if ($url == '') {
continue;
}
$url_info = parse_url($url);
$dir = get_supercache_dir() . $url_info['path'];
prune_super_cache($dir);
$fp = @fopen($permalink_counter_msg, 'w');
if ($fp) {
@fwrite($fp, "{$taxonomy}: {$url}");
@fclose($fp);
}
wp_remote_get($url, array('timeout' => 60, 'blocking' => true));
sleep(1);
}
$fp = fopen($taxonomy_filename, 'w');
if ($fp) {
fwrite($fp, implode("\n", $details));
fclose($fp);
}
}
}
if ($wp_cache_preload_posts == 'all' || $c <= $wp_cache_preload_posts) {
$posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE ( post_type != 'revision' AND post_type != 'nav_menu_item' ) AND post_status = 'publish' ORDER BY post_date DESC LIMIT {$c}, 100");
} else {
$posts = false;
}
if (!isset($wp_cache_preload_email_volume)) {
$wp_cache_preload_email_volume = 'medium';
}
update_option('preload_cache_counter', array('c' => $c + 100, 't' => time()));
if ($posts) {
if ($wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many') {
wp_mail(get_option('admin_email'), sprintf(__('[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache'), site_url(), $c, $c + 100), ' ');
}
$msg = '';
$count = $c + 1;
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
foreach ($posts as $post_id) {
set_time_limit(60);
clear_post_supercache($post_id);
$url = get_permalink($post_id);
$fp = @fopen($permalink_counter_msg, 'w');
if ($fp) {
//.........这里部分代码省略.........
示例6: wp_cron_preload_cache
function wp_cron_preload_cache()
{
global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path, $wp_cache_preload_taxonomies;
if (get_option('preload_cache_stop')) {
delete_option('preload_cache_stop');
wp_cache_debug("wp_cron_preload_cache: preload cancelled", 1);
return true;
}
$mutex = $cache_path . "preload_mutex.tmp";
sleep(3 + mt_rand(1, 5));
if (@file_exists($mutex)) {
if (@filemtime($mutex) > time() - 600) {
wp_cache_debug("wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.", 1);
return true;
} else {
wp_cache_debug("wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.", 1);
@unlink($mutex);
}
}
$fp = @fopen($mutex, 'w');
@fclose($fp);
$counter = get_option('preload_cache_counter');
if (is_array($counter) == false) {
wp_cache_debug("wp_cron_preload_cache: setting up preload for the first time!", 5);
$counter = array('c' => 0, 't' => time());
update_option('preload_cache_counter', $counter);
}
$c = $counter['c'];
update_option('preload_cache_counter', array('c' => $c + 100, 't' => time()));
if ($wp_cache_preload_email_me && $c == 0) {
wp_mail(get_option('admin_email'), sprintf(__('[%1$s] Cache Preload Started', 'wp-super-cache'), home_url(), ''), ' ');
}
if ($wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts) {
wp_cache_debug("wp_cron_preload_cache: doing taxonomy preload.", 5);
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
if (isset($wp_cache_preload_taxonomies) && $wp_cache_preload_taxonomies) {
$taxonomies = apply_filters('wp_cache_preload_taxonomies', array('post_tag' => 'tag', 'category' => 'category'));
foreach ($taxonomies as $taxonomy => $path) {
$taxonomy_filename = $cache_path . "taxonomy_" . $taxonomy . ".txt";
if ($c == 0) {
@unlink($taxonomy_filename);
}
if (false == @file_exists($taxonomy_filename)) {
$out = '';
$records = get_terms($taxonomy);
foreach ($records as $term) {
$out .= get_term_link($term) . "\n";
}
$fp = fopen($taxonomy_filename, 'w');
if ($fp) {
fwrite($fp, $out);
fclose($fp);
}
$details = explode("\n", $out);
} else {
$details = explode("\n", file_get_contents($taxonomy_filename));
}
if (count($details) != 1 && $details[0] != '') {
$rows = array_splice($details, 0, 50);
if ($wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many') {
wp_mail(get_option('admin_email'), sprintf(__('[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache'), home_url(), $taxonomy, $c, $c + 100), 'Refreshing: ' . print_r($rows, 1));
}
foreach ((array) $rows as $url) {
set_time_limit(60);
if ($url == '') {
continue;
}
$url_info = parse_url($url);
$dir = get_supercache_dir() . $url_info['path'];
wp_cache_debug("wp_cron_preload_cache: delete {$dir}", 5);
prune_super_cache($dir);
$fp = @fopen($permalink_counter_msg, 'w');
if ($fp) {
@fwrite($fp, "{$taxonomy}: {$url}");
@fclose($fp);
}
wp_remote_get($url, array('timeout' => 60, 'blocking' => true));
wp_cache_debug("wp_cron_preload_cache: fetched {$url}", 5);
sleep(1);
}
$fp = fopen($taxonomy_filename, 'w');
if ($fp) {
fwrite($fp, implode("\n", $details));
fclose($fp);
}
}
}
}
}
if ($wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts) {
$types = get_post_types(array('public' => true, 'publicly_queryable' => true), 'names', 'or');
$types = array_map('esc_sql', $types);
$types = "'" . implode("','", $types) . "'";
$posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE ( post_type IN ( {$types} ) ) AND post_status = 'publish' ORDER BY ID ASC LIMIT {$c}, 100");
wp_cache_debug("wp_cron_preload_cache: got 100 posts from position {$c}.", 5);
} else {
wp_cache_debug("wp_cron_preload_cache: no more posts to get. Limit ({$wp_cache_preload_posts}) reached.", 5);
$posts = false;
}
if (!isset($wp_cache_preload_email_volume)) {
//.........这里部分代码省略.........
示例7: autoptimize_flush_pagecache
function autoptimize_flush_pagecache()
{
if (function_exists('wp_cache_clear_cache')) {
if (is_multisite()) {
$blog_id = get_current_blog_id();
wp_cache_clear_cache($blog_id);
} else {
wp_cache_clear_cache();
}
} else {
if (has_action('cachify_flush_cache')) {
do_action('cachify_flush_cache');
} else {
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
} else {
if (function_exists('wp_fast_cache_bulk_delete_all')) {
wp_fast_cache_bulk_delete_all();
// still to retest
} else {
if (class_exists("WpFastestCache")) {
$wpfc = new WpFastestCache();
$wpfc->deleteCache();
} else {
if (class_exists("c_ws_plugin__qcache_purging_routines")) {
c_ws_plugin__qcache_purging_routines::purge_cache_dir();
// quick cache, still to retest
} else {
if (class_exists("zencache")) {
zencache::clear();
} else {
if (class_exists("comet_cache")) {
comet_cache::clear();
} else {
if (class_exists("WpeCommon")) {
if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
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();
}
} else {
if (file_exists(WP_CONTENT_DIR . '/wp-cache-config.php') && function_exists('prune_super_cache')) {
// fallback for WP-Super-Cache
global $cache_path;
if (is_multisite()) {
$blog_id = get_current_blog_id();
prune_super_cache(get_supercache_dir($blog_id), true);
prune_super_cache($cache_path . 'blogs/', true);
} else {
prune_super_cache($cache_path . 'supercache/', true);
prune_super_cache($cache_path, true);
}
}
}
}
}
}
}
}
}
}
}
}
示例8: wp_cache_post_change
function wp_cache_post_change($post_id)
{
global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $blogcacheid, $wp_cache_refresh_single_only;
static $last_processed = -1;
if ($post_id == $last_processed) {
return $post_id;
}
$last_processed = $post_id;
$post = get_post($post_id);
if ($post->post_status == 'draft') {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("wp_cache_post_change: draft post, not deleting any cache files.", 4);
}
return $post_id;
}
if (!wp_cache_writers_entry()) {
return $post_id;
}
if (isset($wp_cache_refresh_single_only) && $wp_cache_refresh_single_only && strpos($_SERVER['REQUEST_URI'], 'wp-comments-post.php')) {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("wp_cache_post_change: comment detected. only deleting post page.", 4);
}
$all = false;
} else {
$all = true;
}
if ($wp_cache_object_cache) {
reset_oc_version();
}
$permalink = trailingslashit(str_replace(get_option('siteurl'), '', post_permalink($post_id)));
if ($super_cache_enabled) {
$dir = get_supercache_dir();
$siteurl = trailingslashit(strtolower(preg_replace('/:.*$/', '', str_replace('http://', '', get_option('home')))));
// make sure the front page has a rebuild file
wp_cache_post_id_gc($siteurl, $post_id);
// make sure the front page has a rebuild file
if ($all == true) {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("Post change: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4);
}
$files_to_check = get_all_supercache_filenames($dir);
foreach ($files_to_check as $cache_file) {
prune_super_cache($dir . $cache_file, true, true);
}
do_action('gc_cache', 'prune', 'homepage');
}
wp_cache_post_id_gc($siteurl, $post_id);
if ($all == true && get_option('show_on_front') == 'page') {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("Post change: deleting page_on_front and page_for_posts pages.", 4);
}
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("Post change: page_on_front " . get_option('page_on_front'), 4);
}
wp_cache_post_id_gc($siteurl, get_option('page_on_front'), 'single');
$permalink = trailingslashit(str_replace(get_option('home'), '', post_permalink(get_option('page_for_posts'))));
$files_to_check = get_all_supercache_filenames($dir . $permalink);
foreach ($files_to_check as $cache_file) {
prune_super_cache($dir . $permalink . $cache_file, true, true);
}
do_action('gc_cache', 'prune', $permalink);
}
}
$matches = array();
if ($handle = @opendir($blog_cache_dir . 'meta/')) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/^({$file_prefix}{$blogcacheid}.*)\\.meta/", $file, $matches)) {
$meta_pathname = $blog_cache_dir . 'meta/' . $file;
$content_pathname = $blog_cache_dir . $matches[1] . ".html";
$meta = unserialize(@file_get_contents($meta_pathname));
if (false == is_array($meta)) {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("Post change cleaning up stray file: {$content_pathname}", 4);
}
@unlink($meta_pathname);
@unlink($content_pathname);
continue;
}
if ($post_id > 0 && $meta) {
$permalink = trailingslashit(str_replace(get_option('home'), '', post_permalink($post_id)));
if ($meta['blog_id'] == $blog_id && ($all == true && !$meta['post'] || $meta['post'] == $post_id)) {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("Post change: deleting post cache files for {$meta['uri']}: {$content_pathname}", 4);
}
@unlink($meta_pathname);
@unlink($content_pathname);
if ($super_cache_enabled == true) {
@prune_super_cache($dir . $permalink, true, true);
do_action('gc_cache', 'rebuild', $permalink);
}
}
} elseif ($meta['blog_id'] == $blog_id) {
if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) {
wp_cache_debug("Post change: deleting cache files for {$meta['uri']}: {$content_pathname}", 4);
}
@unlink($meta_pathname);
@unlink($content_pathname);
if ($super_cache_enabled == true) {
$files_to_check = get_all_supercache_filenames($dir . $meta['uri']);
foreach ($files_to_check as $cache_file) {
//.........这里部分代码省略.........
示例9: clearall
static function clearall()
{
if (!autoptimizeCache::cacheavail()) {
return false;
}
// scan the cachedirs
foreach (array("", "js", "css") as $scandirName) {
$scan[$scandirName] = scandir(AUTOPTIMIZE_CACHE_DIR . $scandirName);
}
// clear the cachedirs
foreach ($scan as $scandirName => $scanneddir) {
$thisAoCacheDir = rtrim(AUTOPTIMIZE_CACHE_DIR . $scandirName, "/") . "/";
foreach ($scanneddir as $file) {
if (!in_array($file, array('.', '..')) && strpos($file, 'autoptimize') !== false && is_file($thisAoCacheDir . $file)) {
@unlink($thisAoCacheDir . $file);
}
}
}
@unlink(AUTOPTIMIZE_CACHE_DIR . "/.htaccess");
// Do we need to clean any caching plugins cache-files?
if (function_exists('wp_cache_clear_cache')) {
if (is_multisite()) {
$blog_id = get_current_blog_id();
wp_cache_clear_cache($blog_id);
} else {
wp_cache_clear_cache();
}
} else {
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
// w3 total cache
} else {
if (function_exists('hyper_cache_invalidate')) {
hyper_cache_invalidate();
// hypercache
} else {
if (function_exists('wp_fast_cache_bulk_delete_all')) {
wp_fast_cache_bulk_delete_all();
// wp fast cache
} else {
if (class_exists("WpFastestCache")) {
$wpfc = new WpFastestCache();
// wp fastest cache
$wpfc->deleteCache();
} else {
if (class_exists("c_ws_plugin__qcache_purging_routines")) {
c_ws_plugin__qcache_purging_routines::purge_cache_dir();
// quick cache
} else {
if (file_exists(WP_CONTENT_DIR . '/wp-cache-config.php') && function_exists('prune_super_cache')) {
// fallback for WP-Super-Cache
global $cache_path;
if (is_multisite()) {
$blog_id = get_current_blog_id();
prune_super_cache(get_supercache_dir($blog_id), true);
prune_super_cache($cache_path . 'blogs/', true);
} else {
prune_super_cache($cache_path . 'supercache/', true);
prune_super_cache($cache_path, true);
}
} else {
// fallback; schedule event and try to clear there
wp_schedule_single_event(time() + 1, 'ao_flush_pagecache', array(time()));
}
}
}
}
}
}
}
return true;
}
示例10: wp_cache_post_change
function wp_cache_post_change($post_id)
{
global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $blogcacheid, $wp_cache_refresh_single_only, $wp_cache_object_cache;
static $last_processed = -1;
if ($post_id == $last_processed) {
wp_cache_debug("wp_cache_post_change: Already processed post {$post_id}.", 4);
return $post_id;
}
$post = get_post($post_id);
// Some users are inexplicibly seeing this error on scheduled posts.
// define this constant to disable the post status check.
if (false == defined('WPSCFORCEUPDATE') && is_object($post) && $post->post_status != 'publish') {
wp_cache_debug("wp_cache_post_change: draft post, not deleting any cache files.", 4);
return $post_id;
}
$last_processed = $post_id;
if (!wp_cache_writers_entry()) {
return $post_id;
}
if (isset($wp_cache_refresh_single_only) && $wp_cache_refresh_single_only && (strpos($_SERVER['HTTP_REFERER'], 'edit-comments.php') || strpos($_SERVER['REQUEST_URI'], 'wp-comments-post.php'))) {
if (defined('DONOTDELETECACHE')) {
wp_cache_debug("wp_cache_post_change: comment detected and it's moderated or spam. Not deleting cached files.", 4);
return $post_id;
} else {
wp_cache_debug("wp_cache_post_change: comment detected. only deleting post page.", 4);
$all = false;
}
} else {
$all = true;
}
if ($wp_cache_object_cache) {
reset_oc_version();
}
$permalink = trailingslashit(str_replace(get_option('siteurl'), '', post_permalink($post_id)));
if ($super_cache_enabled) {
$dir = get_supercache_dir();
$siteurl = trailingslashit(strtolower(preg_replace('/:.*$/', '', str_replace('https://', '', str_replace('http://', '', get_option('home'))))));
// make sure the front page has a rebuild file
wp_cache_post_id_gc($siteurl, $post_id);
if ($all == true) {
wp_cache_debug("Post change: supercache enabled: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4);
$files_to_check = get_all_supercache_filenames($dir);
foreach ($files_to_check as $cache_file) {
wp_cache_debug("Post change: deleting cache file: " . $dir . $cache_file, 4);
prune_super_cache($dir . $cache_file, true, true);
}
do_action('gc_cache', 'prune', 'homepage');
} else {
wp_cache_debug("wp_cache_post_change: not deleting all pages.", 4);
}
if ($all == true && get_option('show_on_front') == 'page') {
wp_cache_debug("Post change: deleting page_on_front and page_for_posts pages.", 4);
wp_cache_debug("Post change: page_on_front " . get_option('page_on_front'), 4);
wp_cache_post_id_gc($siteurl, get_option('page_on_front'), 'single');
$permalink = trailingslashit(str_replace(get_option('home'), '', post_permalink(get_option('page_for_posts'))));
$files_to_check = get_all_supercache_filenames($dir . $permalink);
foreach ($files_to_check as $cache_file) {
prune_super_cache($dir . $permalink . $cache_file, true, true);
}
do_action('gc_cache', 'prune', $permalink);
} else {
wp_cache_debug("wp_cache_post_change: not deleting front static page.", 4);
}
}
wp_cache_debug("wp_cache_post_change: checking {$blog_cache_dir}meta/", 4);
$matches = array();
if ($handle = @opendir($blog_cache_dir . 'meta/')) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/^({$file_prefix}{$blogcacheid}.*)\\.meta/", $file, $matches)) {
$meta_pathname = $blog_cache_dir . 'meta/' . $file;
$content_pathname = $blog_cache_dir . $matches[1] . ".html";
$meta = unserialize(@file_get_contents($meta_pathname));
if (false == is_array($meta)) {
wp_cache_debug("Post change cleaning up stray file: {$content_pathname}", 4);
@unlink($meta_pathname);
@unlink($content_pathname);
continue;
}
if ($post_id > 0 && $meta) {
$permalink = trailingslashit(str_replace(get_option('home'), '', post_permalink($post_id)));
if ($meta['blog_id'] == $blog_id && ($all == true && !$meta['post'] || $meta['post'] == $post_id)) {
wp_cache_debug("Post change: deleting post cache files for {$meta['uri']}: {$content_pathname}", 4);
@unlink($meta_pathname);
@unlink($content_pathname);
if ($super_cache_enabled == true) {
@prune_super_cache($dir . $permalink, true, true);
do_action('gc_cache', 'rebuild', $permalink);
}
}
} elseif ($meta['blog_id'] == $blog_id) {
wp_cache_debug("Post change: deleting cache files for {$meta['uri']}: {$content_pathname}", 4);
@unlink($meta_pathname);
@unlink($content_pathname);
if ($super_cache_enabled == true) {
$files_to_check = get_all_supercache_filenames($dir . $meta['uri']);
foreach ($files_to_check as $cache_file) {
@wp_cache_rebuild_or_delete($dir . trailingslashit($meta['uri']) . $cache_file);
}
do_action('gc_cache', 'rebuild', trailingslashit($meta['uri']));
}
//.........这里部分代码省略.........