Changeset 22235
- Timestamp:
- 10/15/2012 02:27:16 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/nav-menu.php
r22233 r22235 279 279 if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) ) 280 280 return $menu; 281 282 $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );283 284 $count = count( $menu_items );285 281 286 282 $defaults = array( … … 306 302 $args['menu-item-position'] = 1; 307 303 } elseif ( 0 == (int) $args['menu-item-position'] ) { 304 $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 308 305 $last_item = array_pop( $menu_items ); 309 $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : $count;306 $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items ); 310 307 } 311 308 … … 351 348 ); 352 349 353 if ( 0 != $menu_id)350 if ( $menu_id && ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) 354 351 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); 355 352 353 $update = 0 != $menu_item_db_id; 354 356 355 // New menu item. Default is draft status 357 if ( 0 == $menu_item_db_id) {356 if ( ! $update ) { 358 357 $post['ID'] = 0; 359 358 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; 360 359 $menu_item_db_id = wp_insert_post( $post ); 361 362 // Update existing menu item. Default is publish status 363 } else { 364 $post['ID'] = $menu_item_db_id; 365 $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; 366 wp_update_post( $post ); 360 if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) 361 return $menu_item_db_id; 367 362 } 368 363 … … 372 367 } 373 368 374 if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) )375 return $menu_item_db_id;376 377 369 $menu_item_db_id = (int) $menu_item_db_id; 378 370 379 371 update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) ); 380 update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', (int) $args['menu-item-parent-id']);381 update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $args['menu-item-object-id']);372 update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) ); 373 update_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) ); 382 374 update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) ); 383 375 update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) ); … … 390 382 391 383 if ( 0 == $menu_id ) 392 update_post_meta( $menu_item_db_id, '_menu_item_orphaned', time() );393 else 384 update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); 385 elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) 394 386 delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); 387 388 // Update existing menu item. Default is publish status 389 if ( $update ) { 390 $post['ID'] = $menu_item_db_id; 391 $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; 392 wp_update_post( $post ); 393 } 395 394 396 395 do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args );
Note: See TracChangeset
for help on using the changeset viewer.