~robotparade/wordpress/stable

« back to all changes in this revision

Viewing changes to wp-admin/nav-menus.php

  • Committer: Jeff Waugh
  • Date: 2010-06-11 21:00:40 UTC
  • Revision ID: jdub@bethesignal.org-20100611210040-9narx3kdlayc8x39
WordPress 3.0 RC3

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// Load all the nav menu interface functions
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
 
21
21
// Permissions Check
248
248
                        } else {
249
249
                                // Remove this menu from any locations.
250
250
                                $locations = get_theme_mod( 'nav_menu_locations' );
251
 
                                foreach ( $locations as $location => $menu_id ) {
 
251
                                foreach ( (array) $locations as $location => $menu_id ) {
252
252
                                        if ( $menu_id == $nav_menu_selected_id )
253
253
                                                $locations[ $location ] = 0;
254
254
                                }
282
282
 
283
283
                // Add Menu
284
284
                if ( 0 == $nav_menu_selected_id ) {
285
 
                        $new_menu_title = esc_html( $_POST['menu-name'] );
 
285
                        $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
286
286
 
287
287
                        if ( $new_menu_title ) {
288
288
                                $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
307
307
 
308
308
                        $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
309
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
 
310
316
                        if ( ! is_wp_error( $_menu_object ) ) {
311
 
                                $_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 ) );
312
318
                                if ( is_wp_error( $_nav_menu_selected_id ) ) {
313
319
                                        $_menu_object = $_nav_menu_selected_id;
314
320
                                        $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
321
327
                        // Update menu items
322
328
 
323
329
                        if ( ! is_wp_error( $_menu_object ) ) {
324
 
                                $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') );
325
331
                                $menu_items = array();
326
332
                                // Index menu items by db ID
327
333
                                foreach( $unsorted_menu_items as $_item )
328
334
                                        $menu_items[$_item->db_id] = $_item;
329
335
 
330
 
                                $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' );
331
337
                                wp_defer_term_counting(true);
332
338
                                // Loop through all the menu items' POST variables
333
339
                                if ( ! empty( $_POST['menu-item-db-id'] ) ) {
424
430
        $nav_menus[$key]->truncated_name = $_nav_menu->truncated_name;
425
431
}
426
432
 
427
 
// The theme supports menus
428
 
if ( current_theme_supports('nav-menus') ) {
429
 
        // Set up nav menu
430
 
        wp_nav_menu_setup();
431
 
 
432
 
// The theme does not support menus but supports widgets
433
 
} elseif ( current_theme_supports('widgets') ) {
434
 
        // Set up nav menu
435
 
        wp_nav_menu_setup();
436
 
        $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.
 
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";
437
445
}
438
446
 
 
447
add_action('admin_body_class','wp_nav_menu_max_depth');
 
448
 
 
449
wp_nav_menu_setup();
439
450
wp_initial_nav_menu_meta_boxes();
440
451
 
 
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
 
441
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>';
442
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>';
443
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&#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>';
566
580
                                        <div id="post-body">
567
581
                                                <div id="post-body-content">
568
582
                                                        <?php
569
 
                                                        if ( is_nav_menu( $nav_menu_selected_id ) ) :
570
 
                                                                $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id  );
571
 
                                                                if ( ! is_wp_error( $edit_markup ) ) :
 
583
                                                        if ( isset( $edit_markup ) ) {
 
584
                                                                if ( ! is_wp_error( $edit_markup ) )
572
585
                                                                        echo $edit_markup;
573
 
                                                                endif;
574
 
                                                        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>';
577
589
                                                                echo '<p>' . __('After you have added your items, drag and drop to put them in the order you want. You can also click each item to reveal additional configuration options.') . '</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
                                                        }
581
593
                                                        ?>
582
594
                                                </div><!-- /#post-body-content -->
583
595
                                        </div><!-- /#post-body -->