WordPress.org

Make WordPress Core

Ticket #11647: clean-attachment-cache.patch

File clean-attachment-cache.patch, 1.6 KB (added by azaozz, 8 years ago)
  • wp-admin/upload.php

     
    4848                        continue;
    4949
    5050                $attach[] = $att_id;
     51                clean_attachment_cache($att_id, false);
    5152        }
    5253
    5354        if ( ! empty($attach) ) {
  • wp-includes/post.php

     
    34083408}
    34093409
    34103410/**
     3411 * Will clean the attachment in the cache.
     3412 *
     3413 * Cleaning means delete from the cache. Optionaly will clean the term
     3414 * object cache associated with the attachment ID.
     3415 *
     3416 * This function will not run if $_wp_suspend_cache_invalidation is not empty. See
     3417 * wp_suspend_cache_invalidation().
     3418 *
     3419 * @package WordPress
     3420 * @subpackage Cache
     3421 * @since 3.0
     3422 *
     3423 * @uses do_action() Calls 'clean_attachment_cache' on $id.
     3424 *
     3425 * @param int $id The attachment ID in the cache to clean
     3426 * @param bool $clean_terms optional. Whether to clean terms cache
     3427 */
     3428function clean_attachment_cache($id, $clean_terms = true) {
     3429        global $_wp_suspend_cache_invalidation, $wpdb;
     3430
     3431        if ( !empty($_wp_suspend_cache_invalidation) )
     3432                return;
     3433
     3434        $id = (int) $id;
     3435
     3436        wp_cache_delete($id, 'posts');
     3437        wp_cache_delete($id, 'post_meta');
     3438
     3439        if ( $clean_terms )
     3440                clean_object_term_cache($id, 'attachment');
     3441
     3442        do_action('clean_attachment_cache', $id);
     3443}
     3444
     3445/**
    34113446 * Alias of update_post_cache().
    34123447 *
    34133448 * @see update_post_cache() Posts and pages are the same, alias is intentional