If you’re like me, you probably referenced some website somewhere out there on the internet when you wanted to add items to WordPress’ new admin bar. I, for instance, wanted to add some development links for quick reference. The version I had working threw no errors in 3.2 but in 3.2 I received the following:
WP_Admin_Bar::add_node was called incorrectly
Seems that in 3.2 the “id” field of the “add_menu” function wasn’t required. In 3.3 however, it is.
I had included the “id” field in the top-level item under which I was placing my actual links because I needed it for the “parent” field of the following items but the tutorial or example I read didn’t include the “id” field on any of the child-level links. Seems that was the only real problem. I added in an “id” field for each of the other links and the errors went away.
If you interested in the code, it’s here:
// ===============================
// Development menu
//
// Key parts of the WordPress documentation added to the default admin bar
// labeled as "WordPress Dev."
// ===============================
function rational_admin_bar_menu() {
global $wp_admin_bar;
if (!is_super_admin() || !is_admin_bar_showing())
return;
$wp_admin_bar->add_menu(array(
'id' => 'wp_dev',
'title' => __('WordPress Dev'),
'href' => false
));
$add_menu_meta = array(
'target' => '_blank'
);
$wp_admin_bar->add_menu(array(
'id' => 'wp_dev_template',
'parent' => 'wp_dev',
'title' => __('Template Tags'),
'href' => 'http://codex.wordpress.org/Template_Tags',
'meta' => $add_menu_meta
));
$wp_admin_bar->add_menu(array(
'id' => 'wp_dev_include',
'parent' => 'wp_dev',
'title' => __('Include Tags'),
'href' => 'http://codex.wordpress.org/Include_Tags',
'meta' => $add_menu_meta
));
$wp_admin_bar->add_menu(array(
'id' => 'wp_dev_conditional',
'parent' => 'wp_dev',
'title' => __('Conditional Tags'),
'href' => 'http://codex.wordpress.org/Conditional_Tags',
'meta' => $add_menu_meta
));
$wp_admin_bar->add_menu(array(
'id' => 'wp_dev_function',
'parent' => 'wp_dev',
'title' => __('Function Reference'),
'href' => 'http://codex.wordpress.org/Function_Reference',
'meta' => $add_menu_meta
));
$wp_admin_bar->add_menu(array(
'id' => 'wp_dev_action',
'parent' => 'wp_dev',
'title' => __('Action Reference'),
'href' => 'http://codex.wordpress.org/Plugin_API/Action_Reference',
'meta' => $add_menu_meta
));
}
add_action('admin_bar_menu', 'rational_admin_bar_menu', 999);
This code will add a “WordPress Dev” item into your admin bar, and it won’t throw any errors