Stopping Clients From Switching Their WordPress Theme

When using WordPress as a CMS for client projects, you quite likely do not want to confuse the client by allowing them to change their theme or install new ones. Luckily, disabling these options from the admin menu is quite easy.

Digging into the WordPress code base

If you are only concerned with the solution, you can merely copy and past the code near the end of this article. However, read on if you would like a little insight into how I arrived at this solution.

The sub-menus for changing the theme or adding a new one are under the Appearance admin menu, Themes and Add New Themes respectively. Because “Add New Themes” is a little less ambiguous than “Themes”, I simply searched the WordPress code base for ‘Add New Themes’ and found the following in /wp-admin/menu.php

$menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top', 'menu-appearance', 'div' );
	$submenu['themes.php'][5]  = array(__('Themes'), 'switch_themes', 'themes.php');
	$submenu['themes.php'][10] = array(__('Editor'), 'edit_themes', 'theme-editor.php');
	$submenu['themes.php'][15] = array(__('Add New Themes'), 'install_themes', 'theme-install.php');

Removing the menu items

As you can see, WordPress simply creates the $menu and $submenu arrays to be used later. If we want to get rid of a menu item, all we have to do is remove the entry from the proper array. Because these menus only appear within the admin dashboard, we’ll use the admin_init action hook to run the following code after the arrays have been set but before the menus are actually rendered. Just paste the following code in the functions.php file of your theme.

// Disable theme switching and installation
add_action('admin_init', 'remove_theme_menus');
function remove_theme_menus() {
	global $submenu;	
 
	unset($submenu['themes.php'][5]);
	unset($submenu['themes.php'][15]);
}

Conclusion

This doesn’t have to be limited to the Themes and Add New Themes menus as we have above. You may even want to remove the Posts menu all together, for example. When used as a CMS, at times WordPress is almost too powerful. There are countless options that a client has no use for when all they want to do is a manage a couple pages. It is our responsibility as designers and developers to make things as simple as possible for the client. Removing options that they will never use goes a long way towards achieving this goal.

