Changeset 14295
- Timestamp:
- 04/29/2010 07:33:56 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r14263 r14295 828 828 if ( isset( $_POST['menu-item'] ) ) { 829 829 $item_ids = wp_save_nav_menu_item( $menu_id, $_POST['menu-item'] ); 830 if ( is_wp_error( $item_ids ) ) 831 die('-1'); 830 832 } else { 831 833 $item_ids = array(); -
trunk/wp-admin/includes/nav-menu.php
r14293 r14295 809 809 * @param int $menu_id The menu ID for which to save this item. 810 810 * @param array $menu_data The unsanitized posted menu item data. 811 * @return array The database IDs of the items saved .811 * @return array The database IDs of the items saved 812 812 */ 813 813 function wp_save_nav_menu_item( $menu_id = 0, $menu_data = array() ) { -
trunk/wp-admin/nav-menus.php
r14288 r14295 39 39 40 40 // Container for any messages displayed to the user 41 $messages _div = '';41 $messages = array(); 42 42 43 43 // Container that stores the name of the active menu … … 170 170 if ( wp_delete_post( $menu_item_id, true ) ) { 171 171 172 $messages _div= '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>';172 $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; 173 173 } 174 174 } … … 181 181 182 182 if ( is_wp_error($delete_nav_menu) ) { 183 $messages _div= '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>';183 $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>'; 184 184 } else { 185 $messages _div= '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>';185 $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>'; 186 186 $nav_menu_selected_id = 0; // Reset the selected menu 187 187 } … … 202 202 203 203 if ( is_wp_error( $_nav_menu_selected_id ) ) { 204 $messages _div= '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';204 $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; 205 205 } else { 206 206 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); 207 207 $nav_menu_selected_id = $_nav_menu_selected_id; 208 208 $nav_menu_selected_title = $_menu_object->name; 209 $messages _div= '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>';209 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>'; 210 210 } 211 211 } else { 212 $messages _div= '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>';212 $messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; 213 213 } 214 214 } … … 223 223 if ( is_wp_error( $_nav_menu_selected_id ) ) { 224 224 $_menu_object = $_nav_menu_selected_id; 225 $messages _div= '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';225 $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; 226 226 } else { 227 227 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); … … 249 249 $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args ); 250 250 251 if ( ! is_wp_error( $menu_item_db_id ) && isset( $menu_items[$menu_item_db_id] ) ) { 251 if ( is_wp_error( $menu_item_db_id ) ) 252 $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>'; 253 elseif ( isset( $menu_items[$menu_item_db_id] ) ) 252 254 unset( $menu_items[$menu_item_db_id] ); 253 }254 255 } 255 256 } … … 266 267 do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); 267 268 268 $messages _div= '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>';269 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>'; 269 270 unset( $menu_items ); 270 271 } … … 311 312 // Set up nav menu 312 313 wp_nav_menu_setup(); 313 $messages _div= '<div id="message" class="error"><p>' . __('The current theme does not natively support menus, but you can use the “Navigation Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p></div>';314 $messages[] = '<div id="message" class="error"><p>' . __('The current theme does not natively support menus, but you can use the “Navigation Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p></div>'; 314 315 315 316 // The theme supports neither menus nor widgets. 316 317 } else { 317 318 remove_meta_box( 'create-menu', 'nav-menus', 'side' ); 318 $messages _div= '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>';319 $messages[] = '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>'; 319 320 } 320 321 … … 325 326 <?php screen_icon(); ?> 326 327 <h2><?php esc_html_e('Menus'); ?></h2> 327 <?php echo $messages_div; ?> 328 <?php 329 foreach( $messages as $message ) : 330 echo $message . "\n"; 331 endforeach; 332 ?> 328 333 329 334 <?php if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) : ?> -
trunk/wp-includes/default-filters.php
r14283 r14295 225 225 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); 226 226 add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); 227 add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); 227 add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); 228 add_action( 'trash_post', '_wp_trash_menu_item' ); 229 add_action( 'untrash_post', '_wp_untrash_menu_item' ); 230 add_action( 'delete_post', '_wp_delete_post_menu_item' ); 231 add_action( 'delete_term', '_wp_delete_tax_menu_item' ); 228 232 229 233 // Post Thumbnail CSS class filtering -
trunk/wp-includes/nav-menu.php
r14285 r14295 269 269 $original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' ); 270 270 } elseif ( 'post_type' == $args['menu-item-type'] ) { 271 271 272 $original_object = get_post( $args['menu-item-object-id'] ); 272 273 $original_title = $original_object->post_title; 274 275 if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) ) { 276 $post_type_object = get_post_type_object( $args['menu-item-object'] ); 277 if ( isset( $post_type_object->singular_label ) ) 278 return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to a %2$s that is in the trash, so it cannot be updated.'), $args['menu-item-title'], $post_type_object->singular_label ) ); 279 else 280 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'] ) ); 281 } 273 282 } 274 283 … … 529 538 return apply_filters( 'wp_setup_nav_menu_item', $menu_item ); 530 539 } 540 541 /** 542 * Get the menu items associated with a particular object. 543 * 544 * @since 3.0.0 545 * 546 * @param int $object_id The ID of the original object. 547 * @param string $object_type The type of object, such as "taxonomy" or "post_type." 548 * @return array The array of menu item IDs; empty array if none; 549 */ 550 function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) { 551 $object_id = (int) $object_id; 552 $menu_item_ids = array(); 553 554 $query = new WP_Query; 555 $menu_items = $query->query( 556 array( 557 'meta_key' => '_menu_item_object_id', 558 'meta_value' => $object_id, 559 'post_status' => 'any', 560 'post_type' => 'nav_menu_item', 561 'showposts' => -1, 562 ) 563 ); 564 foreach( (array) $menu_items as $menu_item ) { 565 if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) { 566 if ( get_post_meta($menu_item->ID, '_menu_item_type', true) != $object_type ) 567 continue; 568 569 $menu_item_ids[] = (int) $menu_item->ID; 570 } 571 } 572 573 return array_unique( $menu_item_ids ); 574 } 575 576 /** 577 * Callback for handling a menu item when its original object is trashed. 578 * 579 * @since 3.0.0 580 * @access private 581 * 582 * @param int $object_id The ID of the original object being trashed. 583 * 584 */ 585 function _wp_trash_menu_item( $object_id = 0 ) { 586 $object_id = (int) $object_id; 587 588 $menu_item_ids = wp_get_associated_nav_menu_items( $object_id ); 589 590 foreach( (array) $menu_item_ids as $menu_item_id ) { 591 $menu_item = get_post( $menu_item_id, ARRAY_A ); 592 $menu_item['post_status'] = 'draft'; 593 wp_insert_post($menu_item); 594 } 595 } 596 597 /** 598 * Callback for handling a menu item when its original object is un-trashed. 599 * 600 * @since 3.0.0 601 * @access private 602 * 603 * @param int $object_id The ID of the original object being untrashed. 604 * 605 */ 606 function _wp_untrash_menu_item( $object_id = 0 ) { 607 $object_id = (int) $object_id; 608 609 $menu_item_ids = wp_get_associated_nav_menu_items( $object_id ); 610 611 foreach( (array) $menu_item_ids as $menu_item_id ) { 612 $menu_item = get_post( $menu_item_id, ARRAY_A ); 613 $menu_item['post_status'] = 'publish'; 614 wp_insert_post($menu_item); 615 } 616 } 617 618 /** 619 * Callback for handling a menu item when its original object is deleted. 620 * 621 * @since 3.0.0 622 * @access private 623 * 624 * @param int $object_id The ID of the original object being trashed. 625 * 626 */ 627 function _wp_delete_post_menu_item( $object_id = 0 ) { 628 $object_id = (int) $object_id; 629 630 $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' ); 631 632 foreach( (array) $menu_item_ids as $menu_item_id ) { 633 wp_delete_post( $menu_item_id, true ); 634 } 635 } 636 637 /** 638 * Callback for handling a menu item when its original object is deleted. 639 * 640 * @since 3.0.0 641 * @access private 642 * 643 * @param int $object_id The ID of the original object being trashed. 644 * 645 */ 646 function _wp_delete_tax_menu_item( $object_id = 0 ) { 647 $object_id = (int) $object_id; 648 649 $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy' ); 650 651 foreach( (array) $menu_item_ids as $menu_item_id ) { 652 wp_delete_post( $menu_item_id, true ); 653 } 654 } 655 531 656 ?> -
trunk/wp-includes/post.php
r14262 r14295 2168 2168 $parent_post = get_post($post_parent); 2169 2169 // Check for circular dependency 2170 if ( $parent_post->post_parent == $post_ID )2170 if ( isset( $parent_post->post_parent ) && $parent_post->post_parent == $post_ID ) 2171 2171 $post_parent = 0; 2172 2172 }
Note: See TracChangeset
for help on using the changeset viewer.