WordPress.org

Plugin Directory

Changeset 339902


Ignore:
Timestamp:
02/02/11 13:44:15 (3 years ago)
Author:
duck_
Message:

Correctly update _thumbnail_id on import, props Nano8Blazex for initial patch

File:
1 edited

Legend:

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

    r339895 r339902  
    66Author: wordpressdotorg 
    77Author URI: http://wordpress.org/ 
    8 Version: 0.3-beta6 
     8Version: 0.3-beta7 
    99License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    1010*/ 
     
    5858    var $fetch_attachments = false; 
    5959    var $url_remap = array(); 
     60    var $featured_images = array(); 
    6061 
    6162    function WP_Import() { /* nothing */ } 
     
    111112        wp_suspend_cache_invalidation( false ); 
    112113 
    113         // update items with missing/incorrect parent IDs 
     114        // update incorrect/missing information in the DB 
    114115        $this->backfill_parents(); 
    115         // update attachment references within posts and postmeta 
    116116        $this->backfill_attachment_urls(); 
     117        $this->remap_featured_images(); 
    117118 
    118119        $this->import_end(); 
     
    636637                        update_post_meta( $post_id, $key, $value ); 
    637638                        do_action( 'import_post_meta', $post_id, $key, $value ); 
     639 
     640                        // if the post has a featured image, take note of this in case of remap 
     641                        if ( '_thumbnail_id' == $key ) 
     642                            $this->featured_images[$post_id] = (int) $value; 
    638643                    } 
    639644                } 
     
    880885    function backfill_attachment_urls() { 
    881886        global $wpdb; 
    882  
    883887        // make sure we do the longest urls first, in case one is a substring of another 
    884888        uksort( $this->url_remap, array(&$this, 'cmpr_strlen') ); 
     
    889893            // remap enclosure urls 
    890894            $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) ); 
     895        } 
     896    } 
     897 
     898    /** 
     899     * Update _thumbnail_id meta to new, imported attachment IDs 
     900     */ 
     901    function remap_featured_images() { 
     902        // cycle through posts that have a featured image 
     903        foreach ( $this->featured_images as $post_id => $value ) { 
     904            if ( isset( $this->processed_posts[$value] ) ) { 
     905                $new_id = $this->processed_posts[$value]; 
     906                // only update if there's a difference 
     907                if ( $new_id != $value ) 
     908                    update_post_meta( $post_id, '_thumbnail_id', $new_id ); 
     909            } 
    891910        } 
    892911    } 
Note: See TracChangeset for help on using the changeset viewer.