jweggemans
Member
Posted 16 years ago #
I ran in to the following problem while stripping the admin area..
For non-admin users I want to:
From the admin menu remove 'Design'.
From the admin menu tabs 'Write' and 'Manage' I want to remove from the submenu everything but 'Messages' and 'Media Library'.
I've looked at menu.php and menu-header.php, but because of the complexity I can't figure out how to do this..
It would be nice that these features are still available when logged in as admin.
lunabyte
Member
Posted 16 years ago #
jweggemans
Member
Posted 16 years ago #
Thanks. I've found out to look in wp-admin/includes/schema.php. I see how to add capabilities but cant figure out how to remove them..
To remove menus plop this into an mu-plugins:
function remove_menu_item(){
global $menu, $submenu;
if( !is_site_admin() ) {
unset($menu[15]);
unset($menu[another menu number]);
unset($submenu['parent file name'][and a submenu number]);
}
}
add_action('admin_menu', 'remove_menu_item');
Look at menu.php to see # of the $menu or $submenu.
jweggemans
Member
Posted 16 years ago #
Thanks dsader! Does exactly what I need!
But.. Is just removing from the menu enough? Don't I need to add/delete some PHP code to restrict actual access to the pages?
You could add a header redirect mu-plugin such as
<?php
function ds_themes_closed () {
if(!is_site_admin() && strpos($_SERVER['REQUEST_URI'], 'themes.php'))
{
header('Location: ' . get_settings('siteurl') . '/wp-admin/');
}
}
add_action('admin_head', 'ds_themes_closed');
?>
chinafla
Member
Posted 16 years ago #
the redirect is useful, mark it.
dsader, I heart you so much this week.
I can't seem to get the code for removing the menu option to work.. I found the item number (for example 15), put it in the code, create a filename.php and put it in the mu-plugins folder. but it just shows the code at the top of the page.. what am i doing wrong?
I'm using version 1.51.
thank you!
brianbrey, did you forget to put it in your opening and closing php tags?
If you did, then you will want this http://markjaquith.wordpress.com/2006/03/04/wp-tutorial-your-first-wp-plugin/
cafespain
Member
Posted 16 years ago #
Be careful assuming that your menu is going to be at a set location. Future versions of MU might move things around.
A less likely change is the file name the menu calls - so a check for themes.php will (in future) not remove a menu that happens to now be at location 15.
Just a thought.
Exactly, cafespain,
I use the following for more reliable removal:
foreach($submenu['options-general.php'] as $key => $sm) {
if(__($sm[0]) == "Delete Blog" || $sm[2] == "delete-blog") {
unset($submenu['options-general.php'][$key]);
break;
}
}
Thanks for the code guys... I spruced it up a bit.
<?php
function remove_submenu_items()
{
global $submenu, $remove;
if(!is_site_admin())
{
foreach($submenu as $name => $menu)
{
foreach ($menu as $key => $values)
{
if(in_array($values[2], $remove))
{
unset($submenu[$name][$key]);
}
}
}
}
}
function section_closed ()
{
global $remove;
if(!is_site_admin())
{
foreach($remove as $page)
{
if(strpos($_SERVER['REQUEST_URI'], $page))
{
header('Location: ' . get_settings('siteurl') . '/wp-admin/');
break;
}
}
}
}
$remove = array('upload.php', 'edit-pages.php', 'page-new.php');
add_action('admin_head', 'section_closed');
add_action('admin_menu', 'remove_submenu_items');
?>
I mashed together a variety of menu hacks I use into one plugin: http://wpmudevorg.wordpress.com/project/Menus
whoaa! this is great!
Thank u dsader!