Opened 11 years ago
Last modified 4 weeks ago
#29728 new feature request
Could be very useful 'wp_remove_nav_menu_item'
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0 |
Component: | Menus | Keywords: | has-patch needs-refresh close |
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 (8)
@
11 years ago
Implementation of wp_delete_nav_menu_item()
and its usage in the core, as described in my last reply.
#7
@
4 weeks ago
- Keywords needs-refresh close added; needs-testing removed
Current patch not applying, in case anyone would like to refresh the solution provided by @tyxla (needs-refresh
), although I would not recommend this for the following reasons:
Over the top, as it was pointed out, a menu item is ultimately a post type, so basically it doesn't have anything special apart from a wp_delete_post
.
Checking the code, although I think that the patch provided is nice from a semantical perspective, it doesn't provide much value (probably a reason of why this never moved forward in a 10-year period).
Long story short: This stunt is not necessary, and extenders have been able to sort this without a conflict for all this long.
For this, reasons, I would propose this, as close
wontfix
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.