How to Make WordPress Easier for Clients, Part 2: Hiding Menus

Tweet

In part 1 of this series, we discovered how easy it is to simplify the WordPress interface for clients.

In this article, I describe a technique for hiding unnecessary menus. Why would we want to do that? The fewer options your client has, the less you’ll need to explain, the less they’ll need to remember, and the less likely they’ll do something, er … unexpected.

Before you add any code, I’d recommend you check your WordPress user roles. I suspect most developers add their client as an editor (publish and manage all posts) or an author (publish and manage their own posts). Avoid adding anyone as as administrator unless they specifically request that level of control.

Easier WordPressI’d also suggest you log in as that user and remove any unnecessary items using the Screen Options drop-down. Your client may not need to use features such as tags, slugs, or custom fields.

Now make a note of the menus the client doesn’t need. Options such as Profile, Tools and Settings are obvious candidates. Perhaps the site doesn’t use links or comments? Or should your client be able to manage posts but not static pages?

OK, so let’s add a little code to your theme’s function.php file. Not sure what that is? Take a look at part 1. Ready? Here’s the code:


// remove unnecessary menus
function remove_admin_menus () {
	global $menu;

	// all users
	$restrict = explode(',', 'Links,Comments');
	
	// non-administrator users
	$restrict_user = explode(',', 'Media,Profile,Appearance,Plugins,Users,Tools,Settings');

	// WP localization
	$f = create_function('$v,$i', 'return __($v);');
	array_walk($restrict, $f);
	if (!current_user_can('activate_plugins')) {
		array_walk($restrict_user, $f);
		$restrict = array_merge($restrict, $restrict_user);
	}

	// remove menus
	end($menu);
	while (prev($menu)) {
		$k = key($menu);
		$v = explode(' ', $menu[$k][0]);
		if(in_array(is_null($v[0]) ? '' : $v[0] , $restrict)) unset($menu[$k]);
	}

}
add_action('admin_menu', 'remove_admin_menus');

There are two lines you should edit:

  • $restrict (line 5) contains a comma-delimited list of menu items which will not be shown to any users — including adminstrators. In the example above, we’re hiding Links and Comments, but your requirements may be different.
  • $restrict_user (line 8) contains a comma-delimited list of menu items which will not be shown to non-adminisrators. The example above disables everything expect for the Dashboard, Pages and Posts. (Note that non-administive users would not normally see Appearance and Plugins, but other plugins might change that functionality.)

I hope you and your clients find it useful. Do you have further tips for simplifying WordPress?

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • rob

    there’s a simpler way to do it
    get the Adminimize plugin, it allows you to completly customize what the client can see w/o going into code!

    • Ben

      I love that Plugin!

  • aesqe

    this function is a bit simpler, but generally does the same thing.
    it uses ‘_admin_menu’ hook which runs before ‘admin_menu’, and just after all the menu items have been enumerated.
    the downside is, it requires looking at ‘wp-admin/menu.php’ file so you would know which items in array to unset.
    also, if item positions in $menu and $submenu arrays ever change, you’ll have to modify the function, but I don’t think that’s gonna happen anytime soon.
    function remove_admin_menu_items()
    {
    global $menu, $submenu;

    if( !current_user_can(‘level_10′) ) // you could also check for a certain role or username here
    {
    unset($menu[10]); // media
    unset($menu[15]); // links
    unset($menu[25]); // comments
    unset($menu[60]); // appearance
    unset($menu[75]); // tools

    unset($submenu['users.php'][5]); // edit users
    unset($submenu['users.php'][10]); // add users
    }
    }
    add_action( ‘_admin_menu’, ‘remove_admin_menu_items’ );

  • Troy Dean

    Nice post Craig. We share a similar philosophy regarding making WordPress as simple for your clients as possible to get started. We were constantly reconfiguring our dashboards for clients. So much so that we made a plugin to streamline the process.
    Our White-label CMS plugin allows you re-brand the login screen and admin dashboard as well as remove the nag update and unnecessary dashboard modules. We also wrote the functionality to insert your own custom dashboard module; a “Welcome” message if you like.
    Anyway this has given us something to think about. Maybe incorporating the option to hide menus is a feature we should include in future releases.
    Would love any feedback.
    Check it out at http://www.videousermanuals.com/white-label-cms/
    Keep up the great work.
    By the way I had trouble logging in here.

    • http://www.optimalworks.net/ Craig Buckler

      Thanks Troy. That plugin looks a lot easier and is certainly a good option if you don’t want to get your hands dirty with PHP code.

  • astrotim

    This is great. I knew there would be a way to do this but I hadn’t gotten around to searching it out yet. Thanks to Sitepoint being my homepage, it came right to me.

    Going further – does anyone know how to disable “Add new page” for non-administrators? I sometimes do projects with limited pages and I would like to prevent a savvy client from going ahead and adding more pages if they have negotiated a cheaper price for such a project.

  • Troy Dean

    Hi Craig, turns out we liked your idea of hiding menus so much that we did integrate some of your ideas into the new version of our plugin which we released yesterday. We set up two profiles, one for a straight website and the other for blogging. These profiles will automagically hide irrelevant menus. Of course you can also select a custom profile and choose the menus you want to hide.

    Thought you might like to see some of your ideas in action.

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

    Cheers.