| [ Index ] |
PHP Cross Reference of Wordpress 2.9.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', 'separator1', '', 'wp-menu-separator' ); 31 32 $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top', 'menu-posts', 'div' ); 33 $submenu['edit.php'][5] = array( __('Edit'), 'edit_posts', 'edit.php' ); 34 /* translators: add new post */ 35 $submenu['edit.php'][10] = array( _x('Add New', 'post'), 'edit_posts', 'post-new.php' ); 36 37 $i = 15; 38 foreach ( $wp_taxonomies as $tax ) { 39 if ( $tax->hierarchical || ! in_array('post', (array) $tax->object_type, true) ) 40 continue; 41 42 $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name ); 43 ++$i; 44 } 45 46 $submenu['edit.php'][50] = array( __('Categories'), 'manage_categories', 'categories.php' ); 47 48 $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' ); 49 $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php'); 50 /* translators: add new file */ 51 $submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php'); 52 53 $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top', 'menu-links', 'div' ); 54 $submenu['link-manager.php'][5] = array( __('Edit'), 'manage_links', 'link-manager.php' ); 55 /* translators: add new links */ 56 $submenu['link-manager.php'][10] = array( _x('Add New', 'links'), 'manage_links', 'link-add.php' ); 57 $submenu['link-manager.php'][15] = array( __('Link Categories'), 'manage_categories', 'edit-link-categories.php' ); 58 59 $menu[20] = array( __('Pages'), 'edit_pages', 'edit-pages.php', '', 'menu-top', 'menu-pages', 'div' ); 60 $submenu['edit-pages.php'][5] = array( __('Edit'), 'edit_pages', 'edit-pages.php' ); 61 /* translators: add new page */ 62 $submenu['edit-pages.php'][10] = array( _x('Add New', 'page'), 'edit_pages', 'page-new.php' ); 63 64 $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' ); 65 66 $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group 67 68 $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); 69 70 $menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top', 'menu-appearance', 'div' ); 71 $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); 72 $submenu['themes.php'][10] = array(__('Editor'), 'edit_themes', 'theme-editor.php'); 73 $submenu['themes.php'][15] = array(__('Add New Themes'), 'install_themes', 'theme-install.php'); 74 75 $update_plugins = get_transient( 'update_plugins' ); 76 $update_count = 0; 77 if ( !empty($update_plugins->response) ) 78 $update_count = count( $update_plugins->response ); 79 80 $menu[65] = 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' ); 81 $submenu['plugins.php'][5] = array( __('Installed'), 'activate_plugins', 'plugins.php' ); 82 /* translators: add new plugin */ 83 $submenu['plugins.php'][10] = array(_x('Add New', 'plugin'), 'install_plugins', 'plugin-install.php'); 84 $submenu['plugins.php'][15] = array( __('Editor'), 'edit_plugins', 'plugin-editor.php' ); 85 86 if ( current_user_can('edit_users') ) 87 $menu[70] = array( __('Users'), 'edit_users', 'users.php', '', 'menu-top', 'menu-users', 'div' ); 88 else 89 $menu[70] = array( __('Profile'), 'read', 'profile.php', '', 'menu-top', 'menu-users', 'div' ); 90 91 if ( current_user_can('edit_users') ) { 92 $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php. 93 $submenu['users.php'][5] = array(__('Authors & Users'), 'edit_users', 'users.php'); 94 $submenu['users.php'][10] = array(_x('Add New', 'user'), 'create_users', 'user-new.php'); 95 $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php'); 96 } else { 97 $_wp_real_parent_file['users.php'] = 'profile.php'; 98 $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php'); 99 } 100 101 $menu[75] = array( __('Tools'), 'read', 'tools.php', '', 'menu-top', 'menu-tools', 'div' ); 102 $submenu['tools.php'][5] = array( __('Tools'), 'read', 'tools.php' ); 103 $submenu['tools.php'][10] = array( __('Import'), 'import', 'import.php' ); 104 $submenu['tools.php'][15] = array( __('Export'), 'import', 'export.php' ); 105 $submenu['tools.php'][20] = array( __('Upgrade'), 'install_plugins', 'update-core.php'); 106 107 $menu[80] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top', 'menu-settings', 'div' ); 108 $submenu['options-general.php'][10] = array(__('General'), 'manage_options', 'options-general.php'); 109 $submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php'); 110 $submenu['options-general.php'][20] = array(__('Reading'), 'manage_options', 'options-reading.php'); 111 $submenu['options-general.php'][25] = array(__('Discussion'), 'manage_options', 'options-discussion.php'); 112 $submenu['options-general.php'][30] = array(__('Media'), 'manage_options', 'options-media.php'); 113 $submenu['options-general.php'][35] = array(__('Privacy'), 'manage_options', 'options-privacy.php'); 114 $submenu['options-general.php'][40] = array(__('Permalinks'), 'manage_options', 'options-permalink.php'); 115 $submenu['options-general.php'][45] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php'); 116 117 $_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group 118 119 $menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator-last' ); 120 121 // Back-compat for old top-levels 122 $_wp_real_parent_file['post.php'] = 'edit.php'; 123 $_wp_real_parent_file['post-new.php'] = 'edit.php'; 124 $_wp_real_parent_file['page-new.php'] = 'edit-pages.php'; 125 126 do_action('_admin_menu'); 127 128 // Create list of page plugin hook names. 129 foreach ($menu as $menu_page) { 130 $hook_name = sanitize_title(basename($menu_page[2], '.php')); 131 132 // ensure we're backwards compatible 133 $compat = array( 134 'index' => 'dashboard', 135 'edit' => 'posts', 136 'upload' => 'media', 137 'link-manager' => 'links', 138 'edit-pages' => 'pages', 139 'edit-comments' => 'comments', 140 'options-general' => 'settings', 141 'themes' => 'appearance', 142 ); 143 144 if ( isset($compat[$hook_name]) ) 145 $hook_name = $compat[$hook_name]; 146 elseif ( !$hook_name ) 147 continue; 148 149 $admin_page_hooks[$menu_page[2]] = $hook_name; 150 } 151 152 $_wp_submenu_nopriv = array(); 153 $_wp_menu_nopriv = array(); 154 // Loop over submenus and remove pages for which the user does not have privs. 155 foreach ( array( 'submenu' ) as $sub_loop ) { 156 foreach ($$sub_loop as $parent => $sub) { 157 foreach ($sub as $index => $data) { 158 if ( ! current_user_can($data[1]) ) { 159 unset(${$sub_loop}[$parent][$index]); 160 $_wp_submenu_nopriv[$parent][$data[2]] = true; 161 } 162 } 163 164 if ( empty(${$sub_loop}[$parent]) ) 165 unset(${$sub_loop}[$parent]); 166 } 167 } 168 169 // Loop over the top-level menu. 170 // Menus for which the original parent is not acessible due to lack of privs will have the next 171 // submenu in line be assigned as the new menu parent. 172 foreach ( $menu as $id => $data ) { 173 if ( empty($submenu[$data[2]]) ) 174 continue; 175 $subs = $submenu[$data[2]]; 176 $first_sub = array_shift($subs); 177 $old_parent = $data[2]; 178 $new_parent = $first_sub[2]; 179 // If the first submenu is not the same as the assigned parent, 180 // make the first submenu the new parent. 181 if ( $new_parent != $old_parent ) { 182 $_wp_real_parent_file[$old_parent] = $new_parent; 183 $menu[$id][2] = $new_parent; 184 185 foreach ($submenu[$old_parent] as $index => $data) { 186 $submenu[$new_parent][$index] = $submenu[$old_parent][$index]; 187 unset($submenu[$old_parent][$index]); 188 } 189 unset($submenu[$old_parent]); 190 191 if ( isset($_wp_submenu_nopriv[$old_parent]) ) 192 $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent]; 193 } 194 } 195 196 do_action('admin_menu', ''); 197 198 // Remove menus that have no accessible submenus and require privs that the user does not have. 199 // Run re-parent loop again. 200 foreach ( $menu as $id => $data ) { 201 // If submenu is empty... 202 if ( empty($submenu[$data[2]]) ) { 203 // And user doesn't have privs, remove menu. 204 if ( ! current_user_can($data[1]) ) { 205 $_wp_menu_nopriv[$data[2]] = true; 206 unset($menu[$id]); 207 } 208 } 209 } 210 211 // Remove any duplicated seperators 212 $seperator_found = false; 213 foreach ( $menu as $id => $data ) { 214 if ( 0 == strcmp('wp-menu-separator', $data[4] ) ) { 215 if (false == $seperator_found) { 216 $seperator_found = true; 217 } else { 218 unset($menu[$id]); 219 $seperator_found = false; 220 } 221 } else { 222 $seperator_found = false; 223 } 224 } 225 226 unset($id); 227 228 function add_cssclass($add, $class) { 229 $class = empty($class) ? $add : $class .= ' ' . $add; 230 return $class; 231 } 232 233 function add_menu_classes($menu) { 234 235 $first = $lastorder = false; 236 $i = 0; 237 $mc = count($menu); 238 foreach ( $menu as $order => $top ) { 239 $i++; 240 241 if ( 0 == $order ) { // dashboard is always shown/single 242 $menu[0][4] = add_cssclass('menu-top-first', $top[4]); 243 $lastorder = 0; 244 continue; 245 } 246 247 if ( 0 === strpos($top[2], 'separator') ) { // if separator 248 $first = true; 249 $c = $menu[$lastorder][4]; 250 $menu[$lastorder][4] = add_cssclass('menu-top-last', $c); 251 continue; 252 } 253 254 if ( $first ) { 255 $c = $menu[$order][4]; 256 $menu[$order][4] = add_cssclass('menu-top-first', $c); 257 $first = false; 258 } 259 260 if ( $mc == $i ) { // last item 261 $c = $menu[$order][4]; 262 $menu[$order][4] = add_cssclass('menu-top-last', $c); 263 } 264 265 $lastorder = $order; 266 } 267 268 return apply_filters( 'add_menu_classes', $menu ); 269 } 270 271 uksort($menu, "strnatcasecmp"); // make it all pretty 272 273 if ( apply_filters('custom_menu_order', false) ) { 274 $menu_order = array(); 275 foreach ( $menu as $menu_item ) { 276 $menu_order[] = $menu_item[2]; 277 } 278 unset($menu_item); 279 $default_menu_order = $menu_order; 280 $menu_order = apply_filters('menu_order', $menu_order); 281 $menu_order = array_flip($menu_order); 282 $default_menu_order = array_flip($default_menu_order); 283 284 function sort_menu($a, $b) { 285 global $menu_order, $default_menu_order; 286 $a = $a[2]; 287 $b = $b[2]; 288 if ( isset($menu_order[$a]) && !isset($menu_order[$b]) ) { 289 return -1; 290 } elseif ( !isset($menu_order[$a]) && isset($menu_order[$b]) ) { 291 return 1; 292 } elseif ( isset($menu_order[$a]) && isset($menu_order[$b]) ) { 293 if ( $menu_order[$a] == $menu_order[$b] ) 294 return 0; 295 return ($menu_order[$a] < $menu_order[$b]) ? -1 : 1; 296 } else { 297 return ($default_menu_order[$a] <= $default_menu_order[$b]) ? -1 : 1; 298 } 299 } 300 301 usort($menu, 'sort_menu'); 302 unset($menu_order, $default_menu_order); 303 } 304 305 $menu = add_menu_classes($menu); 306 307 if (! user_can_access_admin_page()) { 308 do_action('admin_page_access_denied'); 309 wp_die( __('You do not have sufficient permissions to access this page.') ); 310 } 311 312 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jan 8 00:19:48 2010 | Cross-referenced by PHPXref 0.7 |