[wp-trac] [WordPress Trac] #32632: Update wp_setup_nav_menu_item() to stop overriding empty properties from supplied $menu_item
WordPress Trac
noreply at wordpress.org
Sat Jun 13 00:06:51 UTC 2015
#32632: Update wp_setup_nav_menu_item() to stop overriding empty properties from
supplied $menu_item
-------------------------+-----------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.3
Component: Menus | Version: 3.0
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------
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
[https://github.com/voldemortensen/menu-
customizer/blob/981c82cad7effd1c8bb84ded0c1cc04f204e74cb/class-wp-
customize-nav-menu-item-setting.php#L327-L348 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`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32632>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list