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