24 Comments

  1. AlexMarch 4, 2010

    Great post! I’ve been searching for this specific option – thanks!

     
  2. uwiuwMarch 11, 2010

    yes this is great solution. But i think you need to redirect(using wo_redirect($url)) or kill using(wp_die) them everytime they want to access the page.

    An admin still able to access those pages.

    use wordpress global variable $pagenow and hook the function in ‘admin_init’ to check which pages the user use.

     
  3. Best On WordPress From The Past Week N.2 | wpCanyonApril 18, 2010

    [...] Stopping Clients From Switching Their WordPress Theme [...]

     
  4. Deluxe Blog TipsApril 20, 2010

    Nice tip. And I think we should check user’s role or capability before delete these menu, like that:

    if (!user_can(‘edit_themes’)) {}

    I’m not sure about this, but should we use the hook ‘admin_init’ instead of ‘admin_header’?

     
  5. soulsizzleApril 20, 2010

    @uwiuw – I use this solution with clients who aren’t especially computer literate. Therefore, it is unlikely that they will access the page by any means other than the menu (ie. directly by URL). So I personally don’t see any need for worrying about redirection, a feature which adds a small amount of additional overhead. Your situation my differ though.

    @Deluxe Blog Tips – The whole point of this is to remove access to theme-changing for everyone. This means that we don’t really care what capabilities the user has. As far as admin_head vs. admin_init, you can use either. But using the admin_init hook makes a little more sense I suppose, so I’ve changed the code above to reflect that.

     
  6. AshfameApril 21, 2010

    @soulsizzle
    Use Just in time approach for choosing hooks. Things should be delayed till the point they are needed.

     
  7. Top WordPress hacks of early 2010April 26, 2010

    [...] { global $submenu; unset($submenu['themes.php'][5]); unset($submenu['themes.php'][15]); }Source: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/Get rid of unused shortcodes in your postsWordPress shortcodes are extremely useful, but they have a [...]

     
  8. Top WordPress hacks of early 2010 | WPGrind.comApril 27, 2010

    [...] add_action('admin_init', 'remove_theme_menus'); function remove_theme_menus() { global $submenu; unset($submenu['themes.php'][5]); unset($submenu['themes.php'][15]); } Source: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/ [...]

     
  9. Top WordPress hacks of early 2010 | Private GardensMay 26, 2010

    [...] { global $submenu; unset($submenu['themes.php'][5]); unset($submenu['themes.php'][15]); }Source: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/Get rid of unused shortcodes in your postsWordPress shortcodes are extremely useful, but they have a [...]

     
  10.  
  11.  
  12. WP prevent theme switchingJuly 8, 2010

    [...] want to prevent client from switching WP theme by accident, use this WP snippet, brought to you by SoulSizzle design. Just put this code into your functions.php file, and users won’t have an option to switch [...]

     
  13. Top WordPress hacks of early 2010 - FaredigitaleJuly 11, 2010

    [...] { global $submenu; unset($submenu['themes.php'][5]); unset($submenu['themes.php'][15]); }Source: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/Get rid of unused shortcodes in your postsWordPress shortcodes are extremely useful, but they have a [...]

     
  14. Mencegah Klien Mengubah Theme Wordpress | My Unconscious MindAugust 3, 2010

    [...] mencegah kasus seperti itu, sedikit tips dari soulsizzle.com bisa menjadi alternatif [...]

     
  15.  
  16. Fort CollinsOctober 29, 2010

    Wicked Nice. That will save a lot of “re-do” time.. Thank you!

     
  17. Dion GeBordeNovember 5, 2010

    Hey Ryan, nice tutorial.

    I’m digging into my functions.php file with a vengeance, making all kinds of customizations for client sites, but I’m really a php newbie, and have a couple questions:

    1. You said you dug around the WordPress code base to find “Add New Themes”. How did you do that? Specifically, where did you go to find the whole code base and what tool or process did you use to search it?

    2. I’m currently using WP 3.0.1 and there are two submenus in the Appearance tab that are not located in /menu.php, nor am I able to find a specific tutorial on them, namely “Widgets” and “Menu”. Do you have a great tutorial, or would you be willing to do one, on removing those? Thanks again!

     
  18. MatiasMarch 12, 2011

    Truly great! Thanks for sharing. :-)

     
  19. ny giants rumorsJuly 15, 2011

    Super good post, i totally love this blog, keep on it

     
  20. Dsc Alarm SistemleriJuly 20, 2011

    Things should be delayed till the point they are needed. Thanks for sharing, very nice article.

     
  21. Bebek KameralariJuly 20, 2011

    It’s very useful for me to study CSS. Thank you very much.

     
  22. ShermJuly 25, 2011

    Things have changed a little in WordPress 3.2.1 (I can’t speak for previous versions) and the Editor menu is no longer included in the array. In order to remove it, simply edit wp-admin/menu.php and comment out line 174

    //add_submenu_page(‘themes.php’, _x(‘Editor’, ‘theme editor’), _x(‘Editor’, ‘theme editor’), ‘edit_themes’, ‘theme-editor.php’);

    Dion:
    When I want to remove whole admin panels I use the follow code:

    function remove_menus () {
    global $menu;

    $restricted = array(__(‘Dashboard’), __(‘Posts’), __(‘Media’), __(‘Links’), __(‘Pages’), __(‘Appearance’), __(‘Tools’), __(‘Users’), __(‘Settings’), __(‘Comments’), __(‘Plugins’));
    end ($menu);
    while (prev($menu)){
    $value = explode(‘ ‘,$menu[key($menu)][0]);
    if(in_array($value[0] != NULL?$value[0]:”" , $restricted)){unset($menu[key($menu)]);}
    }
    }
    add_action(‘admin_menu’, ‘remove_menus’);

    Simply remove the items from the $restricted array that you want to still have visible. Anything left inside the array will be removed. I usually remove the Plugins panel, and the Themes, and Editor submenus from the Appearance panel.

     
  23. turbochargerOctober 17, 2011

    Good – I should definitely say I’m impressed with your blog.
    I had no trouble navigating through all the tabs as well as related info.
    The site ended up being truly simple to access. Excellent job..

     
  24.  

Leave a Reply