WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/29/2010 07:33:56 AM (11 years ago)
Author:
nacin
Message:

When posts/terms are deleted/trashed, update associated menu items. Deleted post = deleted menu item, trashed post = menu item becomes a draft. props filosofo, see #13174

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/nav-menus.php

    r14288 r14295  
    3939
    4040// Container for any messages displayed to the user
    41 $messages_div = '';
     41$messages = array();
    4242
    4343// Container that stores the name of the active menu
     
    170170            if ( wp_delete_post( $menu_item_id, true ) ) {
    171171               
    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>';
    173173            }
    174174        }
     
    181181
    182182            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>';
    184184            } 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>';
    186186                $nav_menu_selected_id = 0; // Reset the selected menu
    187187            }
     
    202202
    203203                    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>';
    205205                    } else {
    206206                        $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
    207207                        $nav_menu_selected_id = $_nav_menu_selected_id;
    208208                        $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>';
    210210                    }
    211211                } 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>';
    213213                }
    214214            }
     
    223223                if ( is_wp_error( $_nav_menu_selected_id ) ) {
    224224                    $_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>';
    226226                } else {
    227227                    $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
     
    249249                        $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );
    250250
    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] ) )
    252254                            unset( $menu_items[$menu_item_db_id] );
    253                         }
    254255                    }
    255256                }
     
    266267                do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
    267268
    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>';
    269270                unset( $menu_items );
    270271            }
     
    311312    // Set up nav menu
    312313    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 &#8220;Navigation Menu&#8221; widget to add any menus you create here to the theme&#8217;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 &#8220;Navigation Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>';
    314315
    315316// The theme supports neither menus nor widgets.
    316317} else {
    317318    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>';
    319320}
    320321
     
    325326    <?php screen_icon(); ?>
    326327    <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    ?>
    328333   
    329334    <?php if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) : ?>
Note: See TracChangeset for help on using the changeset viewer.