Ticket #13822: 13822-reverts-r15219.diff
File 13822-reverts-r15219.diff, 14.8 KB (added by , 15 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-template.php
151 151 if ( ! $menu && !$args->theme_location ) { 152 152 $menus = wp_get_nav_menus(); 153 153 foreach ( $menus as $menu_maybe ) { 154 if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id ) ) {154 if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id, array( 'public' => true ) ) ) { 155 155 $menu = $menu_maybe; 156 156 break; 157 157 } … … 160 160 161 161 // If the menu exists, get its items. 162 162 if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) 163 $menu_items = wp_get_nav_menu_items( $menu->term_id );163 $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'public' => true ) ); 164 164 165 165 // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists 166 166 if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) -
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 … … 454 454 455 455 $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 456 456 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 457 'update_post_term_cache' => false );457 'update_post_term_cache' => false, 'public' => false ); 458 458 $args = wp_parse_args( $args, $defaults ); 459 $public_consumption = $args['public']; 460 unset( $args['public'] ); 459 461 if ( count( $items ) > 1 ) 460 462 $args['include'] = implode( ',', $items ); 461 463 else … … 497 499 unset($terms); 498 500 } 499 501 500 $items = array_map( 'wp_setup_nav_menu_item', $items ); 502 if ( $public_consumption ) 503 $items = array_filter( array_map( 'wp_setup_nav_menu_item_published', $items ) ); 504 else 505 $items = array_map( 'wp_setup_nav_menu_item', $items ); 501 506 502 507 if ( ARRAY_A == $args['output'] ) { 503 508 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; … … 512 517 } 513 518 514 519 /** 520 * Callback that wraps wp_setup_nav_menu_item() to ensure only published posts are shown publicly. 521 * 522 * @uses wp_setup_nav_menu_item() 523 * @since 3.0.0 524 */ 525 function wp_setup_nav_menu_item_published( $menu_item ) { 526 return wp_setup_nav_menu_item( $menu_item, array( 'post_object_status' => 'publish' ) ); 527 } 528 529 /** 515 530 * Decorates a menu item object with the shared navigation menu item properties. 516 531 * 517 532 * Properties: … … 533 548 * @since 3.0.0 534 549 * 535 550 * @param object $menu_item The menu item to modify. 551 * @param array $args 536 552 * @return object $menu_item The menu item with standard menu item properties. 537 553 */ 538 function wp_setup_nav_menu_item( $menu_item ) { 554 function wp_setup_nav_menu_item( $menu_item, $args = array() ) { 555 $defaults = array( 'post_object_status' => 'any' ); 556 $args = wp_parse_args( $args, $defaults ); 557 539 558 if ( isset( $menu_item->post_type ) ) { 540 559 if ( 'nav_menu_item' == $menu_item->post_type ) { 541 560 $menu_item->db_id = (int) $menu_item->ID; … … 545 564 $menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; 546 565 547 566 if ( 'post_type' == $menu_item->type ) { 567 $original_object = get_post( $menu_item->object_id ); 568 if ( 'publish' == $args['post_object_status'] && $original_object->post_status != 'publish' ) 569 return null; 570 548 571 $object = get_post_type_object( $menu_item->object ); 549 572 $menu_item->type_label = $object->labels->singular_name; 550 573 $menu_item->url = get_permalink( $menu_item->object_id ); 551 574 552 $original_object = get_post( $menu_item->object_id );553 575 $original_title = $original_object->post_title; 554 576 $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 555 577 … … 670 692 671 693 foreach( (array) $menu_item_ids as $menu_item_id ) { 672 694 $menu_item = get_post( $menu_item_id, ARRAY_A ); 673 $menu_item['post_status'] = ' pending';695 $menu_item['post_status'] = 'draft'; 674 696 wp_insert_post($menu_item); 675 697 } 676 698 } … … 735 757 } 736 758 737 759 /** 738 * Modify a navigational menu upon post object status change, if appropos.760 * Automatically add newly published page objects to menus with that as an option. 739 761 * 740 762 * @since 3.0.0 741 763 * @access private … … 745 767 * @param object $post The post object being transitioned from one status to another. 746 768 * @return void 747 769 */ 748 function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) { 749 // append new top-level page objects to a menu for which that option is selected 750 if ( 751 'publish' == $new_status && 752 'publish' != $old_status && 753 'page' == $post->post_type && 754 empty( $post->post_parent ) 755 ) { 756 $auto_add = get_option( 'nav_menu_options' ); 757 if ( 758 isset( $auto_add['auto_add'] ) && 759 is_array( $auto_add['auto_add'] ) 760 ) { 761 $args = array( 762 'menu-item-object-id' => $post->ID, 763 'menu-item-object' => $post->post_type, 764 'menu-item-type' => 'post_type', 765 'menu-item-status' => 'publish', 766 ); 770 function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { 771 if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) 772 return; 773 if ( ! empty( $post->post_parent ) ) 774 return; 775 $auto_add = get_option( 'nav_menu_options' ); 776 if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) 777 return; 778 $auto_add = $auto_add['auto_add']; 779 if ( empty( $auto_add ) || ! is_array( $auto_add ) ) 780 return; 767 781 768 foreach ( $auto_add['auto_add'] as $menu_id ) { 769 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) ); 770 if ( ! is_array( $items ) ) 771 continue; 772 foreach ( $items as $item ) { 773 if ( $post->ID == $item->object_id ) 774 continue 2; 775 } 776 wp_update_nav_menu_item( $menu_id, 0, $args ); 777 } 778 } 779 } 782 $args = array( 783 'menu-item-object-id' => $post->ID, 784 'menu-item-object' => $post->post_type, 785 'menu-item-type' => 'post_type', 786 'menu-item-status' => 'publish', 787 ); 780 788 781 // give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published) 782 if ( 783 ! empty( $post->ID ) && 784 ( 785 ( 'publish' == $old_status && 'draft' == $new_status ) || 786 ( 'draft' == $old_status && 'publish' == $new_status ) 787 ) 788 ) { 789 $menu_items = get_posts(array( 790 'meta_key' => '_menu_item_object_id', 791 'meta_value' => $post->ID, 792 'post_status' => 'any', 793 'post_type' => 'nav_menu_item', 794 )); 795 796 foreach( (array) $menu_items as $menu_item ) { 797 if ( ! empty( $menu_item->ID ) ) { 798 $properties = get_object_vars( $menu_item ); 799 $properties['post_status'] = $new_status; 800 801 wp_insert_post( $properties ); 802 } 789 foreach ( $auto_add as $menu_id ) { 790 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 791 if ( ! is_array( $items ) ) 792 continue; 793 foreach ( $items as $item ) { 794 if ( $post->ID == $item->object_id ) 795 continue 2; 803 796 } 797 wp_update_nav_menu_item( $menu_id, 0, $args ); 804 798 } 805 799 } 806 800 -
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';74 $classes[] = 'unsaved'; 75 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 $classes[] = 'pending'; 79 /* translators: %s: title of menu item in pending status */ 80 $title = sprintf( __('%s (Pending)'), $item->title ); 76 $title = sprintf( __('%s (Unsaved)'), $item->title ); 77 } elseif ( 'post_type' == $item->type && $original_object->post_status != 'publish' ) { 78 $classes[] = 'unpublished-post'; 79 $original_status = get_post_status_object( $original_object->post_status ); 80 /* translators: 1: title of menu item in unpublished status, 2: actual post status. */ 81 $title = sprintf( __('%1$s (%2$s)'), $item->title, $original_status->label ); 81 82 } 82 83 83 84 $title = empty( $item->label ) ? $title : $item->label; … … 198 199 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> 199 200 <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 201 <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 202 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 203 203 </div><!-- .menu-item-settings--> 204 204 <ul class="menu-item-transport"></ul> … … 952 952 * 953 953 * @since 3.0.0 954 954 * 955 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a pending, orphaned menu item.955 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. 956 956 * @param array $menu_data The unsanitized posted menu item data. 957 957 * @return array The database IDs of the items saved 958 958 */ … … 1084 1084 1085 1085 $some_pending_menu_items = false; 1086 1086 foreach( (array) $menu_items as $menu_item ) { 1087 if ( isset( $menu_item->post_status ) && ' pending' == $menu_item->post_status )1087 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1088 1088 $some_pending_menu_items = true; 1089 1089 } 1090 1090 … … 1122 1122 } 1123 1123 1124 1124 /** 1125 * Deletes orphaned pendingmenu items1125 * Deletes orphaned draft menu items 1126 1126 * 1127 1127 * @access private 1128 1128 * @since 3.0.0 1129 1129 * 1130 1130 */ 1131 function _wp_delete_orphaned_ pending_menu_items() {1131 function _wp_delete_orphaned_draft_menu_items() { 1132 1132 global $wpdb; 1133 1133 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 1134 1134 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 ) );1135 // delete orphaned draft menu items 1136 $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 1137 1138 1138 foreach( (array) $menu_items_to_delete as $menu_item_id ) 1139 1139 wp_delete_post( $menu_item_id, true ); 1140 1140 } 1141 1141 1142 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_ pending_menu_items');1142 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); 1143 1143 1144 1144 ?> -
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'] ) ) {