diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index a4ed7b75c..ce78e519a 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -717,10 +717,12 @@ class WP_Import { $this->import_start(); $this->get_authors_from_post(); + wp_suspend_cache_invalidation(true); $this->get_entries(); $this->process_categories(); $this->process_tags(); $result = $this->process_posts(); + wp_suspend_cache_invalidation(false); $this->backfill_parents(); $this->backfill_attachment_urls(); $this->import_end(); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 45fae39e0..c81aebac6 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2847,4 +2847,24 @@ function wp_guess_url() { return $url; } +/** + * Suspend cache invalidation. + * + * Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations + * every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent + * cache when invalidation is suspended. + * + * @since 2.7.0 + * + * @param bool $suspend Whether to suspend or enable cache invalidation + * @return bool The current suspend setting + */ +function wp_suspend_cache_invalidation($suspend = true) { + global $_wp_suspend_cache_invalidation; + + $current_suspend = $_wp_suspend_cache_invalidation; + $_wp_suspend_cache_invalidation = $suspend; + return $current_suspend; +} + ?> diff --git a/wp-includes/post.php b/wp-includes/post.php index 71a2b1835..ab8a89df2 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2861,7 +2861,11 @@ function update_post_cache(&$posts) { * @param int $id The Post ID in the cache to clean */ function clean_post_cache($id) { - global $wpdb; + global $_wp_suspend_cache_invalidation, $wpdb; + + if ( !empty($_wp_suspend_cache_invalidation) ) + return; + $id = (int) $id; wp_cache_delete($id, 'posts');