Make WordPress Core

Changeset 20569


Ignore:
Timestamp:
04/23/2012 10:04:35 PM (15 years ago)
Author:
duck_
Message:

Accept a post object in clean_post_cache(). Fixes #20486.

The post_type can then be accessed to properly clean the taxonomy relationships cache.
The full object is useful in situations when an ID might reference a post that has been
removed from the database (e.g. wp_delete_post()).

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-posts-list-table.php

    r20423 r20569  
    361361                                        $page->post_parent = 0;
    362362                                        $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
    363                                         clean_post_cache( $page->ID, $page->post_type );
     363                                        clean_post_cache( $page );
    364364                                }
    365365
  • trunk/wp-includes/comment.php

    r20435 r20569  
    15801580        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
    15811581
    1582         clean_post_cache( $post_id, $post->post_type );
     1582        clean_post_cache( $post );
    15831583
    15841584        do_action('wp_update_comment_count', $post_id, $new, $old);
  • trunk/wp-includes/deprecated.php

    r20423 r20569  
    31513151        _deprecated_function( __FUNCTION__, 3.4, 'clean_post_cache()' );
    31523152
    3153         clean_post_cache( $id, 'page' );
    3154 }
     3153        clean_post_cache( $id );
     3154}
  • trunk/wp-includes/post.php

    r20465 r20569  
    13621362        $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
    13631363
    1364         clean_post_cache( $post_id, $post_type );
     1364        clean_post_cache( $post_id );
    13651365
    13661366        return $return;
    … …  
    20462046        do_action( 'deleted_post', $postid );
    20472047
    2048         clean_post_cache( $postid, $post->post_type );
     2048        clean_post_cache( $post );
    20492049
    20502050        if ( is_post_type_hierarchical( $post->post_type ) ) {
    20512051                foreach ( (array) $children as $child )
    2052                         clean_post_cache( $child->ID, $child->post_type );
     2052                        clean_post_cache( $child );
    20532053        }
    20542054
    … …  
    26292629        $current_guid = get_post_field( 'guid', $post_ID );
    26302630
    2631         clean_post_cache( $post_ID, $data['post_type'] );
     2631        clean_post_cache( $post_ID );
    26322632
    26332633        // Set GUID
    … …  
    37343734                update_attached_file( $post_ID, $file );
    37353735
    3736         clean_post_cache( $post_ID, $post_type );
     3736        clean_post_cache( $post_ID );
    37373737
    37383738        if ( ! empty( $context ) )
    … …  
    38393839                @ unlink($file);
    38403840
    3841         clean_post_cache( $post_id, $post->post_type );
     3841        clean_post_cache( $post );
    38423842
    38433843        return $post;
    … …  
    43204320 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
    43214321 *
    4322  * @param int $id The Post ID in the cache to clean
    4323  * @param string $post_type The post_type of the post. Defaults to "post"
    4324  */
    4325 function clean_post_cache($id, $post_type = 'post') {
     4322 * @param object|int $post The post object or ID to remove from the cache
     4323 */
     4324function clean_post_cache( $post ) {
    43264325        global $_wp_suspend_cache_invalidation, $wpdb;
    43274326
    … …  
    43294328                return;
    43304329
    4331         $id = (int) $id;
    4332 
    4333         if ( 0 === $id )
     4330        $post = get_post( $post );
     4331        if ( empty( $post ) )
    43344332                return;
    43354333
    4336         wp_cache_delete($id, 'posts');
    4337         wp_cache_delete($id, 'post_meta');
    4338 
    4339         clean_object_term_cache( $id, $post_type );
     4334        wp_cache_delete( $post->ID, 'posts' );
     4335        wp_cache_delete( $post->ID, 'post_meta' );
     4336
     4337        clean_object_term_cache( $post->ID, $post->post_type );
    43404338
    43414339        wp_cache_delete( 'wp_get_archives', 'general' );
    43424340
    4343         do_action( 'clean_post_cache', $id, $post_type );
    4344 
    4345         if ( 'page' == $post_type ) {
     4341        do_action( 'clean_post_cache', $post->ID, $post );
     4342
     4343        if ( 'page' == $post->post_type ) {
    43464344                wp_cache_delete( 'all_page_ids', 'posts' );
    43474345                wp_cache_delete( 'get_pages', 'posts' );
    4348                 do_action( 'clean_page_cache', $id );
    4349         }
    4350 
    4351         if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
    4352                 foreach ( $children as $cid ) {
     4346                do_action( 'clean_page_cache', $post->ID );
     4347        }
     4348
     4349        if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $post->ID) ) ) {
     4350                foreach ( $children as $child ) {
    43534351                        // Loop detection
    4354                         if ( $cid->ID == $id )
     4352                        if ( $child->ID == $post->ID )
    43554353                                continue;
    4356                         clean_post_cache( $cid->ID, $cid->post_type );
     4354                        clean_post_cache( $child );
    43574355                }
    43584356        }
    43594357
    43604358        if ( is_multisite() )
    4361                 wp_cache_delete( $wpdb->blogid . '-' . $id, 'global-posts' );
     4359                wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' );
    43624360}
    43634361
    … …  
    45644562 * @param object $post Object type containing the post information
    45654563 */
    4566 function _save_post_hook($post_id, $post) {
    4567         clean_post_cache($post_id, $post->post_type);
     4564function _save_post_hook( $post_id, $post ) {
     4565        clean_post_cache( $post );
    45684566}
    45694567
Note: See TracChangeset for help on using the changeset viewer.