Ticket #12896: nav_menu_bug_fixes.diff
File nav_menu_bug_fixes.diff, 11.0 KB (added by , 15 years ago) |
---|
-
wp-includes/nav-menu-template.php
22 22 * link_before - Text before the link. 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.26 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. 27 * 27 28 * @since 3.0.0 28 29 * 29 30 * @param array $args Arguments … … 31 32 function wp_nav_menu( $args = array() ) { 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 ); 37 38 $args = apply_filters( 'wp_nav_menu_args', $args ); … … 51 52 } 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) ) 109 58 $menu_items = wp_get_nav_menu_items( $menu->term_id, $args->context ); 110 59 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 } 117 65 } 66 67 $nav_menu = ''; 68 $items = ''; 69 $container_allowedtags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'p', 'nav' ) ); 118 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 .'>'; 74 } 75 119 76 // Set up the $menu_item variables 120 77 foreach ( (array) $menu_items as $key => $menu_item ) 121 78 $menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item( $menu_item, 'frontend' ); 122 79 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 130 89 if ( 'frontend' == $args->context ) { … … 137 96 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 143 110 /** … … 161 128 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; 167 134 … … 218 185 break; 219 186 } 220 187 221 return $output;188 return apply_filters( 'wp_get_nav_menu_item', $output, $context, $args ); 222 189 } 223 190 ?> 191 No newline at end of file -
wp-includes/classes.php
1178 1178 * @param object $item Menu item data object. 1179 1179 * @param int $depth Depth of menu item. Used for padding. 1180 1180 * @param int $current_page Menu item ID. 1181 * @param array$args1181 * @param object $args 1182 1182 */ 1183 1183 function start_el(&$output, $item, $depth, $args) { 1184 1184 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; … … 1217 1217 function end_el(&$output, $item, $depth) { 1218 1218 $output .= "</li>\n"; 1219 1219 } 1220 1221 1220 } 1222 1221 1223 1222 /** -
wp-includes/nav-menu.php
178 178 $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; 179 179 $args = array( $items, $depth, $r ); 180 180 181 return call_user_func_array( array(&$walker, 'walk'), $args);181 return call_user_func_array( array(&$walker, 'walk'), $args ); 182 182 } 183 183 184 184 /** … … 202 202 if ( 'post_type' == $menu_item->type ) { 203 203 $object = get_post_type_object( $menu_item->object ); 204 204 $menu_item->append = $object->singular_label; 205 $menu_item->url = get_permalink( $menu_item->object_id ); 205 206 206 207 } elseif ( 'taxonomy' == $menu_item->type ) { 207 208 $object = get_taxonomy( $menu_item->object ); 208 209 $menu_item->append = $object->singular_label; 210 $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); 209 211 210 212 } else { 211 213 $menu_item->append = __('Custom'); 214 $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); 212 215 } 213 216 214 217 $menu_item->title = $menu_item->post_title; 215 $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );216 218 $menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true ); 217 219 218 220 $menu_item->attr_title = strip_tags( $menu_item->post_excerpt ); … … 221 223 $menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true ); 222 224 $menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true ); 223 225 break; 224 226 225 227 case 'custom': 226 228 $menu_item->db_id = 0; 227 229 $menu_item->object_id = (int) $menu_item->ID; … … 235 237 $menu_item->title = $menu_item->post_title; 236 238 $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); 237 239 $menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true ); 238 $menu_item->classes = '';239 $menu_item->xfn = '';240 $menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_target', true ); 241 $menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true ); 240 242 break; 241 243 242 244 case 'post_type': … … 273 275 $menu_item->url = get_term_link( $menu_item, $menu_item_object ); 274 276 $menu_item->target = ''; 275 277 $menu_item->attr_title = ''; 276 $menu_item->description = strip_tags( $menu_item->description );278 $menu_item->description = ''; 277 279 $menu_item->classes = ''; 278 280 $menu_item->xfn = ''; 279 281 break; 280 282 } 281 return $menu_item; 283 284 return apply_filters( 'wp_setup_nav_menu_item', $menu_item, $menu_item_type, $menu_item_object ); 282 285 } 283 ?> 286 ?> 287 No newline at end of file -
wp-content/themes/twentyten/style.css
113 113 h3#comments-title, 114 114 h3#reply-title, 115 115 #access .menu, 116 #access div.menu ul, 116 117 #cancel-comment-reply-link, 117 118 .form-allowed-tags, 118 119 #site-info, … … 153 154 154 155 /* The main theme structure */ 155 156 #access .menu-header, 157 div.menu, 156 158 #colophon, 157 159 #branding, 158 160 #main, … … 360 362 display:block; 361 363 float:left; 362 364 } 363 #access .menu-header {365 #access .menu-header, div.menu { 364 366 font-size: 13px; 365 367 margin-left: 12px; 366 368 } 367 #access .menu-header ul {369 #access .menu-header ul, div.menu ul { 368 370 list-style: none; 369 371 margin: 0; 370 372 } 371 #access .menu-header li {373 #access .menu-header li, div.menu li { 372 374 float:left; 373 375 position: relative; 374 376 } -
wp-admin/includes/nav-menu.php
55 55 56 56 foreach ( $post_types as $post_type ) { 57 57 $id = $post_type->name; 58 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type );58 add_meta_box( "add-{$id}", sprintf( __('Add %s'), $post_type->label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type ); 59 59 } 60 60 } 61 61 … … 72 72 73 73 foreach ( $taxonomies as $tax ) { 74 74 $id = $tax->name; 75 76 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax ); 75 add_meta_box( "add-{$id}", sprintf( __('Add %s'), $tax->label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax ); 77 76 } 78 77 } 79 78 -
wp-admin/nav-menus.php
274 274 <div id="menu-container" class="postbox"> 275 275 <h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3> 276 276 <div class="inside"> 277 <?php echo wp_get_nav_menu( array( 'context' => 'backend', 'menu' => $nav_menu_selected_id) ); ?>277 <?php wp_nav_menu( array( 'menu' => $nav_menu_selected_id, 'context' => 'backend' ) ); ?> 278 278 </div><!-- /.inside --> 279 279 <!-- /#nav-menu-canvas .postbox--> 280 280 </div>