Make WordPress Core

Ticket #19690: 19690.4.diff

File 19690.4.diff, 7.7 KB (added by ryan, 13 years ago)

Formatting tweaks

  • wp-includes/post.php

     
    13591359        global $wpdb;
    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) );
     1362        $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
    13631363
    1364         if ( 'page' == $post_type )
    1365                 clean_page_cache($post_id);
    1366         else
    1367                 clean_post_cache($post_id);
     1364        clean_post_cache( $post_id, $post_type );
    13681365
    13691366        return $return;
    13701367}
     
    20562053        $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
    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
    20702063        wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
     
    26432636
    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
    26522642        if ( !$update && '' == $current_guid )
     
    35353525        }
    35363526
    35373527        // Update cache.
    3538         update_page_cache($pages);
     3528        update_post_cache( $pages );
    35393529
    35403530        if ( $child_of || $hierarchical )
    35413531                $pages = & get_page_children($child_of, $pages);
     
    37513741        if ( $file )
    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 ) )
    37573747                add_post_meta( $post_ID, '_wp_attachment_context', $context, true );
     
    38643854        if ( ! empty($file) )
    38653855                @ unlink($file);
    38663856
    3867         clean_post_cache($post_id);
     3857        clean_post_cache( $post_id, $post->post_type );
    38683858
    38693859        return $post;
    38703860}
     
    43144304/**
    43154305 * Updates posts in cache.
    43164306 *
    4317  * @usedby update_page_cache() Aliased by this function.
    4318  *
    43194307 * @package WordPress
    43204308 * @subpackage Cache
    43214309 * @since 1.5.1
    43224310 *
    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
    43334321/**
     
    43484336 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
    43494337 *
    43504338 * @param int $id The Post ID in the cache to clean
     4339 * @param string $post_type The post_type of the post. Defaults to "post"
    43514340 */
    4352 function clean_post_cache($id) {
     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
    43584347        $id = (int) $id;
     
    43604349        if ( 0 === $id )
    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
    43724359        do_action('clean_post_cache', $id);
    43734360
     4361        if ( 'page' == $post_type ) {
     4362                wp_cache_delete( 'all_page_ids', 'posts' );
     4363                wp_cache_delete( 'get_pages', 'posts' );
     4364        }
     4365
    43744366        if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
    43754367                foreach ( $children as $cid ) {
    43764368                        // Loop detection
    43774369                        if ( $cid == $id )
    43784370                                continue;
    4379                         clean_post_cache( $cid );
     4371                        clean_post_cache( $cid, $post_type );
    43804372                }
    43814373        }
    43824374
     
    43854377}
    43864378
    43874379/**
    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);
    4423 }
    4424 
    4425 /**
    44264380 * Call major cache updating functions for list of Post objects.
    44274381 *
    44284382 * @package WordPress
     
    46294583 * @param object $post Object type containing the post information
    46304584 */
    46314585function _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         }
     4586        clean_post_cache($post_id, $post->post_type);
    46374587}
    46384588
    46394589/**
     
    53615311
    53625312                update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
    53635313        }
    5364 }
    5365  No newline at end of file
     5314}
  • wp-includes/comment.php

     
    15831583        $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
    15841584        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
    15851585
    1586         if ( 'page' == $post->post_type )
    1587                 clean_page_cache( $post_id );
    1588         else
    1589                 clean_post_cache( $post_id );
     1586        clean_post_cache( $post_id, $post->post_type );
    15901587
    15911588        do_action('wp_update_comment_count', $post_id, $new, $old);
    15921589        do_action('edit_post', $post_id, $post);
  • wp-includes/deprecated.php

     
    31163116        );
    31173117
    31183118        return $theme_data;
    3119 }
    3120  No newline at end of file
     3119}
     3120
     3121/**
     3122 * Alias of update_post_cache().
     3123 *
     3124 * @see update_post_cache() Posts and pages are the same, alias is intentional
     3125 *
     3126 * @since 1.5.1
     3127 * @deprecated 3.4.0
     3128 *
     3129 * @param array $pages list of page objects
     3130 */
     3131function update_page_cache( &$pages ) {
     3132        _deprecated_function( __FUNCTION__, 3.4, 'update_post_cache()' );
     3133
     3134        update_post_cache( $pages );
     3135}
     3136
     3137/**
     3138 * Will clean the page in the cache.
     3139 *
     3140 * Clean (read: delete) page from cache that matches $id. Will also clean cache
     3141 * associated with 'all_page_ids' and 'get_pages'.
     3142 *
     3143 * @since 2.0.0
     3144 * @deprecated 3.4.0
     3145 *
     3146 * @uses do_action() Will call the 'clean_page_cache' hook action.
     3147 *
     3148 * @param int $id Page ID to clean
     3149 */
     3150function clean_page_cache( $id ) {
     3151        _deprecated_function( __FUNCTION__, 3.4, 'clean_post_cache()' );
     3152
     3153        clean_post_cache( $id, 'page' );
     3154}
  • wp-admin/includes/class-wp-posts-list-table.php

     
    360360                                if ( $page->post_parent == $page->ID ) {
    361361                                        $page->post_parent = 0;
    362362                                        $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
    363                                         clean_page_cache( $page->ID );
     363                                        clean_post_cache( $page->ID, $page->post_type );
    364364                                }
    365365
    366366                                if ( 0 == $page->post_parent )