WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/27/2010 11:06:56 PM (11 years ago)
Author:
wpmuguru
Message:

more menu improvements, props ptahdunbar, see #11817

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/nav-menu-template.php

    r13415 r13473  
    33/**
    44 * Outputs a navigation menu.
     5 *
     6 * Optional $args contents:
     7 *
     8 * id - The menu id. Defaults to blank.
     9 * slug - The menu slug. Defaults to blank.
     10 * menu_class - CSS class to use for the div container of the menu list. Defaults to 'menu'.
     11 * format - Whether to format the ul. Defaults to 'div'.
     12 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'.
     13 *
     14 * TODO:
     15 * 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.
     16 * link_before - Text before show_home argument text.
     17 * link_after - Text after show_home argument text.
     18 * echo - Whether to echo the menu or return it. Defaults to echo.
    519 *
    620 * @since 3.0.0
     
    923 */
    1024function wp_nav_menu( $args = array() ) {
    11     $defaults = array('id' => '', 'slug' => '', 'menu_class' => 'menu', 'format' => 'div', 'fallback_cb' => 'wp_page_menu');
    12     $args = wp_parse_args($args, $defaults);
     25    $defaults = array( 'id' => '', 'slug' => '', 'menu_class' => 'menu', 'format' => 'div', 'fallback_cb' => 'wp_page_menu', 'echo' => true, 'link_before' => '', 'link_after' => '' );
     26    $args = wp_parse_args( $args, $defaults );
    1327    $args = (object) $args;
    14 
     28   
     29    // Get the menu
    1530    $menu = null;
    1631    if ( !empty($args->id) ) {
    1732        $menu = wp_get_nav_menu( $args->id );
    1833    } elseif ( !empty($args->slug) ) {
    19         $menu = get_term_by('slug', $args->slug, 'nav_menu');
     34        $menu = get_term_by( 'slug', $args->slug, 'nav_menu' );
    2035    } else {
    2136        $menus = wp_get_nav_menus();
     
    2742        }
    2843    }
    29 
     44   
     45    // If the menu doesn't exists, call the fallback_cb
    3046    if ( !$menu || is_wp_error($menu) )
    3147        return call_user_func($args->fallback_cb, $args );
     
    86102}
    87103
    88 function wp_print_nav_menu_item($menu_item, $context, $args = array() ) {
     104function wp_print_nav_menu_item( $menu_item, $context, $args = array() ) {
    89105    switch ( $context ) {
    90106        case 'backend':
     
    93109                        <dl>
    94110                            <dt>
    95                                 <span class="title"><?php echo esc_html($menu_item->title); ?></span>
    96                                 <span class="controls">
    97                                 <span class="type"><?php echo esc_html($menu_item->type); ?></span>
    98                                 <a id="edit<?php echo esc_attr( $menu_item->menu_order ); ?>" onclick="edititem(<?php echo esc_attr( $menu_item->menu_order ); ?>)" value="<?php echo esc_attr( $menu_item->menu_order ); ?>"><img class="edit" alt="<?php esc_attr_e('Edit Menu Item'); ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" src="<?php echo admin_url('images/ico-edit.png'); ?>" /></a>
    99                                 <a id="remove<?php echo esc_attr( $menu_item->menu_order ); ?>" onclick="removeitem(<?php echo esc_attr( $menu_item->menu_order ); ?>)" value="<?php echo esc_attr( $menu_item->menu_order ); ?>"><img class="remove" alt="<?php esc_attr_e('Remove from Menu'); ?>" title="<?php esc_attr_e('Remove from Menu'); ?>" src="<?php echo admin_url('images/ico-close.png'); ?>" /></a>
    100                                 <a id="view<?php echo esc_attr( $menu_item->menu_order ); ?>" target="_blank" href="<?php echo $menu_item->link; ?>"><img alt="<?php esc_attr_e('View Page'); ?>" title="<?php esc_attr_e('View Page'); ?>" src="<?php echo admin_url('images/ico-viewpage.png'); ?>" /></a>
     111                                <span class="item-title"><?php echo esc_html($menu_item->title); ?></span>
     112                                <span class="item-controls">
     113                                    <span class="item-type"><?php echo esc_html($menu_item->type); ?></span>
     114                                    <a class="item-edit thickbox" id="edit<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" title="<?php _e('Edit Menu Item'); ?>" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings"><?php _e('Edit'); ?></a> |
     115                                    <a class="item-delete" id="delete<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->menu_order ); ?>"><?php _e('Delete'); ?></a>
    101116                                </span>
    102117                            </dt>
     
    110125                        <input type="hidden" name="postmenu<?php echo esc_attr( $menu_item->menu_order ); ?>" id="postmenu<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( get_post_meta( $menu_item->ID, 'object_id', true ) ); ?>" />
    111126                        <input type="hidden" name="parent<?php echo esc_attr( $menu_item->menu_order ); ?>" id="parent<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->parent_item ); ?>" />
    112                         <input type="hidden" name="title<?php echo esc_attr( $menu_item->menu_order ); ?>" id="title<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->title ); ?>" />
    113                         <input type="hidden" name="linkurl<?php echo esc_attr( $menu_item->menu_order ); ?>" id="linkurl<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->link ); ?>" />
    114                         <input type="hidden" name="description<?php echo esc_attr( $menu_item->menu_order ); ?>" id="description<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->description ); ?>" />
    115127                        <input type="hidden" name="icon<?php echo esc_attr( $menu_item->menu_order ); ?>" id="icon<?php echo esc_attr( $menu_item->menu_order ); ?>" value="0" />
    116128                        <input type="hidden" name="position<?php echo esc_attr( $menu_item->menu_order ); ?>" id="position<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" />
    117129                        <input type="hidden" name="linktype<?php echo esc_attr( $menu_item->menu_order ); ?>" id="linktype<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( get_post_meta( $menu_item->ID, 'menu_type', true ) ); ?>" />
    118                         <input type="hidden" name="anchortitle<?php echo esc_attr( $menu_item->menu_order ); ?>" id="anchortitle<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" />
    119                         <input type="hidden" name="newwindow<?php echo esc_attr( $menu_item->menu_order ); ?>" id="newwindow<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo ( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ? '1' : '0' ); ?>" />
     130                        <input type="hidden" name="item-title<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-title<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->title ); ?>" />
     131                        <input type="hidden" name="item-url<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-url<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->link ); ?>" />
     132                        <input type="hidden" name="item-description<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-description<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->description ); ?>" />
     133                        <input type="hidden" name="item-attr-title<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-attr-title<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" />
     134                        <input type="hidden" name="item-target<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-target<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo ( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ? '1' : '0' ); ?>" />
    120135<?php
    121136        break;
     
    123138        case 'frontend':
    124139            // Override for menu descriptions
    125             $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options');
     140            $advanced_option_descriptions = get_option('wp_settings_nav_menu_advanced_options');
    126141            if ( $advanced_option_descriptions == 'no' )
    127142                $args['desc'] = 2;
     
    149164
    150165        case 'default':
    151             $template_dir = get_bloginfo('url');
     166            $menu_id = 'menu-item-' . $menu_item->ID;
    152167?>
    153168                    <dl>
    154169                        <dt>
    155                             <a class="title" title="<?php esc_attr_e('Add to Menu'); ?>" onclick="appendToList('<?php echo esc_js( esc_url_raw( $template_dir ) ); ?>','<?php echo esc_js( $menu_item->append ); ?>','<?php echo esc_js( $menu_item->title ); ?>','<?php echo esc_js( $menu_item->link ); ?>','<?php echo esc_js( $menu_item->ID ); ?>','<?php echo esc_js( $menu_item->parent_item ); ?>','<?php echo esc_js( $menu_item->description ); ?>')" name="<?php echo esc_attr( $menu_item->title ); ?>" value="<?php echo esc_attr( $menu_item->link ); ?>"><?php echo $menu_item->title; ?></a>
     170                            <label class="item-title"><input type="checkbox" id="<?php echo esc_attr($menu_id); ?>" onclick="wp_update_queue('<?php echo esc_js( $menu_item->append ); ?>','<?php echo esc_js( $menu_item->title ); ?>','<?php echo esc_js( $menu_item->link ); ?>','<?php echo esc_js( $menu_item->ID ); ?>','<?php echo esc_js( $menu_item->parent_item ); ?>','<?php echo esc_js( $menu_item->description ); ?>')" name="<?php echo esc_attr( $menu_item->title ); ?>" value="<?php echo esc_attr( $menu_item->link ); ?>" /><?php echo $menu_item->title; ?></label>
    156171                        </dt>
    157172                    </dl>
Note: See TracChangeset for help on using the changeset viewer.