From 5b8000ebce50ec9cdc505d72be49d4c55f3d4e7a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 25 Feb 2014 00:50:36 +0000 Subject: [PATCH] Consistently return a WP_Error object in case of an error in wp_update_nav_menu_item(). props bootsz, ocean90. fixes #21652. git-svn-id: https://develop.svn.wordpress.org/trunk@27251 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/nav-menu.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 1672b03b8a..363c2ac4de 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -276,7 +276,7 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) { * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item. * @param array $menu_item_data The menu item's data. - * @return int The menu item's database ID or WP_Error object on failure. + * @return int|WP_Error The menu item's database ID or WP_Error object on failure. */ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) { $menu_id = (int) $menu_id; @@ -284,12 +284,17 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) - return new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.')); + return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) ); $menu = wp_get_nav_menu_object( $menu_id ); - if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) ) + if ( ! $menu && 0 !== $menu_id ) { + return new WP_Error( 'invalid_menu_id', __( 'Invalid menu ID.' ) ); + } + + if ( is_wp_error( $menu ) ) { return $menu; + } $defaults = array( 'menu-item-db-id' => $menu_item_db_id,