Ticket #13525: 13822.diff
File 13822.diff, 9.4 KB (added by , 14 years ago) |
---|
-
wp-includes/default-filters.php
235 235 add_action( 'untrash_post', '_wp_untrash_menu_item' ); 236 236 add_action( 'delete_post', '_wp_delete_post_menu_item' ); 237 237 add_action( 'delete_term', '_wp_delete_tax_menu_item' ); 238 add_action( 'transition_post_status', '_wp_ menu_changing_status_observer', 10, 3 );238 add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu', 10, 3 ); 239 239 240 240 // Post Thumbnail CSS class filtering 241 241 add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add' ); -
wp-includes/nav-menu.php
244 244 * 245 245 * @since 3.0.0 246 246 * 247 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a pendingorphan.247 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. 248 248 * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item. 249 249 * @param array $menu_item_data The menu item's data. 250 250 * @return int The menu item's database ID or WP_Error object on failure. … … 262 262 if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) ) 263 263 return $menu; 264 264 265 $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => ' draft,pending,publish' ) );265 $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 266 266 267 267 $count = count( $menu_items ); 268 268 … … 339 339 if ( 0 != $menu_id ) 340 340 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); 341 341 342 // New menu item. Default is pendingstatus342 // New menu item. Default is draft status 343 343 if ( 0 == $menu_item_db_id ) { 344 344 $post['ID'] = 0; 345 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : ' pending';345 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; 346 346 $menu_item_db_id = wp_insert_post( $post ); 347 347 348 348 // Update existing menu item. Default is publish status … … 497 497 unset($terms); 498 498 } 499 499 500 $items = array_map( 'wp_setup_nav_menu_item', $items ); 500 if ( 'publish' == $args['post_status'] ) 501 $items = array_filter( array_map( 'wp_setup_nav_menu_item', $items, true ) ); 502 else 503 $items = array_map( 'wp_setup_nav_menu_item', $items ); 501 504 502 505 if ( ARRAY_A == $args['output'] ) { 503 506 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; … … 535 538 * @param object $menu_item The menu item to modify. 536 539 * @return object $menu_item The menu item with standard menu item properties. 537 540 */ 538 function wp_setup_nav_menu_item( $menu_item ) {541 function wp_setup_nav_menu_item( $menu_item, $published_post_only = false ) { 539 542 if ( isset( $menu_item->post_type ) ) { 540 543 if ( 'nav_menu_item' == $menu_item->post_type ) { 541 544 $menu_item->db_id = (int) $menu_item->ID; … … 545 548 $menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; 546 549 547 550 if ( 'post_type' == $menu_item->type ) { 551 $original_object = get_post( $menu_item->object_id ); 552 if ( $published_post_only && $original_object->post_status != 'publish' ) 553 return null; 554 548 555 $object = get_post_type_object( $menu_item->object ); 549 556 $menu_item->type_label = $object->labels->singular_name; 550 557 $menu_item->url = get_permalink( $menu_item->object_id ); 551 558 552 $original_object = get_post( $menu_item->object_id );553 559 $original_title = $original_object->post_title; 554 560 $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 555 561 … … 670 676 671 677 foreach( (array) $menu_item_ids as $menu_item_id ) { 672 678 $menu_item = get_post( $menu_item_id, ARRAY_A ); 673 $menu_item['post_status'] = ' pending';679 $menu_item['post_status'] = 'draft'; 674 680 wp_insert_post($menu_item); 675 681 } 676 682 } … … 735 741 } 736 742 737 743 /** 738 * Modify a navigational menu upon post object status change, if appropos.744 * Automatically add newly published page objects to menus with that as an option. 739 745 * 740 746 * @since 3.0.0 741 747 * @access private -
wp-admin/includes/nav-menu.php
71 71 $title = $item->title; 72 72 73 73 if ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 74 $classes[] = 'draft';75 /* translators: %s: title of menu item in draft status */76 $title = sprintf( __('%s (Draft)'), $item->title );77 } elseif ( isset( $item->post_status ) && 'pending' == $item->post_status ) {78 74 $classes[] = 'pending'; 79 /* translators: %s: title of menu item in pendingstatus */75 /* translators: %s: title of menu item in draft status */ 80 76 $title = sprintf( __('%s (Pending)'), $item->title ); 81 77 } 82 78 … … 198 194 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> 199 195 <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" /> 200 196 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> 201 <input class="menu-item-data-status" type="hidden" name="menu-item-status[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_status ); ?>" />202 197 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 203 198 </div><!-- .menu-item-settings--> 204 199 <ul class="menu-item-transport"></ul> … … 952 947 * 953 948 * @since 3.0.0 954 949 * 955 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a pending, orphaned menu item.950 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. 956 951 * @param array $menu_data The unsanitized posted menu item data. 957 952 * @return array The database IDs of the items saved 958 953 */ … … 1084 1079 1085 1080 $some_pending_menu_items = false; 1086 1081 foreach( (array) $menu_items as $menu_item ) { 1087 if ( isset( $menu_item->post_status ) && ' pending' == $menu_item->post_status )1082 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1088 1083 $some_pending_menu_items = true; 1089 1084 } 1090 1085 … … 1122 1117 } 1123 1118 1124 1119 /** 1125 * Deletes orphaned pendingmenu items1120 * Deletes orphaned draft menu items 1126 1121 * 1127 1122 * @access private 1128 1123 * @since 3.0.0 1129 1124 * 1130 1125 */ 1131 function _wp_delete_orphaned_ pending_menu_items() {1126 function _wp_delete_orphaned_draft_menu_items() { 1132 1127 global $wpdb; 1133 1128 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 1134 1129 1135 // delete orphaned pendingmenu items1136 $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 = ' pending' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );1130 // delete orphaned draft menu items 1131 $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 ) ); 1137 1132 1138 1133 foreach( (array) $menu_items_to_delete as $menu_item_id ) 1139 1134 wp_delete_post( $menu_item_id, true ); 1140 1135 } 1141 1136 1142 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_ pending_menu_items');1137 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); 1143 1138 1144 1139 ?> -
wp-admin/nav-menus.php
327 327 // Update menu items 328 328 329 329 if ( ! is_wp_error( $_menu_object ) ) { 330 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,p ending,publish') );330 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish') ); 331 331 $menu_items = array(); 332 332 // Index menu items by db ID 333 333 foreach( $unsorted_menu_items as $_item ) 334 334 $menu_items[$_item->db_id] = $_item; 335 335 336 $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item- status', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' );336 $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ); 337 337 wp_defer_term_counting(true); 338 338 // Loop through all the menu items' POST variables 339 339 if ( ! empty( $_POST['menu-item-db-id'] ) ) {