Preserve attachment IDs during import. Props mtdewvirus. fixes #7972

git-svn-id: https://develop.svn.wordpress.org/trunk@9357 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-10-26 17:05:56 +00:00
parent 3940c8b9f1
commit f3ea00820e
1 changed files with 9 additions and 1 deletions

View File

@ -2245,7 +2245,7 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '');
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0);
$object = wp_parse_args($object, $defaults);
if ( !empty($parent) )
@ -2341,6 +2341,14 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
if ( $update ) {
$wpdb->update( $wpdb->posts, $data, array( 'ID' => $post_ID ) );
} else {
// If there is a suggested ID, use it if not already present
if ( !empty($import_id) ) {
$import_id = (int) $import_id;
if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {
$data['ID'] = $import_id;
}
}
$wpdb->insert( $wpdb->posts, $data );
$post_ID = (int) $wpdb->insert_id;
}