Changes from branches/3.0/wp-includes/nav-menu-template.php at r15408 to trunk/wp-includes/nav-menu-template.php at r17228
- File:
-
- 1 edited
-
trunk/wp-includes/nav-menu-template.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/nav-menu-template.php
r15408 r17228 74 74 $classes[] = 'menu-item-' . $item->ID; 75 75 76 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );76 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); 77 77 $class_names = ' class="' . esc_attr( $class_names ) . '"'; 78 78 … … 120 120 * container_class - the class that is applied to the container. Defaults to 'menu-{menu slug}-container'. 121 121 * container_id - The ID that is applied to the container. Defaults to blank. 122 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'. 122 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'. Set to false for no fallback. 123 123 * before - Text before the link text. 124 124 * after - Text after the link text. … … 129 129 * walker - allows a custom walker to be specified. 130 130 * theme_location - the location in the theme to be used. Must be registered with register_nav_menu() in order to be selectable by the user. 131 * items_wrap - How the list items should be wrapped. Defaults to a ul with an id and class. Uses printf() format with numbered placeholders. 131 132 * 132 133 * @since 3.0.0 … … 138 139 139 140 $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 140 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 141 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 141 142 'depth' => 0, 'walker' => '', 'theme_location' => '' ); 142 143 … … 169 170 // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists 170 171 if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) 171 && ( function_exists($args->fallback_cb) || is_callable( $args->fallback_cb )) )172 && $args->fallback_cb && is_callable( $args->fallback_cb ) ) 172 173 return call_user_func( $args->fallback_cb, (array) $args ); 173 174 … … 198 199 unset($menu_items); 199 200 201 $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); 202 200 203 $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args ); 201 204 unset($sorted_menu_items); … … 203 206 // Attributes 204 207 if ( ! empty( $args->menu_id ) ) { 205 $ slug= $args->menu_id;208 $wrap_id = $args->menu_id; 206 209 } else { 207 $ slug= 'menu-' . $menu->slug;208 while ( in_array( $ slug, $menu_id_slugs ) ) {209 if ( preg_match( '#-(\d+)$#', $ slug, $matches ) )210 $ slug = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $slug);210 $wrap_id = 'menu-' . $menu->slug; 211 while ( in_array( $wrap_id, $menu_id_slugs ) ) { 212 if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) 213 $wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id ); 211 214 else 212 $slug = $slug . '-1'; 213 } 214 } 215 $menu_id_slugs[] = $slug; 216 $attributes = ' id="' . $slug . '"'; 217 $attributes .= $args->menu_class ? ' class="'. $args->menu_class .'"' : ''; 218 219 $nav_menu .= '<ul'. $attributes .'>'; 215 $wrap_id = $wrap_id . '-1'; 216 } 217 } 218 $menu_id_slugs[] = $wrap_id; 219 220 $wrap_class = $args->menu_class ? $args->menu_class : ''; 220 221 221 222 // Allow plugins to hook into the menu to add their own <li>'s 222 223 $items = apply_filters( 'wp_nav_menu_items', $items, $args ); 223 224 $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); 224 $nav_menu .= $items; 225 unset($items); 226 227 $nav_menu .= '</ul>'; 225 226 $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); 227 unset( $items ); 228 228 229 229 if ( $show_container ) … … 312 312 $possible_object_parents = array_filter( $possible_object_parents ); 313 313 314 $front_page_url = home_url(); 315 314 316 foreach ( (array) $menu_items as $key => $menu_item ) { 317 318 $menu_items[$key]->current = false; 319 315 320 $classes = (array) $menu_item->classes; 316 321 $classes[] = 'menu-item'; 317 322 $classes[] = 'menu-item-type-' . $menu_item->type; 323 $classes[] = 'menu-item-object-' . $menu_item->object; 318 324 319 325 // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object … … 333 339 ) { 334 340 $classes[] = 'current-menu-item'; 341 $menu_items[$key]->current = true; 335 342 $_anc_id = (int) $menu_item->db_id; 336 343 … … 354 361 // if the menu item corresponds to the currently-requested URL 355 362 } elseif ( 'custom' == $menu_item->object ) { 356 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];357 $item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;358 $_indexless_current = preg_replace( '/index.php$/', '', $current_url);359 363 $current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 364 $item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url ); 365 $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); 366 360 367 if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) { 361 368 $classes[] = 'current-menu-item'; 369 $menu_items[$key]->current = true; 362 370 $_anc_id = (int) $menu_item->db_id; 363 371 … … 370 378 371 379 if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) { 372 // Back compat for home li mk to match wp_page_menu()380 // Back compat for home link to match wp_page_menu() 373 381 $classes[] = 'current_page_item'; 374 382 } … … 376 384 $active_parent_object_ids[] = (int) $menu_item->post_parent; 377 385 $active_object = $menu_item->object; 378 } 379 386 387 // give front page item current-menu-item class when extra query arguments involved 388 } elseif ( $item_url == $front_page_url && is_front_page() ) { 389 $classes[] = 'current-menu-item'; 390 } 391 380 392 if ( untrailingslashit($item_url) == home_url() ) 381 393 $classes[] = 'menu-item-home'; … … 395 407 foreach ( (array) $menu_items as $key => $parent_item ) { 396 408 $classes = (array) $parent_item->classes; 409 $menu_items[$key]->current_item_ancestor = false; 410 $menu_items[$key]->current_item_parent = false; 397 411 398 412 if ( … … 404 418 ! empty( $queried_object->post_type ) && 405 419 is_post_type_hierarchical( $queried_object->post_type ) && 406 in_array( $parent_item->object_id, $queried_object->ancestors ) 420 in_array( $parent_item->object_id, $queried_object->ancestors ) && 421 $parent_item->object != $queried_object->ID 407 422 ) || 408 423 … … 411 426 'taxonomy' == $parent_item->type && 412 427 isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) && 413 in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) 428 in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) && 429 ( 430 ! isset( $queried_object->term_id ) || 431 $parent_item->object_id != $queried_object->term_id 432 ) 414 433 ) 415 434 ) … … 420 439 if ( in_array( intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) { 421 440 $classes[] = 'current-menu-ancestor'; 422 } 423 if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) 441 $menu_items[$key]->current_item_ancestor = true; 442 } 443 if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) { 424 444 $classes[] = 'current-menu-parent'; 445 $menu_items[$key]->current_item_parent = true; 446 } 425 447 if ( in_array( $parent_item->object_id, $active_parent_object_ids ) ) 426 448 $classes[] = 'current-' . $active_object . '-parent'; … … 466 488 } 467 489 add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); 468 469 ?>
Note: See TracChangeset
for help on using the changeset viewer.