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.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Twitter

15 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.  

Leave a Reply