Cleansing the Dashboard

Pre-Intervention

normal WordPress dashboard

Post-Intervention

cleansed WordPress dashboard

I’ve often had requests to make the admin dashboard in WordPress simpler for students (although it’s just as likely applicable to faculty or humans in general).

The example in the Juxtapose box above (slide it!)1 The result above is an example based on one such request. The goal was to take the initial dashboard and reduce it down to the absolute minimum of items needed for students and to move them directly into the place they were likely to spend most of their time working (not the dashboard).

The code below is all stuff that ends up living the functions file of the custom theme or could be incorporated into a plugin.2

This following code from here makes sure that the only posts an author sees are the ones they wrote. I’m not sure why that’s not the default but . . .

/**
HIDE Posts from authors who didn't write them
**/

function posts_for_current_author($query) {
	global $pagenow;

	if( 'edit.php' != $pagenow || !$query->is_admin )
	    return $query;

	if( !current_user_can( 'manage_options' ) ) {
		global $user_ID;
		$query->set('author', $user_ID );
	}
	return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');

The following removes menu items from the sidebar. It’s a combination of things I found in the Codex and in this post. It’s probable I can combine and simplify them but I haven’t taken the time to do that yet.

/** HIDE MORE ADMIN STUFF from AUTHORS **/

/* Clean up the admin sidebar navigation *************************************************/
function remove_admin_menu_items() {
if( current_user_can( 'manage_options' ) ) { }
	else {	
  $remove_menu_items = array(__('Media'),__('Tools'),__('Episodes'),__('Contact'), __('Comments'));  //removes episodes custom post type from the theme as well 
  global $menu;
  end ($menu);
  while (prev($menu)){
    $item = explode(' ',$menu[key($menu)][0]);
    if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){
      unset($menu[key($menu)]);
    }
  }
}
}
add_action('admin_menu', 'remove_admin_menu_items');

function remove_menus(){
if( current_user_can( 'manage_options' ) ) { }
	else {		
  
  remove_menu_page( 'index.php' );                  //Dashboard
  remove_menu_page( 'jetpack' );                    //Jetpack* 
  remove_menu_page( 'options-general.php' );        //Settings
  remove_menu_page( 'vc-welcome' );        //a sidebar item added by the theme 
  remove_menu_page( 'profile' );        //profile
  //remove_menu_page('profile.php');

}
}
add_action( 'admin_menu', 'remove_menus', 999 );

Since there was one sidebar item coming from the theme/plugin, I wasn’t sure how WordPress would handle removing it. Turned out to be pretty straightforward. Mousing over the sidebar item got me the http://MYSITE.com/wp-admin/admin.php?page=vc-general and I just needed to target the vc-general portion.

mouse over sidebar item to get name to remove in php

And finally this chunk redirects non-admins from the dashboard view to the post editing view.

//redirects from dashboard to edit post list 
function remove_the_dashboard () {
if (current_user_can('level_10')) {
	return;
	}else {
	global $menu, $submenu, $user_ID;
	$the_user = new WP_User($user_ID);
	reset($menu); $page = key($menu);
	while ((__('Dashboard') != $menu[$page][0]) && next($menu))
	$page = key($menu);
	if (__('Dashboard') == $menu[$page][0]) unset($menu[$page]);
	reset($menu); $page = key($menu);
	while (!$the_user->has_cap($menu[$page][1]) && next($menu))
	$page = key($menu);
	if (preg_match('#wp-admin/?(index.php)?$#',$_SERVER['REQUEST_URI']) && ('index.php' != $menu[$page][2]))
	wp_redirect(get_option('siteurl') . '/wp-admin/edit.php');}
}
add_action('admin_menu', 'remove_the_dashboard');

Now what might make this more than a one-off, is playing around with how to expose these elements as choices. You could expose additional pieces based on number of posts or time spent logged in or something like that. You could also do some sort of guided intro where you walk people through the things they might consider activating in their main view. Currently WordPress tries to do some of this with the Screen Options tab (contextual to a number of different views). In my experience this hides things well but many people never realize it exists. It is very easy to forget even if you know it exists. It lead me to some really frustrating exchanges before I added it to my early troubleshooting considerations.

selected screen options tab in wordpress

If I were really slick, I’d do something to remind people of additional options in a intro.js style based on what they were doing or how often they’ve done something. It could be good but it could also veer into Clippy-land if you’re not careful.

via GIPHY


1 I’ve been having some issues with Knightlab stuff loading recently. Maybe they’re too popular or VCU is flagging them on the network in some way. They run fine when I install the libraries locally.

2 There are plugins that do aspects of this but I wanted to keep this fairly lean and didn’t want the overhead of multiple plugins to achieve this particular result.

Comments on this post

No comments.

Leave a Reply

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL