Make WordPress Core

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: westonruter's profile westonruter Owned by: ocean90's profile ocean90
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)

#1 @westonruter
8 years ago

  • Keywords has-patch added

#2 @azaozz
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.

#3 @westonruter
8 years ago

  • Keywords commit added

#4 @ocean90
8 years ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 32762:

Nav Menus: Update wp_setup_nav_menu_item() to stop overriding empty properties from supplied $menu_item.

Update docs for WP_Post constructor to indicate that WP_Post|object can be the supplied param, as opposed to just WP_Post.

props westonruter.
fixes #32632.

Note: See TracTickets for help on using tickets.