From c059c511df24d8fe44912d90a4f9036e6c71341d Mon Sep 17 00:00:00 2001 From: nacin Date: Sun, 4 Apr 2010 12:42:34 +0000 Subject: [PATCH] Use the API to remove comments when deleting a post. Cleans up comment meta in the process. fixes #12766, props briancolinger git-svn-id: http://svn.automattic.com/wordpress/trunk@13997 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 26dbb152a8..66eed66677 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1664,8 +1664,8 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); if ( ! empty($comment_ids) ) { do_action( 'delete_comment', $comment_ids ); - $in_comment_ids = "'" . implode("', '", $comment_ids) . "'"; - $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_ID IN($in_comment_ids)" ); + foreach ( $comment_ids as $comment_id ) + wp_delete_comment( $comment_id, true ); do_action( 'deleted_comment', $comment_ids ); } @@ -3350,10 +3350,10 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND meta_value = %d", $post_id )); $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id )); - if ( ! empty($comment_ids) ) { + if ( ! empty( $comment_ids ) ) { do_action( 'delete_comment', $comment_ids ); - $in_comment_ids = "'" . implode("', '", $comment_ids) . "'"; - $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_ID IN($in_comment_ids)" ); + foreach ( $comment_ids as $comment_id ) + wp_delete_comment( $comment_id, true ); do_action( 'deleted_comment', $comment_ids ); }