Opened 8 years ago
Closed 8 years ago
#32632 closed enhancement (fixed)
Update wp_setup_nav_menu_item() to stop overriding empty properties from supplied $menu_item
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.3 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Menus | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
For Menu Customizer (#32576) we take a previewed menu item and create a mock WP_Post
object out of it, and then pass it into wp_get_nav_menu_items()
to get the proper properties added. See class-wp-customize-nav-menu-item-setting.php.
However, wp_setup_nav_menu_item()
is currently written in a way that it uses ! empty(...)
checks as opposed to isset()
checks. This means that if the menu item is Customized to preview a change where the menu_item_parent
is changed from the DB-saved value 1
to the new value 0
, this will get overwritten by wp_setup_nav_menu_item()
because $menu_item->parent_menu_item
as 0
will be considered empty in:
$menu_item->menu_item_parent = empty( $menu_item->menu_item_parent ) ? get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true ) : $menu_item->menu_item_parent;
So I suggest that the ! empty()
checks be replaced with isset()
checks.
Also, I suggest that the WP_Post
constructor to be updated to indicate that WP_Post|object
can be the supplied param, as opposed to just WP_Post
.
Attachments (1)
Change History (5)
#2
@
8 years ago
Looking at 32632.diff: replacing empty()
with ! isset()
doesn't seem to break anything on the current Appearance => Menus screen. It has the potential for introducing edge cases that might break some plugins, but we can deal with these as they are reported.
Fixing the docs for the WP_Post
constructor sounds good.
Source: https://github.com/xwp/wordpress-develop/pull/91/files#diff-8ffabe2d2470a815389fd77c045d2c7fL657