<!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>[15113] trunk/wp-includes/nav-menu-template.php: Add menu_id to wp_nav_menu
() and move container_id to the container.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15113">15113</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-06-02 17:04:07 +0000 (Wed, 02 Jun 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add menu_id to wp_nav_menu() and move container_id to the container. Set the container arg to false to not use a container. fixes <a href="http://trac.wordpress.org/ticket/13669">#13669</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesnavmenutemplatephp">trunk/wp-includes/nav-menu-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesnavmenutemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/nav-menu-template.php (15112 => 15113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/nav-menu-template.php        2010-06-02 16:31:42 UTC (rev 15112)
+++ trunk/wp-includes/nav-menu-template.php        2010-06-02 17:04:07 UTC (rev 15113)
</span><span class="lines">@@ -110,10 +110,11 @@
</span><span class="cx"> * Optional $args contents:
</span><span class="cx"> *
</span><span class="cx"> * menu - The menu that is desired. Accepts (matching in order) id, slug, name. Defaults to blank.
</span><del>- * menu_class - CSS class to use for the ul container of the menu list. Defaults to 'menu'.
</del><ins>+ * menu_class - CSS class to use for the ul element which forms the menu. Defaults to 'menu'.
+ * menu_id - The ID that is applied to the ul element which forms the menu. Defaults to the menu slug, incremented.
</ins><span class="cx"> * container - Whether to wrap the ul, and what to wrap it with. Defaults to 'div'.
</span><del>- * container_class - the class that is applied to the container. Defaults to blank.
- * container_id - The ID that is applied to the container. Defaults to the menu slug, incremented.
</del><ins>+ * container_class - the class that is applied to the container. Defaults to 'menu-{menu slug}-container'.
+ * container_id - The ID that is applied to the container. Defaults to blank.
</ins><span class="cx"> * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'.
</span><span class="cx"> * before - Text before the link text.
</span><span class="cx"> * after - Text after the link text.
</span><span class="lines">@@ -129,8 +130,9 @@
</span><span class="cx"> * @param array $args Arguments
</span><span class="cx"> */
</span><span class="cx"> function wp_nav_menu( $args = array() ) {
</span><del>-        global $_wp_nav_menu_slugs;
-        $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu',
</del><ins>+        static $menu_id_slugs = array();
+
+        $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',
</ins><span class="cx">         'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
</span><span class="cx">         'depth' => 0, 'walker' => '', 'theme_location' => '' );
</span><span class="cx">
</span><span class="lines">@@ -169,13 +171,17 @@
</span><span class="cx">         if ( !$menu || is_wp_error($menu) )
</span><span class="cx">                 return false;
</span><span class="cx">
</span><del>-        $nav_menu = '';
-        $items = '';
-        $container_allowedtags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
</del><ins>+        $nav_menu = $items = '';
</ins><span class="cx">
</span><del>-        if ( in_array( $args->container, $container_allowedtags ) ) {
-                $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-'. $menu->slug .'-container"';
-                $nav_menu .= '<'. $args->container . $class .'>';
</del><ins>+        $show_container = false;
+        if ( $args->container ) {
+                $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
+                if ( in_array( $args->container, $allowed_tags ) ) {
+                        $show_container = true;
+                        $class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"';
+                        $id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
+                        $nav_menu .= '<'. $args->container . $id . $class . '>';
+                }
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         // Set up the $menu_item variables
</span><span class="lines">@@ -191,20 +197,19 @@
</span><span class="cx">         unset($sorted_menu_items);
</span><span class="cx">
</span><span class="cx">         // Attributes
</span><del>-        $slug = 'menu-' . $menu->slug;
-        if ( ! is_array( $_wp_nav_menu_slugs ) )
-                $_wp_nav_menu_slugs = array();
-
-        while ( in_array( $slug, $_wp_nav_menu_slugs ) ) {
-                if ( preg_match( '#-(\d+)$#', $slug, $matches ) )
-                        $slug = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $slug);
-                else
-                        $slug = $slug . '-1';
</del><ins>+        if ( ! empty( $args->menu_id ) ) {
+                $slug = $args->menu_id;
+        } else {
+                $slug = 'menu-' . $menu->slug;
+                while ( in_array( $slug, $menu_id_slugs ) ) {
+                        if ( preg_match( '#-(\d+)$#', $slug, $matches ) )
+                                $slug = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $slug);
+                        else
+                                $slug = $slug . '-1';
+                }
</ins><span class="cx">         }
</span><del>-        
-        $_wp_nav_menu_slugs[] = $slug;
-                
-        $attributes = ' id="' . ( empty( $args->container_id ) ? $slug : $args->container_id ) . '"';
</del><ins>+        $menu_id_slugs[] = $slug;
+        $attributes = ' id="' . $slug . '"';
</ins><span class="cx">         $attributes .= $args->menu_class ? ' class="'. $args->menu_class .'"' : '';
</span><span class="cx">
</span><span class="cx">         $nav_menu .= '<ul'. $attributes .'>';
</span><span class="lines">@@ -217,8 +222,8 @@
</span><span class="cx">
</span><span class="cx">         $nav_menu .= '</ul>';
</span><span class="cx">
</span><del>-        if ( in_array( $args->container, $container_allowedtags ) )
-                $nav_menu .= '</'. $args->container .'>';
</del><ins>+        if ( $show_container )
+                $nav_menu .= '</' . $args->container . '>';
</ins><span class="cx">
</span><span class="cx">         $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>