Ticket #13822: 13822-reverts-r15219.3.diff
File 13822-reverts-r15219.3.diff, 18.3 KB (added by , 15 years ago) |
---|
-
wp-includes/default-filters.php
231 231 add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); 232 232 233 233 // Navigation menu actions 234 add_action( 'trash_post', '_wp_trash_menu_item' );235 add_action( 'untrash_post', '_wp_untrash_menu_item' );236 234 add_action( 'delete_post', '_wp_delete_post_menu_item' ); 237 235 add_action( 'delete_term', '_wp_delete_tax_menu_item' ); 238 add_action( 'transition_post_status', '_wp_ menu_changing_status_observer', 10, 3 );236 add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu', 10, 3 ); 239 237 240 238 // Post Thumbnail CSS class filtering 241 239 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 … … 311 311 $original_object = get_post( $args['menu-item-object-id'] ); 312 312 $original_parent = (int) $original_object->post_parent; 313 313 $original_title = $original_object->post_title; 314 315 if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) )316 return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to something that is in the trash, so it cannot be updated.'), $args['menu-item-title'] ) );317 314 } 318 315 319 316 if ( empty( $args['menu-item-title'] ) || $args['menu-item-title'] == $original_title ) { … … 339 336 if ( 0 != $menu_id ) 340 337 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); 341 338 342 // New menu item. Default is pendingstatus339 // New menu item. Default is draft status 343 340 if ( 0 == $menu_item_db_id ) { 344 341 $post['ID'] = 0; 345 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : ' pending';342 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; 346 343 $menu_item_db_id = wp_insert_post( $post ); 347 344 348 345 // Update existing menu item. Default is publish status … … 454 451 455 452 $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 456 453 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 457 'update_post_term_cache' => false );454 'update_post_term_cache' => false, 'public' => false ); 458 455 $args = wp_parse_args( $args, $defaults ); 456 $public_consumption = $args['public']; 457 unset( $args['public'] ); 459 458 if ( count( $items ) > 1 ) 460 459 $args['include'] = implode( ',', $items ); 461 460 else … … 497 496 unset($terms); 498 497 } 499 498 500 $items = array_map( 'wp_setup_nav_menu_item', $items ); 499 if ( $public_consumption ) 500 $items = array_filter( array_map( 'wp_setup_nav_menu_item_published', $items ) ); 501 else 502 $items = array_map( 'wp_setup_nav_menu_item', $items ); 501 503 502 504 if ( ARRAY_A == $args['output'] ) { 503 505 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; … … 512 514 } 513 515 514 516 /** 517 * Callback that wraps wp_setup_nav_menu_item() to ensure only published posts are shown publicly. 518 * 519 * @uses wp_setup_nav_menu_item() 520 * @since 3.0.0 521 */ 522 function wp_setup_nav_menu_item_published( $menu_item ) { 523 return wp_setup_nav_menu_item( $menu_item, array( 'post_object_status' => 'publish' ) ); 524 } 525 526 /** 515 527 * Decorates a menu item object with the shared navigation menu item properties. 516 528 * 517 529 * Properties: … … 533 545 * @since 3.0.0 534 546 * 535 547 * @param object $menu_item The menu item to modify. 548 * @param array $args 536 549 * @return object $menu_item The menu item with standard menu item properties. 537 550 */ 538 function wp_setup_nav_menu_item( $menu_item ) { 551 function wp_setup_nav_menu_item( $menu_item, $args = array() ) { 552 $defaults = array( 'post_object_status' => 'any' ); 553 $args = wp_parse_args( $args, $defaults ); 554 539 555 if ( isset( $menu_item->post_type ) ) { 540 556 if ( 'nav_menu_item' == $menu_item->post_type ) { 541 557 $menu_item->db_id = (int) $menu_item->ID; … … 545 561 $menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; 546 562 547 563 if ( 'post_type' == $menu_item->type ) { 564 $original_object = get_post( $menu_item->object_id ); 565 if ( 'publish' == $args['post_object_status'] && $original_object->post_status != 'publish' ) 566 return null; 567 548 568 $object = get_post_type_object( $menu_item->object ); 549 569 $menu_item->type_label = $object->labels->singular_name; 550 570 $menu_item->url = get_permalink( $menu_item->object_id ); 551 571 552 $original_object = get_post( $menu_item->object_id );553 572 $original_title = $original_object->post_title; 554 573 $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 555 574 … … 655 674 } 656 675 657 676 /** 658 * Callback for handling a menu item when its original object is trashed.659 *660 * @since 3.0.0661 * @access private662 *663 * @param int $object_id The ID of the original object being trashed.664 *665 */666 function _wp_trash_menu_item( $object_id = 0 ) {667 $object_id = (int) $object_id;668 669 $menu_item_ids = wp_get_associated_nav_menu_items( $object_id );670 671 foreach( (array) $menu_item_ids as $menu_item_id ) {672 $menu_item = get_post( $menu_item_id, ARRAY_A );673 $menu_item['post_status'] = 'pending';674 wp_insert_post($menu_item);675 }676 }677 678 /**679 * Callback for handling a menu item when its original object is un-trashed.680 *681 * @since 3.0.0682 * @access private683 *684 * @param int $object_id The ID of the original object being untrashed.685 *686 */687 function _wp_untrash_menu_item( $object_id = 0 ) {688 $object_id = (int) $object_id;689 690 $menu_item_ids = wp_get_associated_nav_menu_items( $object_id );691 692 foreach( (array) $menu_item_ids as $menu_item_id ) {693 $menu_item = get_post( $menu_item_id, ARRAY_A );694 $menu_item['post_status'] = 'publish';695 wp_insert_post($menu_item);696 }697 }698 699 /**700 677 * Callback for handling a menu item when its original object is deleted. 701 678 * 702 679 * @since 3.0.0 … … 735 712 } 736 713 737 714 /** 738 * Modify a navigational menu upon post object status change, if appropos.715 * Automatically add newly published page objects to menus with that as an option. 739 716 * 740 717 * @since 3.0.0 741 718 * @access private … … 745 722 * @param object $post The post object being transitioned from one status to another. 746 723 * @return void 747 724 */ 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 ); 725 function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { 726 if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) 727 return; 728 if ( ! empty( $post->post_parent ) ) 729 return; 730 $auto_add = get_option( 'nav_menu_options' ); 731 if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) 732 return; 733 $auto_add = $auto_add['auto_add']; 734 if ( empty( $auto_add ) || ! is_array( $auto_add ) ) 735 return; 767 736 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 } 737 $args = array( 738 'menu-item-object-id' => $post->ID, 739 'menu-item-object' => $post->post_type, 740 'menu-item-type' => 'post_type', 741 'menu-item-status' => 'publish', 742 ); 780 743 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 } 744 foreach ( $auto_add as $menu_id ) { 745 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 746 if ( ! is_array( $items ) ) 747 continue; 748 foreach ( $items as $item ) { 749 if ( $post->ID == $item->object_id ) 750 continue 2; 803 751 } 752 wp_update_nav_menu_item( $menu_id, 0, $args ); 804 753 } 805 754 } 806 755 -
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 $original_status = get_post_status_object( $original_object->post_status ); 79 $classes[] = "unpublished-post post-status-$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; … … 176 177 <div class="menu-item-actions description-wide submitbox"> 177 178 <?php if( 'custom' != $item->type ) : ?> 178 179 <p class="link-to-original"> 179 <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> 180 <?php 181 $post_status = get_post_status( $item->object_id ); 182 if( 'publish' == $post_status ) { 183 printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>', '' ); 184 } else { 185 $original_url = $item->url; 186 if( 'trash' == $post_status ) { 187 $original_url = add_query_arg( 188 array( 189 'post_status' => 'trash', 190 'post_type' => $item->object, 191 ), 192 admin_url( 'edit.php' ) 193 ); 194 } 195 $post_status_obj = get_post_status_object( $post_status ); 196 /* translators: 1: title, 2: post status. */ 197 printf( __('Original: %1$s (%2$s)'), '<a href="' . esc_attr( $original_url ) . '">' . esc_html( $original_title ) . '</a>', 198 $post_status_obj->label ); 199 } 200 ?> 180 201 </p> 181 202 <?php endif; ?> 182 203 <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php … … 198 219 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> 199 220 <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 221 <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 222 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 203 223 </div><!-- .menu-item-settings--> 204 224 <ul class="menu-item-transport"></ul> … … 952 972 * 953 973 * @since 3.0.0 954 974 * 955 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a pending, orphaned menu item.975 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. 956 976 * @param array $menu_data The unsanitized posted menu item data. 957 977 * @return array The database IDs of the items saved 958 978 */ … … 1084 1104 1085 1105 $some_pending_menu_items = false; 1086 1106 foreach( (array) $menu_items as $menu_item ) { 1087 if ( isset( $menu_item->post_status ) && ' pending' == $menu_item->post_status )1107 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1088 1108 $some_pending_menu_items = true; 1089 1109 } 1090 1110 1091 1111 if ( $some_pending_menu_items ) 1092 $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pendingmenu items public.') . '</p></div>';1112 $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make unsaved menu items public.') . '</p></div>'; 1093 1113 1094 1114 $result .= '<ul class="menu" id="menu-to-edit"> '; 1095 1115 $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); … … 1122 1142 } 1123 1143 1124 1144 /** 1125 * Deletes orphaned pendingmenu items1145 * Deletes orphaned draft menu items 1126 1146 * 1127 1147 * @access private 1128 1148 * @since 3.0.0 1129 1149 * 1130 1150 */ 1131 function _wp_delete_orphaned_ pending_menu_items() {1151 function _wp_delete_orphaned_draft_menu_items() { 1132 1152 global $wpdb; 1133 1153 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 1134 1154 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 ) );1155 // delete orphaned draft menu items 1156 $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 1157 1138 1158 foreach( (array) $menu_items_to_delete as $menu_item_id ) 1139 1159 wp_delete_post( $menu_item_id, true ); 1140 1160 } 1141 1161 1142 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_ pending_menu_items');1162 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); 1143 1163 1144 1164 ?> -
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'] ) ) {