diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 7d05ab1cc7..3341fd6792 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -827,6 +827,8 @@ case 'add-menu-item' : $menu_id = (int) $_POST['menu']; if ( isset( $_POST['menu-item'] ) ) { $item_ids = wp_save_nav_menu_item( $menu_id, $_POST['menu-item'] ); + if ( is_wp_error( $item_ids ) ) + die('-1'); } else { $item_ids = array(); } diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 6e1584c864..1914509615 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -808,7 +808,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) { * * @param int $menu_id The menu ID for which to save this item. * @param array $menu_data The unsanitized posted menu item data. - * @return array The database IDs of the items saved. + * @return array The database IDs of the items saved */ function wp_save_nav_menu_item( $menu_id = 0, $menu_data = array() ) { $menu_id = (int) $menu_id; diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index d49fbe61ed..db0fcc9ca7 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -38,7 +38,7 @@ wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'postbox' ); // Container for any messages displayed to the user -$messages_div = ''; +$messages = array(); // Container that stores the name of the active menu $nav_menu_selected_title = ''; @@ -169,7 +169,7 @@ switch ( $action ) { if ( is_nav_menu_item( $menu_item_id ) ) { if ( wp_delete_post( $menu_item_id, true ) ) { - $messages_div = '

' . __('The menu item has been successfully deleted.') . '

'; + $messages[] = '

' . __('The menu item has been successfully deleted.') . '

'; } } break; @@ -180,9 +180,9 @@ switch ( $action ) { $delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id ); if ( is_wp_error($delete_nav_menu) ) { - $messages_div = '

' . $delete_nav_menu->get_error_message() . '

'; + $messages[] = '

' . $delete_nav_menu->get_error_message() . '

'; } else { - $messages_div = '

' . __('The menu has been successfully deleted.') . '

'; + $messages[] = '

' . __('The menu has been successfully deleted.') . '

'; $nav_menu_selected_id = 0; // Reset the selected menu } unset( $delete_nav_menu ); @@ -201,15 +201,15 @@ switch ( $action ) { $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) ); if ( is_wp_error( $_nav_menu_selected_id ) ) { - $messages_div = '

' . $_nav_menu_selected_id->get_error_message() . '

'; + $messages[] = '

' . $_nav_menu_selected_id->get_error_message() . '

'; } else { $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); $nav_menu_selected_id = $_nav_menu_selected_id; $nav_menu_selected_title = $_menu_object->name; - $messages_div = '

' . sprintf( __('The %s menu has been successfully created.'), $nav_menu_selected_title ) . '

'; + $messages[] = '

' . sprintf( __('The %s menu has been successfully created.'), $nav_menu_selected_title ) . '

'; } } else { - $messages_div = '

' . __('Please enter a valid menu name.') . '

'; + $messages[] = '

' . __('Please enter a valid menu name.') . '

'; } } @@ -222,7 +222,7 @@ switch ( $action ) { $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $_POST['menu-name'] ) ); if ( is_wp_error( $_nav_menu_selected_id ) ) { $_menu_object = $_nav_menu_selected_id; - $messages_div = '

' . $_nav_menu_selected_id->get_error_message() . '

'; + $messages[] = '

' . $_nav_menu_selected_id->get_error_message() . '

'; } else { $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); $nav_menu_selected_title = $_menu_object->name; @@ -248,9 +248,10 @@ switch ( $action ) { $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args ); - if ( ! is_wp_error( $menu_item_db_id ) && isset( $menu_items[$menu_item_db_id] ) ) { + if ( is_wp_error( $menu_item_db_id ) ) + $messages[] = '

' . $menu_item_db_id->get_error_message() . '

'; + elseif ( isset( $menu_items[$menu_item_db_id] ) ) unset( $menu_items[$menu_item_db_id] ); - } } } @@ -265,7 +266,7 @@ switch ( $action ) { do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); - $messages_div = '

' . sprintf( __('The %s menu has been updated.'), $nav_menu_selected_title ) . '

'; + $messages[] = '

' . sprintf( __('The %s menu has been updated.'), $nav_menu_selected_title ) . '

'; unset( $menu_items ); } } @@ -310,12 +311,12 @@ if ( current_theme_supports('nav-menus') ) { } elseif ( current_theme_supports('widgets') ) { // Set up nav menu wp_nav_menu_setup(); - $messages_div = '

' . __('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.') . '

'; + $messages[] = '

' . __('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.') . '

'; // The theme supports neither menus nor widgets. } else { remove_meta_box( 'create-menu', 'nav-menus', 'side' ); - $messages_div = '

' . __('The current theme does not support menus.') . '

'; + $messages[] = '

' . __('The current theme does not support menus.') . '

'; } // Get the admin header @@ -324,7 +325,11 @@ require_once( 'admin-header.php' );

- +