From 0a926ab21a8e4fc81b8d73ac2255a9ab6f066e5c Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 18 Nov 2006 16:24:31 +0000 Subject: [PATCH] Menu reparenting fixes. Now even more complex and incomprehensible. git-svn-id: http://svn.automattic.com/wordpress/trunk@4481 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-functions.php | 16 ++++++++-------- wp-admin/menu-header.php | 13 ++++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 5753642574..36edc16d44 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -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
"; - echo "
";
-	print_r( $_wp_menu_nopriv );
-	print_r( $_wp_submenu_nopriv );
-	echo "
";*/ + 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; - } } } diff --git a/wp-admin/menu-header.php b/wp-admin/menu-header.php index d113276713..50b5701f80 100644 --- a/wp-admin/menu-header.php +++ b/wp-admin/menu-header.php @@ -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
  • {$item[0]}
  • "; + else + echo "\n\t
  • {$item[0]}
  • "; + } else if ( current_user_can($item[1]) ) { if ( file_exists(ABSPATH . PLUGINDIR . "/{$item[2]}") ) echo "\n\t
  • {$item[0]}
  • "; else @@ -62,4 +69,4 @@ endif; do_action('admin_notices'); -?> +?> \ No newline at end of file