From 6daee9e140679eace0a4a910cadd788044edaea2 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 17 Dec 2009 17:54:23 +0000 Subject: [PATCH] Delete all comment meta when deleting a comment. Props nacin. fixes #11463 git-svn-id: http://svn.automattic.com/wordpress/trunk@12430 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 0ff2c8997..2024c13ef 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -806,6 +806,7 @@ function wp_count_comments( $post_id = 0 ) { * @since 2.0.0 * @uses $wpdb * @uses do_action() Calls 'delete_comment' hook on comment ID + * @uses do_action() Calls 'deleted_comment' hook on comment ID after deletion, on success * @uses do_action() Calls 'wp_set_comment_status' hook on comment ID with 'delete' set for the second parameter * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object * @@ -822,9 +823,6 @@ function wp_delete_comment($comment_id) { do_action('delete_comment', $comment_id); - if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) - return false; - // Move children up a level. $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment_id) ); if ( !empty($children) ) { @@ -841,6 +839,10 @@ function wp_delete_comment($comment_id) { do_action( 'deleted_commentmeta', $meta_ids ); } + if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) + return false; + do_action('deleted_comment', $comment_id); + $post_id = $comment->comment_post_ID; if ( $post_id && $comment->comment_approved == 1 ) wp_update_comment_count($post_id);