Ticket #13579: pending-menu-items.13579.diff
| File pending-menu-items.13579.diff, 9.8 KB (added by filosofo, 3 years ago) |
|---|
-
wp-includes/functions.php
4130 4130 wp_delete_comment($comment_id); 4131 4131 } 4132 4132 } 4133 4134 // delete orphaned draft menu items 4135 $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 ) ); 4136 4137 foreach( (array) $menu_items_to_delete as $menu_item_id ) 4138 wp_delete_post( $menu_item_id, true ); 4133 4139 } 4134 4140 4135 4141 /** -
wp-includes/nav-menu.php
247 247 * 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. 253 253 * @return int The menu item's database ID or WP_Error object on failure. … … 263 263 264 264 $menu = wp_get_nav_menu_object( $menu_id ); 265 265 266 if ( ! $menu|| is_wp_error( $menu ) ) {266 if ( ( ! $menu && 0 != $menu_id ) || is_wp_error( $menu ) ) { 267 267 return $menu; 268 268 } 269 269 270 $menu_items = (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );270 $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 271 271 272 272 $count = count( $menu_items ); 273 273 … … 289 289 ); 290 290 291 291 $args = wp_parse_args( $menu_item_data, $defaults ); 292 293 if ( 0 == (int) $args['menu-item-position'] ) { 292 293 if ( 0 == $menu_id ) { 294 $args['menu-item-position'] = 1; 295 } elseif ( 0 == (int) $args['menu-item-position'] ) { 294 296 $last_item = array_pop( $menu_items ); 295 297 $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : $count; 296 298 } … … 339 341 'post_parent' => $original_parent, 340 342 'post_title' => $args['menu-item-title'], 341 343 'post_type' => 'nav_menu_item', 342 'tax_input' => array( 'nav_menu' => array( intval( $menu->term_id ) ) ),343 344 ); 344 345 346 if ( 0 != $menu_id ) 347 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); 348 345 349 // New menu item. Default is draft status 346 350 if ( 0 == $menu_item_db_id ) { 347 351 $post['ID'] = 0; … … 374 378 $args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) ); 375 379 update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] ); 376 380 update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); 377 378 // @todo: only save custom link urls.379 381 update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); 382 383 if ( 0 == $menu_id ) 384 update_post_meta( $menu_item_db_id, '_menu_item_orphaned', time() ); 385 else 386 delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); 380 387 381 388 do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args ); 382 389 } … … 740 747 } 741 748 } 742 749 750 /** 751 * Automatically add newly published page objects to menus with that as an option. 752 * 753 * @since 3.0.0 754 * @access private 755 * 756 * @param string $new_status The new status of the post object. 757 * @param string $old_status The old status of the post object. 758 * @param object $post The post object being transitioned from one status to another. 759 * @return void 760 */ 743 761 function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { 744 762 if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) 745 763 return; -
wp-admin/admin-ajax.php
816 816 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 ) { 829 824 $menu_obj = get_post( $menu_item_id ); -
wp-admin/includes/nav-menu.php
58 58 $original_object = get_post( $item->object_id ); 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 $title = sprintf( _x('%s (Pending)', 'menu item title with "pending" indicating its draft status'), $item->title ); 73 } 74 61 75 ?> 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'; ?>">76 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> 63 77 <dl class="menu-item-bar"> 64 78 <dt class="menu-item-handle"> 65 <span class="item-title"><?php echo esc_html( $ item->title ); ?></span>79 <span class="item-title"><?php echo esc_html( $title ); ?></span> 66 80 <span class="item-controls"> 67 81 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> 68 82 <span class="item-order"> … … 871 885 * 872 886 * @since 3.0.0 873 887 * 874 * @param int $menu_id The menu ID for which to save this item. 888 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. 875 889 * @param array $menu_data The unsanitized posted menu item data. 876 890 * @return array The database IDs of the items saved 877 891 */ … … 879 893 $menu_id = (int) $menu_id; 880 894 $items_saved = array(); 881 895 882 if ( is_nav_menu( $menu_id ) ) {896 if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { 883 897 884 898 // Loop through all the menu items' POST values 885 899 foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) { … … 888 902 ( 889 903 ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set 890 904 in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default 891 'custom' != $_item_object_data['menu-item-type'] || // or it's not a custom menu item905 ! ( '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) 892 906 ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists 893 907 ) 894 908 ) { … … 1004 1018 else 1005 1019 return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) ); 1006 1020 1021 $some_pending_menu_items = false; 1022 foreach( (array) $menu_items as $menu_item ) { 1023 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1024 $some_pending_menu_items = true; 1025 } 1026 1027 if ( $some_pending_menu_items ) 1028 $result .= '<div class="updated post-body-plain">' . __('Click <em>Save</em> to make pending menu items public.') . '</div>'; 1029 1007 1030 $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); 1008 1031 return $result; 1009 1032 } elseif ( is_wp_error( $menu ) ) { -
wp-admin/nav-menus.php
543 543 <br class="clear" /> 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 ); 557 557 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); … … 559 559 ?> 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"> 565 565 <?php if ( is_nav_menu( $nav_menu_selected_id ) ) : ?>
