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

git-svn-id: https://develop.svn.wordpress.org/trunk@13997 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-04-04 12:42:34 +00:00
parent f3b49e98b6
commit 966b3a13e7
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 );
}