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
Leave a Reply
About
Welcome to the blog of Ryan Marganti, the owner of SoulSizzle Design. I am currently booked until the end of time and not accepting freelance work. 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
Just voted @talenthouse for Chris http://t.co/I1qRfAUh #ladyantebellum #
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/ [...]
Wicked Nice. That will save a lot of “re-do” time.. Thank you!
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!
Truly great! Thanks for sharing.
Super good post, i totally love this blog, keep on it
Things should be delayed till the point they are needed. Thanks for sharing, very nice article.
It’s very useful for me to study CSS. Thank you very much.
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.
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..
[...] 来源: http://soulsizzle.com/quick-tips/stopping-clients-from-switching-their-wordpress-theme/ [...]