From cdfda5dd2c76469e515d0e078d8cacfa2c6d422e Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 17 Dec 2009 17:10:40 +0000 Subject: [PATCH] Delete all comment meta when deleting a comment. Props nacin. fixes #11463 git-svn-id: http://svn.automattic.com/wordpress/trunk@12428 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 36861f7774..0ff2c89973 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -822,9 +822,6 @@ function wp_delete_comment($comment_id) { do_action('delete_comment', $comment_id); - delete_comment_meta($comment_id,'_wp_trash_meta_status'); - delete_comment_meta($comment_id,'_wp_trash_meta_time'); - if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) return false; @@ -835,6 +832,15 @@ function wp_delete_comment($comment_id) { clean_comment_cache($children); } + // Delete metadata + $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) ); + if ( !empty($meta_ids) ) { + do_action( 'delete_commentmeta', $meta_ids ); + $in_meta_ids = "'" . implode("', '", $meta_ids) . "'"; + $wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" ); + do_action( 'deleted_commentmeta', $meta_ids ); + } + $post_id = $comment->comment_post_ID; if ( $post_id && $comment->comment_approved == 1 ) wp_update_comment_count($post_id);