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