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:
parent
f8af178264
commit
5b8000ebce
@ -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;
|
||||||
@ -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
|
// 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 ) )
|
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 );
|
$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,
|
||||||
|
Loading…
Reference in New Issue
Block a user