Make WordPress Core


Ignore:
Timestamp:
04/27/2010 01:05:58 AM (15 years ago)
Author:
ryan
Message:

New menu UI. Props filosofo. see #12713

File:
1 edited

Legend:

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

    r14113 r14248  
    11<?php
     2
     3/**
     4 * Create HTML list of nav menu input items.
     5 *
     6 * @package WordPress
     7 * @since 3.0.0
     8 * @uses Walker_Nav_Menu
     9 */
     10class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
     11
     12    /**
     13     * @see Walker::start_el()
     14     * @since 3.0.0
     15     *
     16     * @param string $output Passed by reference. Used to append additional content.
     17     * @param object $item Menu item data object.
     18     * @param int $depth Depth of menu item. Used for padding.
     19     * @param int $current_page Menu item ID.
     20     * @param object $args
     21     */
     22    function start_el(&$output, $item, $depth, $args) {
     23        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
     24
     25        ob_start();
     26        $item_id = esc_attr( $item->ID );
     27        $removed_args = array(
     28            'action',
     29            'customlink-tab',
     30            'edit-menu-item',
     31            'menu-item',
     32            'page-tab',
     33            '_wpnonce',
     34        );
     35        ?>
     36        <li id="menu-item-<?php echo $item_id; ?>">
     37            <dl>
     38                <dt>
     39                    <span class="item-title"><?php echo esc_html( $item->title ); ?></span>
     40                    <span class="item-controls">
     41                        <span class="item-type"><?php echo esc_html( $item->append ); ?></span>
     42                        <span class="item-order">
     43                            <a href="<?php
     44                                echo wp_nonce_url(
     45                                    add_query_arg(
     46                                        array(
     47                                            'action' => 'move-up-menu-item',
     48                                            'menu-item' => $item_id,
     49                                        ),
     50                                        remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
     51                                    ),
     52                                    'move-item'
     53                                );
     54                            ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
     55                            |
     56                            <a href="<?php
     57                                echo wp_nonce_url(
     58                                    add_query_arg(
     59                                        array(
     60                                            'action' => 'move-down-menu-item',
     61                                            'menu-item' => $item_id,
     62                                        ),
     63                                        remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
     64                                    ),
     65                                    'move-item'
     66                                );
     67                            ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
     68                            |
     69                        </span>
     70                        <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php _e('Edit Menu Item'); ?>" href="<?php
     71                            echo add_query_arg('edit-menu-item', $item_id, remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) );
     72                        ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Edit'); ?></a> |
     73                        <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
     74                        echo wp_nonce_url(
     75                            add_query_arg(
     76                                array(
     77                                    'action' => 'delete-menu-item',
     78                                    'menu-item' => $item_id,
     79                                ),
     80                                remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
     81                            ),
     82                            'delete-menu_item_' . $item_id
     83                        ); ?>"><?php _e('Delete'); ?></a>
     84                    </span>
     85                </dt>
     86            </dl>
     87
     88            <div class="menu-item-settings <?php
     89                if ( isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ) :
     90                    echo ' menu-item-edit-active';
     91                else :
     92                    echo ' menu-item-edit-inactive';
     93                endif;
     94            ?>" id="menu-item-settings-<?php echo $item_id; ?>">
     95                <p class="description">
     96                    <label for="edit-menu-item-title-<?php echo $item_id; ?>">
     97                        <?php _e( 'Menu Title' ); ?><br />
     98                        <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
     99                    </label>
     100                </p>
     101                <p class="description">
     102                    <label for="edit-menu-item-url-<?php echo $item_id; ?>">
     103                        <?php _e( 'URL' ); ?><br />
     104                        <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
     105                    </label>
     106                </p>
     107                <p class="description">
     108                    <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
     109                        <?php _e( 'Title Attribute' ); ?><br />
     110                        <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
     111                    </label>
     112                </p>
     113                <p class="description">
     114                    <label for="edit-menu-item-target-<?php echo $item_id; ?>">
     115                        <?php _e( 'Link Target' ); ?><br />
     116                        <select id="edit-menu-item-target-<?php echo $item_id; ?>" class="widefat edit-menu-item-target" name="menu-item-target[<?php echo $item_id; ?>]">
     117                            <option value="" <?php selected( $item->target, ''); ?>><?php _e('Same window or tab'); ?></option>
     118                            <option value="_blank" <?php selected( $item->target, '_blank'); ?>><?php _e('New window or tab'); ?></option>
     119                        </select>
     120                    </label>
     121                </p>
     122                <p class="description">
     123                    <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
     124                        <?php _e( 'CSS Classes (optional)' ); ?><br />
     125                        <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->classes ); ?>" />
     126                    </label>
     127                </p>
     128                <p class="description">
     129                    <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
     130                        <?php _e( 'Link Relationship (XFN) (optional)' ); ?><br />
     131                        <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
     132                    </label>
     133                </p>
     134                <p class="description">
     135                    <label for="edit-menu-item-description-<?php echo $item_id; ?>">
     136                        <?php _e( 'Description (optional)' ); ?><br />
     137                        <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); ?></textarea>
     138                        <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
     139                    </label>
     140                </p>
     141               
     142                <input type="hidden" name="menu-item-append[<?php echo $item_id; ?>]" value="<?php echo $item->append; ?>" />
     143                <input type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
     144                <input type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
     145                <input type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
     146                <input type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_parent ); ?>" />
     147                <input type="hidden" class="menu-item-position" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
     148                <input type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
     149            </div><!-- .menu-item-settings-->
     150        <?php
     151        $output .= ob_get_clean();
     152    }
     153}
     154
     155/**
     156 * Prints the appropriate response to a menu quick search.
     157 *
     158 * @since 3.0.0
     159 *
     160 * @param array $request The unsanitized request values.
     161 */
     162function _wp_ajax_menu_quick_search( $request = array() ) {
     163    $args = array();
     164    $type = isset( $request['type'] ) ? $request['type'] : '';
     165    $object_type = isset( $request['object_type'] ) ? $request['object_type'] : '';
     166    $query = isset( $request['q'] ) ? $request['q'] : '';
     167    $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json';
     168
     169    if ( 'markup' == $response_format ) {
     170        $args['walker'] = new Walker_Nav_Menu_Checklist;
     171    }
     172
     173    if ( 'get-post-item' == $type ) {
     174        if ( get_post_type_object( $object_type ) ) {
     175            if ( isset( $request['ID'] ) ) {
     176                $object_id = (int) $request['ID'];
     177                if ( 'markup' == $response_format ) {
     178                    echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
     179                } elseif ( 'json' == $response_format ) {
     180                    $post_obj = get_post( $object_id );
     181                    echo json_encode(
     182                        array(
     183                            'ID' => $object_id,
     184                            'post_title' => get_the_title( $object_id ),
     185                            'post_type' => get_post_type( $object_id ),
     186                        )
     187                    );
     188                    echo "\n";
     189                }
     190            }
     191        } elseif ( is_taxonomy( $object_type ) ) {
     192            if ( isset( $request['ID'] ) ) {
     193                $object_id = (int) $request['ID'];
     194                if ( 'markup' == $response_format ) {
     195                    echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
     196                } elseif ( 'json' == $response_format ) {
     197                    $post_obj = get_term( $object_id, $object_type );
     198                    echo json_encode(
     199                        array(
     200                            'ID' => $object_id,
     201                            'post_title' => $post_obj->name,
     202                            'post_type' => $object_type,
     203                        )
     204                    );
     205                    echo "\n";
     206                }
     207            }
     208
     209        }
     210
     211
     212    } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
     213        if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
     214            query_posts(array(
     215                'posts_per_page' => 10,
     216                'post_type' => $matches[2],
     217                's' => $query,
     218            ));
     219            while ( have_posts() ) {
     220                the_post();
     221                if ( 'markup' == $response_format ) {
     222                    echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( get_the_ID() ) ) ), 0, (object) $args );
     223                } elseif ( 'json' == $response_format ) {
     224                    echo json_encode(
     225                        array(
     226                            'ID' => get_the_ID(),
     227                            'post_title' => get_the_title(),
     228                            'post_type' => get_post_type(),
     229                        )
     230                    );
     231                    echo "\n";
     232                }
     233            }
     234        } elseif ( 'taxonomy' == $matches[1] ) {
     235            $terms = get_terms( $matches[2], array(
     236                'name__like' => $query,
     237                'number' => 10,
     238            ));
     239            foreach( (array) $terms as $term ) {
     240                if ( 'markup' == $response_format ) {
     241                    echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
     242                } elseif ( 'json' == $response_format ) {
     243                    echo json_encode(
     244                        array(
     245                            'ID' => $term->term_id,
     246                            'post_title' => $term->name,
     247                            'post_type' => $matches[2],
     248                        )
     249                    );
     250                    echo "\n";
     251                }
     252            }
     253        }
     254    }
     255}
     256
    2257/**
    3258 * Register nav menu metaboxes
     
    5260 * @since 3.0.0
    6261 **/
    7 function wp_nav_menu_metaboxes_setup() {
    8     add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_metabox', 'nav-menus', 'side', 'default' );
    9     wp_nav_menu_post_type_metaboxes();
    10     wp_nav_menu_taxonomy_metaboxes();
     262function wp_nav_menu_meta_boxes_setup() {
     263    add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
     264    wp_nav_menu_post_type_meta_boxes();
     265    wp_nav_menu_taxonomy_meta_boxes();
    11266}
    12267
     
    19274    global $wp_meta_boxes;
    20275
    21     if ( !get_user_option( 'metaboxhidden_nav-menus' ) && is_array($wp_meta_boxes) ) {
     276    if ( !get_user_option( 'meta-box-hidden_nav-menus' ) && is_array($wp_meta_boxes) ) {
    22277
    23278        $initial_meta_boxes = array( 'manage-menu', 'create-menu', 'add-custom-links', 'add-page', 'add-category' );
     
    36291        }
    37292        $user = wp_get_current_user();
    38         update_user_meta( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes );
     293        update_user_meta( $user->ID, 'meta-box-hidden_nav-menus', $hidden_meta_boxes );
    39294
    40295        // returns all the hidden metaboxes to the js function: wpNavMenu.initial_meta_boxes()
     
    48303 * @since 3.0.0
    49304 */
    50 function wp_nav_menu_post_type_metaboxes() {
     305function wp_nav_menu_post_type_meta_boxes() {
    51306    $post_types = get_post_types( array( 'public' => true ), 'object' );
    52307
     
    56311    foreach ( $post_types as $post_type ) {
    57312        $id = $post_type->name;
    58         add_meta_box( "add-{$id}", sprintf( __('Add %s'), $post_type->label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type );
     313        add_meta_box( "add-{$id}", sprintf( __('Add %s'), $post_type->label ), 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
    59314    }
    60315}
     
    65320 * @since 3.0.0
    66321 */
    67 function wp_nav_menu_taxonomy_metaboxes() {
     322function wp_nav_menu_taxonomy_meta_boxes() {
    68323    $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' );
    69324
     
    73328    foreach ( $taxonomies as $tax ) {
    74329        $id = $tax->name;
    75         add_meta_box( "add-{$id}", sprintf( __('Add %s'), $tax->label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax );
    76     }
    77 }
    78 
    79 /**
    80  * Displays a metabox for managing the active menu being edited.
     330        add_meta_box( "add-{$id}", sprintf( __('Add %s'), $tax->label ), 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
     331    }
     332}
     333
     334/**
     335 * Displays a metabox for the custom links menu item.
    81336 *
    82337 * @since 3.0.0
    83338 */
    84 function wp_nav_menu_manage_menu_metabox( $object, $menu ) { ?>
    85     <div id="submitpost" class="submitbox">
    86         <div id="minor-publishing">
    87             <div class="misc-pub-section misc-pub-section-last">
    88                 <label class="howto" for="menu-name">
    89                     <span><?php _e('Name'); ?></span>
    90                     <input id="menu-name" name="menu-name" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( $menu['args'][1] ); ?>" />
    91                     <br class="clear" />
    92                 </label>
    93             </div><!--END .misc-pub-section misc-pub-section-last-->
    94             <br class="clear" />
    95         </div><!--END #misc-publishing-actions-->
    96         <div id="major-publishing-actions">
    97             <div id="delete-action">
    98                 <a class="submitdelete deletion" href="<?php echo wp_nonce_url( admin_url('nav-menus.php?action=delete&amp;menu=' . $menu['args'][0]), 'delete-nav_menu-' . $menu['args'][0] ); ?>"><?php _e('Delete Menu'); ?></a>
    99             </div><!--END #delete-action-->
    100 
    101             <div id="publishing-action">
    102                 <input class="button-primary" name="save_menu" type="submit" value="<?php esc_attr_e('Save Menu'); ?>" />
    103             </div><!--END #publishing-action-->
    104             <br class="clear" />
    105         </div><!--END #major-publishing-actions-->
    106     </div><!--END #submitpost .submitbox-->
    107     <?php
    108 }
    109 
    110 /**
    111  * Displays a metabox for creating a new menu.
    112  *
    113  * @since 3.0.0
    114  */
    115 function wp_nav_menu_create_metabox() { ?>
    116     <p>
    117         <input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value="<?php esc_attr_e( 'Menu name' ); ?>"  />
    118         <input type="submit" name="create-menu-button" id="create-menu-button" class="button" value="<?php esc_attr_e('Create Menu'); ?>" />
    119     </p>
    120     <?php
    121 }
    122 
    123 /**
    124  * Displays a metabox for the custom links menu item.
    125  *
    126  * @since 3.0.0
    127  */
    128 function wp_nav_menu_item_link_metabox() {
     339function wp_nav_menu_item_link_meta_box() {
     340    static $_placeholder;
     341    $_placeholder = 0 > $_placeholder ? $_placeholder - 1 : -1;
     342
    129343    // @note: hacky query, see #12660
    130344    $args = array( 'post_type' => 'nav_menu_item', 'post_status' => 'any', 'meta_key' => '_menu_item_type', 'numberposts' => -1, 'orderby' => 'title', );
     
    132346    // @todo transient caching of these results with proper invalidation on updating links
    133347    $links = get_posts( $args );
     348
     349    $current_tab = 'create';
     350    if ( isset( $_REQUEST['customlink-tab'] ) && in_array( $_REQUEST['customlink-tab'], array('create', 'all') ) ) {
     351        $current_tab = $_REQUEST['customlink-tab'];
     352    }
     353
     354    $removed_args = array(
     355        'action',
     356        'customlink-tab',
     357        'edit-menu-item',
     358        'menu-item',
     359        'page-tab',
     360        '_wpnonce',
     361    );
     362
    134363    ?>
    135     <p id="menu-item-url-wrap">
    136         <label class="howto" for="menu-item-url">
    137             <span><?php _e('URL'); ?></span>
    138             <input id="custom-menu-item-url" name="custom-menu-item-url" type="text" class="code menu-item-textbox" value="http://" />
    139         </label>
    140     </p>
    141     <p id="menu-item-name-wrap">
    142         <label class="howto" for="custom-menu-item-name">
    143             <span><?php _e('Text'); ?></span>
    144             <input id="custom-menu-item-name" name="custom-menu-item-name" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( __('Menu Item') ); ?>" />
    145         </label>
    146     </p>
    147 
    148     <p class="button-controls">
    149         <span class="lists-controls">
    150             <a class="show-all"><?php _e('View All'); ?></a>
    151             <a class="hide-all"><?php _e('Hide All'); ?></a>
    152         </span>
    153 
    154         <span class="add-to-menu">
    155             <a class="button"><?php _e('Add to Menu'); ?></a>
    156         </span>
    157     </p>
    158     <div id="available-links" class="list-wrap">
    159         <div class="list-container">
    160             <ul class="list">
    161                 <?php echo wp_nav_menu_get_items( $links, 'custom', 'custom' ); ?>
     364    <div class="customlinkdiv">
     365        <ul id="customlink-tabs" class="customlink-tabs add-menu-item-tabs">
     366            <li <?php echo ( 'create' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg('customlink-tab', 'create', remove_query_arg($removed_args)); ?>#tabs-panel-create-custom"><?php _e('Create New'); ?></a></li>
     367            <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg('customlink-tab', 'all', remove_query_arg($removed_args)); ?>#tabs-panel-all-custom"><?php _e('View All'); ?></a></li>
     368        </ul>
     369
     370        <div class="tabs-panel <?php
     371            echo ( 'create' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     372        ?>" id="tabs-panel-create-custom">
     373            <input type="hidden" value="custom" name="menu-item[<?php echo $_placeholder; ?>][menu-item-type]" />
     374            <p id="menu-item-url-wrap">
     375                <label class="howto" for="custom-menu-item-url">
     376                    <span><?php _e('URL'); ?></span>
     377                    <input id="custom-menu-item-url" name="menu-item[<?php echo $_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
     378                </label>
     379            </p>
     380
     381            <p id="menu-item-name-wrap">
     382                <label class="howto" for="custom-menu-item-name">
     383                    <span><?php _e('Text'); ?></span>
     384                    <input id="custom-menu-item-name" name="menu-item[<?php echo $_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( __('Menu Item') ); ?>" />
     385                </label>
     386            </p>
     387        </div><!-- /.tabs-panel -->
     388
     389        <div class="tabs-panel <?php
     390            echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     391        ?>" id="tabs-panel-all-custom">
     392            <ul id="customlinkchecklist" class="list:customlink customlinkchecklist form-no-clear">
     393                <?php
     394                $args['walker'] = new Walker_Nav_Menu_Checklist;
     395                echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $links), 0, (object) $args );
     396                ?>
    162397            </ul>
    163         </div><!-- /.list-container-->
    164     </div><!-- /#available-links-->
    165     <div class="clear"></div>
     398        </div><!-- /.tabs-panel -->
     399
     400        <p class="button-controls">
     401            <span class="add-to-menu">
     402                <input type="submit" class="button-secondary" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" />
     403            </span>
     404        </p>
     405
     406        <div class="clear"></div>
     407    </div><!-- /.customlinkdiv -->
    166408    <?php
    167409}
     
    175417 * @param string $post_type The post type object.
    176418 */
    177 function wp_nav_menu_item_post_type_metabox( $object, $post_type ) {
    178     $args = array( 'post_type' => $post_type['args']->name, 'numberposts' => -1, 'orderby' => 'title', );
     419function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
     420    $post_type_name = $post_type['args']->name;
     421
     422    // paginate browsing for large numbers of post objects
     423    $per_page = 50;
     424    $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
     425    $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
     426
     427    $args = array(
     428        'offset' => $offset,
     429        'order' => 'ASC',
     430        'orderby' => 'title',
     431        'posts_per_page' => $per_page,
     432        'post_type' => $post_type_name,
     433        'suppress_filters' => true,
     434    );
    179435
    180436    // @todo transient caching of these results with proper invalidation on updating of a post of this type
    181     $posts = get_posts( $args );
    182 
     437    $get_posts = new WP_Query;
     438    $posts = $get_posts->query( $args );
     439
     440    $post_type_object = get_post_type_object($post_type_name);
     441
     442    $num_pages = $get_posts->max_num_pages;
     443
     444    $count_posts = (int) @count( $posts );
     445
     446    if ( isset( $get_posts->found_posts ) && ( $get_posts->found_posts > $count_posts ) ) {
     447        // somewhat like display_page_row(), let's make sure ancestors show up on paged display
     448        $parent_ids = array();
     449        $child_ids = array();
     450        foreach( (array) $posts as $post ) {
     451            $parent_ids[] = (int) $post->post_parent;
     452            $child_ids[] = (int) $post->ID;
     453        }
     454        $parent_ids = array_unique($parent_ids);
     455        $child_ids = array_unique($child_ids);
     456       
     457        $missing_parents = array();
     458        do {
     459            foreach( (array) $missing_parents as $missing_parent_id ) {
     460                $missing_parent = get_post($missing_parent_id);
     461                $posts[] = $missing_parent;
     462                $child_ids[] = $missing_parent_id;
     463                $parent_ids[] = $missing_parent->post_parent;
     464            }
     465           
     466            $missing_parents = array_filter( array_diff( array_unique( $parent_ids ), array_unique( $child_ids ) ) );
     467
     468        } while( 0 < count( $missing_parents ) );
     469       
     470    }
     471
     472    $page_links = paginate_links( array(
     473        'base' => add_query_arg(
     474            array(
     475                $post_type_name . '-tab' => 'all',
     476                'paged' => '%#%',
     477            )
     478        ),
     479        'format' => '',
     480        'prev_text' => __('&laquo;'),
     481        'next_text' => __('&raquo;'),
     482        'total' => $num_pages,
     483        'current' => $pagenum
     484    ));
     485   
    183486    if ( !$posts )
    184487        $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>';
    185488
    186     $pt_names = '';
    187     if ( is_array($posts) ) {
    188         foreach ( $posts as $post ) {
    189             if ( $post->post_title ) {
    190                 $pt_names .= htmlentities( $post->post_title ) .'|';
    191             }
    192         }
    193     }
    194 
    195     $id = $post_type['args']->name;
     489    $current_tab = 'search';
     490    if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) {
     491        $current_tab = $_REQUEST[$post_type_name . '-tab'];
     492    }
     493
     494    if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
     495        $current_tab = 'search';
     496    }
     497
     498    $removed_args = array(
     499        'action',
     500        'customlink-tab',
     501        'edit-menu-item',
     502        'menu-item',
     503        'page-tab',
     504        '_wpnonce',
     505    );
     506
    196507    ?>
    197     <p class="quick-search-wrap">
    198         <input type="text" class="quick-search regular-text" value="" />
    199         <a class="quick-search-submit button-secondary"><?php _e('Search'); ?></a>
    200     </p>
    201 
    202     <p class="button-controls">
    203         <span class="lists-controls">
    204             <a class="show-all"><?php _e('View All'); ?></a>
    205             <a class="hide-all"><?php _e('Hide All'); ?></a>
    206         </span>
    207 
    208         <span class="add-to-menu">
    209             <a class="button"><?php _e('Add to Menu'); ?></a>
    210         </span>
    211     </p>
    212 
    213     <div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap">
    214         <div class="list-container">
    215             <ul class="list">
    216                 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $posts, 'post_type', $id ); ?>
     508    <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
     509        <ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
     510            <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args)); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li>
     511            <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args)); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li>
     512        </ul>
     513
     514        <div class="tabs-panel <?php
     515            echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     516        ?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search">
     517            <?php
     518            if ( isset( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
     519                $searched = esc_attr( $_REQUEST['quick-search-posttype-' . $post_type_name] );
     520                $search_results = get_posts( array( 's' => $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) );
     521            } else {
     522                $searched = '';
     523                $search_results = array();
     524            }
     525            ?>
     526            <p class="quick-search-wrap">
     527                <input type="text" class="quick-search regular-text" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" />
     528                <input type="submit" class="quick-search-submit button-secondary" value="<?php esc_attr_e('Search'); ?>" />
     529            </p>
     530
     531            <ul id="<?php echo $post_type_name; ?>-search-checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear">
     532            <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
     533                <?php
     534                $args['walker'] = new Walker_Nav_Menu_Checklist;
     535                echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args );
     536                ?>
     537            <?php endif; ?>
    217538            </ul>
    218         </div><!-- /.list-container-->
    219     </div><!-- /#existing-categories-->
    220     <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr( $id ); ?>-names" value="<?php echo esc_js( $pt_names ); ?>" />
    221     <br class="clear" />
    222     <script type="text/javascript" charset="utf-8">
    223         // <![CDATA[
    224         jQuery(document).ready(function(){
    225             wpNavMenu.autocomplete('<?php echo esc_attr($id); ?>');
    226         });
    227         // ]]>
    228     </script>
     539        </div><!-- /.tabs-panel -->
     540
     541
     542        <div id="<?php echo $post_type_name; ?>-all" class="tabs-panel <?php
     543            echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     544        ?>">
     545            <div class="add-menu-item-pagelinks">
     546                <?php echo $page_links; ?>
     547            </div>
     548            <ul id="<?php echo $post_type_name; ?>checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear">
     549                <?php
     550                $args['walker'] = new Walker_Nav_Menu_Checklist;
     551                $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
     552
     553                if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
     554                    $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items);
     555                   
     556                }
     557                echo $checkbox_items;
     558                ?>
     559            </ul>
     560            <div class="add-menu-item-pagelinks">
     561                <?php echo $page_links; ?>
     562            </div>
     563        </div><!-- /.tabs-panel -->
     564
     565
     566        <p class="button-controls">
     567            <span class="lists-controls">
     568                <a href="<?php
     569                    echo add_query_arg(
     570                        array(
     571                            $post_type_name . '-tab' => 'all',
     572                            'selectall' => 1,
     573                        ),
     574                        remove_query_arg($removed_args)
     575                    );
     576                ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
     577            </span>
     578
     579            <span class="add-to-menu">
     580                <input type="submit" class="button-secondary" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" />
     581            </span>
     582        </p>
     583
     584        <br class="clear" />
     585    </div><!-- /.posttypediv -->
    229586    <?php
    230587}
     
    238595 * @param string $taxonomy The taxonomy object.
    239596 */
    240 function wp_nav_menu_item_taxonomy_metabox( $object, $taxonomy ) {
     597function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
     598    $taxonomy_name = $taxonomy['args']->name;
     599    // paginate browsing for large numbers of objects
     600    $per_page = 50;
     601    $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
     602    $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
     603   
    241604    $args = array(
    242         'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
    243         'hide_empty' => false, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '',
    244         'include' => '', 'number' => '', 'pad_counts' => false
     605        'child_of' => 0,
     606        'exclude' => '',
     607        'hide_empty' => false,
     608        'hierarchical' => 1,
     609        'include' => '',
     610        'include_last_update_time' => false,
     611        'number' => $per_page,
     612        'offset' => $offset,
     613        'order' => 'ASC',
     614        'orderby' => 'name',
     615        'pad_counts' => false,
    245616    );
    246617
     618    $num_pages = ceil( wp_count_terms($taxonomy_name) / $per_page );
     619
     620    $page_links = paginate_links( array(
     621        'base' => add_query_arg(
     622            array(
     623                $taxonomy_name . '-tab' => 'all',
     624                'paged' => '%#%',
     625            )
     626        ),
     627        'format' => '',
     628        'prev_text' => __('&laquo;'),
     629        'next_text' => __('&raquo;'),
     630        'total' => $num_pages,
     631        'current' => $pagenum
     632    ));
     633   
     634    $walker = new Walker_Nav_Menu_Checklist;
    247635    // @todo transient caching of these results with proper invalidation on updating of a tax of this type
    248     $terms = get_terms( $taxonomy['args']->name, $args );
    249 
    250     if ( !$terms || is_wp_error($terms) )
     636    $terms = get_terms( $taxonomy_name, $args );
     637
     638    if ( ! $terms || is_wp_error($terms) )
    251639        $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $taxonomy['args']->label ) .'</li>';
    252640
    253     $term_names = '';
    254     if ( is_array($terms) ) {
    255         foreach ( $terms as $term ) {
    256             if ( $term->name ) {
    257                 $term_names .= htmlentities( $term->name ) .'|';
    258             }
     641    $current_tab = 'most-used';
     642    if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) {
     643        $current_tab = $_REQUEST[$taxonomy_name . '-tab'];
     644    }
     645
     646    if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) {
     647        $current_tab = 'search';
     648    }
     649
     650    $removed_args = array(
     651        'action',
     652        'customlink-tab',
     653        'edit-menu-item',
     654        'menu-item',
     655        'page-tab',
     656        '_wpnonce',
     657    );
     658
     659    ?>
     660    <div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
     661        <ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
     662            <li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args)); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
     663            <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args)); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"><?php _e('Search'); ?></a></li>
     664            <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args)); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all"><?php _e('View All'); ?></a></li>
     665        </ul>
     666
     667        <div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php
     668            echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     669        ?>">
     670            <ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
     671                <?php
     672                $popular_terms = get_terms( $taxonomy_name, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
     673                $args['walker'] = $walker;
     674                echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args );
     675                ?>
     676                <?php
     677                ?>
     678            </ul>
     679        </div><!-- /.tabs-panel -->
     680
     681        <div class="tabs-panel <?php
     682            echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     683        ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>">
     684            <?php
     685            if ( isset( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) {
     686                $searched = esc_attr( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] );
     687                $search_results = get_terms( $taxonomy_name, array( 'name__like' => $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) );
     688            } else {
     689                $searched = '';
     690                $search_results = array();
     691            }
     692            ?>
     693            <p class="quick-search-wrap">
     694                <input type="text" class="quick-search regular-text" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" />
     695                <input type="submit" class="quick-search-submit button-secondary" value="<?php esc_attr_e('Search'); ?>" />
     696            </p>
     697       
     698            <ul id="<?php echo $taxonomy_name; ?>-search-checklist" class="list:<?php echo $taxonomy_name?> categorychecklist form-no-clear">
     699            <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
     700                <?php
     701                $args['walker'] = $walker;
     702                echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args );
     703                ?>
     704            <?php endif; ?>
     705            </ul>
     706        </div><!-- /.tabs-panel -->
     707
     708        <div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel <?php
     709            echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
     710        ?>">
     711            <div class="add-menu-item-pagelinks">
     712                <?php echo $page_links; ?>
     713            </div>
     714            <ul id="<?php echo $taxonomy_name; ?>checklist" class="list:<?php echo $taxonomy_name?> categorychecklist form-no-clear">
     715                <?php
     716                $args['walker'] = $walker;
     717                echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args );
     718                ?>
     719            </ul>
     720            <div class="add-menu-item-pagelinks">
     721                <?php echo $page_links; ?>
     722            </div>
     723        </div><!-- /.tabs-panel -->
     724
     725        <p class="button-controls">
     726            <span class="lists-controls">
     727                <a href="<?php
     728                    echo add_query_arg(
     729                        array(
     730                            $taxonomy_name . '-tab' => 'all',
     731                            'selectall' => 1,
     732                        ),
     733                        remove_query_arg($removed_args)
     734                    );
     735                ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
     736            </span>
     737
     738            <span class="add-to-menu">
     739                <input type="submit" class="button-secondary" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-taxonomy-menu-item" />
     740            </span>
     741        </p>
     742
     743        <br class="clear" />
     744    </div><!-- /.taxonomydiv -->
     745    <?php
     746}
     747
     748/**
     749 * Save posted nav menu item data.
     750 *
     751 * @since 3.0.0
     752 *
     753 * @param int $menu_id The menu ID for which to save this item.
     754 * @param array $menu_data The unsanitized posted menu item data.
     755 * @return array The database IDs of the items saved.
     756 */
     757function wp_save_nav_menu_item( $menu_id = 0, $menu_data = array() ) {
     758    $menu_id = (int) $menu_id;
     759    $items_saved = array();
     760
     761    if ( is_nav_menu( $menu_id ) ) {
     762
     763        // Loop through all the menu items' POST values
     764        foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
     765            if (
     766                empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked
     767                (
     768                    ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set
     769                    in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default
     770                    'custom' != $_item_object_data['menu-item-type'] ||  // or it's not a custom menu item 
     771                    ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists
     772                )
     773            ) {
     774                continue; // then this potential menu item is not getting added to this menu
     775            }
     776
     777            // if this possible menu item doesn't actually have a menu database ID yet
     778            if (
     779                empty( $_item_object_data['menu-item-db-id'] ) ||
     780                ( 0 > $_possible_db_id ) ||
     781                $_possible_db_id != $_item_object_data['menu-item-db-id']
     782            ) {
     783                $_actual_db_id = 0;
     784            } else {
     785                $_actual_db_id = (int) $_item_object_data['menu-item-db-id'];
     786            }
     787           
     788            $args = array(
     789                'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ),
     790                'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ),
     791                'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ),
     792                'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ),
     793                'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ),
     794                'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ),
     795                'menu-item-append' => ( isset( $_item_object_data['menu-item-append'] ) ? $_item_object_data['menu-item-append'] : '' ),
     796                'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ),
     797                'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ),
     798                'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ),
     799                'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ),
     800                'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ),
     801                'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ),
     802                'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ),
     803            );
     804
     805            $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args );
     806
    259807        }
    260808    }
    261 
    262     $id = $taxonomy['args']->name;
    263     ?>
    264     <p class="quick-search-wrap">
    265         <input type="text" class="quick-search regular-text" value="" />
    266         <a class="quick-search-submit button-secondary"><?php _e('Search'); ?></a>
    267     </p>
    268 
    269     <p class="button-controls">
    270         <span class="lists-controls">
    271             <a class="show-all"><?php _e('View All'); ?></a>
    272             <a class="hide-all"><?php _e('Hide All'); ?></a>
    273         </span>
    274 
    275         <span class="add-to-menu">
    276             <a class="button"><?php _e('Add to Menu'); ?></a>
    277         </span>
    278     </p>
    279 
    280     <div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap">
    281         <div class="list-container">
    282             <ul class="list">
    283                 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $terms, 'taxonomy', $id ); ?>
    284             </ul>
    285         </div><!-- /.list-container-->
    286     </div><!-- /#existing-categories-->
    287     <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr($id); ?>-names" value="<?php echo esc_js( $term_names ); ?>" />
    288     <br class="clear" />
    289     <script type="text/javascript" charset="utf-8">
    290         // <![CDATA[
    291         jQuery(document).ready(function(){
    292             wpNavMenu.autocomplete('<?php echo esc_attr($id); ?>');
    293         });
    294         // ]]>
    295     </script>
    296     <?php
    297 }
    298 
    299 /**
    300  * Abstract function for returning all menu items of a menu item type.
    301  *
    302  * @since 3.0.0
    303  *
    304  * @param string $menu_items Array of objects containing all menu items to be displayed.
    305  * @param string $object_type Menu item type.
    306  * @param string $object Optional. Menu item type name.
    307  * @param string $context Optional. The context for how the menu items should be formatted.
    308  * @return string $ouput Menu items.
     809    return $items_saved;
     810}
     811
     812/**
     813 * Returns the menu item formatted to edit.
     814 *
     815 * @since 3.0.0
     816 *
     817 * @param string $menu_item_id The ID of the menu item to format.
     818 * @return string|WP_Error $output The menu formatted to edit or error object on failure.
    309819 */
    310 function wp_nav_menu_get_items( $menu_items, $object_type, $object = null, $context = 'frontend' ) {
    311     if ( !$menu_items )
    312         return __( 'Not Found' );
    313 
    314     $output = '';
    315     $i = 1;
    316     foreach ( $menu_items as $menu_item ) {
    317         // convert the 'parent' taxonomy property to 'post_parent'
    318         // so we don't have to duplicate this entire function.
    319         if ( !isset($menu_item->post_parent) )
    320             $menu_item->post_parent = $menu_item->parent;
    321 
    322         // Get all attachements and links
    323         if ( in_array($object, array( 'attachment', 'custom' )) )
    324             $menu_item->post_parent = 0;
    325 
    326         if ( 0 == $menu_item->post_parent ) {
    327             // Set up the menu item
    328             $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
    329 
    330             // No blank titles
    331             if ( empty($menu_item->title) )
    332                 continue;
    333 
    334             $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
    335 
    336             $output .= '<li'. $attributes .'>';
    337             $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
    338             $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context );
    339             $output .= '</li>';
    340 
    341             ++$i;
    342         }
    343     }
    344 
    345     return $output;
    346 }
    347 
    348 /**
    349  * Recursive function to retrieve sub menu items.
    350  *
    351  * @since 3.0.0
    352  *
    353  * @param string $childof The Parent ID.
    354  * @param string $object_type The object type.
    355  * @param string $object The object name.
    356  * @return string $output sub menu items.
    357  */
    358 function wp_get_nav_menu_sub_items( $childof, $object_type, $object = null, $context = 'frontend' ) {
    359     $args = array( 'child_of' => $childof, 'parent' => $childof, 'hide_empty' => false, );
    360 
    361     switch ( $object_type ) {
    362         case 'post_type':
    363             $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
    364             if ( in_array( $object, $hierarchical_post_types ) ) {
    365                 $args['post_type'] = $object;
    366                 $sub_menu_items = get_pages( $args );
    367             } else {
    368                 $sub_menu_items = array();
    369             }
    370             break;
    371 
    372         case 'taxonomy':
    373             if ( is_taxonomy_hierarchical( $object ) ) {
    374                 $sub_menu_items = get_terms( $object, $args );
    375             } else {
    376                 $sub_menu_items = array();
    377             }
    378             break;
    379 
    380         default:
    381             $sub_menu_items = array();
    382             break;
    383     }
    384 
    385     $output = '';
    386     $i = 1;
    387     if ( !empty($sub_menu_items) && !is_wp_error($sub_menu_items) ) {
    388         $output .= '<ul class="sub-menu menu-item-type-'. $object_type .'">';
    389         foreach ( $sub_menu_items as $menu_item ) {
    390             // Set up the menu item
    391             $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
    392             $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
    393 
    394             $output .= '<li'. $attributes .'>';
    395             $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
    396             $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object );
    397             $output .= '</li>';
    398 
    399             ++$i;
    400         }
    401         $output .= '</ul>';
    402     }
    403     return $output;
    404 }
     820function wp_get_nav_menu_to_edit( $menu_item_id = 0 ) {
     821    static $_placeholder;
     822   
     823    $menu = wp_get_nav_menu_object( $menu_item_id );
     824   
     825    // If the menu exists, get its items.
     826    if ( is_nav_menu( $menu ) ) {
     827        $menu_items = wp_get_nav_menu_items( $menu->term_id );
     828
     829        $walker = new Walker_Nav_Menu_Edit;
     830
     831        return walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
     832    } elseif ( is_wp_error( $menu ) ) {
     833        return $menu;   
     834    }
     835
     836
     837}
     838
    405839?>
Note: See TracChangeset for help on using the changeset viewer.