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.
15 Comments
Leave a Reply
About
Welcome to the blog of Ryan Marganti, the owner of SoulSizzle Design. I am currently accepting freelance and long-term employment. Contact me with any questions or comments.
Categories
Recent Posts
-
Create an Ajax Sorter for WordPress Custom Post Types
Create an AJAX sorter for WordPress custom post types
-
Adding Additional Image Sizes to WordPress Themes
Define and implement Wordpress images resolutions beyond the default Large, Medium, and Thumb sizes.
-
Manage a Boatload of WordPress Sidebars With Help From jQuery
Enhance the Wordpress dashboard with jQuery
-
Display a Different Number of Posts in WordPress Searches
Change the number of results shown in a Wordpress search
Canvas Tree // http://is.gd/eQ5uq #
Great post! I’ve been searching for this specific option – thanks!
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.
[...] Stopping Clients From Switching Their WordPress Theme [...]
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’?
@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.
@soulsizzle
Use Just in time approach for choosing hooks. Things should be delayed till the point they are needed.
[...] { 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 [...]
[...] 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/ [...]
[...] { 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 [...]
[...] 来源: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/ [...]
[...] Source: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/ [...]
[...] 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 [...]
[...] { 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 [...]
[...] mencegah kasus seperti itu, sedikit tips dari soulsizzle.com bisa menjadi alternatif [...]
[...] Source: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/ [...]