mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-09 18:08:09 +01:00
Optimize menu item creation. Props filosofo. Fixes #14415
git-svn-id: http://svn.automattic.com/wordpress/trunk@16096 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0fceac8180
commit
089a7226f1
@ -743,7 +743,37 @@ case 'add-menu-item' :
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
|
||||
|
||||
$item_ids = wp_save_nav_menu_items( 0, $_POST['menu-item'] );
|
||||
/**
|
||||
* For performance reasons, we omit some object properties from the checklist.
|
||||
* The following is a hacky way to restore them when adding non-custom items.
|
||||
*/
|
||||
$menu_items_data = (array) $_POST['menu-item'];
|
||||
$menu_item_data = array_shift( $menu_items_data );
|
||||
if (
|
||||
! empty( $menu_item_data['menu-item-type'] ) &&
|
||||
'custom' != $menu_item_data['menu-item-type'] &&
|
||||
! empty( $menu_item_data['menu-item-object-id'] )
|
||||
) {
|
||||
switch( $menu_item_data['menu-item-type'] ) {
|
||||
case 'post_type' :
|
||||
$_object = get_post( $menu_item_data['menu-item-object-id'] );
|
||||
break;
|
||||
|
||||
case 'taxonomy' :
|
||||
$_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
|
||||
break;
|
||||
}
|
||||
|
||||
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
|
||||
$_menu_item = array_shift( $_menu_items );
|
||||
|
||||
/** Restore the missing menu item properties **/
|
||||
$menu_item_data['menu-item-description'] = $_menu_item->description;
|
||||
|
||||
$menu_items_data = array( $menu_item_data );
|
||||
}
|
||||
|
||||
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
|
||||
if ( is_wp_error( $item_ids ) )
|
||||
die('-1');
|
||||
|
||||
|
@ -245,7 +245,6 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
|
||||
$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
|
||||
$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 ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-description" name="menu-item[' . $possible_object_id . '][menu-item-description]" value="'. esc_attr( $item->description ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user