More fun with menus.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4100 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-08-15 22:13:36 +00:00
parent b929433507
commit 44b3783d36
2 changed files with 23 additions and 21 deletions

View File

@ -1343,15 +1343,32 @@ 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;
if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$parent][$plugin_page]) )
return false;
//if ( empty($parent) )
//return false;
if ( empty($parent) ) {
if ( isset($_wp_menu_nopriv[$pagenow]) )
return false;
if ( isset($_wp_submenu_nopriv[$pagenow][$pagenow]) )
return false;
if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) )
return false;
foreach (array_keys($_wp_submenu_nopriv) as $key) {
if ( isset($_wp_submenu_nopriv[$key][$pagenow]) )
return false;
if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$key][$plugin_page]) )
return false;
}
return true;
}
if (isset ($submenu[$parent])) {
foreach ($submenu[$parent] as $submenu_array) {

View File

@ -69,11 +69,14 @@ foreach ($menu as $menu_page) {
$admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
}
$_wp_submenu_nopriv = array();
$_wp_menu_nopriv = array();
// Loop over submenus and remove pages for which the user does not have privs.
foreach ($submenu as $parent => $sub) {
foreach ($sub as $index => $data) {
if ( ! current_user_can($data[1]) ) {
unset($submenu[$parent][$index]);
$_wp_submenu_nopriv[$parent][$data[2]] = true;
}
}
@ -118,24 +121,6 @@ foreach ( $menu as $id => $data ) {
$_wp_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 ) {
$_wp_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]);
$_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent];
} */
}
}