WordPress.org

Plugin Directory

Changeset 365515 for wordpress-importer


Ignore:
Timestamp:
03/27/11 19:48:13 (3 years ago)
Author:
duck_
Message:

Grab attachment upload directory from _wp_attached_file, ticket 16981

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wordpress-importer/trunk/wordpress-importer.php

    r350057 r365515  
    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 
     
    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 { 
     
    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'] ); 
Note: See TracChangeset for help on using the changeset viewer.