Make WordPress Core

Ticket #16981: 16981.importer.diff

File 16981.importer.diff, 1.8 KB (added by duck_, 14 years ago)
  • trunk/wordpress-importer.php

     
    55Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
    66Author: wordpressdotorg
    77Author URI: http://wordpress.org/
    8 Version: 0.4-alpha2
     8Version: 0.4-alpha3
    99Text Domain: wordpress-importer
    1010License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    1111*/
     
    572572
    573573                                if ( 'attachment' == $postdata['post_type'] ) {
    574574                                        $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
     575
     576                                        // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
     577                                        // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
     578                                        $postdata['upload_date'] = $post['post_date'];
     579                                        if ( isset( $post['postmeta'] ) ) {
     580                                                foreach( $post['postmeta'] as $meta ) {
     581                                                        if ( $meta['key'] == '_wp_attached_file' ) {
     582                                                                if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
     583                                                                        $postdata['upload_date'] = $matches[0];
     584                                                                break;
     585                                                        }
     586                                                }
     587                                        }
     588
    575589                                        $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
    576590                                } else {
    577591                                        $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
     
    833847                $file_name = basename( $url );
    834848
    835849                // get placeholder file in the upload dir with a unique, sanitized filename
    836                 $upload = wp_upload_bits( $file_name, 0, '', $post['post_date'] );
     850                $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
    837851                if ( $upload['error'] )
    838852                        return new WP_Error( 'upload_dir_error', $upload['error'] );
    839853