Dec
12
2008

Hiding the WordPress Dashboard for Non-Admin Users

by   |  Posted in Tutorials  |  27 comments

There are two plugins out there that I have found that help customize your WordPress install by removing the dashboard. Why would you want to do this? Well, perhaps you have installed and customized WordPress for a client who really doesn’t need the dashboard, or you don’t want users who login to see the dashboard. Either way, there are options. Something like this is best left to a plugin so that when you upgrade is still functions and you don’t have to go in and change everything.

Deep Wave has created a plugin called Hide Dashboard. It allows Admins to see the dashboard and removes it for regular users. There are a few options like allowing Authors and Editors to see the dashboard. I tried using this plugin on WordPress 2.7 and it did remove the dashboard for non-Admin users, but when they logged in it brought them straight to the dashboard even though the link was removed. Not really what you want.

Il Filosofo created a small plugin called Remove the Dashboard which worked great but hasn’t yet been updated for 2.7. I went in and made a few changes to get it to do what I wanted. Here is the original plugin code written by Austin Matzko and full credit is given to him for figuring it all out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
Plugin Name: Filosofo Remove Dashboard
Plugin URI: http://www.ilfilosofo.com/blog/
Description: Make the Dashboard, that page that takes forever to load when you log in, disappear.
Version: 1.0
Author: Austin Matzko
Author URI: http://www.ilfilosofo.com/blog/
*/
 
/*  Copyright 2006  Austin Matzko  (email : if.website at gmail.com)
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
 
function remove_the_dashboard () {
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/' . $menu[$page][2]);
}
add_action('admin_menu', 'remove_the_dashboard');
?>

I made some minor changes so that now it works in WordPress 2.7 and Admins have the ability to view the dashboard when they login.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
Plugin Name: Filosofo Remove Dashboard
Plugin URI: http://www.ilfilosofo.com/blog/
Description: Make the Dashboard, that page that takes forever to load when you log in, disappear.
Version: 1.0
Author: Austin Matzko
Author URI: http://www.ilfilosofo.com/blog/
*/
 
/*  Copyright 2006  Austin Matzko  (email : if.website at gmail.com)
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
*/
 
/*	
 
Update 12/12/2008
 
Modified by c.bavota of http://bavotasan.com for WordPress 2.7 and to allow the dashboard for Admins.
 
*/
 
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/post-new.php');
}
}
add_action('admin_menu', 'remove_the_dashboard');
?>

About the author:

A freelance web developer living in Montreal who spends most of his time writing for this site and building Premium themes for WordPress. You can find him on Twitter @bavotasan.

Site5 Affiliate Link
If you liked this, please share it.

Tags: , , , , , , , , , , , , , , , ,

Short URL: http://bit.ly/bCSyzR

