skip to Main Content
Menu

Minimize WordPress Menu items for public sites

Have you ever wanted to be able to create a site that was designed to have a membership and not fear whether or not you have assigned user roles properly?

Well here is a nifty little snippet that you can add to your bp-custom.php or functions.php.  What this does (please refer to image in blue) is to take the wordpress menu shown and turn it into (please refer to the image in light grey) a very basic menu that still allows its users to create and edit their own posts.

function remove_menus () {
global $menu;
// check if the logged-in user is an adminstrator or not
if( !current_user_can('administrator') ) {
// items found on this array are those items we do not want to show the public
$restricted = array(__('Dashboard'), __('Photo Albums'), __('Profile'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
}else{
// if we reached this place, it simply means that the current user is an admin and //that we should leave the array empty since we are supposed to let the admin show //all menu items.
$restricted = array();
}

 

end ($menu);
// delete all menu items found in the $restricted array.
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');

Well that's it... don't forget to save in either your bp-custom.php(for buddypress installations) or your functions.php (found in your theme folder.)

Alphonse

Editorial Staff at ETN Multimedia is led by Alphonse Tan. Page maintained by Alphonse Tan

Back To Top