Skip to content

Commit

Permalink
Delete all comment meta when deleting a comment. Props nacin. fixes #…
Browse files Browse the repository at this point in the history
…11463 for 2.9

git-svn-id: http://svn.automattic.com/wordpress/branches/2.9@12429 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ryan committed Dec 17, 2009
1 parent 7ad0c5c commit 899892a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 899892a

Please sign in to comment.