Opened 13 years ago
Closed 11 years ago
#21652 closed defect (bug) (fixed)
wp_update_nav_menu_item returns false instead of WP_Error for non-existent menu items
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.4.1 |
Component: | Menus | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Use case:
Calling wp_update_nav_menu_items with a non-existent menu_item_id as the first parameter
Expected return value: WP_Error object (as per the method's documentation)
Actual return value: Boolean false
Fix: wp-includes/nav-menu.php#L279 - This line should check for a false value first, and if $menu == false
, set it equal to a new WP_Error
object - then check is_wp_error($menu)
Attachments (2)
Change History (7)
#3
@
11 years ago
- Keywords commit added
- Milestone changed from Awaiting Review to 3.9
Hello mltsy and bootsz, thanks for the report and the patch.
I agree, the error handling can be improved here. Since we already returning WP_Error objects we easily can add one more, so the change is backward compatible.
We're doing similar checks on other places, like wp_insert_term()
or is_object_in_term()
, where we just declare the input as invalid. In 21652.2.patch I have used a similar phrase.
Correction: the first parameter is a menu_id, not a menu_item_id. So this happens when you provide a non-existent menu_id.
The main reason this bug is important to fix is for the error message the WP_Error would provide, which should be something like "The specified menu ID does not exist in this site".
Without that, I had no idea why the method was failing, and had to go looking through the source code :)