Changeset 20423 for trunk/wp-includes/post.php
- Timestamp:
- 04/10/2012 04:09:44 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r20287 r20423 1360 1360 1361 1361 $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 ); 1368 1365 1369 1366 return $return; … … 2057 2054 do_action( 'deleted_post', $postid ); 2058 2055 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 ); 2064 2057 2065 2058 if ( is_post_type_hierarchical( $post->post_type ) ) { 2066 2059 foreach ( (array) $children as $child ) 2067 clean_post_cache( $child->ID );2060 clean_post_cache( $child->ID, $child->post_type ); 2068 2061 } 2069 2062 … … 2644 2637 $current_guid = get_post_field( 'guid', $post_ID ); 2645 2638 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'] ); 2650 2640 2651 2641 // Set GUID … … 3536 3526 3537 3527 // Update cache. 3538 update_p age_cache($pages);3528 update_post_cache( $pages ); 3539 3529 3540 3530 if ( $child_of || $hierarchical ) … … 3752 3742 update_attached_file( $post_ID, $file ); 3753 3743 3754 clean_post_cache( $post_ID);3744 clean_post_cache( $post_ID, $post_type ); 3755 3745 3756 3746 if ( ! empty( $context ) ) … … 3865 3855 @ unlink($file); 3866 3856 3867 clean_post_cache( $post_id);3857 clean_post_cache( $post_id, $post->post_type ); 3868 3858 3869 3859 return $post; … … 4315 4305 * Updates posts in cache. 4316 4306 * 4317 * @usedby update_page_cache() Aliased by this function.4318 *4319 4307 * @package WordPress 4320 4308 * @subpackage Cache … … 4323 4311 * @param array $posts Array of post objects 4324 4312 */ 4325 function update_post_cache( &$posts) {4326 if ( ! $posts )4313 function update_post_cache( &$posts ) { 4314 if ( ! $posts ) 4327 4315 return; 4328 4316 4329 4317 foreach ( $posts as $post ) 4330 wp_cache_add( $post->ID, $post, 'posts');4318 wp_cache_add( $post->ID, $post, 'posts' ); 4331 4319 } 4332 4320 … … 4349 4337 * 4350 4338 * @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 */ 4341 function clean_post_cache($id, $post_type = 'post') { 4353 4342 global $_wp_suspend_cache_invalidation, $wpdb; 4354 4343 4355 if ( ! empty($_wp_suspend_cache_invalidation) )4344 if ( ! empty( $_wp_suspend_cache_invalidation ) ) 4356 4345 return; 4357 4346 … … 4361 4350 return; 4362 4351 4363 $post = get_post( $id );4364 4365 4352 wp_cache_delete($id, 'posts'); 4366 4353 wp_cache_delete($id, 'post_meta'); 4367 4354 4368 clean_object_term_cache( $id, $post ->post_type );4355 clean_object_term_cache( $id, $post_type ); 4369 4356 4370 4357 wp_cache_delete( 'wp_get_archives', 'general' ); 4371 4358 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) ) ) { 4375 4368 foreach ( $children as $cid ) { 4376 4369 // Loop detection 4377 if ( $cid == $id )4370 if ( $cid->ID == $id ) 4378 4371 continue; 4379 clean_post_cache( $cid );4372 clean_post_cache( $cid->ID, $cid->post_type ); 4380 4373 } 4381 4374 } … … 4383 4376 if ( is_multisite() ) 4384 4377 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 intentional4391 *4392 * @package WordPress4393 * @subpackage Cache4394 * @since 1.5.14395 *4396 * @param array $pages list of page objects4397 */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 cache4406 * associated with 'all_page_ids' and 'get_pages'.4407 *4408 * @package WordPress4409 * @subpackage Cache4410 * @since 2.0.04411 *4412 * @uses do_action() Will call the 'clean_page_cache' hook action.4413 *4414 * @param int $id Page ID to clean4415 */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 4378 } 4424 4379 … … 4630 4585 */ 4631 4586 function _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); 4637 4588 } 4638 4589
Note: See TracChangeset
for help on using the changeset viewer.