/wp-includes/nav-menu-template.php

  1. <?php 
  2. /** 
  3. * Nav Menu API: Template functions 
  4. * 
  5. * @package WordPress 
  6. * @subpackage Nav_Menus 
  7. * @since 3.0.0 
  8. */ 
  9.  
  10. /** Walker_Nav_Menu class */ 
  11. require_once ABSPATH . WPINC . '/class-walker-nav-menu.php'; 
  12.  
  13. /** 
  14. * Displays a navigation menu. 
  15. * 
  16. * @since 3.0.0 
  17. * @since 4.7.0 Added the `item_spacing` argument. 
  18. * 
  19. * @staticvar array $menu_id_slugs 
  20. * 
  21. * @param array $args { 
  22. * Optional. Array of nav menu arguments. 
  23. * 
  24. * @type int|string|WP_Term $menu Desired menu. Accepts (matching in order) id, slug, name, menu object. Default empty. 
  25. * @type string $menu_class CSS class to use for the ul element which forms the menu. Default 'menu'. 
  26. * @type string $menu_id The ID that is applied to the ul element which forms the menu. 
  27. * Default is the menu slug, incremented. 
  28. * @type string $container Whether to wrap the ul, and what to wrap it with. Default 'div'. 
  29. * @type string $container_class Class that is applied to the container. Default 'menu-{menu slug}-container'. 
  30. * @type string $container_id The ID that is applied to the container. Default empty. 
  31. * @type callable|bool $fallback_cb If the menu doesn't exists, a callback function will fire. 
  32. * Default is 'wp_page_menu'. Set to false for no fallback. 
  33. * @type string $before Text before the link markup. Default empty. 
  34. * @type string $after Text after the link markup. Default empty. 
  35. * @type string $link_before Text before the link text. Default empty. 
  36. * @type string $link_after Text after the link text. Default empty. 
  37. * @type bool $echo Whether to echo the menu or return it. Default true. 
  38. * @type int $depth How many levels of the hierarchy are to be included. 0 means all. Default 0. 
  39. * @type object $walker Instance of a custom walker class. Default empty. 
  40. * @type string $theme_location Theme location to be used. Must be registered with register_nav_menu() 
  41. * in order to be selectable by the user. 
  42. * @type string $items_wrap How the list items should be wrapped. Default is a ul with an id and class. 
  43. * Uses printf() format with numbered placeholders. 
  44. * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'preserve'. 
  45. * } 
  46. * @return object|false|void Menu output if $echo is false, false if there are no items or no menu was found. 
  47. */ 
  48. function wp_nav_menu( $args = array() ) { 
  49. static $menu_id_slugs = array(); 
  50.  
  51. $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',  
  52. '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>', 'item_spacing' => 'preserve',  
  53. 'depth' => 0, 'walker' => '', 'theme_location' => '' ); 
  54.  
  55. $args = wp_parse_args( $args, $defaults ); 
  56.  
  57. if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) { 
  58. // invalid value, fall back to default. 
  59. $args['item_spacing'] = $defaults['item_spacing']; 
  60.  
  61. /** 
  62. * Filters the arguments used to display a navigation menu. 
  63. * 
  64. * @since 3.0.0 
  65. * 
  66. * @see wp_nav_menu() 
  67. * 
  68. * @param array $args Array of wp_nav_menu() arguments. 
  69. */ 
  70. $args = apply_filters( 'wp_nav_menu_args', $args ); 
  71. $args = (object) $args; 
  72.  
  73. /** 
  74. * Filters whether to short-circuit the wp_nav_menu() output. 
  75. * 
  76. * Returning a non-null value to the filter will short-circuit 
  77. * wp_nav_menu(), echoing that value if $args->echo is true,  
  78. * returning that value otherwise. 
  79. * 
  80. * @since 3.9.0 
  81. * 
  82. * @see wp_nav_menu() 
  83. * 
  84. * @param string|null $output Nav menu output to short-circuit with. Default null. 
  85. * @param stdClass $args An object containing wp_nav_menu() arguments. 
  86. */ 
  87. $nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args ); 
  88.  
  89. if ( null !== $nav_menu ) { 
  90. if ( $args->echo ) { 
  91. echo $nav_menu; 
  92. return; 
  93.  
  94. return $nav_menu; 
  95.  
  96. // Get the nav menu based on the requested menu 
  97. $menu = wp_get_nav_menu_object( $args->menu ); 
  98.  
  99. // Get the nav menu based on the theme_location 
  100. if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) 
  101. $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); 
  102.  
  103. // get the first menu that has items if we still can't find a menu 
  104. if ( ! $menu && !$args->theme_location ) { 
  105. $menus = wp_get_nav_menus(); 
  106. foreach ( $menus as $menu_maybe ) { 
  107. if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { 
  108. $menu = $menu_maybe; 
  109. break; 
  110.  
  111. if ( empty( $args->menu ) ) { 
  112. $args->menu = $menu; 
  113.  
  114. // If the menu exists, get its items. 
  115. if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) 
  116. $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); 
  117.  
  118. /** 
  119. * If no menu was found: 
  120. * - Fall back (if one was specified), or bail. 
  121. * 
  122. * If no menu items were found: 
  123. * - Fall back, but only if no theme location was specified. 
  124. * - Otherwise, bail. 
  125. */ 
  126. if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) 
  127. && isset( $args->fallback_cb ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) 
  128. return call_user_func( $args->fallback_cb, (array) $args ); 
  129.  
  130. if ( ! $menu || is_wp_error( $menu ) ) 
  131. return false; 
  132.  
  133. $nav_menu = $items = ''; 
  134.  
  135. $show_container = false; 
  136. if ( $args->container ) { 
  137. /** 
  138. * Filters the list of HTML tags that are valid for use as menu containers. 
  139. * 
  140. * @since 3.0.0 
  141. * 
  142. * @param array $tags The acceptable HTML tags for use as menu containers. 
  143. * Default is array containing 'div' and 'nav'. 
  144. */ 
  145. $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); 
  146. if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags ) ) { 
  147. $show_container = true; 
  148. $class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"'; 
  149. $id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : ''; 
  150. $nav_menu .= '<'. $args->container . $id . $class . '>'; 
  151.  
  152. // Set up the $menu_item variables 
  153. _wp_menu_item_classes_by_context( $menu_items ); 
  154.  
  155. $sorted_menu_items = $menu_items_with_children = array(); 
  156. foreach ( (array) $menu_items as $menu_item ) { 
  157. $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; 
  158. if ( $menu_item->menu_item_parent ) 
  159. $menu_items_with_children[ $menu_item->menu_item_parent ] = true; 
  160.  
  161. // Add the menu-item-has-children class where applicable 
  162. if ( $menu_items_with_children ) { 
  163. foreach ( $sorted_menu_items as &$menu_item ) { 
  164. if ( isset( $menu_items_with_children[ $menu_item->ID ] ) ) 
  165. $menu_item->classes[] = 'menu-item-has-children'; 
  166.  
  167. unset( $menu_items, $menu_item ); 
  168.  
  169. /** 
  170. * Filters the sorted list of menu item objects before generating the menu's HTML. 
  171. * 
  172. * @since 3.1.0 
  173. * 
  174. * @param array $sorted_menu_items The menu items, sorted by each menu item's menu order. 
  175. * @param stdClass $args An object containing wp_nav_menu() arguments. 
  176. */ 
  177. $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); 
  178.  
  179. $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args ); 
  180. unset($sorted_menu_items); 
  181.  
  182. // Attributes 
  183. if ( ! empty( $args->menu_id ) ) { 
  184. $wrap_id = $args->menu_id; 
  185. } else { 
  186. $wrap_id = 'menu-' . $menu->slug; 
  187. while ( in_array( $wrap_id, $menu_id_slugs ) ) { 
  188. if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) 
  189. $wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id ); 
  190. else 
  191. $wrap_id = $wrap_id . '-1'; 
  192. $menu_id_slugs[] = $wrap_id; 
  193.  
  194. $wrap_class = $args->menu_class ? $args->menu_class : ''; 
  195.  
  196. /** 
  197. * Filters the HTML list content for navigation menus. 
  198. * 
  199. * @since 3.0.0 
  200. * 
  201. * @see wp_nav_menu() 
  202. * 
  203. * @param string $items The HTML list content for the menu items. 
  204. * @param stdClass $args An object containing wp_nav_menu() arguments. 
  205. */ 
  206. $items = apply_filters( 'wp_nav_menu_items', $items, $args ); 
  207. /** 
  208. * Filters the HTML list content for a specific navigation menu. 
  209. * 
  210. * @since 3.0.0 
  211. * 
  212. * @see wp_nav_menu() 
  213. * 
  214. * @param string $items The HTML list content for the menu items. 
  215. * @param stdClass $args An object containing wp_nav_menu() arguments. 
  216. */ 
  217. $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); 
  218.  
  219. // Don't print any markup if there are no items at this point. 
  220. if ( empty( $items ) ) 
  221. return false; 
  222.  
  223. $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); 
  224. unset( $items ); 
  225.  
  226. if ( $show_container ) 
  227. $nav_menu .= '</' . $args->container . '>'; 
  228.  
  229. /** 
  230. * Filters the HTML content for navigation menus. 
  231. * 
  232. * @since 3.0.0 
  233. * 
  234. * @see wp_nav_menu() 
  235. * 
  236. * @param string $nav_menu The HTML content for the navigation menu. 
  237. * @param stdClass $args An object containing wp_nav_menu() arguments. 
  238. */ 
  239. $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); 
  240.  
  241. if ( $args->echo ) 
  242. echo $nav_menu; 
  243. else 
  244. return $nav_menu; 
  245.  
  246. /** 
  247. * Add the class property classes for the current context, if applicable. 
  248. * 
  249. * @access private 
  250. * @since 3.0.0 
  251. * 
  252. * @global WP_Query $wp_query 
  253. * @global WP_Rewrite $wp_rewrite 
  254. * 
  255. * @param array $menu_items The current menu item objects to which to add the class property information. 
  256. */ 
  257. function _wp_menu_item_classes_by_context( &$menu_items ) { 
  258. global $wp_query, $wp_rewrite; 
  259.  
  260. $queried_object = $wp_query->get_queried_object(); 
  261. $queried_object_id = (int) $wp_query->queried_object_id; 
  262.  
  263. $active_object = ''; 
  264. $active_ancestor_item_ids = array(); 
  265. $active_parent_item_ids = array(); 
  266. $active_parent_object_ids = array(); 
  267. $possible_taxonomy_ancestors = array(); 
  268. $possible_object_parents = array(); 
  269. $home_page_id = (int) get_option( 'page_for_posts' ); 
  270.  
  271. if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) { 
  272. foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) { 
  273. if ( is_taxonomy_hierarchical( $taxonomy ) ) { 
  274. $term_hierarchy = _get_term_hierarchy( $taxonomy ); 
  275. $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) ); 
  276. if ( is_array( $terms ) ) { 
  277. $possible_object_parents = array_merge( $possible_object_parents, $terms ); 
  278. $term_to_ancestor = array(); 
  279. foreach ( (array) $term_hierarchy as $anc => $descs ) { 
  280. foreach ( (array) $descs as $desc ) 
  281. $term_to_ancestor[ $desc ] = $anc; 
  282.  
  283. foreach ( $terms as $desc ) { 
  284. do { 
  285. $possible_taxonomy_ancestors[ $taxonomy ][] = $desc; 
  286. if ( isset( $term_to_ancestor[ $desc ] ) ) { 
  287. $_desc = $term_to_ancestor[ $desc ]; 
  288. unset( $term_to_ancestor[ $desc ] ); 
  289. $desc = $_desc; 
  290. } else { 
  291. $desc = 0; 
  292. } while ( ! empty( $desc ) ); 
  293. } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { 
  294. $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); 
  295. $term_to_ancestor = array(); 
  296. foreach ( (array) $term_hierarchy as $anc => $descs ) { 
  297. foreach ( (array) $descs as $desc ) 
  298. $term_to_ancestor[ $desc ] = $anc; 
  299. $desc = $queried_object->term_id; 
  300. do { 
  301. $possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc; 
  302. if ( isset( $term_to_ancestor[ $desc ] ) ) { 
  303. $_desc = $term_to_ancestor[ $desc ]; 
  304. unset( $term_to_ancestor[ $desc ] ); 
  305. $desc = $_desc; 
  306. } else { 
  307. $desc = 0; 
  308. } while ( ! empty( $desc ) ); 
  309.  
  310. $possible_object_parents = array_filter( $possible_object_parents ); 
  311.  
  312. $front_page_url = home_url(); 
  313. $front_page_id = (int) get_option( 'page_on_front' ); 
  314.  
  315. foreach ( (array) $menu_items as $key => $menu_item ) { 
  316.  
  317. $menu_items[$key]->current = false; 
  318.  
  319. $classes = (array) $menu_item->classes; 
  320. $classes[] = 'menu-item'; 
  321. $classes[] = 'menu-item-type-' . $menu_item->type; 
  322. $classes[] = 'menu-item-object-' . $menu_item->object; 
  323.  
  324. // This menu item is set as the 'Front Page'. 
  325. if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) { 
  326. $classes[] = 'menu-item-home'; 
  327.  
  328. // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object 
  329. if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { 
  330. $active_parent_object_ids[] = (int) $menu_item->object_id; 
  331. $active_parent_item_ids[] = (int) $menu_item->db_id; 
  332. $active_object = $queried_object->post_type; 
  333.  
  334. // if the menu item corresponds to the currently-queried post or taxonomy object 
  335. } elseif ( 
  336. $menu_item->object_id == $queried_object_id && 
  337. ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || 
  338. ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || 
  339. ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object ) 
  340. ) { 
  341. $classes[] = 'current-menu-item'; 
  342. $menu_items[$key]->current = true; 
  343. $_anc_id = (int) $menu_item->db_id; 
  344.  
  345. while( 
  346. ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && 
  347. ! in_array( $_anc_id, $active_ancestor_item_ids ) 
  348. ) { 
  349. $active_ancestor_item_ids[] = $_anc_id; 
  350.  
  351. if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) { 
  352. // Back compat classes for pages to match wp_page_menu() 
  353. $classes[] = 'page_item'; 
  354. $classes[] = 'page-item-' . $menu_item->object_id; 
  355. $classes[] = 'current_page_item'; 
  356.  
  357. $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; 
  358. $active_parent_object_ids[] = (int) $menu_item->post_parent; 
  359. $active_object = $menu_item->object; 
  360.  
  361. // if the menu item corresponds to the currently-queried post type archive 
  362. } elseif ( 
  363. 'post_type_archive' == $menu_item->type && 
  364. is_post_type_archive( array( $menu_item->object ) ) 
  365. ) { 
  366. $classes[] = 'current-menu-item'; 
  367. $menu_items[$key]->current = true; 
  368. // if the menu item corresponds to the currently-requested URL 
  369. } elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) { 
  370. $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); 
  371. $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current ); 
  372. $raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; 
  373. $item_url = set_url_scheme( untrailingslashit( $raw_item_url ) ); 
  374. $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) ); 
  375.  
  376. if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { 
  377. $classes[] = 'current-menu-item'; 
  378. $menu_items[$key]->current = true; 
  379. $_anc_id = (int) $menu_item->db_id; 
  380.  
  381. while( 
  382. ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && 
  383. ! in_array( $_anc_id, $active_ancestor_item_ids ) 
  384. ) { 
  385. $active_ancestor_item_ids[] = $_anc_id; 
  386.  
  387. if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) { 
  388. // Back compat for home link to match wp_page_menu() 
  389. $classes[] = 'current_page_item'; 
  390. $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; 
  391. $active_parent_object_ids[] = (int) $menu_item->post_parent; 
  392. $active_object = $menu_item->object; 
  393.  
  394. // give front page item current-menu-item class when extra query arguments involved 
  395. } elseif ( $item_url == $front_page_url && is_front_page() ) { 
  396. $classes[] = 'current-menu-item'; 
  397.  
  398. if ( untrailingslashit($item_url) == home_url() ) 
  399. $classes[] = 'menu-item-home'; 
  400.  
  401. // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query 
  402. if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ) 
  403. $classes[] = 'current_page_parent'; 
  404.  
  405. $menu_items[$key]->classes = array_unique( $classes ); 
  406. $active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) ); 
  407. $active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) ); 
  408. $active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) ); 
  409.  
  410. // set parent's class 
  411. foreach ( (array) $menu_items as $key => $parent_item ) { 
  412. $classes = (array) $parent_item->classes; 
  413. $menu_items[$key]->current_item_ancestor = false; 
  414. $menu_items[$key]->current_item_parent = false; 
  415.  
  416. if ( 
  417. isset( $parent_item->type ) && 
  418. // ancestral post object 
  419. 'post_type' == $parent_item->type && 
  420. ! empty( $queried_object->post_type ) && 
  421. is_post_type_hierarchical( $queried_object->post_type ) && 
  422. in_array( $parent_item->object_id, $queried_object->ancestors ) && 
  423. $parent_item->object != $queried_object->ID 
  424. ) || 
  425.  
  426. // ancestral term 
  427. 'taxonomy' == $parent_item->type && 
  428. isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) && 
  429. in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) && 
  430. ! isset( $queried_object->term_id ) || 
  431. $parent_item->object_id != $queried_object->term_id 
  432. ) { 
  433. $classes[] = empty( $queried_object->taxonomy ) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor'; 
  434.  
  435. if ( in_array( intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) { 
  436. $classes[] = 'current-menu-ancestor'; 
  437. $menu_items[$key]->current_item_ancestor = true; 
  438. if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) { 
  439. $classes[] = 'current-menu-parent'; 
  440. $menu_items[$key]->current_item_parent = true; 
  441. if ( in_array( $parent_item->object_id, $active_parent_object_ids ) ) 
  442. $classes[] = 'current-' . $active_object . '-parent'; 
  443.  
  444. if ( 'post_type' == $parent_item->type && 'page' == $parent_item->object ) { 
  445. // Back compat classes for pages to match wp_page_menu() 
  446. if ( in_array('current-menu-parent', $classes) ) 
  447. $classes[] = 'current_page_parent'; 
  448. if ( in_array('current-menu-ancestor', $classes) ) 
  449. $classes[] = 'current_page_ancestor'; 
  450.  
  451. $menu_items[$key]->classes = array_unique( $classes ); 
  452.  
  453. /** 
  454. * Retrieve the HTML list content for nav menu items. 
  455. * 
  456. * @uses Walker_Nav_Menu to create HTML list content. 
  457. * @since 3.0.0 
  458. * 
  459. * @param array $items The menu items, sorted by each menu item's menu order. 
  460. * @param int $depth Depth of the item in reference to parents. 
  461. * @param stdClass $r An object containing wp_nav_menu() arguments. 
  462. * @return string The HTML list content for the menu items. 
  463. */ 
  464. function walk_nav_menu_tree( $items, $depth, $r ) { 
  465. $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; 
  466. $args = array( $items, $depth, $r ); 
  467.  
  468. return call_user_func_array( array( $walker, 'walk' ), $args ); 
  469.  
  470. /** 
  471. * Prevents a menu item ID from being used more than once. 
  472. * 
  473. * @since 3.0.1 
  474. * @access private 
  475. * 
  476. * @staticvar array $used_ids 
  477. * @param string $id 
  478. * @param object $item 
  479. * @return string 
  480. */ 
  481. function _nav_menu_item_id_use_once( $id, $item ) { 
  482. static $_used_ids = array(); 
  483. if ( in_array( $item->ID, $_used_ids ) ) { 
  484. return ''; 
  485. $_used_ids[] = $item->ID; 
  486. return $id; 
.