[wp-trac] [WordPress Trac] #29728: Could be very useful 'wp_remove_nav_menu_item'

WordPress Trac noreply at wordpress.org
Sun Jan 4 22:08:33 UTC 2015


#29728: Could be very useful 'wp_remove_nav_menu_item'
-----------------------------+------------------------------
 Reporter:  JonathanBesomi   |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Menus            |     Version:  3.0
 Severity:  normal           |  Resolution:
 Keywords:  needs-patch      |     Focuses:  administration
-----------------------------+------------------------------

Comment (by tyxla):

 Great idea.

 Let me start with the fact that menu items are being stored as posts (of
 post type `nav_menu_item`) and menus are being stored as taxonomies (of
 taxonomy `nav_menu`). And menu items of a certain menu are simply menu
 item posts assigned to the menu term.

 Therefore, deleting a menu item basically consists of deleting the
 `nav_menu_item` post by using `wp_delete_post()` function. So a separate
 function is not required, but will probably be more friendly for the
 developers.

 Now, concerning the proposed solution by @JonathanBesomi: each menu item
 can be present only in one menu, so the `$menu_id` is not necessary -
 deleting the menu item post is sufficient. In addition, I believe deleting
 item by `$item_title` is not a good idea, as there can be multiple items
 with the same name, and this could unintentionally delete menu items that
 should not be deleted.

 So in case this function is to be added to the core, I suggest that the
 function simply deletes the menu item by ID. Then this function can also
 be used to delete menu items in the core instead of using
 `wp_delete_post()` for that purpose.

 I'll attach a patch in a couple of minutes.

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


More information about the wp-trac mailing list