How do I create menu items programatically?

I want to be able to create menus with either an installation profile, or by running code from the devel Execute PHP block.

Thanks for help.

Comments

Jerimee’s picture

Here's how to do it on node creation. Would still like to know how to do it outside of node creation.

You can execute this with the devel execute php console:

// Create an Donate node
$form_state = array();
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => 'page');
$form_state['values']['title'] = 'Donate';
$form_state['values']['menu']['link_title'] = 'Donate';
$form_state['values']['body'] = 'Please donate';
$form_state['values']['name'] = 'robo-user';
$form_state['values']['op'] = t('Save');
drupal_execute('page_node_form', $form_state, $node);

Note for above code to work you need to have a user named "robo-user"