[wp-trac] [WordPress Trac] #57169: Prevent saving of invalid menu_item_parent

WordPress Trac noreply at wordpress.org
Thu Jan 5 21:18:21 UTC 2023


#57169: Prevent saving of invalid menu_item_parent
--------------------------+-----------------------
 Reporter:  azaozz        |       Owner:  azaozz
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  6.1.2
Component:  Menus         |     Version:  6.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+-----------------------

Comment (by azaozz):

 Replying to [comment:9 manooweb]:

 > menu_item->ID is really string with non numeric value as "**9-en**"  for
 example.
 >
 > So if menu item ("9-en") has its menu item parent 9 (real case), the new
 condition you introduce is true and you override menu_item_parent property
 with 0.

 Right, that was my intention. It prevents a menu item to be set as its own
 parent (i.e. may cause infinite loop/fatal error).

 Looking at Polylang
 (https://github.com/polylang/polylang/blob/3.3/frontend/frontend-nav-
 menu.php#L134), the language code is appended to `$menu_item->ID` and it
 becomes a string, but `$menu_item->menu_item_parent` is not
 changed/remains numeric. So using `intval()` reverts the $menu_item->ID
 back to being numeric and it can be compared to menu_item_parent.

 I may be missing something but thinking this is the desired behaviour. Or
 does Polylang also append the language code to the
 `$menu_item->menu_item_parent`?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57169#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list