Make WordPress Core


Ignore:
Timestamp:
07/30/2010 08:34:54 PM (16 years ago)
Author:
ryan
Message:

Network Admin, first pass. see #14435

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/menu.php

    r15424 r15481  
    2626$awaiting_mod = $awaiting_mod->moderated;
    2727
    28 if ( is_multisite() && is_super_admin() ) {
    29         /* translators: Network menu item */
    30         $menu[0] = array(__('Super Admin'), 'manage_network', 'ms-admin.php', '', 'menu-top menu-top-first menu-icon-site', 'menu-site', 'div');
    31         $submenu[ 'ms-admin.php' ][1] = array( __('Admin'), 'manage_network', 'ms-admin.php' );
    32         /* translators: Sites menu item */
    33         $submenu[ 'ms-admin.php' ][5] = array( __('Sites'), 'manage_sites', 'ms-sites.php' );
    34         $submenu[ 'ms-admin.php' ][10] = array( __('Users'), 'manage_network_users', 'ms-users.php' );
    35         $submenu[ 'ms-admin.php' ][20] = array( __('Themes'), 'manage_network_themes', 'ms-themes.php' );
    36         $submenu[ 'ms-admin.php' ][25] = array( __('Options'), 'manage_network_options', 'ms-options.php' );
    37         $submenu[ 'ms-admin.php' ][30] = array( __('Update'), 'manage_network', 'ms-upgrade-network.php' );
    38 
    39         $menu[1] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
    40 
    41         $menu[2] = array( __('Dashboard'), 'read', 'index.php', '', 'menu-top menu-icon-dashboard', 'menu-dashboard', 'div' );
    42 } else {
    43         $menu[2] = array( __('Dashboard'), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'div' );
    44 }
     28$menu[2] = array( __('Dashboard'), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'div' );
    4529
    4630if ( is_multisite() || is_super_admin() ) {
     
    235219$_wp_real_parent_file['wpmu-admin.php'] = 'ms-admin.php';
    236220
    237 do_action('_admin_menu');
    238 
    239 // Create list of page plugin hook names.
    240 foreach ($menu as $menu_page) {
    241         if ( false !== $pos = strpos($menu_page[2], '?') ) {
    242                 // Handle post_type=post|page|foo pages.
    243                 $hook_name = substr($menu_page[2], 0, $pos);
    244                 $hook_args = substr($menu_page[2], $pos + 1);
    245                 wp_parse_str($hook_args, $hook_args);
    246                 // Set the hook name to be the post type.
    247                 if ( isset($hook_args['post_type']) )
    248                         $hook_name = $hook_args['post_type'];
    249                 else
    250                         $hook_name = basename($hook_name, '.php');
    251                 unset($hook_args);
    252         } else {
    253                 $hook_name = basename($menu_page[2], '.php');
    254         }
    255         $hook_name = sanitize_title($hook_name);
    256 
    257         // ensure we're backwards compatible
    258         $compat = array(
    259                 'index' => 'dashboard',
    260                 'edit' => 'posts',
    261                 'post' => 'posts',
    262                 'upload' => 'media',
    263                 'link-manager' => 'links',
    264                 'edit-pages' => 'pages',
    265                 'page' => 'pages',
    266                 'edit-comments' => 'comments',
    267                 'options-general' => 'settings',
    268                 'themes' => 'appearance',
    269                 );
    270 
    271         if ( isset($compat[$hook_name]) )
    272                 $hook_name = $compat[$hook_name];
    273         elseif ( !$hook_name )
    274                 continue;
    275 
    276         $admin_page_hooks[$menu_page[2]] = $hook_name;
    277 }
    278 unset($menu_page);
    279 
    280 $_wp_submenu_nopriv = array();
    281 $_wp_menu_nopriv = array();
    282 // Loop over submenus and remove pages for which the user does not have privs.
    283 foreach ( array( 'submenu' ) as $sub_loop ) {
    284         foreach ($$sub_loop as $parent => $sub) {
    285                 foreach ($sub as $index => $data) {
    286                         if ( ! current_user_can($data[1]) ) {
    287                                 unset(${$sub_loop}[$parent][$index]);
    288                                 $_wp_submenu_nopriv[$parent][$data[2]] = true;
    289                         }
    290                 }
    291                 unset($index, $data);
    292 
    293                 if ( empty(${$sub_loop}[$parent]) )
    294                         unset(${$sub_loop}[$parent]);
    295         }
    296         unset($sub, $parent);
    297 }
    298 unset($sub_loop);
    299 
    300 // Loop over the top-level menu.
    301 // Menus for which the original parent is not accessible due to lack of privs will have the next
    302 // submenu in line be assigned as the new menu parent.
    303 foreach ( $menu as $id => $data ) {
    304         if ( empty($submenu[$data[2]]) )
    305                 continue;
    306         $subs = $submenu[$data[2]];
    307         $first_sub = array_shift($subs);
    308         $old_parent = $data[2];
    309         $new_parent = $first_sub[2];
    310         // If the first submenu is not the same as the assigned parent,
    311         // make the first submenu the new parent.
    312         if ( $new_parent != $old_parent ) {
    313                 $_wp_real_parent_file[$old_parent] = $new_parent;
    314                 $menu[$id][2] = $new_parent;
    315 
    316                 foreach ($submenu[$old_parent] as $index => $data) {
    317                         $submenu[$new_parent][$index] = $submenu[$old_parent][$index];
    318                         unset($submenu[$old_parent][$index]);
    319                 }
    320                 unset($submenu[$old_parent], $index);
    321 
    322                 if ( isset($_wp_submenu_nopriv[$old_parent]) )
    323                         $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent];
    324         }
    325 }
    326 unset($id, $data, $subs, $first_sub, $old_parent, $new_parent);
    327 
    328 do_action('admin_menu', '');
    329 
    330 // Remove menus that have no accessible submenus and require privs that the user does not have.
    331 // Run re-parent loop again.
    332 foreach ( $menu as $id => $data ) {
    333         if ( ! current_user_can($data[1]) )
    334                 $_wp_menu_nopriv[$data[2]] = true;
    335 
    336         // If submenu is empty...
    337         if ( empty($submenu[$data[2]]) ) {
    338                 // And user doesn't have privs, remove menu.
    339                 if ( isset( $_wp_menu_nopriv[$data[2]] ) ) {
    340                         unset($menu[$id]);
    341                 }
    342         }
    343 }
    344 unset($id, $data);
    345 
    346 // Remove any duplicated seperators
    347 $seperator_found = false;
    348 foreach ( $menu as $id => $data ) {
    349         if ( 0 == strcmp('wp-menu-separator', $data[4] ) ) {
    350                 if (false == $seperator_found) {
    351                         $seperator_found = true;
    352                 } else {
    353                         unset($menu[$id]);
    354                         $seperator_found = false;
    355                 }
    356         } else {
    357                 $seperator_found = false;
    358         }
    359 }
    360 unset($id, $data);
    361 
    362 function add_cssclass($add, $class) {
    363         $class = empty($class) ? $add : $class .= ' ' . $add;
    364         return $class;
    365 }
    366 
    367 function add_menu_classes($menu) {
    368 
    369         $first = $lastorder = false;
    370         $i = 0;
    371         $mc = count($menu);
    372         foreach ( $menu as $order => $top ) {
    373                 $i++;
    374 
    375                 if ( 0 == $order ) { // dashboard is always shown/single
    376                         $menu[0][4] = add_cssclass('menu-top-first', $top[4]);
    377                         $lastorder = 0;
    378                         continue;
    379                 }
    380 
    381                 if ( 0 === strpos($top[2], 'separator') ) { // if separator
    382                         $first = true;
    383                         $c = $menu[$lastorder][4];
    384                         $menu[$lastorder][4] = add_cssclass('menu-top-last', $c);
    385                         continue;
    386                 }
    387 
    388                 if ( $first ) {
    389                         $c = $menu[$order][4];
    390                         $menu[$order][4] = add_cssclass('menu-top-first', $c);
    391                         $first = false;
    392                 }
    393 
    394                 if ( $mc == $i ) { // last item
    395                         $c = $menu[$order][4];
    396                         $menu[$order][4] = add_cssclass('menu-top-last', $c);
    397                 }
    398 
    399                 $lastorder = $order;
    400         }
    401 
    402         return apply_filters( 'add_menu_classes', $menu );
    403 }
    404 
    405 uksort($menu, "strnatcasecmp"); // make it all pretty
    406 
    407 if ( apply_filters('custom_menu_order', false) ) {
    408         $menu_order = array();
    409         foreach ( $menu as $menu_item ) {
    410                 $menu_order[] = $menu_item[2];
    411         }
    412         unset($menu_item);
    413         $default_menu_order = $menu_order;
    414         $menu_order = apply_filters('menu_order', $menu_order);
    415         $menu_order = array_flip($menu_order);
    416         $default_menu_order = array_flip($default_menu_order);
    417 
    418         function sort_menu($a, $b) {
    419                 global $menu_order, $default_menu_order;
    420                 $a = $a[2];
    421                 $b = $b[2];
    422                 if ( isset($menu_order[$a]) && !isset($menu_order[$b]) ) {
    423                         return -1;
    424                 } elseif ( !isset($menu_order[$a]) && isset($menu_order[$b]) ) {
    425                         return 1;
    426                 } elseif ( isset($menu_order[$a]) && isset($menu_order[$b]) ) {
    427                         if ( $menu_order[$a] == $menu_order[$b] )
    428                                 return 0;
    429                         return ($menu_order[$a] < $menu_order[$b]) ? -1 : 1;
    430                 } else {
    431                         return ($default_menu_order[$a] <= $default_menu_order[$b]) ? -1 : 1;
    432                 }
    433         }
    434 
    435         usort($menu, 'sort_menu');
    436         unset($menu_order, $default_menu_order);
    437 }
    438 
    439 $menu = add_menu_classes($menu);
    440 
    441 if ( !user_can_access_admin_page() ) {
    442         do_action('admin_page_access_denied');
    443         wp_die( __('You do not have sufficient permissions to access this page.') );
    444 }
     221// ensure we're backwards compatible
     222$compat = array(
     223        'index' => 'dashboard',
     224        'edit' => 'posts',
     225        'post' => 'posts',
     226        'upload' => 'media',
     227        'link-manager' => 'links',
     228        'edit-pages' => 'pages',
     229        'page' => 'pages',
     230        'edit-comments' => 'comments',
     231        'options-general' => 'settings',
     232        'themes' => 'appearance',
     233        );
     234
     235require(ABSPATH . 'wp-admin/includes/menu.php');
    445236
    446237?>
Note: See TracChangeset for help on using the changeset viewer.