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…

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…

Drupal and PHP 5.3

Drupal states on it’s site that it doesn’t support PHP 5.3. And, if you attempt to install drupal on a server running PHP 5.3 you get a lovely series of errors along the lines of “Function ereg() is deprecated in…” and so on. This was a bit troublesome consider my development environment is XAMPP and it happens to be using version 5.3. Luckily, there’s a way to “hack” the drupal version 6.x to get it to work.

Read more…

Expires Headers

One of those annoying little quirks you run into when checking the relative loading speed of your site. Expire headers will let your browser know if the current file is up-to-date or if it needs to be re-downloaded. If the file hasn’t changed there’s no sense in downloading the file again, thus, saving a little time in the loading of the page. This could apply to your CSS, images, movies and other media.

Read more…