WordPress.org

Make WordPress Core

Ticket #7972: preserve-attachment-ids.diff

File preserve-attachment-ids.diff, 1.1 KB (added by mtdewvirus, 10 years ago)
  • post.php

     
    22452245        $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
    22462246                'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
    22472247                'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
    2248                 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '');
     2248                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0);
    22492249
    22502250        $object = wp_parse_args($object, $defaults);
    22512251        if ( !empty($parent) )
     
    23412341        if ( $update ) {
    23422342                $wpdb->update( $wpdb->posts, $data, array( 'ID' => $post_ID ) );
    23432343        } else {
     2344                // If there is a suggested ID, use it if not already present
     2345                if ( !empty($import_id) ) {
     2346                        $import_id = (int) $import_id;
     2347                        if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {
     2348                                $data['ID'] = $import_id;
     2349                        }
     2350                }
     2351
    23442352                $wpdb->insert( $wpdb->posts, $data );
    23452353                $post_ID = (int) $wpdb->insert_id;
    23462354        }