diff --git a/src/wp-includes/comment-functions.php b/src/wp-includes/comment-functions.php index b54528d56c..4b680c8194 100644 --- a/src/wp-includes/comment-functions.php +++ b/src/wp-includes/comment-functions.php @@ -1907,6 +1907,10 @@ function wp_update_comment_count_now($post_id) { $post_id = (int) $post_id; if ( !$post_id ) return false; + + wp_cache_delete( 'comments-0', 'counts' ); + wp_cache_delete( "comments-{$post_id}", 'counts' ); + if ( !$post = get_post($post_id) ) return false; @@ -1916,9 +1920,6 @@ function wp_update_comment_count_now($post_id) { clean_post_cache( $post ); - wp_cache_delete( 'comments-0', 'counts' ); - wp_cache_delete( "comments-{$post_id}", 'counts' ); - /** * Fires immediately after a post's comment count is updated in the database. * diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index ea731753ac..820b6a078d 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -1394,7 +1394,7 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { } $labels = array_merge( $defaults, $object->labels ); $object->labels = (object) $object->labels; - + return (object) $labels; } @@ -2370,9 +2370,14 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { // Point all attachments to this post up one level. $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); + wp_defer_comment_counting( true ); + $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); - foreach ( $comment_ids as $comment_id ) + foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); + } + + wp_defer_comment_counting( false ); $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); foreach ( $post_meta_ids as $mid ) @@ -4637,9 +4642,14 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { // Delete all for any posts. delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); + wp_defer_comment_counting( true ); + $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id )); - foreach ( $comment_ids as $comment_id ) + foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); + } + + wp_defer_comment_counting( false ); $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id )); foreach ( $post_meta_ids as $mid )