Company Logo
Click To read more about We’ll be at Speak The Web

We’ll be at Speak The Web

Speak the Web is a series of small, intimate, low cost web design & development events

Read More

Click To read more about The uploaded file could not be moved…

The uploaded file could not be moved…

Akin to Windows' dreaded blue screen of death

Read More

Click To read more about Adding an update bubble to a WordPress plugin

Adding an update bubble to a WordPress plugin

It's the small things that make a big difference

Read More

Reading
Click To read more about Using TimThumb, WPMU & catch_that_image

Using TimThumb, WPMU & catch_that_image

Does exactly what it says on the tin

Read More

Click To read more about Our Process

Our Process

Find out how we do what we do and why we do what we do. Do it!

Read More

Have your say

Adding an update bubble to a WordPress plugin

guitar
Following swiftly on from our previous post about how to get TimThumb to work with WPMU, we present to you, dear reader, another geek-filled WordPress tip. If you have no inclination to write your own WP plugin then I suggest you cease your reading of this post.

WordPress, since days of yore, has a nice way of telling you when there are updates available for your plugins. The little ‘update bubble’ that it puts next to the ‘Plugins’ item menu since version 2.7 (see below) is an excellent, efficient and useful way of telling you when you have some updating to be doing. As I’m sure you know, keeping up-to-date is vital.
plugin_update
What if you’ve just written a plugin, say for example a Contact Form plugin which allows you to see the form submissions from your dashboard. (Yes, we have written one. Yes, we will be releasing it. When it’s ready.) Wouldn’t it be nice if, when you have a new message, that your snazzy little menu item tells you so? Chances are that this is only really a UX benefit, because you’ll have an e-mail telling that you that you have a new form submission (well, you do with ours, anyway). But considering just how easy it is to implement, it’s a bit of a no-brainer.

If your plugin has it’s own menu item (which is generally frowned upon, but in some cases, necessary) then it really is a cinch to add. In the function that you utilise to create your menu pages, you’ll have something that looks like the following:

1
2
3
4
5
//Specify a custom icon for our new menu page
$icon_url = get_bloginfo(wpurl)."/wp-content/plugins/WP-Friendly-Contact/images/icon-trans.png";

$friendly_contact_add_main_page = add_menu_page('Contact Form', "Contact", 10, __FILE__, 'friendly_contact_main_page',$icon_url);
add_action( "admin_print_scripts-$friendly_contact_add_main_page", 'friendly_contact_main_page_head_scripts' );

Relatively straight forward – The WordPress Codex Page tells you all about the add_menu_page() function.

This simply adds your menu page with a pretty icon. It doesn’t give you the nice update bubble. However, simply by appending a couple of span tags with the correct classes, you’re away in update-bubble bliss.

1
2
3
<?php
$friendly_contact_add_main_page = add_menu_page('Contact Form', "Contact<span class='update-plugins count-$update_count'><span class='plugin-count'>$update_count</span></span>", 10, __FILE__, 'friendly_contact_main_page',$icon_url);
?>

Yes, we know it’s a hack and it bastardises the existing WordPress classes for the plugin menu item. Yes, we know, it’s not exactly elegant. And yes, we know, there’s probably an easier way to do it using a function that we haven’t stumbled across yet. However, it works. And it takes 30 seconds to implement.
contact_update
So, if you have some sort of function which provides you with how many unread messages you have (or pretty much any function which provides you with a number that would be useful to you in some way), then all you need do is replace

1
2
3
<?php
$update_count;
?>

with your own variable name.

In due course, we’ll be releasing our contact plugin and we also use this feature in our WP-FreeLance plugin which will be coming in 2010.

Can you think of any other way of doing this? Or can you think of other little features like this which really add another ‘wow’ layer to your plugins? Let us know in the comments!

Comments (0)