Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r15010 r15219  
    1616require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
    1717
    18 if ( ! current_theme_supports( 'nav-menus' ) && ! current_theme_supports( 'widgets' ) )
     18if ( ! current_theme_supports( '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', $_REQUEST['menu-locations'] );
     58            set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_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 ) ) {
    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>';
    242238        break;
    243239    case 'delete':
     
    251247                $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>';
    252248            } 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 );
    253256                $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>';
    254257                // Select the next available menu
     
    276279        // Update menu theme locations
    277280        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'] ) );
    279282
    280283        // Add Menu
    281284        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'] ) );
    283286
    284287            if ( $new_menu_title ) {
     
    305308            $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
    306309
     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
    307316            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 ) );
    309318                if ( is_wp_error( $_nav_menu_selected_id ) ) {
    310319                    $_menu_object = $_nav_menu_selected_id;
     
    319328
    320329            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,publish') );
     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') );
    322331                $menu_items = array();
    323332                // Index menu items by db ID
     
    325334                    $menu_items[$_item->db_id] = $_item;
    326335
    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' );
    328337                wp_defer_term_counting(true);
    329338                // Loop through all the menu items' POST variables
     
    422431}
    423432
    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 &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>';
     433// Ensure the user will be able to scroll horizontally
     434// by adding a class for the max menu depth.
     435global $_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
     439if ( is_nav_menu( $nav_menu_selected_id ) )
     440    $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id  );
     441
     442function wp_nav_menu_max_depth() {
     443    global $_wp_nav_menu_max_depth;
     444    return "menu-max-depth-$_wp_nav_menu_max_depth";
    434445}
    435446
     447add_action('admin_body_class','wp_nav_menu_max_depth');
     448
     449wp_nav_menu_setup();
    436450wp_initial_nav_menu_meta_boxes();
    437451
    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>';
     452if ( ! 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>';
    439456$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>';
    440457$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>';
    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>';
    444461
    445462add_contextual_help($current_screen, $help);
     
    457474    ?>
    458475    <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'; } ?>">
    460477
    461478        <form id="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-menu-meta" method="post" enctype="multipart/form-data">
     
    563580                    <div id="post-body">
    564581                        <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 ) )
    570585                                    echo $edit_markup;
    571                                 }
    572                                 ?>
    573                                 </ul>
    574                             <?php elseif ( empty($nav_menu_selected_id) ):
     586                            } else if ( empty( $nav_menu_selected_id ) ) {
    575587                                echo '<div class="post-body-plain">';
    576588                                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>';
     
    578590                                echo '<p>' . __('When you have finished building your custom menu, make sure you click the Save Menu button.') . '</p>';
    579591                                echo '</div>';
    580                             endif; ?>
     592                            }
     593                            ?>
    581594                        </div><!-- /#post-body-content -->
    582595                    </div><!-- /#post-body -->
Note: See TracChangeset for help on using the changeset viewer.