How to Make WordPress Easier By Removing Widgets, Meta Boxes and Options

Thumbnail

In my previous post we created a new WordPress plugin which simplified the administration panels for your clients. If you haven’t read it, please do so first. In this article, we’ll use the same plugin file for deeper configuration changes.

Remove the WordPress Update Notification

WordPress informs you when an update is available. Unfortunately, it tells everyone — including your clients. That could lead to unnecessary concern or tempt them call you every half an hour until it’s upgraded.

Append the following code to easy-admin.php to remove the notification for everyone except for WordPress administrators:


function no_update_notification() {
	if (!current_user_can('activate_plugins')) remove_action('admin_notices', 'update_nag', 3);
}
add_action('admin_notices', 'no_update_notification', 1);

Remove Unnecessary Dashboard Widgets

You can remove dashboard widgets for a user by logging in as them and un-checking items in the “Screen Options” pull-down panel. However, that may not be practical and there’s nothing to prevent your client re-enabling them.

Append the following function to easy-admin.php to remove unnecessary dashboard widgets. You may need to add, remove or modify unset commands as required. For example, the first section (lines 5-7) removes “Right Now” for everyone but WordPress administrators. The second section (lines 9-13) removes widgets regardless of the user’s rights.

The dashboard widget’s ID is assigned to its box div element — use Firebug or inspect the source to find that value.


// remove unnecessary dashboard widgets
function remove_dashboard_widgets(){
	global $wp_meta_boxes;
	// do not remove "Right Now" for administrators
	if (!current_user_can('activate_plugins')) {
		unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	}
	// remove widgets for everyone
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'remove_dashboard_widgets');

Remove Unnecessary Page and Post Meta Boxes

Few developers use all the features WordPress has to offer. For example, if all posts are assigned to a single default category, you don’t require the Categories box. Or perhaps you’re not permitting comments and can remove associated boxes.

Append the following function to easy-admin.php to remove unnecessary meta boxes from the posts and pages panels. You may have to add or remove remove_meta_box() calls in this function. The first argument is the ID assigned to the box’s div element — again, this can be discovered in the source or with Firebug.


// remove unnecessary page/post meta boxes
function remove_meta_boxes() {
	// posts
	remove_meta_box('postcustom','post','normal');
	remove_meta_box('trackbacksdiv','post','normal');
	remove_meta_box('commentstatusdiv','post','normal');
	remove_meta_box('commentsdiv','post','normal');
	remove_meta_box('categorydiv','post','normal');
	remove_meta_box('tagsdiv-post_tag','post','normal');
	remove_meta_box('slugdiv','post','normal');
	remove_meta_box('authordiv','post','normal');
	// pages
	remove_meta_box('postcustom','page','normal');
	remove_meta_box('commentstatusdiv','page','normal');
	remove_meta_box('trackbacksdiv','page','normal');
	remove_meta_box('commentsdiv','page','normal');
	remove_meta_box('slugdiv','page','normal');
	remove_meta_box('authordiv','page','normal');
}
add_action('admin_init','remove_meta_boxes');

Remove Favorite Actions

The favorite actions button resides in the WordPress header next to the “Howdy” message. It normally provides quick links to New Post, Drafts, New Page, Upload and perhaps a few plugin-specific options such as “Empty Cache”. Let’s remove the options we don’t require by appending the following code to easy-admin.php:


// remove favorite actions
function remove_favorite_actions($actions) {
	if (!current_user_can('activate_plugins')) {
		unset($actions['edit-comments.php']);
	}
	return $actions;
}
add_filter('favorite_actions', 'remove_favorite_actions');

In this example, we’ve removed the Comments link for everyone except administrators. To remove other items, you need to find the action’s URL in the page source. Locate the element with the ID “favorite-actions” and, within that, an element with the ID “favorite-inside”. The child divs contain links to URLs such as “media-new.php”. To remove that option, simply add unset($actions['media-new.php']); to the function.

Phew. In my next WordPress post, we’ll address the WordPress menu and remove all the dangerous options you want to hide from clients.

This entry was posted in clients, CMS, open source, PHP & MySQL Tutorials, PHP Tutorials & Articles, plugin, Software Tutorials, UX, Web Tech, WordPress plugins, WordPress Tutorials & Articles, Work Smarter and tagged , , , , , , , , , . Bookmark the permalink.