PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/ -> menu.php (source)

   1  <?php
   2  // This array constructs the admin menu bar.
   3  //
   4  // Menu item name
   5  // The minimum level the user needs to access the item: between 0 and 10
   6  // The URL of the item's file
   7  $menu[0] = array(__('Dashboard'), 'read', 'index.php');
   8  
   9  if (strpos($_SERVER['REQUEST_URI'], 'edit-pages.php') !== false)
  10      $menu[5] = array(__('Write'), 'edit_pages', 'page-new.php');
  11  else
  12      $menu[5] = array(__('Write'), 'edit_posts', 'post-new.php');
  13  if (strpos($_SERVER['REQUEST_URI'], 'page-new.php') !== false)
  14      $menu[10] = array(__('Manage'), 'edit_pages', 'edit-pages.php');
  15  else
  16      $menu[10] = array(__('Manage'), 'edit_posts', 'edit.php');
  17  
  18  $menu[15] = array(__('Comments'), 'edit_posts', 'edit-comments.php');
  19  $menu[20] = array(__('Blogroll'), 'manage_links', 'link-manager.php');
  20  $menu[25] = array(__('Presentation'), 'switch_themes', 'themes.php');
  21  $menu[30] = array(__('Plugins'), 'activate_plugins', 'plugins.php');
  22  if ( current_user_can('edit_users') )
  23      $menu[35] = array(__('Users'), 'edit_users', 'users.php');
  24  else
  25      $menu[35] = array(__('Profile'), 'read', 'profile.php');
  26  $menu[40] = array(__('Options'), 'manage_options', 'options-general.php');
  27  
  28  
  29  $_wp_real_parent_file['post.php'] = 'post-new.php'; // Back-compat
  30  $submenu['post-new.php'][5] = array(__('Write Post'), 'edit_posts', 'post-new.php');
  31  $submenu['post-new.php'][10] = array(__('Write Page'), 'edit_pages', 'page-new.php');
  32  
  33  $submenu['edit-comments.php'][5] = array(__('Comments'), 'edit_posts', 'edit-comments.php');
  34  $awaiting_mod = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
  35  $submenu['edit-comments.php'][25] = array(sprintf(__("Awaiting Moderation (%s)"), "<span id='awaitmod'>$awaiting_mod</span>"), 'edit_posts', 'moderation.php');
  36  
  37  
  38  $submenu['edit.php'][5] = array(__('Posts'), 'edit_posts', 'edit.php');
  39  $submenu['edit.php'][10] = array(__('Pages'), 'edit_pages', 'edit-pages.php');
  40  $submenu['edit.php'][12] = array(__('Uploads'), 'upload_files', 'upload.php');
  41  $submenu['edit.php'][15] = array(__('Categories'), 'manage_categories', 'categories.php');
  42  $submenu['edit.php'][30] = array(__('Files'), 'edit_files', 'templates.php');
  43  $submenu['edit.php'][35] = array(__('Import'), 'import', 'import.php');
  44  $submenu['edit.php'][40] = array(__('Export'), 'import', 'export.php');
  45  
  46  $submenu['link-manager.php'][5] = array(__('Manage Blogroll'), 'manage_links', 'link-manager.php');
  47  $submenu['link-manager.php'][10] = array(__('Add Link'), 'manage_links', 'link-add.php');
  48  $submenu['link-manager.php'][20] = array(__('Import Links'), 'manage_links', 'link-import.php');
  49  $submenu['link-manager.php'][30] = array(__('Categories'), 'manage_links', 'edit-link-categories.php');
  50  
  51  if ( current_user_can('edit_users') ) {
  52      $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
  53      $submenu['users.php'][5] = array(__('Authors &amp; Users'), 'edit_users', 'users.php');
  54      $submenu['users.php'][10] = array(__('Your Profile'), 'read', 'profile.php');
  55  } else {
  56      $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php');
  57  }
  58  
  59  $submenu['options-general.php'][10] = array(__('General'), 'manage_options', 'options-general.php');
  60  $submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php');
  61  $submenu['options-general.php'][20] = array(__('Reading'), 'manage_options', 'options-reading.php');
  62  $submenu['options-general.php'][25] = array(__('Discussion'), 'manage_options', 'options-discussion.php');
  63  $submenu['options-general.php'][30] = array(__('Privacy'), 'manage_options', 'options-privacy.php');
  64  $submenu['options-general.php'][35] = array(__('Permalinks'), 'manage_options', 'options-permalink.php');
  65  $submenu['options-general.php'][40] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php');
  66  
  67  $submenu['plugins.php'][5] = array(__('Plugins'), 'activate_plugins', 'plugins.php');
  68  $submenu['plugins.php'][10] = array(__('Plugin Editor'), 'edit_plugins', 'plugin-editor.php');
  69  
  70  $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php');
  71  $submenu['themes.php'][10] = array(__('Theme Editor'), 'edit_themes', 'theme-editor.php');
  72  
  73  do_action('_admin_menu');
  74  
  75  // Create list of page plugin hook names.
  76  foreach ($menu as $menu_page) {
  77      $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
  78  }
  79  
  80  $_wp_submenu_nopriv = array();
  81  $_wp_menu_nopriv = array();
  82  // Loop over submenus and remove pages for which the user does not have privs.
  83  foreach ($submenu as $parent => $sub) {
  84      foreach ($sub as $index => $data) {
  85          if ( ! current_user_can($data[1]) ) {
  86              unset($submenu[$parent][$index]);
  87              $_wp_submenu_nopriv[$parent][$data[2]] = true;
  88          }
  89      }
  90  
  91      if ( empty($submenu[$parent]) )
  92          unset($submenu[$parent]);
  93  }
  94  
  95  // Loop over the top-level menu.
  96  // Menus for which the original parent is not acessible due to lack of privs will have the next
  97  // submenu in line be assigned as the new menu parent.
  98  foreach ( $menu as $id => $data ) {
  99      if ( empty($submenu[$data[2]]) )
 100          continue;
 101      $subs = $submenu[$data[2]];
 102      $first_sub = array_shift($subs);
 103      $old_parent = $data[2];
 104      $new_parent = $first_sub[2];
 105      // If the first submenu is not the same as the assigned parent,
 106      // make the first submenu the new parent.
 107      if ( $new_parent != $old_parent ) {
 108          $_wp_real_parent_file[$old_parent] = $new_parent;
 109          $menu[$id][2] = $new_parent;
 110  
 111          foreach ($submenu[$old_parent] as $index => $data) {
 112              $submenu[$new_parent][$index] = $submenu[$old_parent][$index];
 113              unset($submenu[$old_parent][$index]);
 114          }
 115          unset($submenu[$old_parent]);
 116          $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent];
 117      }
 118  }
 119  
 120  do_action('admin_menu', '');
 121  
 122  // Remove menus that have no accessible submenus and require privs that the user does not have.
 123  // Run re-parent loop again.
 124  foreach ( $menu as $id => $data ) {
 125      // If submenu is empty...
 126      if ( empty($submenu[$data[2]]) ) {
 127          // And user doesn't have privs, remove menu.
 128          if ( ! current_user_can($data[1]) ) {
 129              $_wp_menu_nopriv[$data[2]] = true;
 130              unset($menu[$id]);
 131          }
 132      }
 133  }
 134  
 135  unset($id);
 136  
 137  uksort($menu, "strnatcasecmp"); // make it all pretty
 138  
 139  if (! user_can_access_admin_page()) {
 140      do_action('admin_page_access_denied');
 141      wp_die( __('You do not have sufficient permissions to access this page.') );
 142  }
 143  
 144  ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt