Changeset 15008
- Timestamp:
- 05/27/2010 10:22:09 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r14943 r15008 817 817 require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; 818 818 819 $menu_id = (int) $_POST['menu']; 820 if ( isset( $_POST['menu-item'] ) ) { 821 $item_ids = wp_save_nav_menu_items( $menu_id, $_POST['menu-item'] ); 822 if ( is_wp_error( $item_ids ) ) 823 die('-1'); 824 } else { 825 $item_ids = array(); 826 } 819 $item_ids = wp_save_nav_menu_items( 0, $_POST['menu-item'] ); 820 if ( is_wp_error( $item_ids ) ) 821 die('-1'); 827 822 828 823 foreach ( (array) $item_ids as $menu_item_id ) { -
trunk/wp-admin/includes/nav-menu.php
r15007 r15008 59 59 $original_title = $original_object->post_title; 60 60 } 61 62 $classes = array( 63 'menu-item menu-item-depth-' . $depth, 64 'menu-item-' . esc_attr( $item->object ), 65 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'), 66 ); 67 68 $title = $item->title; 69 70 if ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 71 $classes[] = 'pending'; 72 /* translators: %s: title of menu item in draft status */ 73 $title = sprintf( __('%s (Pending)'), $item->title ); 74 } 75 61 76 ?> 62 <li id="menu-item-<?php echo $item_id; ?>" class=" menu-item menu-item-depth-<?php echo $depth; ?> menu-item-<?php echo esc_attr( $item->object ); ?> menu-item-edit-<?php echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'; ?>">77 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> 63 78 <dl class="menu-item-bar"> 64 79 <dt class="menu-item-handle"> 65 <span class="item-title"><?php echo esc_html( $ item->title ); ?></span>80 <span class="item-title"><?php echo esc_html( $title ); ?></span> 66 81 <span class="item-controls"> 67 82 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> … … 866 881 * @since 3.0.0 867 882 * 868 * @param int $menu_id The menu ID for which to save this item. 883 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. 869 884 * @param array $menu_data The unsanitized posted menu item data. 870 885 * @return array The database IDs of the items saved … … 874 889 $items_saved = array(); 875 890 876 if ( is_nav_menu( $menu_id ) ) {891 if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { 877 892 878 893 // Loop through all the menu items' POST values … … 883 898 ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set 884 899 in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default 885 'custom' != $_item_object_data['menu-item-type'] || // or it's not a custom menu item900 ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page) 886 901 ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists 887 902 ) … … 999 1014 return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) ); 1000 1015 1016 $some_pending_menu_items = false; 1017 foreach( (array) $menu_items as $menu_item ) { 1018 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1019 $some_pending_menu_items = true; 1020 } 1021 1022 if ( $some_pending_menu_items ) 1023 $result .= '<div class="updated inline"><p>' . __('Click <em>Save Menu</em> to make pending menu items public.') . '</p></div>'; 1024 1001 1025 $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); 1002 1026 return $result; … … 1027 1051 } 1028 1052 1053 /** 1054 * Deletes orphaned draft menu items 1055 * 1056 * @access private 1057 * @since 3.0.0 1058 * 1059 */ 1060 function _wp_delete_orphaned_draft_menu_items() { 1061 global $wpdb; 1062 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 1063 1064 // delete orphaned draft menu items 1065 $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) ); 1066 1067 foreach( (array) $menu_items_to_delete as $menu_item_id ) 1068 wp_delete_post( $menu_item_id, true ); 1069 } 1070 1071 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); 1072 1029 1073 ?> -
trunk/wp-admin/nav-menus.php
r14993 r15008 544 544 <div class="publishing-action"> 545 545 <input class="button-primary menu-save" name="save_menu" type="submit" value="<?php empty($nav_menu_selected_id) ? esc_attr_e('Create Menu') : esc_attr_e('Save Menu'); ?>" /> 546 </div><!-- END .publishing-action-->546 </div><!-- END .publishing-action --> 547 547 548 548 <?php if ( ! empty( $nav_menu_selected_id ) ) : ?> 549 549 <div class="delete-action"> 550 550 <a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( admin_url('nav-menus.php?action=delete&menu=' . $nav_menu_selected_id), 'delete-nav_menu-' . $nav_menu_selected_id ) ); ?>"><?php _e('Delete Menu'); ?></a> 551 </div><!-- END .delete-action-->551 </div><!-- END .delete-action --> 552 552 <?php endif; ?> 553 </div><!-- END .major-publishing-actions-->554 </div><!-- END #submitpost .submitbox-->553 </div><!-- END .major-publishing-actions --> 554 </div><!-- END #submitpost .submitbox --> 555 555 <?php 556 556 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); … … 560 560 <input type="hidden" name="action" value="update" /> 561 561 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 562 </div><!-- END #nav-menu-header-->562 </div><!-- END #nav-menu-header --> 563 563 <div id="post-body"> 564 564 <div id="post-body-content"> … … 581 581 echo '</div>'; 582 582 endif; ?> 583 </div><!-- /#post-body-content -->584 </div><!-- -/#post-body -->585 </form><!-- /#update-nav-menu-->583 </div><!-- /#post-body-content --> 584 </div><!-- /#post-body --> 585 </form><!-- /#update-nav-menu --> 586 586 </div><!-- /.menu-edit --> 587 587 </div><!-- /#menu-management --> 588 588 </div><!-- /#menu-management-liquid --> 589 </div><!-- /#nav-menus-frame -->589 </div><!-- /#nav-menus-frame --> 590 590 </div><!-- /.wrap--> 591 591 -
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.