<!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>[15105] trunk/wp-includes/nav-menu-template.php:
  Consolidate nav menu class assignments.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15105">15105</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-06-02 13:48:26 +0000 (Wed, 02 Jun 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Consolidate nav menu class assignments. Props filosofo. fixes <a href="http://trac.wordpress.org/ticket/13664">#13664</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 (15104 => 15105)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/nav-menu-template.php        2010-06-02 13:43:46 UTC (rev 15104)
+++ trunk/wp-includes/nav-menu-template.php        2010-06-02 13:48:26 UTC (rev 15105)
</span><span class="lines">@@ -68,38 +68,15 @@
</span><span class="cx">                 global $wp_query;
</span><span class="cx">                 $indent = ( $depth ) ? str_repeat( &quot;\t&quot;, $depth ) : '';
</span><span class="cx"> 
</span><del>-                $classes = $value = '';
</del><ins>+                $class_names = $value = '';
</ins><span class="cx"> 
</span><del>-                $classes = array( 'menu-item', 'menu-item-type-' . $item-&gt;type );
-                if ( !empty($item-&gt;classes) )
-                        $classes = array_merge( $classes, $item-&gt;classes );
</del><ins>+                $classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes;
</ins><span class="cx"> 
</span><del>-                if ( 'custom' != $item-&gt;type ) {
-                        $classes[] = 'menu-item-object-' . $item-&gt;object;
-                        $classes[] = 'menu-item-object-' . $item-&gt;type . '-' . $item-&gt;object_id;
-                        if ( 'post_type' == $item-&gt;type &amp;&amp; 'page' == $item-&gt;object ) {
-                                // Back compat classes for pages to match wp_page_menu()
-                                $classes[] = 'page_item';
-                                $classes[] = 'page-item-' . $item-&gt;object_id;
-                                if ( ! empty( $item-&gt;classes ) ) {
-                                        if ( in_array('current-menu-item', $classes) )
-                                                $classes[] = 'current_page_item';
-                                        if ( in_array('current-menu-parent', $classes) )
-                                                $classes[] = 'current_page_parent';
-                                        if ( in_array('current-menu-ancestor', $classes) )
-                                                $classes[] = 'current_page_ancestor';
-                                }
-                        }
-                } elseif ( 'custom' == $item-&gt;type &amp;&amp; in_array('current-menu-item', $classes) &amp;&amp; in_array('menu-item-home', $classes) ) {
-                        // Back compat for home limk to match wp_page_menu()
-                        $classes[] = 'current_page_item';
-                }
</del><ins>+                $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
+                $class_names = ' class=&quot;' . esc_attr( $class_names ) . '&quot;';
</ins><span class="cx"> 
</span><del>-                $classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
-                $classes = ' class=&quot;' . esc_attr( $classes ) . '&quot;';
</del><ins>+                $output .= $indent . '&lt;li id=&quot;menu-item-'. $item-&gt;ID . '&quot;' . $value . $class_names .'&gt;';
</ins><span class="cx"> 
</span><del>-                $output .= $indent . '&lt;li id=&quot;menu-item-'. $item-&gt;ID . '&quot;' . $value . $classes .'&gt;';
-
</del><span class="cx">                 $attributes  = ! empty( $item-&gt;attr_title ) ? ' title=&quot;'  . esc_attr( $item-&gt;attr_title ) .'&quot;' : '';
</span><span class="cx">                 $attributes .= ! empty( $item-&gt;target )     ? ' target=&quot;' . esc_attr( $item-&gt;target     ) .'&quot;' : '';
</span><span class="cx">                 $attributes .= ! empty( $item-&gt;xfn )        ? ' rel=&quot;'    . esc_attr( $item-&gt;xfn        ) .'&quot;' : '';
</span><span class="lines">@@ -286,6 +263,10 @@
</span><span class="cx">         $possible_object_parents = array_filter( $possible_object_parents );
</span><span class="cx"> 
</span><span class="cx">         foreach ( (array) $menu_items as $key =&gt; $menu_item ) {
</span><ins>+                $classes = (array) $menu_item-&gt;classes;
+                $classes[] = 'menu-item';
+                $classes[] = 'menu-item-type-' . $menu_item-&gt;type;
+
</ins><span class="cx">                 // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
</span><span class="cx">                 if ( $wp_query-&gt;is_singular &amp;&amp; 'taxonomy' == $menu_item-&gt;type &amp;&amp; in_array( $menu_item-&gt;object_id, $possible_object_parents ) ) {
</span><span class="cx">                         $active_parent_object_ids[] = (int) $menu_item-&gt;object_id;
</span><span class="lines">@@ -301,7 +282,13 @@
</span><span class="cx">                                 ( 'taxonomy' == $menu_item-&gt;type &amp;&amp; ( $wp_query-&gt;is_category || $wp_query-&gt;is_tag || $wp_query-&gt;is_tax ) )
</span><span class="cx">                         )
</span><span class="cx">                 ) {
</span><del>-                        $menu_items[$key]-&gt;classes[] = 'current-menu-item';
</del><ins>+                        $classes[] = 'current-menu-item';
+                        if ( 'post_type' == $menu_item-&gt;type &amp;&amp; 'page' == $menu_item-&gt;object ) {
+                                // Back compat classes for pages to match wp_page_menu()
+                                $classes[] = 'page_item';
+                                $classes[] = 'page-item-' . $menu_item-&gt;object_id;
+                                $classes[] = 'current_page_item';
+                        }
</ins><span class="cx">                         $active_parent_item_ids[] = (int) $menu_item-&gt;menu_item_parent;
</span><span class="cx">                         $active_parent_object_ids[] = (int) $menu_item-&gt;post_parent;
</span><span class="cx">                         $active_object = $menu_item-&gt;object;
</span><span class="lines">@@ -311,9 +298,12 @@
</span><span class="cx">                         $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
</span><span class="cx">                         $item_url = strpos( $menu_item-&gt;url, '#' ) ? substr( $menu_item-&gt;url, 0, strpos( $menu_item-&gt;url, '#' ) ) : $menu_item-&gt;url;
</span><span class="cx">                         if ( $item_url == $current_url ) {
</span><del>-                                $menu_items[$key]-&gt;classes[] = 'current-menu-item';
-                                if ( untrailingslashit($current_url) == home_url() )
-                                        $menu_items[$key]-&gt;classes[] = 'menu-item-home';
</del><ins>+                                $classes[] = 'current-menu-item';
+                                if ( untrailingslashit($current_url) == home_url() ) {
+                                        $classes[] = 'menu-item-home';
+                                        // Back compat for home limk to match wp_page_menu()
+                                        $classes[] = 'current_page_item';
+                                }
</ins><span class="cx">                                 $active_parent_item_ids[] = (int) $menu_item-&gt;menu_item_parent;
</span><span class="cx">                                 $active_parent_object_ids[] = (int) $menu_item-&gt;post_parent;
</span><span class="cx">                                 $active_object = $menu_item-&gt;object;
</span><span class="lines">@@ -322,7 +312,9 @@
</span><span class="cx">                 
</span><span class="cx">                 // back-compat with wp_page_menu: add &quot;current_page_parent&quot; to static home page link for any non-page query
</span><span class="cx">                 if ( ! empty( $home_page_id ) &amp;&amp; 'post_type' == $menu_item-&gt;type &amp;&amp; empty( $wp_query-&gt;is_page ) &amp;&amp; $home_page_id == $menu_item-&gt;object_id ) 
</span><del>-                        $menu_items[$key]-&gt;classes[] = 'current_page_parent';
</del><ins>+                        $classes[] = 'current_page_parent';
+
+                $menu_items[$key]-&gt;classes = array_unique( $classes );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) );
</span><span class="lines">@@ -330,18 +322,32 @@
</span><span class="cx"> 
</span><span class="cx">         // set parent's class
</span><span class="cx">         foreach ( (array) $menu_items as $key =&gt; $parent_item ) {
</span><ins>+                $classes = (array) $parent_item-&gt;classes;
+
</ins><span class="cx">                 if (
</span><span class="cx">                         isset( $parent_item-&gt;type ) &amp;&amp;
</span><span class="cx">                         'post_type' == $parent_item-&gt;type &amp;&amp;
</span><span class="cx">                         ! empty( $queried_object-&gt;post_type ) &amp;&amp;
</span><span class="cx">                         is_post_type_hierarchical( $queried_object-&gt;post_type ) &amp;&amp;
</span><span class="cx">                         in_array( $parent_item-&gt;object_id, $queried_object-&gt;ancestors )
</span><del>-                )
-                        $menu_items[$key]-&gt;classes[] = 'current-' . $queried_object-&gt;post_type . '-ancestor current-menu-ancestor';
</del><ins>+                ) {
+                        $classes[] = 'current-' . $queried_object-&gt;post_type . '-ancestor';
+                        $classes[] = 'current-menu-ancestor';
+                }
</ins><span class="cx">                 if ( in_array( $parent_item-&gt;db_id, $active_parent_item_ids ) )
</span><del>-                        $menu_items[$key]-&gt;classes[] = 'current-menu-parent';
</del><ins>+                        $classes[] = 'current-menu-parent';
</ins><span class="cx">                 if ( in_array( $parent_item-&gt;object_id, $active_parent_object_ids ) )
</span><del>-                        $menu_items[$key]-&gt;classes[] = 'current-' . $active_object . '-parent';
</del><ins>+                        $classes[] = 'current-' . $active_object . '-parent';
+                
+                if ( 'post_type' == $parent_item-&gt;type &amp;&amp; 'page' == $parent_item-&gt;object ) {
+                        // Back compat classes for pages to match wp_page_menu()
+                        if ( in_array('current-menu-parent', $classes) )
+                                $classes[] = 'current_page_parent';
+                        if ( in_array('current-menu-ancestor', $classes) )
+                                $classes[] = 'current_page_ancestor';
+                }
+                
+                $menu_items[$key]-&gt;classes = array_unique( $classes );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>