6.x menu.inc menu_link_delete($mlid, $path = NULL)
7.x menu.inc menu_link_delete($mlid, $path = NULL)

Delete one or several menu links.

Parameters

$mlid: A valid menu link mlid or NULL. If NULL, $path is used.

$path: The path to the menu items to be deleted. $mlid must be NULL.

Related topics

9 calls to menu_link_delete()
book_node_delete in modules/book/book.module
Implements hook_node_delete().
book_remove_form_submit in modules/book/book.pages.inc
Form submission handler for book_remove_form().
MenuLinksUnitTestCase::testMenuLinkReparenting in modules/simpletest/tests/menu.test
Test automatic reparenting of menu links.
menu_delete_menu_confirm_submit in modules/menu/menu.admin.inc
Delete a custom menu and all links in it.
menu_item_delete_form_submit in modules/menu/menu.admin.inc
Process menu delete form submissions.

... See full list

1 string reference to 'menu_link_delete'
_menu_delete_item in includes/menu.inc
Deletes a single menu link.

File

includes/menu.inc, line 3056
API for the Drupal menu system.

Code

function menu_link_delete($mlid, $path = NULL) {
  if (isset($mlid)) {
    _menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc());
  }
  else {
    $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));
    foreach ($result as $link) {
      _menu_delete_item($link);
    }
  }
}

Comments

This doesn't work (but I think it should):

$path = 'node/281';
menu_link_delete(NULL, $path);

The cause:

$result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));

should be:

$result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path))->fetchAllAssoc('mlid');

... edit ... never mind... I'm wrong. Should be made more clear you can never delete 'system' menu-links.

Given i have added a new menu item in my install file that additionally points to user/login, placed in the main menu (instead of moving the original one), how can i delete this in my uninstall routine?
When using
menu_link_delete(NULL, 'user/login')
I'm afraid that the system link is deleted too as it just does a select and deletes all of the found ones.
DO I have to keep a mlid somewhere (in a variable) of all created menu items to be able to delete them later at uninstall?