Changeset 15008 for trunk/wp-includes/nav-menu.php
- Timestamp:
- 05/27/2010 10:22:09 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/nav-menu.php
r14971 r15008 248 248 * @since 3.0.0 249 249 * 250 * @param int $menu_id The ID of the menu. Required. 250 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. 251 251 * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item. 252 252 * @param array $menu_item_data The menu item's data. … … 258 258 259 259 // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects 260 if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) {260 if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) 261 261 return new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.')); 262 }263 262 264 263 $menu = wp_get_nav_menu_object( $menu_id ); 265 264 266 if ( ! $menu || is_wp_error( $menu ) ) {265 if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) ) 267 266 return $menu; 268 } 269 270 $menu_items = (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 267 268 $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 271 269 272 270 $count = count( $menu_items ); … … 290 288 291 289 $args = wp_parse_args( $menu_item_data, $defaults ); 292 293 if ( 0 == (int) $args['menu-item-position'] ) { 290 291 if ( 0 == $menu_id ) { 292 $args['menu-item-position'] = 1; 293 } elseif ( 0 == (int) $args['menu-item-position'] ) { 294 294 $last_item = array_pop( $menu_items ); 295 295 $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : $count; … … 340 340 'post_title' => $args['menu-item-title'], 341 341 'post_type' => 'nav_menu_item', 342 'tax_input' => array( 'nav_menu' => array( intval( $menu->term_id ) ) ),343 342 ); 343 344 if ( 0 != $menu_id ) 345 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); 344 346 345 347 // New menu item. Default is draft status … … 375 377 update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] ); 376 378 update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); 377 378 // @todo: only save custom link urls.379 379 update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); 380 381 if ( 0 == $menu_id ) 382 update_post_meta( $menu_item_db_id, '_menu_item_orphaned', time() ); 383 else 384 delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); 380 385 381 386 do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args ); … … 741 746 } 742 747 748 /** 749 * Automatically add newly published page objects to menus with that as an option. 750 * 751 * @since 3.0.0 752 * @access private 753 * 754 * @param string $new_status The new status of the post object. 755 * @param string $old_status The old status of the post object. 756 * @param object $post The post object being transitioned from one status to another. 757 * @return void 758 */ 743 759 function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { 744 760 if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
Note: See TracChangeset
for help on using the changeset viewer.