Changeset 15254
- Timestamp:
- 06/14/2010 07:52:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/nav-menu.php
r15250 r15254 72 72 73 73 if ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 74 $original_status = get_post_status_object( $original_object->post_status ); 75 $classes[] = "draft post-status-$original_object->post_status"; 76 /* translators: 1: title of menu item in draft status, 2: actual post status. */ 77 $title = sprintf( __('%1$s (%2$s)'), $item->title, $original_status->label ); 78 } elseif ( isset( $item->post_status ) && 'pending' == $item->post_status ) { 79 $classes[] = 'unsaved'; 80 /* translators: %s: title of menu item in pending status */ 81 $title = sprintf( __('%s (Unsaved)'), $item->title ); 74 $classes[] = 'pending'; 75 /* translators: %s: title of menu item in draft status */ 76 $title = sprintf( __('%s (Pending)'), $item->title ); 82 77 } 83 78 … … 178 173 <?php if( 'custom' != $item->type ) : ?> 179 174 <p class="link-to-original"> 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 ?> 175 <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> 201 176 </p> 202 177 <?php endif; ?> … … 220 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 ); ?>" /> 221 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 ); ?>" /> 222 <input class="menu-item-data-status" type="hidden" name="menu-item-status[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_status ); ?>" />223 197 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 224 198 </div><!-- .menu-item-settings--> … … 974 948 * @since 3.0.0 975 949 * 976 * @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. 977 951 * @param array $menu_data The unsanitized posted menu item data. 978 952 * @return array The database IDs of the items saved … … 1106 1080 $some_pending_menu_items = false; 1107 1081 foreach( (array) $menu_items as $menu_item ) { 1108 if ( isset( $menu_item->post_status ) && ' pending' == $menu_item->post_status )1082 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1109 1083 $some_pending_menu_items = true; 1110 1084 } 1111 1085 1112 1086 if ( $some_pending_menu_items ) 1113 $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make unsavedmenu items public.') . '</p></div>';1087 $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>'; 1114 1088 1115 1089 $result .= '<ul class="menu" id="menu-to-edit"> '; … … 1144 1118 1145 1119 /** 1146 * Deletes orphaned pendingmenu items1120 * Deletes orphaned draft menu items 1147 1121 * 1148 1122 * @access private … … 1150 1124 * 1151 1125 */ 1152 function _wp_delete_orphaned_ pending_menu_items() {1126 function _wp_delete_orphaned_draft_menu_items() { 1153 1127 global $wpdb; 1154 1128 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 1155 1129 1156 // delete orphaned pendingmenu items1157 $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 ) ); 1158 1132 1159 1133 foreach( (array) $menu_items_to_delete as $menu_item_id ) … … 1161 1135 } 1162 1136 1163 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'); 1164 1138 1165 1139 ?> -
trunk/wp-admin/nav-menus.php
r15219 r15254 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 … … 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 -
trunk/wp-includes/default-filters.php
r15249 r15254 234 234 add_action( 'delete_post', '_wp_delete_post_menu_item' ); 235 235 add_action( 'delete_term', '_wp_delete_tax_menu_item' ); 236 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 ); 237 237 238 238 // Post Thumbnail CSS class filtering -
trunk/wp-includes/nav-menu.php
r15249 r15254 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. … … 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 ); … … 337 337 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); 338 338 339 // New menu item. Default is pendingstatus339 // New menu item. Default is draft status 340 340 if ( 0 == $menu_item_db_id ) { 341 341 $post['ID'] = 0; 342 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : ' pending';342 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; 343 343 $menu_item_db_id = wp_insert_post( $post ); 344 344 … … 691 691 692 692 /** 693 * Modify a navigational menu upon post object status change, if appropos.693 * Automatically add newly published page objects to menus with that as an option. 694 694 * 695 695 * @since 3.0.0 … … 701 701 * @return void 702 702 */ 703 function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) { 704 // append new top-level page objects to a menu for which that option is selected 705 if ( 706 'publish' == $new_status && 707 'publish' != $old_status && 708 'page' == $post->post_type && 709 empty( $post->post_parent ) 710 ) { 711 $auto_add = get_option( 'nav_menu_options' ); 712 if ( 713 isset( $auto_add['auto_add'] ) && 714 is_array( $auto_add['auto_add'] ) 715 ) { 716 $args = array( 717 'menu-item-object-id' => $post->ID, 718 'menu-item-object' => $post->post_type, 719 'menu-item-type' => 'post_type', 720 'menu-item-status' => 'publish', 721 ); 722 723 foreach ( $auto_add['auto_add'] as $menu_id ) { 724 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) ); 725 if ( ! is_array( $items ) ) 726 continue; 727 foreach ( $items as $item ) { 728 if ( $post->ID == $item->object_id ) 729 continue 2; 730 } 731 wp_update_nav_menu_item( $menu_id, 0, $args ); 732 } 733 } 734 } 735 736 // give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published) 737 if ( 738 ( $new_status != $old_status ) && 739 ! empty( $post->ID ) && ! empty( $post->post_type ) && 740 'nav_menu_item' != $post->post_type && 741 ( 'publish' == $old_status || 'publish' == $new_status ) 742 ) { 743 $menu_items = get_posts(array( 744 'meta_key' => '_menu_item_object_id', 745 'meta_value' => $post->ID, 746 'post_status' => 'any', 747 'post_type' => 'nav_menu_item', 748 )); 749 750 foreach( (array) $menu_items as $menu_item ) { 751 if ( ! empty( $menu_item->ID ) ) { 752 $properties = get_object_vars( $menu_item ); 753 $properties['post_status'] = 'publish' == $new_status ? 'publish' : 'draft'; 754 755 wp_insert_post( $properties ); 756 } 757 } 703 function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) { 704 if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type ) 705 return; 706 if ( ! empty( $post->post_parent ) ) 707 return; 708 $auto_add = get_option( 'nav_menu_options' ); 709 if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) ) 710 return; 711 $auto_add = $auto_add['auto_add']; 712 if ( empty( $auto_add ) || ! is_array( $auto_add ) ) 713 return; 714 715 $args = array( 716 'menu-item-object-id' => $post->ID, 717 'menu-item-object' => $post->post_type, 718 'menu-item-type' => 'post_type', 719 'menu-item-status' => 'publish', 720 ); 721 722 foreach ( $auto_add as $menu_id ) { 723 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); 724 if ( ! is_array( $items ) ) 725 continue; 726 foreach ( $items as $item ) { 727 if ( $post->ID == $item->object_id ) 728 continue 2; 729 } 730 wp_update_nav_menu_item( $menu_id, 0, $args ); 758 731 } 759 732 }
Note: See TracChangeset
for help on using the changeset viewer.