WordPress.org

Make WordPress Core

Ticket #23276: 23276.patch

File 23276.patch, 2.6 KB (added by WraithKenny, 5 months ago)
  • wordpress-importer.php

     
    800800                        'menu-item-xfn' => $_menu_item_xfn, 
    801801                        'menu-item-status' => $item['status'] 
    802802                ); 
    803  
    804                 $id = wp_update_nav_menu_item( $menu_id, 0, $args ); 
     803                 
     804                // Attempt to find existing nav-item 
     805                $menu_item_db_id = (int) $item['post_id']; 
     806                $original_object = get_post( $menu_item_db_id ); 
     807                 
     808                // Not found, so create with original ID 
     809                if ( is_null( $original_object ) )  { 
     810                 
     811                        // Logic reused from line 552 of this file (@ version 0.6) 
     812                        $post_parent = (int) $item['post_parent']; 
     813                        if ( $post_parent ) { 
     814                                // if we already know the parent, map it to the new local ID 
     815                                if ( isset( $this->processed_posts[$post_parent] ) ) { 
     816                                        $post_parent = $this->processed_posts[$post_parent]; 
     817                                // otherwise record the parent for later 
     818                                } else { 
     819                                        $this->post_orphans[intval($post['post_id'])] = $post_parent; 
     820                                        $post_parent = 0; 
     821                                } 
     822                        } 
     823                 
     824                        // map the post author 
     825                        $author = sanitize_user( $item['post_author'], true ); 
     826                        if ( isset( $this->author_mapping[$author] ) ) 
     827                                $author = $this->author_mapping[$author]; 
     828                        else 
     829                                $author = (int) get_current_user_id(); 
     830                 
     831                        $postdata = array( 
     832                                'import_id' => $item['post_id'], 
     833                                'post_author' => $author, 
     834                                'post_date' => $item['post_date'], 
     835                                'post_date_gmt' => $item['post_date_gmt'], 
     836                                'post_content' => $item['post_content'], 
     837                                'post_excerpt' => $item['post_excerpt'], 
     838                                'post_title' => $item['post_title'], 
     839                                'post_status' => $item['status'], 
     840                                'post_name' => $item['post_name'], 
     841                                'comment_status' => $item['comment_status'], 
     842                                'ping_status' => $item['ping_status'], 
     843                                'guid' => $item['guid'], 
     844                                'post_parent' => $post_parent, 
     845                                'menu_order' => $item['menu_order'], 
     846                                'post_type' => $item['post_type'], 
     847                                'post_password' => $item['post_password'] 
     848                        ); 
     849                        $menu_item_db_id = wp_insert_post( $postdata, true ); 
     850                 
     851                        if ( is_wp_error( $menu_item_db_id ) ) { 
     852                                $post_type_object = get_post_type_object( $item['post_type'] ); 
     853                                printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), 
     854                                        $post_type_object->labels->singular_name, esc_html($item['post_title']) ); 
     855                                if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) 
     856                                        echo ': ' . $post_id->get_error_message(); 
     857                                echo '<br />'; 
     858                        } 
     859                } 
     860                 
     861                $id = wp_update_nav_menu_item( $menu_id, $menu_item_db_id, $args ); 
     862                 
    805863                if ( $id && ! is_wp_error( $id ) ) 
    806864                        $this->processed_menu_items[intval($item['post_id'])] = (int) $id; 
    807865        }