Make WordPress Core


Ignore:
Timestamp:
03/31/2009 07:16:53 PM (15 years ago)
Author:
ryan
Message:

Fix delete statements to ensure data integrity when innodb and foreign keys are used. Props Denis-de-Bernardy. see #9422

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r10810 r10851  
    11601160        wp_delete_post_revision( $revision_id );
    11611161
     1162    do_action('deleted_post', $postid);
     1163
    11621164    // Point all attachments to this post up one level
    11631165    $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
    11641166
     1167    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
     1168
     1169    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d", $postid ));
     1170
    11651171    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid ));
    1166 
    1167     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
    1168 
    1169     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d", $postid ));
    11701172
    11711173    if ( 'page' == $post->post_type ) {
     
    11791181        clean_post_cache($postid);
    11801182    }
    1181 
    1182     do_action('deleted_post', $postid);
    11831183
    11841184    return $post;
     
    25172517    wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
    25182518
     2519    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
     2520
     2521    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
     2522
    25192523    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid ));
    2520 
    2521     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
    2522 
    2523     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
    25242524
    25252525    $uploadPath = wp_upload_dir();
Note: See TracChangeset for help on using the changeset viewer.