function wp_cache_post_change($post_id)
{
    global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $blogcacheid;
    static $last_processed = -1;
    if ($post_id == $last_processed) {
        return $post_id;
    }
    $last_processed = $post_id;
    if (!wp_cache_writers_entry()) {
        return $post_id;
    }
    $permalink = trailingslashit(str_replace(get_option('siteurl'), '', post_permalink($post_id)));
    if ($super_cache_enabled) {
        $siteurl = trailingslashit(strtolower(preg_replace('/:.*$/', '', str_replace('http://', '', get_option('home')))));
        // make sure the front page has a rebuild file
        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);
        }
        prune_super_cache($cache_path . 'supercache/' . $siteurl . 'index.html', true, true);
        prune_super_cache($cache_path . 'supercache/' . $siteurl . 'index.html.gz', true, true);
        wp_cache_post_id_gc($siteurl, $post_id);
        if (get_option('show_on_front') == 'page') {
            wp_cache_post_id_gc($siteurl, get_option('page_on_front'));
            wp_cache_post_id_gc($siteurl, get_option('page_for_posts'));
        }
    }
    $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)) {
                    @unlink($meta_pathname);
                    @unlink($content_pathname);
                    continue;
                }
                if ($post_id > 0 && $meta) {
                    if ($meta['blog_id'] == $blog_id && (!$meta['post'] || $meta['post'] == $post_id)) {
                        @unlink($meta_pathname);
                        @unlink($content_pathname);
                        @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit($meta['uri']) . 'index.html');
                        @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit($meta['uri']) . 'index.html.gz');
                    }
                } elseif ($meta['blog_id'] == $blog_id) {
                    @unlink($meta_pathname);
                    @unlink($content_pathname);
                    @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit($meta['uri']) . 'index.html');
                    @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit($meta['uri']) . 'index.html.gz');
                }
            }
        }
        closedir($handle);
    }
    wp_cache_writers_exit();
    return $post_id;
}
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) {
                            @wp_cache_rebuild_or_delete($dir . trailingslashit($meta['uri']) . $cache_file);
                        }
                        do_action('gc_cache', 'rebuild', trailingslashit($meta['uri']));
                    }
                }
            }
        }
        closedir($handle);
    }
    wp_cache_writers_exit();
    return $post_id;
}
Beispiel #3
0
function wp_cache_post_change($post_id)
{
    global $file_prefix, $cache_path, $blog_id, $blogcacheid, $super_cache_enabled;
    static $last_processed = -1;
    if ($post_id == $last_processed) {
        return $post_id;
    }
    $last_processed = $post_id;
    if (!wp_cache_writers_entry()) {
        return $post_id;
    }
    $permalink = trailingslashit(str_replace(get_option('siteurl'), '', post_permalink($post_id)));
    if ($super_cache_enabled) {
        $siteurl = trailingslashit(strtolower(preg_replace('/:.*$/', '', str_replace('http://', '', get_option('home')))));
        // make sure the front page has a rebuild file
        prune_super_cache($cache_path . 'supercache/' . $siteurl . 'index.html', true, true);
        prune_super_cache($cache_path . 'supercache/' . $siteurl . 'index.html.gz', true, true);
        if ($post_id != 0) {
            $permalink = trailingslashit(str_replace(get_option('home'), '', post_permalink($post_id)));
            $dir = $cache_path . 'supercache/' . $siteurl;
            prune_super_cache($dir . $permalink, true, true);
            @rmdir($dir . $permalink);
            prune_super_cache($dir . 'page/', true);
        }
    }
    $meta = new CacheMeta();
    $matches = array();
    if ($handle = opendir($cache_path . 'meta/')) {
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/^({$file_prefix}{$blogcacheid}.*)\\.meta/", $file, $matches)) {
                $meta_pathname = $cache_path . 'meta/' . $file;
                $content_pathname = $cache_path . $matches[1] . ".html";
                $meta = unserialize(@file_get_contents($meta_pathname));
                if ($post_id > 0 && $meta) {
                    if ($meta->blog_id == $blog_id && (!$meta->post || $meta->post == $post_id)) {
                        @unlink($meta_pathname);
                        @unlink($content_pathname);
                    }
                } elseif ($meta->blog_id == $blog_id) {
                    @unlink($meta_pathname);
                    @unlink($content_pathname);
                }
            }
        }
        closedir($handle);
    }
    wp_cache_writers_exit();
    return $post_id;
}
function wp_cache_post_change($post_id)
{
    global $file_prefix;
    global $cache_path;
    static $last_processed = -1;
    // Avoid cleaning twice the same pages
    if ($post_id == $last_processed) {
        return $post_id;
    }
    $last_processed = $post_id;
    $meta = new CacheMeta();
    $matches = array();
    wp_cache_writers_entry();
    if ($handle = opendir($cache_path)) {
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/^({$file_prefix}.*)\\.meta/", $file, $matches)) {
                $meta_pathname = $cache_path . $file;
                $content_pathname = $cache_path . $matches[1] . ".html";
                if ($post_id > 0 && ($meta = unserialize(@file_get_contents($meta_pathname)))) {
                    if (!$meta->post || $meta->post == $post_id) {
                        unlink($meta_pathname);
                        unlink($content_pathname);
                    }
                } else {
                    unlink($meta_pathname);
                    unlink($content_pathname);
                }
            }
        }
        closedir($handle);
    }
    wp_cache_writers_exit();
    return $post_id;
}
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']));
                    }
                }
            }
        }
        closedir($handle);
    }
    wp_cache_writers_exit();
    return $post_id;
}