<!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>[13284] trunk:
Use nav_menu as the taxonomy name and nav_menu_item as the post type.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13284">13284</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-21 18:24:41 +0000 (Sun, 21 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use nav_menu as the taxonomy name and nav_menu_item as the post type. Set object_id in postmeta. see <a href="http://trac.wordpress.org/ticket/11817">#11817</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustomnavigationphp">trunk/wp-admin/custom-navigation.php</a></li>
<li><a href="#trunkwpincludescustomnavigationphp">trunk/wp-includes/custom-navigation.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludestaxonomyphp">trunk/wp-includes/taxonomy.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustomnavigationphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-navigation.php (13283 => 13284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-navigation.php        2010-02-21 11:21:32 UTC (rev 13283)
+++ trunk/wp-admin/custom-navigation.php        2010-02-21 18:24:41 UTC (rev 13284)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx">                 $menu_selected_id = 0;
</span><span class="cx">
</span><span class="cx">         // Default Menu to show
</span><del>-        $custom_menus = get_terms( 'menu', array( 'hide_empty' => false ) );
</del><ins>+        $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
</ins><span class="cx">         if ( !empty( $custom_menus ) )
</span><span class="cx">                 $menu_selected_id = $custom_menus[0]->term_id;
</span><span class="cx">
</span><span class="lines">@@ -94,13 +94,13 @@
</span><span class="cx">                  $insert_menu_name = $_POST['add_menu_name'];
</span><span class="cx">
</span><span class="cx">                  if ( $insert_menu_name != '' ) {
</span><del>-                        $existing_term = get_term_by( 'name', $insert_menu_name, 'menu' );
</del><ins>+                        $existing_term = get_term_by( 'name', $insert_menu_name, 'nav_menu' );
</ins><span class="cx">                          if ( $existing_term ) {
</span><del>-                                 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . $insert_menu_name . ' Menu has already created - please try another name</p></div>';
</del><ins>+                                 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . $existing_term->name . ' Menu has already created - please try another name</p></div>';
</ins><span class="cx">                          } else {
</span><del>-                                $term = wp_insert_term( $insert_menu_name, 'menu' );
</del><ins>+                                $term = wp_insert_term( $insert_menu_name, 'nav_menu' );
</ins><span class="cx">                                 if ( !is_wp_error($term) ) {
</span><del>-                                        $term = get_term($term['term_id'], 'menu');
</del><ins>+                                        $term = get_term($term['term_id'], 'nav_menu');
</ins><span class="cx">                                         $custom_menus[$term->term_id] = $term;
</span><span class="cx">                                          $menu_selected_id = $term->term_id;
</span><span class="cx">                                          $menu_id_in_edit = $menu_selected_id;
</span><span class="lines">@@ -127,13 +127,13 @@
</span><span class="cx">                         $messagesdiv = '<div id="message" class="error fade below-h2"><p>'.$themename.'s Custom Menu could not be RESET. Please try again.</p></div>';
</span><span class="cx">          }
</span><span class="cx">         } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
</span><del>-                $menu_objects = get_objects_in_term( $menu_selected_id, 'menu' );
</del><ins>+                $menu_objects = get_objects_in_term( $menu_selected_id, 'nav_menu' );
</ins><span class="cx">                 $menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
</span><span class="cx">
</span><span class="cx">                 // Loop through all POST variables
</span><span class="cx">                 for ( $k = 1; $k <= $postCounter; $k++ ) {
</span><span class="cx">                         if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; }
</span><del>-                         if (isset($_POST['postmenu'.$k])) { $post_id = $_POST['postmenu'.$k]; } else { $post_id = 0; }
</del><ins>+                         if (isset($_POST['postmenu'.$k])) { $object_id = $_POST['postmenu'.$k]; } else { $object_id = 0; }
</ins><span class="cx">                         //@todo implement heirarchy
</span><span class="cx">                         if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; }
</span><span class="cx">                         if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; }
</span><span class="lines">@@ -146,9 +146,9 @@
</span><span class="cx">                         if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; }
</span><span class="cx">                         if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; }
</span><span class="cx">
</span><del>-                        $post = array( 'post_status' => 'publish', 'post_type' => 'menu_item', 'post_author' => $user_ID,
-                                'ping_status' => 0, 'post_parent' => $post_id, 'menu_order' => $position,
-                                'guid' => $custom_linkurl, 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'menu' => $menu_title ),
</del><ins>+                        $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
+                                'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position,
+                                'guid' => $custom_linkurl, 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ),
</ins><span class="cx">                                 'post_content' => $custom_description, 'post_title' => $custom_title );
</span><span class="cx">                         if ( $new_window )
</span><span class="cx">                                 $post['post_content_filtered'] = '_blank';
</span><span class="lines">@@ -157,13 +157,14 @@
</span><span class="cx">
</span><span class="cx">                         // New menu item
</span><span class="cx">                          if ( $db_id == 0 ) {
</span><del>-                                $db_id = $post_id = wp_insert_post( $post );
</del><ins>+                                $db_id = wp_insert_post( $post );
</ins><span class="cx">                         } elseif ( isset( $menu_items[$db_id] ) ) {
</span><span class="cx">                                 $post['ID'] = $db_id;
</span><span class="cx">                                 wp_update_post( $post );
</span><span class="cx">                                 unset( $menu_items[$db_id] );
</span><span class="cx">                         }
</span><span class="cx">                         update_post_meta($db_id, 'menu_type', $linktype);
</span><ins>+                        update_post_meta($db_id, 'object_id', $object_id);
</ins><span class="cx">                 }
</span><span class="cx">                 if ( !empty( $menu_items ) ) {
</span><span class="cx">                         foreach ( array_keys( $menu_items ) as $menu_id ) {
</span><span class="lines">@@ -280,8 +281,8 @@
</span><span class="cx">                                                 <?php
</span><span class="cx">
</span><span class="cx">                                                 //DISPLAY SELECT OPTIONS
</span><del>-                                                foreach( $custom_menus as $menu ) {
-                                                        $menu_term = get_term( $menu, 'menu' );
</del><ins>+                                                foreach ( $custom_menus as $menu ) {
+                                                        $menu_term = get_term( $menu, 'nav_menu' );
</ins><span class="cx">                                                         if ( ( $menu_id_in_edit == $menu->term_id ) || ( $menu_selected_id == $menu->term_id ) )
</span><span class="cx">                                                                 $selected_option = 'selected="selected"';
</span><span class="cx">                                                         else
</span></span></pre></div>
<a id="trunkwpincludescustomnavigationphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/custom-navigation.php (13283 => 13284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/custom-navigation.php        2010-02-21 11:21:32 UTC (rev 13283)
+++ trunk/wp-includes/custom-navigation.php        2010-02-21 18:24:41 UTC (rev 13284)
</span><span class="lines">@@ -13,7 +13,7 @@
</span><span class="cx"> function wp_custom_navigation_get_menu_items( $menu_objects, $key = 'ID' ) {
</span><span class="cx">         $menu_items = array();
</span><span class="cx">         if ( !empty( $menu_objects ) && !empty( $key ) ) {
</span><del>-                $args = array( 'orderby' => 'menu_order', 'post_type' => 'menu_item', 'post_status' => 'publish' );
</del><ins>+                $args = array( 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish' );
</ins><span class="cx">                 if ( count( $menu_objects ) > 1 )
</span><span class="cx">                         $args['include'] = implode( ',', $menu_objects );
</span><span class="cx">                 else
</span><span class="lines">@@ -49,15 +49,15 @@
</span><span class="cx">         if(($nav_version_in_db <> $nav_version) || ($override))
</span><span class="cx">                 update_option('wp_settings_custom_nav_version',$nav_version);
</span><span class="cx">
</span><del>-        $custom_menus = get_terms( 'menu', array( 'hide_empty' => false ) );
</del><ins>+        $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
</ins><span class="cx">         if ( !empty( $custom_menus ) ) {
</span><span class="cx">                 foreach( $custom_menus as $menu ) {
</span><del>-                        $menu_objects = get_objects_in_term( $menu->term_id, 'menu' );
</del><ins>+                        $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
</ins><span class="cx">                         if ( !empty( $menu_objects ) ) {
</span><span class="cx">                                 foreach( $menu_objects as $item )
</span><span class="cx">                                         wp_delete_post( $item );
</span><span class="cx">                         }
</span><del>-                        wp_delete_term( $menu->term_id, 'menu' );
</del><ins>+                        wp_delete_term( $menu->term_id, 'nav_menu' );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -101,35 +101,34 @@
</span><span class="cx">                         extract($args);
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                $menu_objects = get_objects_in_term( $id, 'menu' );
</del><ins>+                $menu_objects = get_objects_in_term( $id, 'nav_menu' );
</ins><span class="cx">                 $menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' );
</span><span class="cx">                 //Override for menu descriptions
</span><span class="cx">                 $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options');
</span><del>-                if ($advanced_option_descriptions == 'no')
-                {
</del><ins>+                if ( $advanced_option_descriptions == 'no' )
</ins><span class="cx">                         $desc = 2;
</span><del>-                }
</del><span class="cx">
</span><span class="cx">                 $queried_id = 0;
</span><span class="cx">                 global $wp_query;
</span><span class="cx">                 if ( is_page() )
</span><del>-                        $queried_id = $wp_query->post->ID;
</del><ins>+                        $queried_id = $wp_query->get_queried_object_id();
</ins><span class="cx">                 elseif ( is_category() )
</span><del>-                        $queried_id = $wp_query->query_vars['cat'];
-         //DISPLAY Loop
-                foreach ($menu_items as $menu_item) {
-
-                        //PREPARE Menu Data
-                        //Page Menu Item
-                        switch ( $menu_item->post_status ) {
-                                case 'menu-page':
-                                        if ($menu_item->guid == '')
-                                                $link = get_permalink( $menu_item->post_parent );
</del><ins>+                        $queried_id = $wp_query->get_queried_object_id();
+         // Display Loop
+                foreach ( $menu_items as $menu_item ) {
+                        $menu_type = get_post_meta($menu_item->ID, 'menu_type', true);
+                        $object_id = get_post_meta($menu_item->ID, 'object_id', true);
+                        
+                        switch ( $menu_type ) {
+                                // Page Menu Item
+                                case 'page':
+                                        if ( $menu_item->guid == '' )
+                                                $link = get_permalink( $object_id );
</ins><span class="cx">                                         else
</span><span class="cx">                                                 $link = $menu_item->guid;
</span><span class="cx">
</span><span class="cx">                                         if ( $menu_item->post_title == '' )
</span><del>-                                                $title = htmlentities( get_the_title( $menu_item->post_parent ) );
</del><ins>+                                                $title = htmlentities( get_the_title( $object_id ) );
</ins><span class="cx">                                         else
</span><span class="cx">                                                 $title = htmlentities( $menu_item->post_title );
</span><span class="cx">
</span><span class="lines">@@ -139,28 +138,28 @@
</span><span class="cx">                                                 $description = htmlentities( $menu_item->post_content );
</span><span class="cx">                                         $target = '';
</span><span class="cx">                                 break;
</span><del>-                        //Category Menu Item
-                                case 'menu-category':
-                                        if ($menu_item->guid == '')
-                                                $link = get_category_link( $menu_item->post_parent );
</del><ins>+                                // Category Menu Item
+                                case 'category':
+                                        if ( $menu_item->guid == '' )
+                                                $link = get_category_link( $object_id );
</ins><span class="cx">                                         else
</span><span class="cx">                                                 $link = $menu_item->guid;
</span><span class="cx">
</span><span class="cx">                                         if ( $menu_item->post_title == '' ) {
</span><del>-                                                $title_raw = get_categories( 'include='.$menu_item->post_parent );
</del><ins>+                                                $title_raw = get_categories( array('include' => $object_id) );
</ins><span class="cx">                                                 $title = htmlentities($title_raw[0]->cat_name);
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 $title = htmlentities( $menu_item->post_title );
</span><span class="cx">                                         }
</span><span class="cx">
</span><span class="cx">                                         if ( $menu_item->post_content == '' )
</span><del>-                                                $description = htmlentities( strip_tags( category_description( $menu_item->post_parent ) ) );
</del><ins>+                                                $description = htmlentities( strip_tags( category_description( $object_id ) ) );
</ins><span class="cx">                                         else
</span><span class="cx">                                                 $description = htmlentities( $menu_item->post_content );
</span><span class="cx">                                         $target = '';
</span><span class="cx">                                 break;
</span><span class="cx">                                 default:
</span><del>-                        //Custom Menu Item
</del><ins>+                                        // Custom Menu Item
</ins><span class="cx">                                         $link = $menu_item->guid;
</span><span class="cx">                                         $title = htmlentities( $menu_item->post_title );
</span><span class="cx">                                         $description = htmlentities( $menu_item->post_content );
</span><span class="lines">@@ -192,16 +191,14 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx"> */
</span><del>-                        //List Items
</del><ins>+                        // List Items
</ins><span class="cx">                         ?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $li_class; ?>><?php
</span><span class="cx">                                         //@todo: update front end to use post data
</span><span class="cx">                                         //FRONTEND Link
</span><del>-                                        if ($type == "frontend")
-                                        {
</del><ins>+                                        if ( $type == 'frontend' ) {
</ins><span class="cx">                                                 ?><a title="<?php echo $anchor_title; ?>" href="<?php echo $link; ?>" <?php echo $target; ?>><?php echo $before_title.$title.$after_title; ?><?php
</span><span class="cx">
</span><del>-                                                        if ( $advanced_option_descriptions == 'no' )
-                                                        {
</del><ins>+                                                        if ( $advanced_option_descriptions == 'no' ) {
</ins><span class="cx">                                                                 // 2 widget override do NOT display descriptions
</span><span class="cx">                                                                 // 1 widget override display descriptions
</span><span class="cx">                                                                 // 0 widget override not set
</span><span class="lines">@@ -213,14 +210,11 @@
</span><span class="cx">                                                                 { }
</span><span class="cx">                                                                 else
</span><span class="cx">                                                                 { }
</span><del>-                                                        }
-                                                        else
-                                                        {
</del><ins>+                                                        } else {
</ins><span class="cx">                                                                 // 2 widget override do NOT display descriptions
</span><span class="cx">                                                                 // 1 widget override display descriptions
</span><span class="cx">                                                                 // 0 widget override not set
</span><del>-                                                                if ($desc == 1)
-                                                                {
</del><ins>+                                                                if ( $desc == 1 ) {
</ins><span class="cx">                                                                         ?><span class="nav-description"><?php echo $description; ?></span><?php
</span><span class="cx">                                                                 }
</span><span class="cx">                                                                 elseif (($desc == 2) || ($desc == 0))
</span><span class="lines">@@ -230,11 +224,9 @@
</span><span class="cx">                                                         }
</span><span class="cx">
</span><span class="cx">                                                 ?></a><?php
</span><del>-                                        }
-                                        //BACKEND draggable and droppable elements
-                                        elseif ($type == "backend")
-                                                $link_type = substr( $menu_item->post_status, 5 );
-                                        {
</del><ins>+                                        } elseif ( $type == 'backend' ) {
+                                                //BACKEND draggable and droppable elements
+                                                $link_type = $menu_type;
</ins><span class="cx">                                                 ?>
</span><span class="cx">
</span><span class="cx">                                                 <dl>
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (13283 => 13284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-02-21 11:21:32 UTC (rev 13283)
+++ trunk/wp-includes/post.php        2010-02-21 18:24:41 UTC (rev 13284)
</span><span class="lines">@@ -63,14 +63,14 @@
</span><span class="cx">                                                                                         'query_var' => false,
</span><span class="cx">                                                                                 ) );
</span><span class="cx">
</span><del>-        register_post_type( 'menu_item', array(        'public' => false,
-                                                                                        'show_ui' => false,
-                                                                                        '_builtin' => true,
-                                                                                        'capability_type' => 'post',
-                                                                                        'hierarchical' => false,
-                                                                                        'rewrite' => false,
-                                                                                        'query_var' => false,
-                                                                                ) );
</del><ins>+        register_post_type( 'nav_menu_item', array(        'public' => false,
+                                                                                                'show_ui' => false,
+                                                                                                '_builtin' => true,
+                                                                                                'capability_type' => 'post',
+                                                                                                'hierarchical' => false,
+                                                                                                'rewrite' => false,
+                                                                                                'query_var' => false,
+                                                                                        ) );
</ins><span class="cx">
</span><span class="cx">         register_post_status( 'publish', array(        'label' => _x('Published', 'post'),
</span><span class="cx">                                                                                         'public' => true,
</span></span></pre></div>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (13283 => 13284)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2010-02-21 11:21:32 UTC (rev 13283)
+++ trunk/wp-includes/taxonomy.php        2010-02-21 18:24:41 UTC (rev 13284)
</span><span class="lines">@@ -38,11 +38,11 @@
</span><span class="cx">                                                                                                         '_builtin' => true
</span><span class="cx">                                                                                                 ) ) ;
</span><span class="cx">
</span><del>-        register_taxonomy( 'menu', 'menu_item', array(        'hierarchical' => false,
-                                                                                                        'query_var' => false,
-                                                                                                        'rewrite' => false,
-                                                                                                        'show_ui' => false,
-                                                                                        ) ) ;
</del><ins>+        register_taxonomy( 'nav_menu', 'nav_menu_item', array(        'hierarchical' => false,
+                                                                                                                'query_var' => false,
+                                                                                                                'rewrite' => false,
+                                                                                                                'show_ui' => false,
+                                                                                                        ) ) ;
</ins><span class="cx">
</span><span class="cx">         register_taxonomy( 'link_category', 'link', array(        'hierarchical' => false,
</span><span class="cx">                                                                                                                  'label' => __('Categories'),
</span></span></pre>
</div>
</div>
</body>
</html>