I’ve blogged a number of times over the years about minimizing the complexity that’s exposed in WordPress’s dashboard. I’ve done that in a couple different ways. The Gravity Forms-driven front end where you avoid WP’s dashboard entirely is one path. The other way was to just remove stuff that’s like irrelevant to different groups. I think I first did that way back in the ANTH101 days with Mike Wesch and Ryan K. That’s circa 2017 if you’re counting. I have to think that either it keeps coming up because it’s a good idea or that I have limited ideas that I recycle consistently. It may be a bit of both.
In either case, I’m bringing it back with the new DLINQ site. In this case, I’m stripping a bunch of stuff from the dashboard and the sidebar menu for everyone by default. I am using ACF’s options to define who sees the normal view with all the stuff. People can still get wherever if they know the URL, but it’s mean to be a more direct editing experience that shows you stuff you need, rather than all the stuff you might need.
Dashboard stuff
The dashboard cleaner is some code I’ve re-used a few times with various tweaks. This adds a bit of direction around when to use certain post types. I intend to make that text clearer and probably fancy it all up with some CSS, icons and what not. In the meantime, it looks like this.
Remive
There’s some extra code in here to get rid of the dashboard widget for the Limit Login Attempts Reloaded plugin. It can be a pain to find the right thing to unregister. If you log the $wp_meta_boxes variable (after guessing a few times), you’ll see what you need to do. In the case of the LLAR plugin, I was missing the high, rather than core pattern.
function disable_default_dashboard_widgets() { global $wp_meta_boxes; // wp.. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); 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']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_site_health']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // bbpress unset($wp_meta_boxes['dashboard']['normal']['core']['bbp-dashboard-right-now']); // yoast seo unset($wp_meta_boxes['dashboard']['normal']['core']['yoast_db_widget']); // gravity forms unset($wp_meta_boxes['dashboard']['normal']['core']['rg_forms_dashboard']); //events calendar unset($wp_meta_boxes['dashboard']['normal']['core']['tribe_dashboard_widget']); //limit logins llar_stats_widget unset($wp_meta_boxes['dashboard']['normal']['high']['llar_stats_widget']); } add_action('wp_dashboard_setup', 'disable_default_dashboard_widgets', 999);
Add
Now to add what we want. If it gets much more complex, I’ll stop being lazy and import a theme template piece for this.
add_action('wp_dashboard_setup', 'dlinq_custom_dashboard_widgets'); function dlinq_custom_dashboard_widgets() { global $wp_meta_boxes; wp_add_dashboard_widget('custom_dlinq_widget', '<h1>Shortcuts</h1>', 'dlinq_custom_dashboard_posts'); } function dlinq_custom_dashboard_posts() { echo " <a class='dash-btn' href='post-new.php?post_type=page'>Pages</a>: for core elements. Use the focus full width template.<br> <a class='dash-btn' href='post-new.php?post_type=topic'>Topics</a>: for all the other static stuff.<br> <a class='dash-btn' href='post-new.php?post_type=project'>Projects</a>: for projects.<br> <a class='dash-btn' href='post-new.php?post_type=person'>People</a>: for people.<br> <a class='dash-btn' href='post-new.php?post_type=workshop'>Workshop</a>: for the catalog of workshops. Use events for workshops with dates.<br> "; }
Make the hide/show conditional
I use a user field in ACF’s options page set to allow more than one selection and returning user IDs to make all this conditional. The field is called “Messy View” and it looks like this.1
The sidebar cleaner code looks like this. Note, it sets $messy_users to an empty array first. That keeps us from having problems with the field not being set initially and throwing an error because there’s no array to check for.2
function dlinq_clean_sidebar(){ $messy_users = []; if(get_field('messy_view', 'options')){ $messy_users = get_field('messy_view', 'options'); } $current_user_id = get_current_user_id(); $messy = in_array($current_user_id,$messy_users, false); if($messy != true){ remove_menu_page( 'index.php' ); //Dashboard remove_menu_page( 'comments' ); //Jetpack* remove_menu_page( 'options-general.php' ); //Settings remove_menu_page( 'themes.php' ); //appearance remove_menu_page( 'users.php' ); //users remove_menu_page( 'plugins.php' ); //plugins remove_menu_page( 'tools.php' ); //tools remove_menu_page( 'upload.php' ); //media remove_menu_page( 'edit.php?post_type=acf-field-group' ); //acf remove_menu_page('limit-login-attempts'); //limit logins } } add_action( 'admin_init', 'dlinq_clean_sidebar', 999 );
That gives a clean view something like this. I may do some more work around order and some CSS to highlight some elements.