From 6ea8ad96efccd5b2fafb878ec369924c098cc32b Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 18 Feb 2010 07:43:35 +0000 Subject: [PATCH] Clean attachment cache when reattaching, fixes #11647 git-svn-id: https://develop.svn.wordpress.org/trunk@13192 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/upload.php | 1 + wp-includes/post.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/wp-admin/upload.php b/wp-admin/upload.php index d6222a5789..eaa9b7cbe3 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -43,6 +43,7 @@ if ( isset($_GET['find_detached']) ) { continue; $attach[] = $att_id; + clean_attachment_cache($att_id); } if ( ! empty($attach) ) { diff --git a/wp-includes/post.php b/wp-includes/post.php index 9f401d0bc5..a519103afd 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3906,6 +3906,41 @@ function update_postmeta_cache($post_ids) { return update_meta_cache('post', $post_ids); } +/** + * Will clean the attachment in the cache. + * + * Cleaning means delete from the cache. Optionaly will clean the term + * object cache associated with the attachment ID. + * + * This function will not run if $_wp_suspend_cache_invalidation is not empty. See + * wp_suspend_cache_invalidation(). + * + * @package WordPress + * @subpackage Cache + * @since 3.0 + * + * @uses do_action() Calls 'clean_attachment_cache' on $id. + * + * @param int $id The attachment ID in the cache to clean + * @param bool $clean_terms optional. Whether to clean terms cache + */ +function clean_attachment_cache($id, $clean_terms = false) { + global $_wp_suspend_cache_invalidation, $wpdb; + + if ( !empty($_wp_suspend_cache_invalidation) ) + return; + + $id = (int) $id; + + wp_cache_delete($id, 'posts'); + wp_cache_delete($id, 'post_meta'); + + if ( $clean_terms ) + clean_object_term_cache($id, 'attachment'); + + do_action('clean_attachment_cache', $id); +} + // // Hooks //