Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/nav-menus.php

    r15219 r15010  
    1616require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
    1717
    18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) )
     18if ( ! current_theme_supports( 'nav-menus' ) && ! current_theme_supports( 'widgets' ) )
    1919    wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
    2020
     
    5656        check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    5757        if ( isset( $_REQUEST['nav-menu-locations'] ) )
    58             set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
     58            set_theme_mod( 'nav_menu_locations', $_REQUEST['menu-locations'] );
    5959        elseif ( isset( $_REQUEST['menu-item'] ) )
    6060            wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
     
    234234
    235235
    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>';
     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        }
    238242        break;
    239243    case 'delete':
     
    247251                $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>';
    248252            } 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 );
    256253                $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>';
    257254                // Select the next available menu
     
    279276        // Update menu theme locations
    280277        if ( isset( $_POST['menu-locations'] ) )
    281             set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
     278            set_theme_mod( 'nav_menu_locations', $_POST['menu-locations'] );
    282279
    283280        // Add Menu
    284281        if ( 0 == $nav_menu_selected_id ) {
    285             $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
     282            $new_menu_title = esc_html( $_POST['menu-name'] );
    286283
    287284            if ( $new_menu_title ) {
     
    308305            $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
    309306
    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 
    316307            if ( ! is_wp_error( $_menu_object ) ) {
    317                 $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
     308                $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $_POST['menu-name'] ) );
    318309                if ( is_wp_error( $_nav_menu_selected_id ) ) {
    319310                    $_menu_object = $_nav_menu_selected_id;
     
    328319
    329320            if ( ! is_wp_error( $_menu_object ) ) {
    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') );
     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,publish') );
    331322                $menu_items = array();
    332323                // Index menu items by db ID
     
    334325                    $menu_items[$_item->db_id] = $_item;
    335326
    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' );
     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' );
    337328                wp_defer_term_counting(true);
    338329                // Loop through all the menu items' POST variables
     
    431422}
    432423
    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";
     424// The theme supports menus
     425if ( 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 &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>';
    445434}
    446435
    447 add_action('admin_body_class','wp_nav_menu_max_depth');
    448 
    449 wp_nav_menu_setup();
    450436wp_initial_nav_menu_meta_boxes();
    451437
    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 &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;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&#8217;s default menus, support for this feature must be registered in the theme&#8217;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>';
     438$help =  '<p>' . __('This feature is new in version 3.0; to use a custom menu in place of your theme&#8217;s default menus, support for this feature must be registered in the theme&#8217;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>';
    456439$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>';
    457440$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&#8217;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&#8217;ll see when the position of the drop target shifts over to create the nested placement. Don&#8217;t forget to click Save when you&#8217;re finished.') . '</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>';
     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>';
    461444
    462445add_contextual_help($current_screen, $help);
     
    474457    ?>
    475458    <div id="nav-menus-frame">
    476     <div id="menu-settings-column" class="metabox-holder<?php if ( !$nav_menu_selected_id ) { echo ' metabox-holder-disabled'; } ?>">
     459    <div id="menu-settings-column" class="metabox-holder">
    477460
    478461        <form id="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-menu-meta" method="post" enctype="multipart/form-data">
     
    580563                    <div id="post-body">
    581564                        <div id="post-body-content">
    582                             <?php
    583                             if ( isset( $edit_markup ) ) {
    584                                 if ( ! is_wp_error( $edit_markup ) )
     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 ) ) {
    585570                                    echo $edit_markup;
    586                             } else if ( empty( $nav_menu_selected_id ) ) {
     571                                }
     572                                ?>
     573                                </ul>
     574                            <?php elseif ( empty($nav_menu_selected_id) ):
    587575                                echo '<div class="post-body-plain">';
    588576                                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>';
     
    590578                                echo '<p>' . __('When you have finished building your custom menu, make sure you click the Save Menu button.') . '</p>';
    591579                                echo '</div>';
    592                             }
    593                             ?>
     580                            endif; ?>
    594581                        </div><!-- /#post-body-content -->
    595582                    </div><!-- /#post-body -->
Note: See TracChangeset for help on using the changeset viewer.