Discussion 27 Comments

  1. c.bavota on December 12, 2008 at 10:28 pm

    Word of warning. Do not use the auto-install function for WordPress 2.7 with the revamped plugin zip file. The file was created on a Mac and it does some pretty funky things when installed automatically through the new 2.7 backend interface. I am looking into the reason but for now please install it the old fashion way, ie. unzipping it and uploading it through ftp.

    • kev on February 24, 2010 at 1:07 pm

      it’s because of mac’s way of storing metadata for files. Apparently apache reads ._ and displays it at the top of . Basically, enable “view hidden files” and look for the ._, delete them, and then re-zip the plugin and it’ll be nice and smooth, no funky characters.

    • Nathan Goddard on December 12, 2010 at 11:35 pm

      Hi I have a site im working on and i dont want people who register on my site to know its a wordpress site, I have a theme editor and made it look like its on my site but by the picture image it says dashboard, is there a way i can remove that option for subscribers?
      cheers, nathan

  2. Austin on December 18, 2008 at 5:13 am

    I’m glad you’re able update the code for your purposes. I wrote the original code back in the day because the Dashboard used to take forever to load all those blog entries; every log-in could hang for 20 seconds or more.

    Nowadays the feeds are loaded asynchronously, so it’s not so much of an issue.

  3. Dorian on January 1, 2009 at 2:10 pm

    Hey, do you know how hard it would be to create a plug-in to hide the various submenus in the dashboard such as:

    Tags
    Categories
    Excerpt
    Send Trackbacks
    Custom Fields
    Discussion
    Post Arthur

    I have a public blog site and I only want these options to be visible to people with an Editor status or above.

  4. belsamber on January 21, 2009 at 5:24 pm

    Hey thanks, this does what I need. FYI, I ended up changing the redirect line to:

    wp_redirect(get_option('siteurl') . '/wp-admin/profile.php');

    as I require membership to post comments, but membership doesn’t entail the ability to make a new post (so I was getting access denied messages.)

  5. thehammer on February 8, 2009 at 10:28 am

    @belsamper: I needed the exact change so you saved me time figuring out where to put it. Thanks for posting.

  6. Jake on March 23, 2009 at 3:57 am

    Awesome. Thanks for the fix. This is extremely useful.

    I simplified it like this to send non-admin to homepage:


    add_action('admin_menu', 'redirect_dashboard');
    function redirect_dashboard(){
    if( !current_user_can('level_10') ){
    if( preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) && ('index.php' != $menu[$page][2]) )
    wp_redirect(get_bloginfo('url'));
    }
    }

  7. bedding sets on April 5, 2009 at 12:08 pm

    It is good information!

  8. Nokao on April 24, 2009 at 5:19 am

    Is it possible with the same trick to remove also that damn “Tools” link?

    • pouet on June 9, 2009 at 9:01 am

      I’m try to do the same thing.

      add_action('admin_head', 'wphd_hide_tool_link', 0);
      function wphd_hide_tool_link() {
      if (!current_user_can('edit_others_posts')) {

      echo "\n" . '<style type="text/css" media="screen">#menu-tools { display: none; }</style>' . "\n";
      }
      }

      this script hides tool menu link, but its accessible by a direct access. I’ve to manage to redirect to another page when somebody tries to access

      The base I use is this one :
      http://www.kpdesign.net/wp-plugins/wp-hide-dashboard/

  9. Robert Neuschul on April 26, 2009 at 8:46 pm

    In the arena of hiding or modifying dashboard and other admin menu items and ordering – I’ve just encountered the following beta.

    Not yet quite right for hiding stuff from users – all changes are currently global, but if the blog is to be believed then role-based configurability is coming

    http://w-shadow.com/blog/2008/12/20/admin-menu-editor-for-wordpress/

    I’ve tested on a private site and it does exactly what it says on the tin :-)

  10. programlar on May 16, 2009 at 1:26 pm

    Great Post Thanks.

  11. wordpress on May 22, 2009 at 7:25 am

    this is really good if you are looking for multi author blogs ,, thanks

  12. dslaney on May 31, 2009 at 10:37 am

    I’m not sure what I’m doing wrong? I have taken the code placed it in a .php file and placed it in the plugin directory, but it is not showing up under the plugin menu. Am I missing something?

    • David Slaney on June 1, 2009 at 8:13 am

      It worked itself out eventually. I’m not really sure why. But for any newbs such as myself if you place the file directly in the plugin folder it will work. I tried placing it in its own directory in the plugin folder as well but that did’nt work for me. Maybe it should work that way as every other plugin is in its own subdirectory?

  13. free software on June 9, 2009 at 10:18 am

    Wow! This fix is awesome. Works like a charm. Thank you !

  14. Watch Year One Online on June 20, 2009 at 3:48 pm

    This is very hot information. I think I’ll share it on Facebook.
    p.s. Year One is already on the Internet and you can watch it for free.

  15. Bryan on July 20, 2009 at 1:58 pm

    I was able to cludge this to remove Posts/Tools/Media by simply making these tweaks:

    Duplicate the code three times in the .php file and revise each code area changing the words “blahblah” to the block you want removed.

    function remove_the_blahblah () {

    while ((__('Blahblah') != $menu[$page][0]) && next($menu))

    if (__('Blahblah') == $menu[$page][0]) unset($menu[$page]);

    add_action('admin_menu', 'remove_the_blahblah');

    Where “blahblah” is Media or Tools or etc… I’m my case I now have four blocks along with four add_action lines.

    Someone can still go directly to the pages if they hand enter the path, but for me that’s not a problem. I just need to make it not visible and I’m good enough.

  16. michael soriano on March 22, 2010 at 10:50 pm

    thank you for this little tool. very useful for my new client

  17. Sue on March 27, 2010 at 12:20 pm

    Thank you! Works beautifully with 2.8.2. :-)

  18. ravi on June 27, 2010 at 9:08 am

    Thanks for this post I was seeking the exact information that you provided here!

  19. Rate My Muscles on December 11, 2010 at 11:22 pm

    any word if this works on 3.0.3? I desperately need to remove some dashboard widgets for non-admin use

  20. Fask on March 6, 2011 at 1:33 pm

    Great Job … Thanks man

  21. Cigar Inspector on March 22, 2011 at 5:24 pm

    Cool, that’s the fix I was looking for. Going to try this in 3.1, hope it works!

  22. Justin Nash on April 25, 2011 at 5:36 pm

    Thanks! This is exactly what I needed. Great job!

  23. atozvision on May 26, 2011 at 11:47 pm

    Thank you! most needed plugins for me.