Ticket #2257: auto_parent.diff
File auto_parent.diff, 5.2 KB (added by , 19 years ago) |
---|
-
wp-admin/menu-header.php
11 11 // 0 = name, 1 = capability, 2 = file 12 12 if (( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file))) $class = ' class="current"'; 13 13 14 if ( current_user_can($item[1]) ) {14 if ( !empty($submenu[$item[2]]) || current_user_can($item[1]) ) { 15 15 if ( file_exists(ABSPATH . "wp-content/plugins/{$item[2]}") ) 16 16 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>"; 17 17 else -
wp-admin/menu.php
49 49 $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); 50 50 $submenu['themes.php'][10] = array(__('Theme Editor'), 'edit_themes', 'theme-editor.php'); 51 51 52 // Loop over submenus and remove pages for which the user does not have privs. 53 foreach ($submenu as $parent => $sub) { 54 foreach ($sub as $index => $data) { 55 if ( ! current_user_can($data[1]) ) { 56 $menu_nopriv[$data[2]] = true; 57 unset($submenu[$parent][$index]); 58 } 59 } 60 61 if ( empty($submenu[$parent]) ) 62 unset($submenu[$parent]); 63 } 64 65 // Loop over the top-level menu. 66 // Remove menus that have no accessible submenus and require privs that the user does not have. 67 // Menus for which the original parent is not acessible due to lack of privs will have the next 68 // submenu in line be assigned as the new menu parent. 69 foreach ( $menu as $id => $data ) { 70 // If submenu is empty... 71 if ( empty($submenu[$data[2]]) ) { 72 // And user doesn't have privs, remove menu. 73 if ( ! current_user_can($data[1]) ) { 74 $menu_nopriv[$data[2]] = true; 75 unset($menu[$id]); 76 } 77 } else { 78 $subs = $submenu[$data[2]]; 79 $first_sub = array_shift($subs); 80 $old_parent = $data[2]; 81 $new_parent = $first_sub[2]; 82 // If the first submenu is not the same as the assigned parent, 83 // make the first submenu the new parent. 84 if ( $new_parent != $old_parent ) { 85 $real_parent_file[$old_parent] = $new_parent; 86 $menu[$id][2] = $new_parent; 87 88 foreach ($submenu[$old_parent] as $index => $data) { 89 $submenu[$new_parent][$index] = $submenu[$old_parent][$index]; 90 unset($submenu[$old_parent][$index]); 91 } 92 unset($submenu[$old_parent]); 93 } 94 } 95 } 96 52 97 // Create list of page plugin hook names. 53 98 foreach ($menu as $menu_page) { 54 99 $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]); -
wp-admin/admin-functions.php
1231 1231 global $pagenow; 1232 1232 global $menu; 1233 1233 global $submenu; 1234 global $menu_nopriv; 1234 1235 1235 1236 $parent = get_admin_page_parent(); 1237 1238 if ( isset($menu_nopriv[$pagenow]) ) 1239 return false; 1236 1240 1237 foreach ($menu as $menu_array) { 1238 //echo "parent array: " . $menu_array[2]; 1239 if ($menu_array[2] == $parent) { 1240 if (!current_user_can($menu_array[1])) { 1241 return false; 1242 } else { 1243 break; 1244 } 1245 } 1246 } 1241 if ( empty($parent) ) 1242 return true; 1247 1243 1248 1244 if (isset ($submenu[$parent])) { 1249 1245 foreach ($submenu[$parent] as $submenu_array) { 1250 1246 if ($submenu_array[2] == $pagenow) { 1251 if (!current_user_can($submenu_array[1])) { 1247 if (current_user_can($submenu_array[1])) 1248 return true; 1249 else 1252 1250 return false; 1253 } else {1254 return true;1255 }1256 1251 } 1257 1252 } 1258 1253 } 1259 1254 1255 foreach ($menu as $menu_array) { 1256 //echo "parent array: " . $menu_array[2]; 1257 if ($menu_array[2] == $parent) { 1258 if (current_user_can($menu_array[1])) 1259 return true; 1260 else 1261 return false; 1262 } 1263 } 1264 1260 1265 return true; 1261 1266 } 1262 1267 … … 1313 1318 global $submenu; 1314 1319 global $pagenow; 1315 1320 global $plugin_page; 1321 global $real_parent_file; 1316 1322 1317 if (isset ($parent_file) && !empty ($parent_file)) { 1323 if ( !empty ($parent_file) ) { 1324 if ( isset($real_parent_file[$parent_file]) ) 1325 $parent_file = $real_parent_file[$parent_file]; 1326 1318 1327 return $parent_file; 1319 1328 } 1320 1329 … … 1322 1331 foreach ($menu as $parent_menu) { 1323 1332 if ($parent_menu[2] == $plugin_page) { 1324 1333 $parent_file = $plugin_page; 1325 return $plugin_page; 1334 if ( isset($real_parent_file[$parent_file]) ) 1335 $parent_file = $real_parent_file[$parent_file]; 1336 1337 return $parent_file; 1326 1338 } 1327 1339 } 1328 1340 } 1329 1341 1330 1342 foreach (array_keys($submenu) as $parent) { 1331 1343 foreach ($submenu[$parent] as $submenu_array) { 1344 if ( isset($real_parent_file[$parent]) ) 1345 $parent = $real_parent_file[$parent]; 1332 1346 if ($submenu_array[2] == $pagenow) { 1333 1347 $parent_file = $parent; 1334 1348 return $parent; … … 1363 1377 function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') { 1364 1378 global $submenu; 1365 1379 global $menu; 1380 global $real_parent_file; 1366 1381 1367 1382 $parent = plugin_basename($parent); 1383 if ( isset($real_parent_file[$parent]) ) 1384 $parent = $real_parent_file[$parent]; 1385 1368 1386 $file = plugin_basename($file); 1369 1387 1370 1388 // If the parent doesn't already have a submenu, add a link to the parent