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 $submenu['themes.php'][10] = array(__('Editor'), 'edit_themes', 'theme-editor.php');
mp-wp_genesis 60
mp-wp_genesis 61 $update_plugins = get_option( 'update_plugins' );
mp-wp_genesis 62 $update_count = 0;
mp-wp_genesis 63 if ( !empty($update_plugins->response) )
mp-wp_genesis 64 $update_count = count( $update_plugins->response );
mp-wp_genesis 65
mp-wp_genesis 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' );
mp-wp_genesis 67 $submenu['plugins.php'][5] = array( __('Installed'), 'activate_plugins', 'plugins.php' );
mp-wp_genesis 68 $submenu['plugins.php'][10] = array(_c('Add New|plugin'), 'install_plugins', 'plugin-install.php');
mp-wp_genesis 69 $submenu['plugins.php'][15] = array( __('Editor'), 'edit_plugins', 'plugin-editor.php' );
mp-wp_genesis 70
mp-wp_genesis 71 if ( current_user_can('edit_users') )
mp-wp_genesis 72 $menu[50] = array( __('Users'), 'edit_users', 'users.php', '', 'menu-top', 'menu-users', 'div' );
mp-wp_genesis 73 else
mp-wp_genesis 74 $menu[50] = array( __('Profile'), 'read', 'profile.php', '', 'menu-top', 'menu-users', 'div' );
mp-wp_genesis 75
mp-wp_genesis 76 if ( current_user_can('edit_users') ) {
mp-wp_genesis 77 $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
mp-wp_genesis 78 $submenu['users.php'][5] = array(__('Authors & Users'), 'edit_users', 'users.php');
mp-wp_genesis 79 $submenu['users.php'][10] = array(__('Add New'), 'create_users', 'user-new.php');
mp-wp_genesis 80 $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php');
mp-wp_genesis 81 } else {
mp-wp_genesis 82 $_wp_real_parent_file['users.php'] = 'profile.php';
mp-wp_genesis 83 $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php');
mp-wp_genesis 84 }
mp-wp_genesis 85
mp-wp_genesis 86 $menu[55] = array( __('Tools'), 'manage_options', 'tools.php', '', 'menu-top', 'menu-tools', 'div' );
mp-wp_genesis 87 $submenu['tools.php'][10] = array( __('Import'), 'import', 'import.php' );
mp-wp_genesis 88 $submenu['tools.php'][15] = array( __('Export'), 'import', 'export.php' );
mp-wp_genesis 89
mp-wp_genesis 90 $menu[60] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top', 'menu-settings', 'div' );
mp-wp_genesis 91 $submenu['options-general.php'][10] = array(__('General'), 'manage_options', 'options-general.php');
mp-wp_genesis 92 $submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php');
mp-wp_genesis 93 $submenu['options-general.php'][20] = array(__('Reading'), 'manage_options', 'options-reading.php');
mp-wp_genesis 94 $submenu['options-general.php'][25] = array(__('Discussion'), 'manage_options', 'options-discussion.php');
mp-wp_genesis 95 $submenu['options-general.php'][30] = array(__('Media'), 'manage_options', 'options-media.php');
mp-wp_genesis 96 $submenu['options-general.php'][35] = array(__('Privacy'), 'manage_options', 'options-privacy.php');
mp-wp_genesis 97 $submenu['options-general.php'][40] = array(__('Permalinks'), 'manage_options', 'options-permalink.php');
mp-wp_genesis 98 $submenu['options-general.php'][45] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php');
mp-wp_genesis 99
mp-wp_genesis 100 $_wp_last_utility_menu = 60; // The index of the last top-level menu in the utility menu group
mp-wp_genesis 101
mp-wp_genesis 102 $menu[79] = array( '', 'read', '', '', 'wp-menu-separator-last' );
mp-wp_genesis 103
mp-wp_genesis 104 // Back-compat for old top-levels
mp-wp_genesis 105 $_wp_real_parent_file['post.php'] = 'edit.php';
mp-wp_genesis 106 $_wp_real_parent_file['post-new.php'] = 'edit.php';
mp-wp_genesis 107 $_wp_real_parent_file['page-new.php'] = 'edit-pages.php';
mp-wp_genesis 108
mp-wp_genesis 109 do_action('_admin_menu');
mp-wp_genesis 110
mp-wp_genesis 111 // Create list of page plugin hook names.
mp-wp_genesis 112 foreach ($menu as $menu_page) {
mp-wp_genesis 113 $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]);
mp-wp_genesis 114 }
mp-wp_genesis 115
mp-wp_genesis 116 $_wp_submenu_nopriv = array();
mp-wp_genesis 117 $_wp_menu_nopriv = array();
mp-wp_genesis 118 // Loop over submenus and remove pages for which the user does not have privs.
mp-wp_genesis 119 foreach ( array( 'submenu' ) as $sub_loop ) {
mp-wp_genesis 120 foreach ($$sub_loop as $parent => $sub) {
mp-wp_genesis 121 foreach ($sub as $index => $data) {
mp-wp_genesis 122 if ( ! current_user_can($data[1]) ) {
mp-wp_genesis 123 unset(${$sub_loop}[$parent][$index]);
mp-wp_genesis 124 $_wp_submenu_nopriv[$parent][$data[2]] = true;
mp-wp_genesis 125 }
mp-wp_genesis 126 }
mp-wp_genesis 127
mp-wp_genesis 128 if ( empty(${$sub_loop}[$parent]) )
mp-wp_genesis 129 unset(${$sub_loop}[$parent]);
mp-wp_genesis 130 }
mp-wp_genesis 131 }
mp-wp_genesis 132
mp-wp_genesis 133 // Loop over the top-level menu.
mp-wp_genesis 134 // Menus for which the original parent is not acessible due to lack of privs will have the next
mp-wp_genesis 135 // submenu in line be assigned as the new menu parent.
mp-wp_genesis 136 foreach ( $menu as $id => $data ) {
mp-wp_genesis 137 if ( empty($submenu[$data[2]]) )
mp-wp_genesis 138 continue;
mp-wp_genesis 139 $subs = $submenu[$data[2]];
mp-wp_genesis 140 $first_sub = array_shift($subs);
mp-wp_genesis 141 $old_parent = $data[2];
mp-wp_genesis 142 $new_parent = $first_sub[2];
mp-wp_genesis 143 // If the first submenu is not the same as the assigned parent,
mp-wp_genesis 144 // make the first submenu the new parent.
mp-wp_genesis 145 if ( $new_parent != $old_parent ) {
mp-wp_genesis 146 $_wp_real_parent_file[$old_parent] = $new_parent;
mp-wp_genesis 147 $menu[$id][2] = $new_parent;
mp-wp_genesis 148
mp-wp_genesis 149 foreach ($submenu[$old_parent] as $index => $data) {
mp-wp_genesis 150 $submenu[$new_parent][$index] = $submenu[$old_parent][$index];
mp-wp_genesis 151 unset($submenu[$old_parent][$index]);
mp-wp_genesis 152 }
mp-wp_genesis 153 unset($submenu[$old_parent]);
mp-wp_genesis 154
mp-wp_genesis 155 if ( isset($_wp_submenu_nopriv[$old_parent]) )
mp-wp_genesis 156 $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent];
mp-wp_genesis 157 }
mp-wp_genesis 158 }
mp-wp_genesis 159
mp-wp_genesis 160 do_action('admin_menu', '');
mp-wp_genesis 161
mp-wp_genesis 162 // Remove menus that have no accessible submenus and require privs that the user does not have.
mp-wp_genesis 163 // Run re-parent loop again.
mp-wp_genesis 164 foreach ( $menu as $id => $data ) {
mp-wp_genesis 165 // If submenu is empty...
mp-wp_genesis 166 if ( empty($submenu[$data[2]]) ) {
mp-wp_genesis 167 // And user doesn't have privs, remove menu.
mp-wp_genesis 168 if ( ! current_user_can($data[1]) ) {
mp-wp_genesis 169 $_wp_menu_nopriv[$data[2]] = true;
mp-wp_genesis 170 unset($menu[$id]);
mp-wp_genesis 171 }
mp-wp_genesis 172 }
mp-wp_genesis 173 }
mp-wp_genesis 174
mp-wp_genesis 175 // Remove any duplicated seperators
mp-wp_genesis 176 $seperator_found = false;
mp-wp_genesis 177 foreach ( $menu as $id => $data ) {
mp-wp_genesis 178 if ( 0 == strcmp('wp-menu-separator', $data[4] ) ) {
mp-wp_genesis 179 if (false == $seperator_found) {
mp-wp_genesis 180 $seperator_found = true;
mp-wp_genesis 181 } else {
mp-wp_genesis 182 unset($menu[$id]);
mp-wp_genesis 183 $seperator_found = false;
mp-wp_genesis 184 }
mp-wp_genesis 185 } else {
mp-wp_genesis 186 $seperator_found = false;
mp-wp_genesis 187 }
mp-wp_genesis 188 }
mp-wp_genesis 189
mp-wp_genesis 190 unset($id);
mp-wp_genesis 191
mp-wp_genesis 192 function add_cssclass($add, $class) {
mp-wp_genesis 193 $class = empty($class) ? $add : $class .= ' ' . $add;
mp-wp_genesis 194 return $class;
mp-wp_genesis 195 }
mp-wp_genesis 196
mp-wp_genesis 197 function add_menu_classes($menu) {
mp-wp_genesis 198
mp-wp_genesis 199 $first = $lastorder = false;
mp-wp_genesis 200 $i = 0;
mp-wp_genesis 201 $mc = count($menu);
mp-wp_genesis 202 foreach ( $menu as $order => $top ) {
mp-wp_genesis 203 $i++;
mp-wp_genesis 204
mp-wp_genesis 205 if ( 0 == $order ) { // dashboard is always shown/single
mp-wp_genesis 206 $menu[0][4] = add_cssclass('menu-top-first menu-top-last', $top[4]);
mp-wp_genesis 207 continue;
mp-wp_genesis 208 }
mp-wp_genesis 209
mp-wp_genesis 210 if ( empty($top[2]) ) { // if separator
mp-wp_genesis 211 $first = true;
mp-wp_genesis 212 if ( $lastorder ) {
mp-wp_genesis 213 $c = $menu[$lastorder][4];
mp-wp_genesis 214 $menu[$lastorder][4] = add_cssclass('menu-top-last', $c);
mp-wp_genesis 215 }
mp-wp_genesis 216 continue;
mp-wp_genesis 217 }
mp-wp_genesis 218
mp-wp_genesis 219 if ( $first ) {
mp-wp_genesis 220 $c = $menu[$order][4];
mp-wp_genesis 221 $menu[$order][4] = add_cssclass('menu-top-first', $c);
mp-wp_genesis 222 $first = false;
mp-wp_genesis 223 }
mp-wp_genesis 224
mp-wp_genesis 225 if ( $mc == $i ) { // last item
mp-wp_genesis 226 $c = $menu[$order][4];
mp-wp_genesis 227 $menu[$order][4] = add_cssclass('menu-top-last', $c);
mp-wp_genesis 228 }
mp-wp_genesis 229
mp-wp_genesis 230 $lastorder = $order;
mp-wp_genesis 231 }
mp-wp_genesis 232
mp-wp_genesis 233 return apply_filters( 'add_menu_classes', $menu );
mp-wp_genesis 234 }
mp-wp_genesis 235
mp-wp_genesis 236 uksort($menu, "strnatcasecmp"); // make it all pretty
mp-wp_genesis 237
mp-wp_genesis 238 $menu = add_menu_classes($menu);
mp-wp_genesis 239
mp-wp_genesis 240 if (! user_can_access_admin_page()) {
mp-wp_genesis 241 do_action('admin_page_access_denied');
mp-wp_genesis 242 wp_die( __('You do not have sufficient permissions to access this page.') );
mp-wp_genesis 243 }
mp-wp_genesis 244
mp-wp_genesis 245 ?>