Disable default WordPress widgets
Delivering a clean custom theme involves removing components or features that will not be used. Here’s how to disable WordPress default widgets:
Disable all default widgets
Just add the following to your theme’s functions.php
file:
// disable default widgets
function diw_disable_default_widgets() {
if(function_exists('unregister_sidebar_widget')) {
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Widget_Text');
}
}
add_action('widgets_init', 'diw_disable_default_widgets');
Remember to test and fine-tune as needed!
Disable all default widgets for a specific user
function remove_menus() {
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login == 'username') {
$restricted = array(__('Posts'),
__('Media'),
__('Links'),
__('Pages'),
__('Comments'),
__('Appearance'),
__('Plugins'),
__('Users'),
__('Tools'),
__('Settings')
);
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');