The MU forums have moved to WordPress.org

Remove items from the menu (15 posts)

  1. jweggemans
    Member
    Posted 14 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.

  2. lunabyte
    Member
    Posted 14 years ago #

  3. jweggemans
    Member
    Posted 14 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..

  4. dsader
    Member
    Posted 14 years ago #

    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.

  5. jweggemans
    Member
    Posted 14 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?

  6. dsader
    Member
    Posted 14 years ago #

    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');
    ?>

  7. chinafla
    Member
    Posted 14 years ago #

    the redirect is useful, mark it.

  8. andrea_r
    Moderator
    Posted 14 years ago #

    dsader, I heart you so much this week.

  9. brianbrey
    Member
    Posted 14 years ago #

    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!

  10. dsader
    Member
    Posted 14 years ago #

    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/

  11. cafespain
    Member
    Posted 14 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.

  12. dsader
    Member
    Posted 14 years ago #

    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;
    }
    }
  13. mdgross
    Member
    Posted 14 years ago #

    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');
    
    ?>
  14. dsader
    Member
    Posted 14 years ago #

    I mashed together a variety of menu hacks I use into one plugin: http://wpmudevorg.wordpress.com/project/Menus

  15. indojepang
    Member
    Posted 14 years ago #

    whoaa! this is great!
    Thank u dsader!

About this Topic

  • Started 14 years ago by jweggemans
  • Latest reply from indojepang