WordPress 3.3 and WP_Admin_Bar

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 :-)

Read more…

Convenient WordPress Snippets

This will be a growing list of my, often used, code snippets. I usually store them in Coda for ease of access but I figure I can put them up here as well for anyone else who might need/want them. Most are created to speed up my development process or reduce the number of database calls in an effort to speed things up. If you have any suggestions for the list let me know.

Read more…

WordPress Admin Menu

Portfolio

WP Admin Menu creates a convenient copy of the Administration menu of your site at the top of every page in your WordPress installation. It is intended to create a more convenient means of navigating your administration options from any point in your website. It uses AJAX to fetch a copy of the administration menu of your website and formats it to fit along the top of your website.

Read more…

Add flare to your WordPress themes with shortcodes

When you’re creating a theme, for yourself or someone else, ease of use should be one of the foremost things in mind when it comes to the interaction between the back end and the front end. Any time you can take a convoluted process and simplify it into language that anyone can understand, without prior knowledge of the various languages we develop with, then that’s a step you should take. WordPress makes this easier with shortcodes.

Read more…

Custom Styles in TinyMCE for WordPress

The default style of TinyMCE included with WordPress is simple and effective. Often, though, it doesn’t give us an accurate representation of the layout and style we’re going to be seeing when the content is published. To remedy this we can add style to TinyMCE through our template’s functions.php file.

Read more…