From df231af292bf3b160306453221886042c66de4fa Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 10 Mar 2009 19:03:03 +0000 Subject: [PATCH] Reparent children when deleting a comment. Props vladimir_kolesnikov. fixes #9003 for 2.7 git-svn-id: http://svn.automattic.com/wordpress/branches/2.7@10763 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 18bf0e1965..79377a05ff 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -739,6 +739,13 @@ function wp_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) ) { + $wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment_id)); + clean_comment_cache($children); + } + $post_id = $comment->comment_post_ID; if ( $post_id && $comment->comment_approved == 1 ) wp_update_comment_count($post_id); @@ -1542,10 +1549,11 @@ function weblog_ping($server = '', $path = '') { * @package WordPress * @subpackage Cache * - * @param int $id Comment ID to remove from cache + * @param int|array $id Comment ID or array of comment IDs to remove from cache */ -function clean_comment_cache($id) { - wp_cache_delete($id, 'comment'); +function clean_comment_cache($ids) { + foreach ( (array) $ids as $id ) + wp_cache_delete($id, 'comment'); } /**