Changeset 4093

Show
Ignore:
Timestamp:
08/14/06 21:24:43 (2 years ago)
Author:
ryan
Message:

menu fixes. #2257 #2696

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/admin-functions.php

    r4082 r4093  
    14901490    global $menu; 
    14911491    global $real_parent_file; 
     1492    global $menu_nopriv; 
     1493 
     1494    $file = plugin_basename($file); 
     1495    //echo "Adding $parent $file $access_level<br />"; 
     1496    if ( !current_user_can($access_level) ) { 
     1497        $menu_nopriv[$file] = true; 
     1498        return false; 
     1499    } 
    14921500 
    14931501    $parent = plugin_basename($parent); 
    14941502    if ( isset($real_parent_file[$parent]) ) 
    14951503        $parent = $real_parent_file[$parent]; 
    1496  
    1497     $file = plugin_basename($file); 
    14981504 
    14991505    // If the parent doesn't already have a submenu, add a link to the parent 
  • trunk/wp-admin/menu.php

    r3999 r4093  
    4444 
    4545if ( current_user_can('edit_users') ) { 
     46    $real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php. 
    4647    $submenu['users.php'][5] = array(__('Authors &amp; Users'), 'edit_users', 'users.php'); 
    4748    $submenu['users.php'][10] = array(__('Your Profile'), 'read', 'profile.php'); 
     
    6970} 
    7071 
    71 do_action('admin_menu', ''); 
    72  
    7372// Loop over submenus and remove pages for which the user does not have privs. 
    7473foreach ($submenu as $parent => $sub) { 
     
    8584 
    8685// Loop over the top-level menu. 
    87 // Remove menus that have no accessible submenus and require privs that the user does not have. 
    8886// Menus for which the original parent is not acessible due to lack of privs will have the next 
    8987// submenu in line be assigned as the new menu parent.  
     88foreach ( $menu as $id => $data ) { 
     89    if ( empty($submenu[$data[2]]) )  
     90        continue; 
     91    $subs = $submenu[$data[2]]; 
     92    $first_sub = array_shift($subs); 
     93    $old_parent = $data[2]; 
     94    $new_parent = $first_sub[2]; 
     95    // If the first submenu is not the same as the assigned parent, 
     96    // make the first submenu the new parent. 
     97    if ( $new_parent != $old_parent ) { 
     98        $real_parent_file[$old_parent] = $new_parent; 
     99        $menu[$id][2] = $new_parent; 
     100         
     101        foreach ($submenu[$old_parent] as $index => $data) { 
     102            $submenu[$new_parent][$index] = $submenu[$old_parent][$index]; 
     103            unset($submenu[$old_parent][$index]); 
     104        } 
     105        unset($submenu[$old_parent]);    
     106    } 
     107} 
     108 
     109do_action('admin_menu', ''); 
     110 
     111// Remove menus that have no accessible submenus and require privs that the user does not have. 
    90112foreach ( $menu as $id => $data ) { 
    91113    // If submenu is empty... 
     
    96118            unset($menu[$id]); 
    97119        } 
    98     } else { 
    99         $subs = $submenu[$data[2]]; 
    100         $first_sub = array_shift($subs); 
    101         $old_parent = $data[2]; 
    102         $new_parent = $first_sub[2]; 
    103         // If the first submenu is not the same as the assigned parent, 
    104         // make the first submenu the new parent. 
    105         if ( $new_parent != $old_parent ) { 
    106             $real_parent_file[$old_parent] = $new_parent; 
    107             $menu[$id][2] = $new_parent; 
    108              
    109             foreach ($submenu[$old_parent] as $index => $data) { 
    110                 $submenu[$new_parent][$index] = $submenu[$old_parent][$index]; 
    111                 unset($submenu[$old_parent][$index]); 
    112             } 
    113             unset($submenu[$old_parent]);    
    114         } 
    115     } 
     120    }  
    116121} 
    117122