Changes in trunk/wp-admin/nav-menus.php [15010:15219]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/nav-menus.php
r15010 r15219 16 16 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); 17 17 18 if ( ! current_theme_supports( ' nav-menus' ) && ! current_theme_supports( 'widgets' ) )18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) 19 19 wp_die( __( 'Your theme does not support navigation menus or widgets.' ) ); 20 20 … … 56 56 check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' ); 57 57 if ( isset( $_REQUEST['nav-menu-locations'] ) ) 58 set_theme_mod( 'nav_menu_locations', $_REQUEST['menu-locations']);58 set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) ); 59 59 elseif ( isset( $_REQUEST['menu-item'] ) ) 60 60 wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] ); … … 234 234 235 235 236 if ( is_nav_menu_item( $menu_item_id ) ) { 237 if ( wp_delete_post( $menu_item_id, true ) ) { 238 239 $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; 240 } 241 } 236 if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) 237 $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; 242 238 break; 243 239 case 'delete': … … 251 247 $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>'; 252 248 } else { 249 // Remove this menu from any locations. 250 $locations = get_theme_mod( 'nav_menu_locations' ); 251 foreach ( (array) $locations as $location => $menu_id ) { 252 if ( $menu_id == $nav_menu_selected_id ) 253 $locations[ $location ] = 0; 254 } 255 set_theme_mod( 'nav_menu_locations', $locations ); 253 256 $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>'; 254 257 // Select the next available menu … … 276 279 // Update menu theme locations 277 280 if ( isset( $_POST['menu-locations'] ) ) 278 set_theme_mod( 'nav_menu_locations', $_POST['menu-locations']);281 set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); 279 282 280 283 // Add Menu 281 284 if ( 0 == $nav_menu_selected_id ) { 282 $new_menu_title = esc_html( $_POST['menu-name']);285 $new_menu_title = trim( esc_html( $_POST['menu-name'] ) ); 283 286 284 287 if ( $new_menu_title ) { … … 305 308 $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); 306 309 310 $menu_title = trim( esc_html( $_POST['menu-name'] ) ); 311 if ( ! $menu_title ) { 312 $messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; 313 $menu_title = $_menu_object->name; 314 } 315 307 316 if ( ! is_wp_error( $_menu_object ) ) { 308 $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $ _POST['menu-name']) );317 $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) ); 309 318 if ( is_wp_error( $_nav_menu_selected_id ) ) { 310 319 $_menu_object = $_nav_menu_selected_id; … … 319 328 320 329 if ( ! is_wp_error( $_menu_object ) ) { 321 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,p ublish') );330 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,pending,publish') ); 322 331 $menu_items = array(); 323 332 // Index menu items by db ID … … 325 334 $menu_items[$_item->db_id] = $_item; 326 335 327 $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item- target', 'menu-item-classes', 'menu-item-xfn' );336 $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-status', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ); 328 337 wp_defer_term_counting(true); 329 338 // Loop through all the menu items' POST variables … … 422 431 } 423 432 424 // The theme supports menus 425 if ( current_theme_supports('nav-menus') ) { 426 // Set up nav menu 427 wp_nav_menu_setup(); 428 429 // The theme does not support menus but supports widgets 430 } elseif ( current_theme_supports('widgets') ) { 431 // Set up nav menu 432 wp_nav_menu_setup(); 433 $messages[] = '<div id="message" class="error"><p>' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p></div>'; 433 // Ensure the user will be able to scroll horizontally 434 // by adding a class for the max menu depth. 435 global $_wp_nav_menu_max_depth; 436 $_wp_nav_menu_max_depth = 0; 437 438 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth 439 if ( is_nav_menu( $nav_menu_selected_id ) ) 440 $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id ); 441 442 function wp_nav_menu_max_depth() { 443 global $_wp_nav_menu_max_depth; 444 return "menu-max-depth-$_wp_nav_menu_max_depth"; 434 445 } 435 446 447 add_action('admin_body_class','wp_nav_menu_max_depth'); 448 449 wp_nav_menu_setup(); 436 450 wp_initial_nav_menu_meta_boxes(); 437 451 438 $help = '<p>' . __('This feature is new in version 3.0; to use a custom menu in place of your theme’s default menus, support for this feature must be registered in the theme’s functions.php file. If your theme does not support the custom menus feature yet (the new default theme Twenty Ten, does), you can learn about adding support yourself by following the below link.') . '</p>'; 452 if ( ! current_theme_supports( 'menus' ) && ! wp_get_nav_menus() ) 453 echo '<div id="message" class="updated"><p>' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p></div>'; 454 455 $help = '<p>' . __('This feature is new in version 3.0; to use a custom menu in place of your theme’s default menus, support for this feature must be registered in the theme’s functions.php file. If your theme does not support the custom menus feature yet (the new default theme, Twenty Ten, does), you can learn about adding support yourself by following the below link.') . '</p>'; 439 456 $help .= '<p>' . __('You can create custom menus for your site. These menus may contain links to pages, categories, custom links or other content types (use the Screen Options tab to decide which ones to show on the screen). You can specify a different navigation label for a menu item as well as other attributes. You can create multiple menus. If your theme includes more than one menu, you can choose which custom menu to associate with each. You can also use custom menus in conjunction with the Custom Menus widget.') . '</p>'; 440 457 $help .= '<p>' . __('To create a new custom menu, click on the + tab, give the menu a name, and click Create Menu. Next, add menu items from the appropriate boxes. You’ll be able to edit the information for each menu item, and can drag and drop to put them in order. You can also drag a menu item a little to the right to make it a submenu, to create menus with hierarchy. You’ll see when the position of the drop target shifts over to create the nested placement. Don’t forget to click Save when you’re finished.') . '</p>'; 441 $help .= '<p><strong>' . __('For more information:') . '</strong></p>'; 442 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Menus_SubPanel" >Menus Documentation</a>') . '</p>';443 $help .= '<p>' . __('<a href="http://wordpress.org/support/" >Support Forums</a>') . '</p>';458 $help .= '<p><strong>' . __('For more information:') . '</strong></p>'; 459 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Menus_SubPanel" target="_blank">Menus Documentation</a>') . '</p>'; 460 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'; 444 461 445 462 add_contextual_help($current_screen, $help); … … 457 474 ?> 458 475 <div id="nav-menus-frame"> 459 <div id="menu-settings-column" class="metabox-holder ">476 <div id="menu-settings-column" class="metabox-holder<?php if ( !$nav_menu_selected_id ) { echo ' metabox-holder-disabled'; } ?>"> 460 477 461 478 <form id="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-menu-meta" method="post" enctype="multipart/form-data"> … … 563 580 <div id="post-body"> 564 581 <div id="post-body-content"> 565 <?php if ( is_nav_menu( $nav_menu_selected_id ) ) : ?> 566 <ul class="menu" id="menu-to-edit"> 567 <?php 568 $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id ); 569 if ( ! is_wp_error( $edit_markup ) ) { 582 <?php 583 if ( isset( $edit_markup ) ) { 584 if ( ! is_wp_error( $edit_markup ) ) 570 585 echo $edit_markup; 571 } 572 ?> 573 </ul> 574 <?php elseif ( empty($nav_menu_selected_id) ): 586 } else if ( empty( $nav_menu_selected_id ) ) { 575 587 echo '<div class="post-body-plain">'; 576 588 echo '<p>' . __('To create a custom menu, give it a name above and click Create Menu. Then choose items like pages, categories or custom links from the left column to add to this menu.') . '</p>'; … … 578 590 echo '<p>' . __('When you have finished building your custom menu, make sure you click the Save Menu button.') . '</p>'; 579 591 echo '</div>'; 580 endif; ?> 592 } 593 ?> 581 594 </div><!-- /#post-body-content --> 582 595 </div><!-- /#post-body -->
Note: See TracChangeset
for help on using the changeset viewer.