Customizing WordPress Part Two

This is the second in a set of three tutorials based on a talk I gave at the 2010 WordCamp in Minneapolis. In this tutorial we will cover how to customize your clients dashboard by first getting rid of some of the things they don’t need and then by adding in some of our own helpful widgets.

Part one where I talk about customizing the logo, and admin header and footer is here.

Cleaning Up The Dashboard

A default WordPress install comes with a few defaults already in place. You normally get the 2010 theme, a couple plugins, and some widgets. You also get some meta boxes that purport to display helpful information on the dashboard when you first log in. These are:

  • Right Now – which displays how many posts you’ve written, what version of WordPress you’re running among others things.
  • Recent Comments – this displays the most recent comments to your site and give you a quick and easy way to manage them. And if you don’t ever get comments it ends up being a sad commentary on your life.
  • Recent Drafts – a quick view of the posts that you intended to finish but probably never will.
  • Quick Press – one of the fastest ways to get something published. You don’t want to be bothered with silly post screens, you need to get stuff done!
  • Incoming Links – this shows how popular you really are with all the cool kids. In your case its like being picked last for dodgeball all over again.
  • Plugins – this tells us all what is new and exciting in the world of WordPress plugins!
  • WordPress Blog – this is a feed of the most recent posts coming from the official WordPress blog.
  • Other WordPress News – if the WordPress blog wasn’t enough you get to double your pleasure with even more WP goodness.

Personally I don’t use many of these and I don’t see a need for the majority of my clients to have access to these items. The dashboard real estate is very valuable – its the one screen that your users will see every time they log in.

Every client will be different, but generally I believe the only items worth keeping around might be the recent comments, simply for the ability to very quickly moderate comments, and the incoming links.

So how do you get rid of the others? Here we go.

Removing Default Meta Boxes

add_action('wp_dashboard_setup', 'custom_dashboard_widgets');

function custom_dashboard_widgets() {
	global $wp_meta_boxes;

	// var_dump( $wp_meta_boxes['dashboard'] );
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);

So what’s going on here?
First, realize that this is not the complete function – we’ll get the rest in a second.

But the first thing we are doing is hooking into the dashboard_setup action in WordPress and we are creating a custom function called “custom_dashboard_widgets.” We’re calling it this because we’ll first get rid of the widgets we don’t want and then we’ll add in a few of our own.

The next thing happening is that we are systematically un-setting or removing specific meta boxes. All we are really looking for is the id of the container of the meta box. So you can remove just about any meta box using the code above and plugging in the id of the meta box you want gone at the end.

You’ll also notice that there is a bit of code commented out. If you un-comment this code it will reveal all the id’s of the meta boxes as well for you.

If you have issues with this – it may be because you’ve moved your widgets around before you added this code to your functions.php file.

Adding In Our Own Custom Widgets

Next we’ll continue the function from above and add in three custom widgets of our own.

wp_add_dashboard_widget('dashboard_custom_feed', 'Latest from Red Letters Studio', 'dashboard_custom_feed_output'); //add new rss feed output
wp_add_dashboard_widget('custom_help_widget', 'Help and Support', 'custom_dashboard_help'); // add a new custom widget for help and support
wp_add_dashboard_widget('random_support_tip', 'Helpful Tips', 'random_tips'); // add a new custom widget for help and support
}

Here’s what you need to add in your own custom widget. The code we pasted above just identifies and calls the widgets. We still need to create the actual widget.
In the parentheses the first thing is the id of the widget (dashboard_custom_feed), the second item is the title of the widget (Latest from Red Letters Studio) and the third item is the name of the function that you will use to run the widget (dashboard_custom_feed_output). And these can be anything you choose – just make sure that your function names are the same.

Next up is to create the functions for the widgets. The first widget we are creating is a simple feed reader. You can use this to bring in any rss feed on the web. I suggested in my talk that this would be a good way to get your latest news in front of your clients. Let them know what is going on in your company. Do you have any new products? Can you showcase anything exciting for them?

function dashboard_custom_feed_output()
{
	echo '<div class="rss-widget">';
	wp_widget_rss_output(array(
		'url' => 'http://redlettersstudio.com/themes/feed',
		'title' => 'New at Red Letters Studio',
		'items' => 3,
		'show_summary' => 1,
		'show_author' => 0,
		'show_date' => 1 ,
		'show_image' => 1
	));
	echo "</div>";
}

Next is a widget that has some simple text. I want my clients to be able to contact me if they have issues or questions so lets get that information in front of them.

function custom_dashboard_help() {
	echo '
		<p>Having trouble figuring out what something does on the page?  Check out the "help" tab in the upper right of your screen. It will provide contextual help throughout the administrative panel. </p>
		<p>If you need additional support, you can contact your web team at <a href="http://redlettersstudio.com">Red Letters Studio</a></p>
		<p><strong>phone:</strong> 515-392-6581<br />
		<strong>email:</strong> <a href="mailto:support@redlettersstudio.com">support@redettersstudio.com</a><p>
	';
}

And lastly I want to post a random tip to help my clients out with some of the functionalities of WordPress. This is not a new concept but it was brought to my attention recently while playing the new Goldeneye game. While you’re waiting for the game to load they pop up helpful tips so that you can play the game better.

So for this example I just re-purposed the code used for the familiar Hello Dolly plugin. The idea of that plugin is that it will display a random line from Hello Dolly. All I did was change the lines.

$tips =
"Posts are for blogging
Use keywords in your titles
Don't copy and paste from Word";

$tips = explode("\n", $tips);
$chosen = wptexturize( $tips[ mt_rand(0, count($tips) - 1) ] );

function random_tips() {
	global $chosen;
	echo "<p id='tips'>$chosen</p>";
}

That’s all folks! In the next and last post in this customizing series, we’ll take a look at Custom Post Types, Custom Taxonomies and Custom Meta Boxes.

Comments

  1. Hi,

    Great article. We have a plugin which is becoming very popular that does exactly what you describe, called White Label CMS. This is certainly a subject which a lot of developers are getting interested in. Check out the video here:

    http://www.videousermanuals.com/white-label-cms/

    Thanks
    Brian

    • Josh Byers says:

      It is a very nice plugin. Of course I’m a big proponent of trying to educate developers and eliminate the use of plugins as much as possible. You guys have some great free ebooks as well.

  2. Ross DeMeyere says:

    Love the idea, but keep getting `Fatal error: Call to undefined function wp_add_dashboard_widget()…` when I try to apply it to my WordPress 3.0.4 site. Any ideas?

Speak Your Mind

*