PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/_splash/blog/wp-admin/menu.php

https://github.com/kuzin/website-2008
PHP | 247 lines | 168 code | 45 blank | 34 comment | 26 complexity | 853574b3f5b81a302fb41a4e8f4128bb MD5 | raw file
  1. <?php
  2. /**
  3. * Build Administration Menu.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * Constructs the admin menu bar.
  10. *
  11. * The elements in the array are :
  12. * 0: Menu item name
  13. * 1: Minimum level or capability required.
  14. * 2: The URL of the item's file
  15. * 3: Class
  16. * 4: ID
  17. * 5: Icon for top level menu
  18. *
  19. * @global array $menu
  20. * @name $menu
  21. * @var array
  22. */
  23. $awaiting_mod = wp_count_comments();
  24. $awaiting_mod = $awaiting_mod->moderated;
  25. $menu[0] = array( __('Dashboard'), 'read', 'index.php', '', 'menu-top', 'menu-dashboard', 'div' );
  26. $menu[4] = array( '', 'read', '', '', 'wp-menu-separator' );
  27. $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'wp-menu-open menu-top', 'menu-posts', 'div' );
  28. $submenu['edit.php'][5] = array( __('Edit'), 'edit_posts', 'edit.php' );
  29. $submenu['edit.php'][10] = array( _c('Add New|post'), 'edit_posts', 'post-new.php' );
  30. $submenu['edit.php'][15] = array( __('Tags'), 'manage_categories', 'edit-tags.php' );
  31. $submenu['edit.php'][20] = array( __('Categories'), 'manage_categories', 'categories.php' );
  32. $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' );
  33. $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
  34. $submenu['upload.php'][10] = array( _c('Add New|file'), 'upload_files', 'media-new.php');
  35. $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top', 'menu-links', 'div' );
  36. $submenu['link-manager.php'][5] = array( __('Edit'), 'manage_links', 'link-manager.php' );
  37. $submenu['link-manager.php'][10] = array( _c('Add New|links'), 'manage_links', 'link-add.php' );
  38. $submenu['link-manager.php'][15] = array( __('Link Categories'), 'manage_categories', 'edit-link-categories.php' );
  39. $menu[20] = array( __('Pages'), 'edit_pages', 'edit-pages.php', '', 'menu-top', 'menu-pages', 'div' );
  40. $submenu['edit-pages.php'][5] = array( __('Edit'), 'edit_pages', 'edit-pages.php' );
  41. $submenu['edit-pages.php'][10] = array( _c('Add New|page'), 'edit_pages', 'page-new.php' );
  42. $menu[25] = array( sprintf( __('Comments %s'), "<span id='awaiting-mod' class='count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts', 'edit-comments.php', '', 'menu-top', 'menu-comments', 'div' );
  43. $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
  44. $menu[39] = array( '', 'read', '', '', 'wp-menu-separator' );
  45. $menu[40] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top', 'menu-appearance', 'div' );
  46. $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php');
  47. $submenu['themes.php'][10] = array(__('Editor'), 'edit_themes', 'theme-editor.php');
  48. $update_plugins = get_option( 'update_plugins' );
  49. $update_count = 0;
  50. if ( !empty($update_plugins->response) )
  51. $update_count = count( $update_plugins->response );
  52. $menu[45] = array( sprintf( __('Plugins %s'), "<span class='update-plugins count-$update_count'><span class='plugin-count'>" . number_format_i18n($update_count) . "</span></span>" ), 'activate_plugins', 'plugins.php', '', 'menu-top', 'menu-plugins', 'div' );
  53. $submenu['plugins.php'][5] = array( __('Installed'), 'activate_plugins', 'plugins.php' );
  54. $submenu['plugins.php'][10] = array(_c('Add New|plugin'), 'install_plugins', 'plugin-install.php');
  55. $submenu['plugins.php'][15] = array( __('Editor'), 'edit_plugins', 'plugin-editor.php' );
  56. if ( current_user_can('edit_users') )
  57. $menu[50] = array( __('Users'), 'edit_users', 'users.php', '', 'menu-top', 'menu-users', 'div' );
  58. else
  59. $menu[50] = array( __('Profile'), 'read', 'profile.php', '', 'menu-top', 'menu-users', 'div' );
  60. if ( current_user_can('edit_users') ) {
  61. $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
  62. $submenu['users.php'][5] = array(__('Authors &amp; Users'), 'edit_users', 'users.php');
  63. $submenu['users.php'][10] = array(__('Add New'), 'create_users', 'user-new.php');
  64. $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php');
  65. } else {
  66. $_wp_real_parent_file['users.php'] = 'profile.php';
  67. $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php');
  68. }
  69. $menu[55] = array( __('Tools'), 'manage_options', 'tools.php', '', 'menu-top', 'menu-tools', 'div' );
  70. $submenu['tools.php'][5] = array( __('Tools'), 'read', 'tools.php' );
  71. $submenu['tools.php'][10] = array( __('Import'), 'import', 'import.php' );
  72. $submenu['tools.php'][15] = array( __('Export'), 'import', 'export.php' );
  73. $submenu['tools.php'][20] = array( __('Upgrade'), 'install_plugins', 'update-core.php');
  74. $menu[60] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top', 'menu-settings', 'div' );
  75. $submenu['options-general.php'][10] = array(__('General'), 'manage_options', 'options-general.php');
  76. $submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php');
  77. $submenu['options-general.php'][20] = array(__('Reading'), 'manage_options', 'options-reading.php');
  78. $submenu['options-general.php'][25] = array(__('Discussion'), 'manage_options', 'options-discussion.php');
  79. $submenu['options-general.php'][30] = array(__('Media'), 'manage_options', 'options-media.php');
  80. $submenu['options-general.php'][35] = array(__('Privacy'), 'manage_options', 'options-privacy.php');
  81. $submenu['options-general.php'][40] = array(__('Permalinks'), 'manage_options', 'options-permalink.php');
  82. $submenu['options-general.php'][45] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php');
  83. $_wp_last_utility_menu = 60; // The index of the last top-level menu in the utility menu group
  84. $menu[79] = array( '', 'read', '', '', 'wp-menu-separator-last' );
  85. // Back-compat for old top-levels
  86. $_wp_real_parent_file['post.php'] = 'edit.php';
  87. $_wp_real_parent_file['post-new.php'] = 'edit.php';
  88. $_wp_real_parent_file['page-new.php'] = 'edit-pages.php';
  89. do_action('_admin_menu');
  90. // Create list of page plugin hook names.
  91. foreach ($menu as $menu_page) {
  92. $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
  93. }
  94. $_wp_submenu_nopriv = array();
  95. $_wp_menu_nopriv = array();
  96. // Loop over submenus and remove pages for which the user does not have privs.
  97. foreach ( array( 'submenu' ) as $sub_loop ) {
  98. foreach ($$sub_loop as $parent => $sub) {
  99. foreach ($sub as $index => $data) {
  100. if ( ! current_user_can($data[1]) ) {
  101. unset(${$sub_loop}[$parent][$index]);
  102. $_wp_submenu_nopriv[$parent][$data[2]] = true;
  103. }
  104. }
  105. if ( empty(${$sub_loop}[$parent]) )
  106. unset(${$sub_loop}[$parent]);
  107. }
  108. }
  109. // Loop over the top-level menu.
  110. // Menus for which the original parent is not acessible due to lack of privs will have the next
  111. // submenu in line be assigned as the new menu parent.
  112. foreach ( $menu as $id => $data ) {
  113. if ( empty($submenu[$data[2]]) )
  114. continue;
  115. $subs = $submenu[$data[2]];
  116. $first_sub = array_shift($subs);
  117. $old_parent = $data[2];
  118. $new_parent = $first_sub[2];
  119. // If the first submenu is not the same as the assigned parent,
  120. // make the first submenu the new parent.
  121. if ( $new_parent != $old_parent ) {
  122. $_wp_real_parent_file[$old_parent] = $new_parent;
  123. $menu[$id][2] = $new_parent;
  124. foreach ($submenu[$old_parent] as $index => $data) {
  125. $submenu[$new_parent][$index] = $submenu[$old_parent][$index];
  126. unset($submenu[$old_parent][$index]);
  127. }
  128. unset($submenu[$old_parent]);
  129. if ( isset($_wp_submenu_nopriv[$old_parent]) )
  130. $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent];
  131. }
  132. }
  133. do_action('admin_menu', '');
  134. // Remove menus that have no accessible submenus and require privs that the user does not have.
  135. // Run re-parent loop again.
  136. foreach ( $menu as $id => $data ) {
  137. // If submenu is empty...
  138. if ( empty($submenu[$data[2]]) ) {
  139. // And user doesn't have privs, remove menu.
  140. if ( ! current_user_can($data[1]) ) {
  141. $_wp_menu_nopriv[$data[2]] = true;
  142. unset($menu[$id]);
  143. }
  144. }
  145. }
  146. // Remove any duplicated seperators
  147. $seperator_found = false;
  148. foreach ( $menu as $id => $data ) {
  149. if ( 0 == strcmp('wp-menu-separator', $data[4] ) ) {
  150. if (false == $seperator_found) {
  151. $seperator_found = true;
  152. } else {
  153. unset($menu[$id]);
  154. $seperator_found = false;
  155. }
  156. } else {
  157. $seperator_found = false;
  158. }
  159. }
  160. unset($id);
  161. function add_cssclass($add, $class) {
  162. $class = empty($class) ? $add : $class .= ' ' . $add;
  163. return $class;
  164. }
  165. function add_menu_classes($menu) {
  166. $first = $lastorder = false;
  167. $i = 0;
  168. $mc = count($menu);
  169. foreach ( $menu as $order => $top ) {
  170. $i++;
  171. if ( 0 == $order ) { // dashboard is always shown/single
  172. $menu[0][4] = add_cssclass('menu-top-first menu-top-last', $top[4]);
  173. continue;
  174. }
  175. if ( empty($top[2]) ) { // if separator
  176. $first = true;
  177. if ( $lastorder ) {
  178. $c = $menu[$lastorder][4];
  179. $menu[$lastorder][4] = add_cssclass('menu-top-last', $c);
  180. }
  181. continue;
  182. }
  183. if ( $first ) {
  184. $c = $menu[$order][4];
  185. $menu[$order][4] = add_cssclass('menu-top-first', $c);
  186. $first = false;
  187. }
  188. if ( $mc == $i ) { // last item
  189. $c = $menu[$order][4];
  190. $menu[$order][4] = add_cssclass('menu-top-last', $c);
  191. }
  192. $lastorder = $order;
  193. }
  194. return apply_filters( 'add_menu_classes', $menu );
  195. }
  196. uksort($menu, "strnatcasecmp"); // make it all pretty
  197. $menu = add_menu_classes($menu);
  198. if (! user_can_access_admin_page()) {
  199. do_action('admin_page_access_denied');
  200. wp_die( __('You do not have sufficient permissions to access this page.') );
  201. }
  202. ?>