<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[14450] trunk: Non-JS menu ordering fixes, also parent handling fixes.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14450">14450</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-05-04 19:40:04 +0000 (Tue, 04 May 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Non-JS menu ordering fixes, also parent handling fixes. props filosofo, fixes <a href="http://trac.wordpress.org/ticket/13135">#13135</a>, fixes <a href="http://trac.wordpress.org/ticket/13249">#13249</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesnavmenuphp">trunk/wp-admin/includes/nav-menu.php</a></li>
<li><a href="#trunkwpadminnavmenusphp">trunk/wp-admin/nav-menus.php</a></li>
<li><a href="#trunkwpincludesnavmenutemplatephp">trunk/wp-includes/nav-menu-template.php</a></li>
<li><a href="#trunkwpincludesnavmenuphp">trunk/wp-includes/nav-menu.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesnavmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/nav-menu.php (14449 => 14450)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/nav-menu.php        2010-05-04 19:34:38 UTC (rev 14449)
+++ trunk/wp-admin/includes/nav-menu.php        2010-05-04 19:40:04 UTC (rev 14450)
</span><span class="lines">@@ -15,7 +15,7 @@
</span><span class="cx">          * @param string $output Passed by reference.
</span><span class="cx">          * @param int $depth Depth of page.
</span><span class="cx">          */
</span><del>-        function start_lvl(&amp;$output, $depth) {}
</del><ins>+        function start_lvl(&amp;$output) {}
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * @see Walker_Nav_Menu::end_lvl()
</span><span class="lines">@@ -24,7 +24,8 @@
</span><span class="cx">          * @param string $output Passed by reference.
</span><span class="cx">          * @param int $depth Depth of page.
</span><span class="cx">          */
</span><del>-        function end_lvl(&amp;$output, $depth) {}
</del><ins>+        function end_lvl(&amp;$output) {
+        }
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * @see Walker::start_el()
</span><span class="lines">@@ -79,7 +80,7 @@
</span><span class="cx">                                                                                 ),
</span><span class="cx">                                                                                 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
</span><span class="cx">                                                                         ),
</span><del>-                                                                        'move-item'
</del><ins>+                                                                        'move-menu_item'
</ins><span class="cx">                                                                 );
</span><span class="cx">                                                         ?&gt;&quot; class=&quot;item-move-up&quot;&gt;&lt;abbr title=&quot;&lt;?php esc_attr_e('Move up'); ?&gt;&quot;&gt;&amp;#8593;&lt;/abbr&gt;&lt;/a&gt;
</span><span class="cx">                                                         |
</span><span class="lines">@@ -92,7 +93,7 @@
</span><span class="cx">                                                                                 ),
</span><span class="cx">                                                                                 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
</span><span class="cx">                                                                         ),
</span><del>-                                                                        'move-item'
</del><ins>+                                                                        'move-menu_item'
</ins><span class="cx">                                                                 );
</span><span class="cx">                                                         ?&gt;&quot; class=&quot;item-move-down&quot;&gt;&lt;abbr title=&quot;&lt;?php esc_attr_e('Move down'); ?&gt;&quot;&gt;&amp;#8595;&lt;/abbr&gt;&lt;/a&gt;
</span><span class="cx">                                                 &lt;/span&gt;
</span><span class="lines">@@ -187,7 +188,7 @@
</span><span class="cx">                                 &lt;input class=&quot;menu-item-data-db-id&quot; type=&quot;hidden&quot; name=&quot;menu-item-db-id[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo $item_id; ?&gt;&quot; /&gt;
</span><span class="cx">                                 &lt;input class=&quot;menu-item-data-object-id&quot; type=&quot;hidden&quot; name=&quot;menu-item-object-id[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo esc_attr( $item-&gt;object_id ); ?&gt;&quot; /&gt;
</span><span class="cx">                                 &lt;input class=&quot;menu-item-data-object&quot; type=&quot;hidden&quot; name=&quot;menu-item-object[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo esc_attr( $item-&gt;object ); ?&gt;&quot; /&gt;
</span><del>-                                &lt;input class=&quot;menu-item-data-parent-id&quot; type=&quot;hidden&quot; name=&quot;menu-item-parent-id[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo esc_attr( $item-&gt;post_parent ); ?&gt;&quot; /&gt;
</del><ins>+                                &lt;input class=&quot;menu-item-data-parent-id&quot; type=&quot;hidden&quot; name=&quot;menu-item-parent-id[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo esc_attr( $item-&gt;menu_item_parent ); ?&gt;&quot; /&gt;
</ins><span class="cx">                                 &lt;input class=&quot;menu-item-data-position&quot; type=&quot;hidden&quot; class=&quot;menu-item-position&quot; name=&quot;menu-item-position[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo esc_attr( $item-&gt;menu_order ); ?&gt;&quot; /&gt;
</span><span class="cx">                                 &lt;input class=&quot;menu-item-data-type&quot; type=&quot;hidden&quot; name=&quot;menu-item-type[&lt;?php echo $item_id; ?&gt;]&quot; value=&quot;&lt;?php echo esc_attr( $item-&gt;type ); ?&gt;&quot; /&gt;
</span><span class="cx">                         &lt;/div&gt;&lt;!-- .menu-item-settings--&gt;
</span></span></pre></div>
<a id="trunkwpadminnavmenusphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/nav-menus.php (14449 => 14450)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/nav-menus.php        2010-05-04 19:34:38 UTC (rev 14449)
+++ trunk/wp-admin/nav-menus.php        2010-05-04 19:40:04 UTC (rev 14450)
</span><span class="lines">@@ -61,99 +61,165 @@
</span><span class="cx">         case 'move-down-menu-item' :
</span><span class="cx">                 // moving down a menu item is the same as moving up the next in order
</span><span class="cx">                 check_admin_referer( 'move-menu_item' );
</span><del>-                $menu_item_id = (int) $_REQUEST['menu-item'];
-                $next_item_id = 0;
</del><ins>+                $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
</ins><span class="cx">                 if ( is_nav_menu_item( $menu_item_id ) ) {
</span><span class="cx">                         $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' =&gt; 'ids' ) );
</span><del>-                        if ( ! is_wp_error( $menus ) ) {
-                                foreach( (array) $menus as $menu_id ) {
-                                        $move_down_ordered_menu_items = (array) wp_get_nav_menu_items( $menu_id );
-                                        while ( $next = array_shift( $move_down_ordered_menu_items ) ) {
-                                                if ( isset( $next-&gt;ID ) &amp;&amp; $next-&gt;ID == $menu_item_id ) {
-                                                        break;
</del><ins>+                        if ( ! is_wp_error( $menus ) &amp;&amp; ! empty( $menus[0] ) ) {
+                                $menu_id = (int) $menus[0];
+                                $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
+                                $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
+
+                                // setup the data we need in one pass through the array of menu items
+                                $dbids_to_orders = array();
+                                $orders_to_dbids = array();
+                                foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
+                                        if ( isset( $ordered_menu_item_object-&gt;ID ) ) {
+                                                if ( isset( $ordered_menu_item_object-&gt;menu_order ) ) {
+                                                        $dbids_to_orders[$ordered_menu_item_object-&gt;ID] = $ordered_menu_item_object-&gt;menu_order;
+                                                        $orders_to_dbids[$ordered_menu_item_object-&gt;menu_order] = $ordered_menu_item_object-&gt;ID;
</ins><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><ins>+                                }
</ins><span class="cx"> 
</span><del>-                                        if ( $following = array_shift( $move_down_ordered_menu_items ) ) {
-                                                $next_item_id = (int) $following-&gt;ID;
</del><ins>+                                // get next in order
+                                if ( 
+                                        isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] )
+                                ) {
+                                        $next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1];
+                                        $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
+
+                                        // if not siblings of same parent, bubble menu item up but keep order
+                                        if ( 
+                                                ! empty( $menu_item_data['menu_item_parent'] ) &amp;&amp;
+                                                (
+                                                        empty( $next_item_data['menu_item_parent'] ) ||
+                                                        $next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent']
+                                                )
+                                        ) {
+
+                                                $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
+        
+                                                $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
+
+                                                if ( ! is_wp_error( $parent_object ) ) {
+                                                        $parent_data = (array) $parent_object;
+                                                        $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];        
+                                                        update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
+
+                                                }
+
+                                        // make menu item a child of its next sibling
+                                        } else {
+                                                $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
+                                                $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;
+
+                                                $menu_item_data['menu_item_parent'] = $next_item_data['ID'];        
+                                                update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
+                                                
+                                                wp_update_post($menu_item_data);
+                                                wp_update_post($next_item_data);
</ins><span class="cx">                                         }
</span><ins>+                                        
+
+                                // the item is last but still has a parent, so bubble up
+                                } elseif ( 
+                                        ! empty( $menu_item_data['menu_item_parent'] ) &amp;&amp;
+                                        in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
+                                ) {
+                                        $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true);
+                                        update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
</ins><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                // fall through to next case
</del><ins>+
+                break;
</ins><span class="cx">         case 'move-up-menu-item' :
</span><span class="cx">                 check_admin_referer( 'move-menu_item' );
</span><del>-                $menu_item_id = empty( $next_item_id ) ? (int) $_REQUEST['menu-item'] : $next_item_id;
</del><ins>+                $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
</ins><span class="cx">                 if ( is_nav_menu_item( $menu_item_id ) ) {
</span><span class="cx">                         $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' =&gt; 'ids' ) );
</span><del>-                        if ( ! is_wp_error( $menus ) ) {
-                                foreach( (array) $menus as $menu_id ) {
-                                        $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
-                                        $menu_item_data = get_post( $menu_item_id , ARRAY_A );
</del><ins>+                        if ( ! is_wp_error( $menus ) &amp;&amp; ! empty( $menus[0] ) ) {
+                                $menu_id = (int) $menus[0];
+                                $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
+                                $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
</ins><span class="cx"> 
</span><del>-                                        // setup the data we need in one pass through the array of menu items
-                                        $dbids_to_orders = array();
-                                        $orders_to_dbids = array();
-                                        $objectids_to_dbids = array();
-                                        $dbids_to_objectids = array();
-                                        foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
-                                                if ( isset( $ordered_menu_item_object-&gt;ID ) ) {
-                                                        if ( isset( $ordered_menu_item_object-&gt;menu_order ) ) {
-                                                                $dbids_to_orders[$ordered_menu_item_object-&gt;ID] = $ordered_menu_item_object-&gt;menu_order;
-                                                                $orders_to_dbids[$ordered_menu_item_object-&gt;menu_order] = $ordered_menu_item_object-&gt;ID;
-                                                        }
-
-                                                        $possible_object_id = (int) get_post_meta( $ordered_menu_item_object-&gt;ID, '_menu_item_object_id', true );
-                                                        if ( ! empty( $possible_object_id ) ) {
-                                                                $dbids_to_objectids[$ordered_menu_item_object-&gt;ID] = $possible_object_id;
-                                                                $objectids_to_dbids[$possible_object_id] = $ordered_menu_item_object-&gt;ID;
-                                                        }
</del><ins>+                                // setup the data we need in one pass through the array of menu items
+                                $dbids_to_orders = array();
+                                $orders_to_dbids = array();
+                                foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
+                                        if ( isset( $ordered_menu_item_object-&gt;ID ) ) {
+                                                if ( isset( $ordered_menu_item_object-&gt;menu_order ) ) {
+                                                        $dbids_to_orders[$ordered_menu_item_object-&gt;ID] = $ordered_menu_item_object-&gt;menu_order;
+                                                        $orders_to_dbids[$ordered_menu_item_object-&gt;menu_order] = $ordered_menu_item_object-&gt;ID;
</ins><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><ins>+                                }
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-                                        // if this menu item is not first
-                                        if ( ! empty( $dbids_to_orders[$menu_item_id] ) &amp;&amp; ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {
</del><ins>+                                // if this menu item is not first
+                                if ( ! empty( $dbids_to_orders[$menu_item_id] ) &amp;&amp; ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {
</ins><span class="cx"> 
</span><del>-                                                // if this menu item is a child of the previous
-                                                if (
-                                                        ! empty( $menu_item_data['post_parent'] ) &amp;&amp;
-                                                        isset( $objectids_to_dbids[$menu_item_data['post_parent']] ) &amp;&amp;
-                                                        isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) &amp;&amp;
-                                                        ( $objectids_to_dbids[$menu_item_data['post_parent']] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] )
-                                                ) {
</del><ins>+                                        // if this menu item is a child of the previous
+                                        if (
+                                                ! empty( $menu_item_data['menu_item_parent'] ) &amp;&amp;
+                                                in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &amp;&amp;
+                                                isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) &amp;&amp;
+                                                ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] )
+                                        ) {
+                                                $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
+                                                $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
</ins><span class="cx"> 
</span><del>-                                                        $parent_db_id = $objectids_to_dbids[$menu_item_data['post_parent']];
-                                                        $parent_data = get_post( $parent_db_id, ARRAY_A );
</del><ins>+                                                if ( ! is_wp_error( $parent_object ) ) {
+                                                        $parent_data = (array) $parent_object;
</ins><span class="cx"> 
</span><del>-                                                        if ( ! is_wp_error( $parent_data ) ) {
</del><ins>+                                                        // if there is something before the parent and parent a child of it, make menu item a child also of it
+                                                        if ( 
+                                                                ! empty( $dbids_to_orders[$parent_db_id] ) &amp;&amp; 
+                                                                ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) &amp;&amp;
+                                                                ! empty( $parent_data['menu_item_parent'] )
+                                                        ) {
+                                                                $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
</ins><span class="cx"> 
</span><del>-                                                                // if there is something before the parent, make menu item a child of the parent's parent
-                                                                if ( ! empty( $dbids_to_orders[$parent_db_id] ) &amp;&amp; ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) ) {
-                                                                        $menu_item_data['post_parent'] = $parent_data['post_parent'];
</del><ins>+                                                        // else if there is something before parent and parent not a child of it, make menu item a child of that something's parent
+                                                        } elseif ( 
+                                                                ! empty( $dbids_to_orders[$parent_db_id] ) &amp;&amp; 
+                                                                ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] )
+                                                        ) {
+                                                                $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true);
+                                                                if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) )
+                                                                        $menu_item_data['menu_item_parent'] = $_possible_parent_id;
+                                                                else
+                                                                        $menu_item_data['menu_item_parent'] = 0;
</ins><span class="cx"> 
</span><del>-                                                                // else there isn't something before the parent
-                                                                } else {
-                                                                        $menu_item_data['post_parent'] = 0;
-                                                                }
</del><ins>+                                                        // else there isn't something before the parent
+                                                        } else {
+                                                                $menu_item_data['menu_item_parent'] = 0;
+                                                        }
</ins><span class="cx"> 
</span><del>-                                                                // set former parent's [menu_order] to that of menu-item's
-                                                                $parent_data['menu_order'] = $parent_data['menu_order'] + 1;
</del><ins>+                                                        // set former parent's [menu_order] to that of menu-item's
+                                                        $parent_data['menu_order'] = $parent_data['menu_order'] + 1;
</ins><span class="cx"> 
</span><del>-                                                                // set menu-item's [menu_order] to that of former parent
-                                                                $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
</del><ins>+                                                        // set menu-item's [menu_order] to that of former parent
+                                                        $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
</ins><span class="cx"> 
</span><del>-                                                                // save changes
-                                                                wp_update_post($menu_item_data);
-                                                                wp_update_post($parent_data);
-                                                        }
-
-                                                // else this menu item is not a child of the previous
-                                                } elseif ( isset($dbids_to_objectids[$orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]] ) ) {
-                                                        // just make it a child of the previous; keep the order
-                                                        $menu_item_data['post_parent'] = (int) $dbids_to_objectids[$orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]];
</del><ins>+                                                        // save changes
+                                                        update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
</ins><span class="cx">                                                         wp_update_post($menu_item_data);
</span><ins>+                                                        wp_update_post($parent_data);
</ins><span class="cx">                                                 }
</span><ins>+
+                                        // else this menu item is not a child of the previous
+                                        } elseif ( 
+                                                empty( $menu_item_data['menu_order'] ) ||
+                                                empty( $menu_item_data['menu_item_parent'] ) ||
+                                                ! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
+                                                empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ||
+                                                $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent']        
+                                        ) {
+                                                // just make it a child of the previous; keep the order
+                                                $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1];
+                                                update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
+                                                wp_update_post($menu_item_data);
</ins><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span></span></pre></div>
<a id="trunkwpincludesnavmenutemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/nav-menu-template.php (14449 => 14450)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/nav-menu-template.php        2010-05-04 19:34:38 UTC (rev 14449)
+++ trunk/wp-includes/nav-menu-template.php        2010-05-04 19:40:04 UTC (rev 14450)
</span><span class="lines">@@ -28,7 +28,7 @@
</span><span class="cx">          * @todo Decouple this.
</span><span class="cx">          * @var array
</span><span class="cx">          */
</span><del>-        var $db_fields = array( 'parent' =&gt; 'post_parent', 'id' =&gt; 'object_id' );
</del><ins>+        var $db_fields = array( 'parent' =&gt; 'menu_item_parent', 'id' =&gt; 'db_id' );
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * @see Walker::start_lvl()
</span><span class="lines">@@ -137,7 +137,6 @@
</span><span class="cx">                 $_nav_menu_placeholder = ( 0 &gt; $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
</span><span class="cx">                 $possible_object_id = isset( $item-&gt;post_type ) &amp;&amp; 'nav_menu_item' == $item-&gt;post_type ? $item-&gt;object_id : $_nav_menu_placeholder;
</span><span class="cx">                 $possible_db_id = ( ! empty( $item-&gt;ID ) ) &amp;&amp; ( 0 &lt; $possible_object_id ) ? (int) $item-&gt;ID : 0;
</span><del>-                $possible_parent_id = ( ! empty( $item-&gt;ID ) ) &amp;&amp; ( 0 &lt; $possible_object_id ) ? (int) $item-&gt;post_parent : 0;
</del><span class="cx"> 
</span><span class="cx">                 $indent = ( $depth ) ? str_repeat( &quot;\t&quot;, $depth ) : '';
</span><span class="cx"> 
</span><span class="lines">@@ -157,7 +156,7 @@
</span><span class="cx">                 // Menu item hidden fields
</span><span class="cx">                 $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-db-id&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-db-id]&quot; value=&quot;' . $possible_db_id . '&quot; /&gt;';
</span><span class="cx">                 $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-object&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-object]&quot; value=&quot;'. esc_attr( $item-&gt;object ) .'&quot; /&gt;';
</span><del>-                $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-parent-id&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-parent-id]&quot; value=&quot;'. $possible_parent_id .'&quot; /&gt;';
</del><ins>+                $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-parent-id&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-parent-id]&quot; value=&quot;'. esc_attr( $item-&gt;menu_item_parent ) .'&quot; /&gt;';
</ins><span class="cx">                 $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-type&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-type]&quot; value=&quot;'. esc_attr( $item-&gt;type ) .'&quot; /&gt;';
</span><span class="cx">                 $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-append&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-append]&quot; value=&quot;'. esc_attr( $item-&gt;append ) .'&quot; /&gt;';
</span><span class="cx">                 $output .= '&lt;input type=&quot;hidden&quot; class=&quot;menu-item-title&quot; name=&quot;menu-item[' . $possible_object_id . '][menu-item-title]&quot; value=&quot;'. esc_attr( $item-&gt;title ) .'&quot; /&gt;';
</span></span></pre></div>
<a id="trunkwpincludesnavmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/nav-menu.php (14449 => 14450)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/nav-menu.php        2010-05-04 19:34:38 UTC (rev 14449)
+++ trunk/wp-includes/nav-menu.php        2010-05-04 19:40:04 UTC (rev 14450)
</span><span class="lines">@@ -256,6 +256,8 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        $original_parent = 0 &lt; $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;
+
</ins><span class="cx">         if ( 'custom' != $args['menu-item-type'] ) {
</span><span class="cx">                 /* if non-custom menu item, then:
</span><span class="cx">                         * use original object's URL
</span><span class="lines">@@ -266,10 +268,12 @@
</span><span class="cx"> 
</span><span class="cx">                 $original_title = '';
</span><span class="cx">                 if ( 'taxonomy' == $args['menu-item-type'] ) {
</span><ins>+                        $original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
</ins><span class="cx">                         $original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
</span><span class="cx">                 } elseif ( 'post_type' == $args['menu-item-type'] ) {
</span><span class="cx"> 
</span><span class="cx">                         $original_object = get_post( $args['menu-item-object-id'] );
</span><ins>+                        $original_parent = (int) $original_object-&gt;post_parent;
</ins><span class="cx">                         $original_title = $original_object-&gt;post_title;
</span><span class="cx"> 
</span><span class="cx">                         if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) ) {
</span><span class="lines">@@ -297,7 +301,7 @@
</span><span class="cx">                 'ping_status' =&gt; 0,
</span><span class="cx">                 'post_content' =&gt; $args['menu-item-description'],
</span><span class="cx">                 'post_excerpt' =&gt; $args['menu-item-attr-title'],
</span><del>-                'post_parent' =&gt; $args['menu-item-parent-id'],
</del><ins>+                'post_parent' =&gt; $original_parent,
</ins><span class="cx">                 'post_title' =&gt; $args['menu-item-title'],
</span><span class="cx">                 'post_type' =&gt; 'nav_menu_item',
</span><span class="cx">                 'tax_input' =&gt; array( 'nav_menu' =&gt; $menu-&gt;name ),
</span><span class="lines">@@ -326,6 +330,7 @@
</span><span class="cx">                 $menu_item_db_id = (int) $menu_item_db_id;
</span><span class="cx"> 
</span><span class="cx">                 update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) );
</span><ins>+                update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', (int) $args['menu-item-parent-id'] );
</ins><span class="cx">                 update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $args['menu-item-object-id'] );
</span><span class="cx">                 update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );
</span><span class="cx">                 update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
</span><span class="lines">@@ -439,12 +444,13 @@
</span><span class="cx">  * Decorates a menu item object with the shared navigation menu item properties.
</span><span class="cx">  *
</span><span class="cx">  * Properties:
</span><del>- * - db_id:                 The DB ID of the this item as a nav_menu_item object, if it exists (0 if it doesn't exist).
</del><ins>+ * - db_id:                 The DB ID of this item as a nav_menu_item object, if it exists (0 if it doesn't exist).
</ins><span class="cx">  * - object_id:                The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.
</span><span class="cx">  * - type:                The family of objects originally represented, such as &quot;post_type&quot; or &quot;taxonomy.&quot;
</span><span class="cx">  * - object:                The type of object originally represented, such as &quot;category,&quot; &quot;post&quot;, or &quot;attachment.&quot;
</span><span class="cx">  * - append:                The singular label used to describe this type of menu item.
</span><del>- * - parent:                The DB ID of the original object's parent object, if any (0 otherwise).
</del><ins>+ * - post_parent:        The DB ID of the original object's parent object, if any (0 otherwise).
+ * - menu_item_parent:         The DB ID of the nav_menu_item that is this item's menu parent, if any.  0 otherwise.
</ins><span class="cx">  * - url:                The URL to which this menu item points.
</span><span class="cx">  * - title:                The title of this menu item.
</span><span class="cx">  * - target:                 The target attribute of the link element for this menu item.
</span><span class="lines">@@ -462,6 +468,7 @@
</span><span class="cx">         if ( isset( $menu_item-&gt;post_type ) ) {
</span><span class="cx">                 if ( 'nav_menu_item' == $menu_item-&gt;post_type ) {
</span><span class="cx">                         $menu_item-&gt;db_id = (int) $menu_item-&gt;ID;
</span><ins>+                        $menu_item-&gt;menu_item_parent = get_post_meta( $menu_item-&gt;ID, '_menu_item_menu_item_parent', true );
</ins><span class="cx">                         $menu_item-&gt;object_id = get_post_meta( $menu_item-&gt;ID, '_menu_item_object_id', true );
</span><span class="cx">                         $menu_item-&gt;object = get_post_meta( $menu_item-&gt;ID, '_menu_item_object', true );
</span><span class="cx">                         $menu_item-&gt;type = get_post_meta( $menu_item-&gt;ID, '_menu_item_type', true );
</span><span class="lines">@@ -498,6 +505,7 @@
</span><span class="cx">                         $menu_item-&gt;xfn = get_post_meta( $menu_item-&gt;ID, '_menu_item_xfn', true );
</span><span class="cx">                 } else {
</span><span class="cx">                         $menu_item-&gt;db_id = 0;
</span><ins>+                        $menu_item-&gt;menu_item_parent = 0;
</ins><span class="cx">                         $menu_item-&gt;object_id = (int) $menu_item-&gt;ID;
</span><span class="cx">                         $menu_item-&gt;type = 'post_type';
</span><span class="cx"> 
</span><span class="lines">@@ -517,6 +525,7 @@
</span><span class="cx">         } elseif ( isset( $menu_item-&gt;taxonomy ) ) {
</span><span class="cx">                 $menu_item-&gt;ID = $menu_item-&gt;term_id;
</span><span class="cx">                 $menu_item-&gt;db_id = 0;
</span><ins>+                $menu_item-&gt;menu_item_parent = 0;
</ins><span class="cx">                 $menu_item-&gt;object_id = (int) $menu_item-&gt;term_id;
</span><span class="cx">                 $menu_item-&gt;post_parent = (int) $menu_item-&gt;parent;
</span><span class="cx">                 $menu_item-&gt;type = 'taxonomy';
</span></span></pre>
</div>
</div>

</body>
</html>