[wp-hackers] RE: simple method to hide admin menus

Mindshare Studios info at mindsharestudios.com
Fri Sep 7 19:49:51 GMT 2007


Hi - I still haven't figured out an elegant way to hide menu items but
perhaps some could take a look at what I am trying to do and offer a
suggestion:

--------------

$default_items = array('index.php', 'post-new.php', 'edit.php',
'edit-comments.php', 'link-manager.php', 'themes.php', 'plugins.php',
'users.php', 'options-general.php' );

function mindshare_admin_menu() {
	global $submenu, $menu, $default_items;
	
	for  ($i = 0; $i < count($default_items); $i++) {
		if (locateInMenu($default_items[$i], $menu)) {
			// item was found
			if(!current_user_can('level_10')) {
				unset($menu[0]); // hide the item, not sure
how to target the item
			}
		}
	}
}

function locateInMenu($needle, $haystack) {
	$inMenu = false;
	$x = 0;
	foreach($haystack as $temp) {
		$search = array_search($needle, $temp);
		if (strlen($search) > 0 && $search >= 0) {
			$value[0] = $x;
			$value[1] = $search;
		}
		$x++;
	}
	return $inMenu;
}

add_action('admin_head','mindshare_admin_menu');

--------------

Thank you,
Damian



More information about the wp-hackers mailing list