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