[wp-trac] [WordPress Trac] #23276: WordPress Importer: Update existing navs instead of new
WordPress Trac
noreply at wordpress.org
Wed Jan 23 17:00:07 UTC 2013
#23276: WordPress Importer: Update existing navs instead of new
-----------------------------+--------------------------
Reporter: WraithKenny | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Import
Version: trunk | Severity: normal
Keywords: |
-----------------------------+--------------------------
A possible solution (reuses logic present in the code):
{{{
$menu_item_db_id = (int) $item['post_id'];
$original_object = get_post( $menu_item_db_id );
if ( is_null( $original_object ) ) {
$post_parent = (int) $item['post_parent'];
if ( $post_parent ) {
// if we already know the parent, map it to the new local
ID
if ( isset( $this->processed_posts[$post_parent] ) ) {
$post_parent =
$this->processed_posts[$post_parent];
// otherwise record the parent for later
} else {
$this->post_orphans[intval($post['post_id'])] =
$post_parent;
$post_parent = 0;
}
}
// map the post author
$author = sanitize_user( $item['post_author'], true );
if ( isset( $this->author_mapping[$author] ) )
$author = $this->author_mapping[$author];
else
$author = (int) get_current_user_id();
$postdata = array(
'import_id' => $item['post_id'],
'post_author' => $author,
'post_date' => $item['post_date'],
'post_date_gmt' => $item['post_date_gmt'],
'post_content' => $item['post_content'],
'post_excerpt' => $item['post_excerpt'],
'post_title' => $item['post_title'],
'post_status' => $item['status'],
'post_name' => $item['post_name'],
'comment_status' => $item['comment_status'],
'ping_status' => $item['ping_status'],
'guid' => $item['guid'],
'post_parent' => $post_parent,
'menu_order' => $item['menu_order'],
'post_type' => $item['post_type'],
'post_password' => $item['post_password']
);
$menu_item_db_id = wp_insert_post( $postdata, true );
if ( is_wp_error( $menu_item_db_id ) ) {
$post_type_object = get_post_type_object(
$item['post_type'] );
printf( __( 'Failed to import %s “%s”', 'wordpress-
importer' ),
$post_type_object->labels->singular_name,
esc_html($item['post_title']) );
if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
echo ': ' . $post_id->get_error_message();
echo '<br />';
}
}
$id = wp_update_nav_menu_item( $menu_id, $menu_item_db_id, $args );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23276>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list