Make WordPress Core


Ignore:
Timestamp:
04/10/2012 04:09:44 PM (13 years ago)
Author:
ryan
Message:

Pass post_type to clean_post_cache() instead of attempting to fetch a post object since the post may have been deleted.

Props leewillis77
see #19690

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r20287 r20423  
    13601360
    13611361    $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
    1362     $return = $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
    1363 
    1364     if ( 'page' == $post_type )
    1365         clean_page_cache($post_id);
    1366     else
    1367         clean_post_cache($post_id);
     1362    $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
     1363
     1364    clean_post_cache( $post_id, $post_type );
    13681365
    13691366    return $return;
     
    20572054    do_action( 'deleted_post', $postid );
    20582055
    2059     if ( 'page' == $post->post_type ) {
    2060         clean_page_cache($postid);
    2061     } else {
    2062         clean_post_cache($postid);
    2063     }
     2056    clean_post_cache( $postid, $post->post_type );
    20642057
    20652058    if ( is_post_type_hierarchical( $post->post_type ) ) {
    20662059        foreach ( (array) $children as $child )
    2067             clean_post_cache( $child->ID );
     2060            clean_post_cache( $child->ID, $child->post_type );
    20682061    }
    20692062
     
    26442637    $current_guid = get_post_field( 'guid', $post_ID );
    26452638
    2646     if ( 'page' == $data['post_type'] )
    2647         clean_page_cache($post_ID);
    2648     else
    2649         clean_post_cache($post_ID);
     2639    clean_post_cache( $post_ID, $data['post_type'] );
    26502640
    26512641    // Set GUID
     
    35363526
    35373527    // Update cache.
    3538     update_page_cache($pages);
     3528    update_post_cache( $pages );
    35393529
    35403530    if ( $child_of || $hierarchical )
     
    37523742        update_attached_file( $post_ID, $file );
    37533743
    3754     clean_post_cache($post_ID);
     3744    clean_post_cache( $post_ID, $post_type );
    37553745
    37563746    if ( ! empty( $context ) )
     
    38653855        @ unlink($file);
    38663856
    3867     clean_post_cache($post_id);
     3857    clean_post_cache( $post_id, $post->post_type );
    38683858
    38693859    return $post;
     
    43154305 * Updates posts in cache.
    43164306 *
    4317  * @usedby update_page_cache() Aliased by this function.
    4318  *
    43194307 * @package WordPress
    43204308 * @subpackage Cache
     
    43234311 * @param array $posts Array of post objects
    43244312 */
    4325 function update_post_cache(&$posts) {
    4326     if ( !$posts )
     4313function update_post_cache( &$posts ) {
     4314    if ( ! $posts )
    43274315        return;
    43284316
    43294317    foreach ( $posts as $post )
    4330         wp_cache_add($post->ID, $post, 'posts');
     4318        wp_cache_add( $post->ID, $post, 'posts' );
    43314319}
    43324320
     
    43494337 *
    43504338 * @param int $id The Post ID in the cache to clean
    4351  */
    4352 function clean_post_cache($id) {
     4339 * @param string $post_type The post_type of the post. Defaults to "post"
     4340 */
     4341function clean_post_cache($id, $post_type = 'post') {
    43534342    global $_wp_suspend_cache_invalidation, $wpdb;
    43544343
    4355     if ( !empty($_wp_suspend_cache_invalidation) )
     4344    if ( ! empty( $_wp_suspend_cache_invalidation ) )
    43564345        return;
    43574346
     
    43614350        return;
    43624351
    4363     $post = get_post( $id );
    4364 
    43654352    wp_cache_delete($id, 'posts');
    43664353    wp_cache_delete($id, 'post_meta');
    43674354
    4368     clean_object_term_cache( $id, $post->post_type );
     4355    clean_object_term_cache( $id, $post_type );
    43694356
    43704357    wp_cache_delete( 'wp_get_archives', 'general' );
    43714358
    4372     do_action('clean_post_cache', $id);
    4373 
    4374     if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
     4359    do_action( 'clean_post_cache', $id, $post_type );
     4360
     4361    if ( 'page' == $post_type ) {
     4362        wp_cache_delete( 'all_page_ids', 'posts' );
     4363        wp_cache_delete( 'get_pages', 'posts' );
     4364        do_action( 'clean_page_cache', $id );
     4365    }
     4366
     4367    if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
    43754368        foreach ( $children as $cid ) {
    43764369            // Loop detection
    4377             if ( $cid == $id )
     4370            if ( $cid->ID == $id )
    43784371                continue;
    4379             clean_post_cache( $cid );
     4372            clean_post_cache( $cid->ID, $cid->post_type );
    43804373        }
    43814374    }
     
    43834376    if ( is_multisite() )
    43844377        wp_cache_delete( $wpdb->blogid . '-' . $id, 'global-posts' );
    4385 }
    4386 
    4387 /**
    4388  * Alias of update_post_cache().
    4389  *
    4390  * @see update_post_cache() Posts and pages are the same, alias is intentional
    4391  *
    4392  * @package WordPress
    4393  * @subpackage Cache
    4394  * @since 1.5.1
    4395  *
    4396  * @param array $pages list of page objects
    4397  */
    4398 function update_page_cache(&$pages) {
    4399     update_post_cache($pages);
    4400 }
    4401 
    4402 /**
    4403  * Will clean the page in the cache.
    4404  *
    4405  * Clean (read: delete) page from cache that matches $id. Will also clean cache
    4406  * associated with 'all_page_ids' and 'get_pages'.
    4407  *
    4408  * @package WordPress
    4409  * @subpackage Cache
    4410  * @since 2.0.0
    4411  *
    4412  * @uses do_action() Will call the 'clean_page_cache' hook action.
    4413  *
    4414  * @param int $id Page ID to clean
    4415  */
    4416 function clean_page_cache($id) {
    4417     clean_post_cache($id);
    4418 
    4419     wp_cache_delete( 'all_page_ids', 'posts' );
    4420     wp_cache_delete( 'get_pages', 'posts' );
    4421 
    4422     do_action('clean_page_cache', $id);
    44234378}
    44244379
     
    46304585 */
    46314586function _save_post_hook($post_id, $post) {
    4632     if ( $post->post_type == 'page' ) {
    4633         clean_page_cache($post_id);
    4634     } else {
    4635         clean_post_cache($post_id);
    4636     }
     4587    clean_post_cache($post_id, $post->post_type);
    46374588}
    46384589
Note: See TracChangeset for help on using the changeset viewer.