Make WordPress Core

Changeset 16096


Ignore:
Timestamp:
10/30/2010 12:13:45 AM (14 years ago)
Author:
scribu
Message:

Optimize menu item creation. Props filosofo. Fixes #14415

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r16009 r16096  
    744744    require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    745745
    746     $item_ids = wp_save_nav_menu_items( 0, $_POST['menu-item'] );
     746    /**
     747     * For performance reasons, we omit some object properties from the checklist. 
     748     * The following is a hacky way to restore them when adding non-custom items.
     749     */
     750    $menu_items_data = (array) $_POST['menu-item'];
     751    $menu_item_data = array_shift( $menu_items_data );
     752    if (
     753        ! empty( $menu_item_data['menu-item-type'] ) &&
     754        'custom' != $menu_item_data['menu-item-type'] &&
     755        ! empty( $menu_item_data['menu-item-object-id'] )
     756    ) {
     757        switch( $menu_item_data['menu-item-type'] ) {
     758            case 'post_type' :
     759                $_object = get_post( $menu_item_data['menu-item-object-id'] );
     760            break;
     761
     762            case 'taxonomy' :
     763                $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
     764            break;
     765        }
     766
     767        $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
     768        $_menu_item = array_shift( $_menu_items );
     769
     770        /** Restore the missing menu item properties **/
     771        $menu_item_data['menu-item-description'] = $_menu_item->description;
     772
     773        $menu_items_data = array( $menu_item_data );
     774    }
     775
     776    $item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
    747777    if ( is_wp_error( $item_ids ) )
    748778        die('-1');
  • trunk/wp-admin/includes/nav-menu.php

    r16061 r16096  
    246246        $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
    247247        $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
    248         $output .= '<input type="hidden" class="menu-item-description" name="menu-item[' . $possible_object_id . '][menu-item-description]" value="'. esc_attr( $item->description ) .'" />';
    249248        $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
    250249        $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
Note: See TracChangeset for help on using the changeset viewer.