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
This commit is contained in:
Sergey Biryukov 2014-02-25 00:50:36 +00:00
parent f8af178264
commit 5b8000ebce

View File

@ -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_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 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. * @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() ) { function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
$menu_id = (int) $menu_id; $menu_id = (int) $menu_id;
@ -288,8 +288,13 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
$menu = wp_get_nav_menu_object( $menu_id ); $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; return $menu;
}
$defaults = array( $defaults = array(
'menu-item-db-id' => $menu_item_db_id, 'menu-item-db-id' => $menu_item_db_id,