+/**
+ * Saves nav menu items
+ *
+ * @since 3.6.0
+ *
+ * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu
+ * @param string $nav_menu_selected_title Title of the currently-selected menu
+ * @return array $messages The menu updated message
+ */
+function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) {
+ $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) );
+ $messages = array();
+ $menu_items = array();
+ // Index menu items by db ID
+ foreach ( $unsorted_menu_items as $_item )
+ $menu_items[$_item->db_id] = $_item;
+
+ $post_fields = array(
+ 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object',
+ 'menu-item-parent-id', 'menu-item-position', 'menu-item-type',
+ 'menu-item-title', 'menu-item-url', 'menu-item-description',
+ 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn'
+ );
+
+ wp_defer_term_counting( true );
+ // Loop through all the menu items' POST variables
+ if ( ! empty( $_POST['menu-item-db-id'] ) ) {
+ foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
+
+ // Menu item title can't be blank
+ if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] )
+ continue;
+
+ $args = array();
+ foreach ( $post_fields as $field )
+ $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : '';
+
+ $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );