Changeset 14031 for trunk/wp-includes/nav-menu-template.php
- Timestamp:
- 04/07/2010 03:25:48 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/nav-menu-template.php
r14013 r14031 23 23 * link_after - Text after the link. 24 24 * echo - Whether to echo the menu or return it. Defaults to echo. 25 * show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link. 25 * 26 * @todo show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link. 26 27 * 27 28 * @since 3.0.0 … … 32 33 $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true, 33 34 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 34 'depth' => 0, 'walker' => '' );35 'depth' => 0, 'walker' => '', 'context' => 'frontend' ); 35 36 36 37 $args = wp_parse_args( $args, $defaults ); … … 52 53 } 53 54 } 54 55 if ( $menu && ! is_wp_error( $menu ) ) 56 $args->menu = $menu->term_id; 57 $nav_menu = ''; 58 59 if ( 'div' == $args->container ) { 60 $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ''; 61 62 if ( is_nav_menu($menu) ) { 63 $nav_menu .= '<div id="menu-' . $menu->slug . '"'. $class .'>'; 64 } else { 65 $nav_menu .= '<div'. $class .'>'; 66 } 67 } 68 69 $nav_menu .= wp_get_nav_menu( $args ); 70 71 if ( 'div' == $args->container ) 72 $nav_menu .= '</div>'; 73 74 $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); 75 76 if ( $args->echo ) 77 echo $nav_menu; 78 else 79 return $nav_menu; 80 } 81 82 /** 83 * Returns a Navigation Menu. 84 * 85 * See wp_nav_menu() for args. 86 * 87 * @since 3.0.0 88 * 89 * @param array $args Arguments 90 * @return mixed $output False if menu doesn't exists, else, returns the menu. 91 **/ 92 function wp_get_nav_menu( $args = array() ) { 93 $defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend', 'depth' => 0, 94 'fallback_cb' => '', 'walker' => '', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', ); 95 96 $args = wp_parse_args( $args, $defaults ); 97 $args = apply_filters( 'wp_get_nav_menu_args', $args ); 98 $args = (object) $args; 99 100 // Variable setup 101 $nav_menu = ''; 102 $items = ''; 103 104 // Get the menu object 105 $menu = wp_get_nav_menu_object( $args->menu ); 106 55 107 56 // If the menu exists, get it's items. 108 57 if ( $menu && !is_wp_error($menu) ) … … 111 60 // If no menu was found or if the menu has no items, call the fallback_cb 112 61 if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) { 113 if ( function_exists($args->fallback_cb) || is_callable( $args->fallback_cb ) ) { 114 $_args = array_merge( (array) $args, array('echo' => false) ); 115 return call_user_func( $args->fallback_cb, $_args ); 62 if ( 'frontend' == $args->context && ( function_exists($args->fallback_cb) || is_callable( $args->fallback_cb ) ) ) { 63 return call_user_func( $args->fallback_cb, (array) $args ); 116 64 } 65 } 66 67 $nav_menu = ''; 68 $items = ''; 69 $container_allowedtags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'p', 'nav' ) ); 70 71 if ( in_array( $args->container, $container_allowedtags ) ) { 72 $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-'. $menu->slug .'-container"'; 73 $nav_menu .= '<'. $args->container . $class .'>'; 117 74 } 118 75 … … 123 80 $items .= walk_nav_menu_tree( $menu_items, $args->depth, $args ); 124 81 125 // CSS class 126 $ul_class = $args->menu_class ? ' class="'. $args->menu_class .'"' : ''; 127 $nav_menu .= '<ul'. $ul_class .'>'; 82 // Attributes 83 $attributes = ' id="menu-' . $menu->slug . '"'; 84 $attributes .= $args->menu_class ? ' class="'. $args->menu_class .'"' : ''; 85 86 $nav_menu .= '<ul'. $attributes .'>'; 128 87 129 88 // Allow plugins to hook into the menu to add their own <li>'s … … 138 97 $nav_menu .= '</ul>'; 139 98 140 return apply_filters( 'wp_get_nav_menu', $nav_menu ); 99 if ( in_array( $args->container, $container_allowedtags ) ) 100 $nav_menu .= '</'. $args->container .'>'; 101 102 $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); 103 104 if ( $args->echo ) 105 echo $nav_menu; 106 else 107 return $nav_menu; 141 108 } 142 109 … … 162 129 $output .= $args->before; 163 130 $output .= '<a'. $attributes .'>'; 164 $output .= $args->link_before . apply_filters( 'the_title', $menu_item->title) . $args->link_after;131 $output .= $args->link_before . apply_filters( 'the_title', $menu_item->title ) . $args->link_after; 165 132 $output .= '</a>'; 166 133 $output .= $args->after; … … 219 186 } 220 187 221 return $output;188 return apply_filters( 'wp_get_nav_menu_item', $output, $context, $args ); 222 189 } 223 190 ?>
Note: See TracChangeset
for help on using the changeset viewer.