diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 7e52e2ffb2..4611f0d295 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -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
"; + 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 diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 7efebe8e97..0cf0f39daa 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -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 & 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,9 +83,32 @@ 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 ( 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 ) { // If submenu is empty... if ( empty($submenu[$data[2]]) ) { @@ -95,24 +117,7 @@ foreach ( $menu as $id => $data ) { $menu_nopriv[$data[2]] = true; 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