git-svn-id: http://svn.automattic.com/wordpress/trunk@4093 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
756caab182
commit
3b33ed195d
|
@ -1489,13 +1489,19 @@ function add_submenu_page($parent, $page_title, $menu_title, $access_level, $fil
|
||||||
global $submenu;
|
global $submenu;
|
||||||
global $menu;
|
global $menu;
|
||||||
global $real_parent_file;
|
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);
|
$parent = plugin_basename($parent);
|
||||||
if ( isset($real_parent_file[$parent]) )
|
if ( isset($real_parent_file[$parent]) )
|
||||||
$parent = $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
|
// 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
|
// 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
|
// parent file someone is trying to link back to the parent manually. In
|
||||||
|
|
|
@ -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');
|
$submenu['link-manager.php'][20] = array(__('Import Links'), 'manage_links', 'link-import.php');
|
||||||
|
|
||||||
if ( current_user_can('edit_users') ) {
|
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 & Users'), 'edit_users', 'users.php');
|
$submenu['users.php'][5] = array(__('Authors & Users'), 'edit_users', 'users.php');
|
||||||
$submenu['users.php'][10] = array(__('Your Profile'), 'read', 'profile.php');
|
$submenu['users.php'][10] = array(__('Your Profile'), 'read', 'profile.php');
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,8 +69,6 @@ foreach ($menu as $menu_page) {
|
||||||
$admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
|
$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.
|
// Loop over submenus and remove pages for which the user does not have privs.
|
||||||
foreach ($submenu as $parent => $sub) {
|
foreach ($submenu as $parent => $sub) {
|
||||||
foreach ($sub as $index => $data) {
|
foreach ($sub as $index => $data) {
|
||||||
|
@ -84,9 +83,32 @@ foreach ($submenu as $parent => $sub) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over the top-level menu.
|
// 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
|
// 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.
|
// submenu in line be assigned as the new menu parent.
|
||||||
|
foreach ( $menu as $id => $data ) {
|
||||||
|
if ( empty($submenu[$data[2]]) )
|
||||||
|
continue;
|
||||||
|
$subs = $submenu[$data[2]];
|
||||||
|
$first_sub = array_shift($subs);
|
||||||
|
$old_parent = $data[2];
|
||||||
|
$new_parent = $first_sub[2];
|
||||||
|
// If the first submenu is not the same as the assigned parent,
|
||||||
|
// make the first submenu the new parent.
|
||||||
|
if ( $new_parent != $old_parent ) {
|
||||||
|
$real_parent_file[$old_parent] = $new_parent;
|
||||||
|
$menu[$id][2] = $new_parent;
|
||||||
|
|
||||||
|
foreach ($submenu[$old_parent] as $index => $data) {
|
||||||
|
$submenu[$new_parent][$index] = $submenu[$old_parent][$index];
|
||||||
|
unset($submenu[$old_parent][$index]);
|
||||||
|
}
|
||||||
|
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 ) {
|
foreach ( $menu as $id => $data ) {
|
||||||
// If submenu is empty...
|
// If submenu is empty...
|
||||||
if ( empty($submenu[$data[2]]) ) {
|
if ( empty($submenu[$data[2]]) ) {
|
||||||
|
@ -95,24 +117,7 @@ foreach ( $menu as $id => $data ) {
|
||||||
$menu_nopriv[$data[2]] = true;
|
$menu_nopriv[$data[2]] = true;
|
||||||
unset($menu[$id]);
|
unset($menu[$id]);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
$subs = $submenu[$data[2]];
|
|
||||||
$first_sub = array_shift($subs);
|
|
||||||
$old_parent = $data[2];
|
|
||||||
$new_parent = $first_sub[2];
|
|
||||||
// If the first submenu is not the same as the assigned parent,
|
|
||||||
// make the first submenu the new parent.
|
|
||||||
if ( $new_parent != $old_parent ) {
|
|
||||||
$real_parent_file[$old_parent] = $new_parent;
|
|
||||||
$menu[$id][2] = $new_parent;
|
|
||||||
|
|
||||||
foreach ($submenu[$old_parent] as $index => $data) {
|
|
||||||
$submenu[$new_parent][$index] = $submenu[$old_parent][$index];
|
|
||||||
unset($submenu[$old_parent][$index]);
|
|
||||||
}
|
|
||||||
unset($submenu[$old_parent]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($menu); // make it all pretty
|
ksort($menu); // make it all pretty
|
||||||
|
|
Loading…
Reference in New Issue