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