Menu reparenting fixes. Now even more complex and incomprehensible.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4481 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-11-18 16:24:31 +00:00
parent eda9021317
commit 0a926ab21a
2 changed files with 18 additions and 11 deletions

View File

@ -1341,11 +1341,7 @@ function user_can_access_admin_page() {
global $plugin_page;
$parent = get_admin_page_parent();
/*echo "pa: $parent pn: $pagenow pp: $plugin_page<br/>";
echo "<pre>";
print_r( $_wp_menu_nopriv );
print_r( $_wp_submenu_nopriv );
echo "</pre>";*/
if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
return false;
@ -1370,7 +1366,12 @@ function user_can_access_admin_page() {
if ( isset( $submenu[$parent] ) ) {
foreach ( $submenu[$parent] as $submenu_array ) {
if ( $submenu_array[2] == $pagenow ) {
if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {
if ( current_user_can( $submenu_array[1] ))
return true;
else
return false;
} else if ( $submenu_array[2] == $pagenow ) {
if ( current_user_can( $submenu_array[1] ))
return true;
else
@ -1549,9 +1550,8 @@ function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $fi
// this case, don't automatically add a link back to avoid duplication.
if (!isset( $submenu[$parent] ) && $file != $parent ) {
foreach ( $menu as $parent_menu ) {
if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) {
if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) )
$submenu[$parent][] = $parent_menu;
}
}
}

View File

@ -10,8 +10,15 @@ foreach ($menu as $item) {
// 0 = name, 1 = capability, 2 = file
if (( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file))) $class = ' class="current"';
if ( !empty($submenu[$item[2]]) || current_user_can($item[1]) ) {
if ( !empty($submenu[$item[2]]) ) {
$submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
$menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
if ( file_exists(ABSPATH . PLUGINDIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
echo "\n\t<li><a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a></li>";
else
echo "\n\t<li><a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a></li>";
} else if ( current_user_can($item[1]) ) {
if ( file_exists(ABSPATH . PLUGINDIR . "/{$item[2]}") )
echo "\n\t<li><a href='admin.php?page={$item[2]}'$class>{$item[0]}</a></li>";
else
@ -62,4 +69,4 @@ endif;
do_action('admin_notices');
?>
?>