Use the API to remove comments when deleting a post. Cleans up comment meta in the process. fixes #12766, props briancolinger

git-svn-id: http://svn.automattic.com/wordpress/trunk@13997 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-04-04 12:42:34 +00:00
parent f181423040
commit c059c511df
1 changed files with 5 additions and 5 deletions

View File

@ -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 );
}