From 966b3a13e72b16e72577db8e2584477fcfd9de16 Mon Sep 17 00:00:00 2001 From: Andrew 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: https://develop.svn.wordpress.org/trunk@13997 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 ); }