git-svn-id: http://svn.automattic.com/wordpress/trunk@4093 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-08-14 21:24:43 +00:00
parent 756caab182
commit 3b33ed195d
2 changed files with 34 additions and 23 deletions

View File

@ -1489,13 +1489,19 @@ function add_submenu_page($parent, $page_title, $menu_title, $access_level, $fil
global $submenu;
global $menu;
global $real_parent_file;
global $menu_nopriv;
$file = plugin_basename($file);
//echo "Adding $parent $file $access_level<br />";
if ( !current_user_can($access_level) ) {
$menu_nopriv[$file] = true;
return false;
}
$parent = plugin_basename($parent);
if ( isset($real_parent_file[$parent]) )
$parent = $real_parent_file[$parent];
$file = plugin_basename($file);
// If the parent doesn't already have a submenu, add a link to the parent
// as the first item in the submenu. If the submenu file is the same as the
// parent file someone is trying to link back to the parent manually. In

View File

@ -43,6 +43,7 @@ $submenu['link-manager.php'][10] = array(__('Add Link'), 'manage_links', 'link-a
$submenu['link-manager.php'][20] = array(__('Import Links'), 'manage_links', 'link-import.php');
if ( current_user_can('edit_users') ) {
$real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
$submenu['users.php'][5] = array(__('Authors &amp; Users'), 'edit_users', 'users.php');
$submenu['users.php'][10] = array(__('Your Profile'), 'read', 'profile.php');
} else {
@ -68,8 +69,6 @@ foreach ($menu as $menu_page) {
$admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
}
do_action('admin_menu', '');
// Loop over submenus and remove pages for which the user does not have privs.
foreach ($submenu as $parent => $sub) {
foreach ($sub as $index => $data) {
@ -84,18 +83,11 @@ foreach ($submenu as $parent => $sub) {
}
// Loop over the top-level menu.
// Remove menus that have no accessible submenus and require privs that the user does not have.
// Menus for which the original parent is not acessible due to lack of privs will have the next
// submenu in line be assigned as the new menu parent.
foreach ( $menu as $id => $data ) {
// If submenu is empty...
if ( empty($submenu[$data[2]]) ) {
// And user doesn't have privs, remove menu.
if ( ! current_user_can($data[1]) ) {
$menu_nopriv[$data[2]] = true;
unset($menu[$id]);
}
} else {
if ( empty($submenu[$data[2]]) )
continue;
$subs = $submenu[$data[2]];
$first_sub = array_shift($subs);
$old_parent = $data[2];
@ -113,6 +105,19 @@ foreach ( $menu as $id => $data ) {
unset($submenu[$old_parent]);
}
}
do_action('admin_menu', '');
// Remove menus that have no accessible submenus and require privs that the user does not have.
foreach ( $menu as $id => $data ) {
// If submenu is empty...
if ( empty($submenu[$data[2]]) ) {
// And user doesn't have privs, remove menu.
if ( ! current_user_can($data[1]) ) {
$menu_nopriv[$data[2]] = true;
unset($menu[$id]);
}
}
}
ksort($menu); // make it all pretty