Opened 10 years ago
Last modified 5 years ago
#29728 new feature request
Could be very useful 'wp_remove_nav_menu_item'
Reported by: | JonathanBesomi | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0 |
Component: | Menus | Keywords: | has-patch needs-testing |
Focuses: | administration | Cc: |
Description
Hello there,
I was developing a plugin that need to manage dynamically wordpress navigation menu.
During develop I needed a function that remove a specific item by item 'id' or 'title'
wp_remove_nav_menu_item( $menu_id, $item_id or $item_title ).
I googled for this but I don't have found a good solutions that work with API.
I think that Wordpress could be better if you had this function in the next wp update.
I hope this help to make Wordpress a better services.
Thanks for developing this extraordinary CMS.
Best regards
Jonathan
Attachments (1)
Change History (7)
Note: See
TracTickets for help on using
tickets.
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 taxonomynav_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 usingwp_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.