| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Build Administration Menu. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 // Don't load directly. 10 if ( ! defined( 'ABSPATH' ) ) { 11 die( '-1' ); 12 } 13 14 /** 15 * Constructs the admin menu. 16 * 17 * The elements in the array are: 18 * 0: Menu item name. 19 * 1: Minimum level or capability required. 20 * 2: The URL of the item's file. 21 * 3: Page title. 22 * 4: Classes. 23 * 5: ID. 24 * 6: Icon for top level menu. 25 * 26 * @global array $menu 27 */ 28 29 $menu[2] = array( __( 'Dashboard' ), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'dashicons-dashboard' ); 30 31 $submenu['index.php'][0] = array( __( 'Home' ), 'read', 'index.php' ); 32 33 if ( is_multisite() ) { 34 $submenu['index.php'][5] = array( __( 'My Sites' ), 'read', 'my-sites.php' ); 35 } 36 37 if ( ! is_multisite() || current_user_can( 'update_core' ) ) { 38 $update_data = wp_get_update_data(); 39 } 40 41 if ( ! is_multisite() ) { 42 if ( current_user_can( 'update_core' ) ) { 43 $capability = 'update_core'; 44 } elseif ( current_user_can( 'update_plugins' ) ) { 45 $capability = 'update_plugins'; 46 } elseif ( current_user_can( 'update_themes' ) ) { 47 $capability = 'update_themes'; 48 } else { 49 $capability = 'update_languages'; 50 } 51 52 $submenu['index.php'][10] = array( 53 sprintf( 54 /* translators: %s: Number of pending updates. */ 55 __( 'Updates %s' ), 56 sprintf( 57 '<span class="update-plugins count-%s"><span class="update-count">%s</span></span>', 58 $update_data['counts']['total'], 59 number_format_i18n( $update_data['counts']['total'] ) 60 ) 61 ), 62 $capability, 63 'update-core.php', 64 ); 65 66 unset( $capability ); 67 } 68 69 $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); 70 71 // $menu[5] = Posts. 72 73 $menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' ); 74 75 $submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' ); 76 $submenu['upload.php'][10] = array( __( 'Add Media File' ), 'upload_files', 'media-new.php' ); 77 $submenu_index = 15; 78 79 foreach ( get_taxonomies_for_attachments( 'objects' ) as $taxonomy ) { 80 if ( ! $taxonomy->show_ui || ! $taxonomy->show_in_menu ) { 81 continue; 82 } 83 84 $submenu['upload.php'][ $submenu_index++ ] = array( esc_attr( $taxonomy->labels->menu_name ), $taxonomy->cap->manage_terms, 'edit-tags.php?taxonomy=' . $taxonomy->name . '&post_type=attachment' ); 85 } 86 87 unset( $taxonomy, $submenu_index ); 88 89 $menu[15] = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' ); 90 91 $submenu['link-manager.php'][5] = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' ); 92 $submenu['link-manager.php'][10] = array( __( 'Add Link' ), 'manage_links', 'link-add.php' ); 93 $submenu['link-manager.php'][15] = array( __( 'Link Categories' ), 'manage_categories', 'edit-tags.php?taxonomy=link_category' ); 94 95 // $menu[20] = Pages. 96 97 // Avoid the comment count query for users who cannot edit_posts. 98 if ( current_user_can( 'edit_posts' ) ) { 99 $awaiting_moderation = wp_count_comments(); 100 $awaiting_moderation = $awaiting_moderation->moderated; 101 $awaiting_moderation_i18n = number_format_i18n( $awaiting_moderation ); 102 /* translators: %s: Number of comments. */ 103 $awaiting_moderation_text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_moderation ), $awaiting_moderation_i18n ); 104 105 $menu[25] = array( 106 /* translators: %s: Number of comments. */ 107 sprintf( __( 'Comments %s' ), '<span class="awaiting-mod count-' . absint( $awaiting_moderation ) . '"><span class="pending-count" aria-hidden="true">' . $awaiting_moderation_i18n . '</span><span class="comments-in-moderation-text screen-reader-text">' . $awaiting_moderation_text . '</span></span>' ), 108 'edit_posts', 109 'edit-comments.php', 110 '', 111 'menu-top menu-icon-comments', 112 'menu-comments', 113 'dashicons-admin-comments', 114 ); 115 116 unset( $awaiting_moderation ); 117 } 118 119 $submenu['edit-comments.php'][0] = array( __( 'All Comments' ), 'edit_posts', 'edit-comments.php' ); 120 121 $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group. 122 123 $post_types = (array) get_post_types( 124 array( 125 'show_ui' => true, 126 '_builtin' => false, 127 'show_in_menu' => true, 128 ) 129 ); 130 $builtin = array( 'post', 'page' ); 131 132 foreach ( array_merge( $builtin, $post_types ) as $post_type ) { 133 $post_type_obj = get_post_type_object( $post_type ); 134 135 // Check if it should be a submenu. 136 if ( true !== $post_type_obj->show_in_menu ) { 137 continue; 138 } 139 140 $post_type_menu_position = is_int( $post_type_obj->menu_position ) 141 ? $post_type_obj->menu_position 142 : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first. 143 $post_type_for_id = sanitize_html_class( $post_type ); 144 145 $menu_icon = 'dashicons-admin-post'; 146 if ( is_string( $post_type_obj->menu_icon ) ) { 147 // Special handling for an empty div.wp-menu-image, data:image/svg+xml, and Dashicons. 148 if ( 'none' === $post_type_obj->menu_icon || 'div' === $post_type_obj->menu_icon 149 || str_starts_with( $post_type_obj->menu_icon, 'data:image/svg+xml;base64,' ) 150 || str_starts_with( $post_type_obj->menu_icon, 'dashicons-' ) 151 ) { 152 $menu_icon = $post_type_obj->menu_icon; 153 } else { 154 $menu_icon = esc_url( $post_type_obj->menu_icon ); 155 } 156 } elseif ( in_array( $post_type, $builtin, true ) ) { 157 $menu_icon = 'dashicons-admin-' . $post_type; 158 } 159 160 $menu_class = 'menu-top menu-icon-' . $post_type_for_id; 161 // 'post' special case. 162 if ( 'post' === $post_type ) { 163 $menu_class .= ' open-if-no-js'; 164 $post_type_file = 'edit.php'; 165 $post_new_file = 'post-new.php'; 166 $edit_tags_file = 'edit-tags.php?taxonomy=%s'; 167 } else { 168 $post_type_file = "edit.php?post_type=$post_type"; 169 $post_new_file = "post-new.php?post_type=$post_type"; 170 $edit_tags_file = "edit-tags.php?taxonomy=%s&post_type=$post_type"; 171 } 172 173 if ( in_array( $post_type, $builtin, true ) ) { 174 $post_type_menu_id = 'menu-' . $post_type_for_id . 's'; 175 } else { 176 $post_type_menu_id = 'menu-posts-' . $post_type_for_id; 177 } 178 179 /* 180 * If $post_type_menu_position is already populated or will be populated 181 * by a hard-coded value below, increment the position. 182 */ 183 $core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 ); 184 while ( isset( $menu[ $post_type_menu_position ] ) || in_array( $post_type_menu_position, $core_menu_positions, true ) ) { 185 ++$post_type_menu_position; 186 } 187 188 $menu[ $post_type_menu_position ] = array( esc_attr( $post_type_obj->labels->menu_name ), $post_type_obj->cap->edit_posts, $post_type_file, '', $menu_class, $post_type_menu_id, $menu_icon ); 189 $submenu[ $post_type_file ][5] = array( $post_type_obj->labels->all_items, $post_type_obj->cap->edit_posts, $post_type_file ); 190 $submenu[ $post_type_file ][10] = array( $post_type_obj->labels->add_new_item, $post_type_obj->cap->create_posts, $post_new_file ); 191 192 $submenu_index = 15; 193 194 foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { 195 if ( ! $taxonomy->show_ui || ! $taxonomy->show_in_menu || ! in_array( $post_type, (array) $taxonomy->object_type, true ) ) { 196 continue; 197 } 198 199 $submenu[ $post_type_file ][ $submenu_index++ ] = array( esc_attr( $taxonomy->labels->menu_name ), $taxonomy->cap->manage_terms, sprintf( $edit_tags_file, $taxonomy->name ) ); 200 } 201 } 202 203 unset( $post_type, $post_type_obj, $post_type_for_id, $post_type_menu_position, $menu_icon, $submenu_index, $taxonomy, $post_new_file ); 204 205 $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); 206 207 $appearance_capability = current_user_can( 'switch_themes' ) ? 'switch_themes' : 'edit_theme_options'; 208 209 $menu[60] = array( __( 'Appearance' ), $appearance_capability, 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'dashicons-admin-appearance' ); 210 211 $count = ''; 212 if ( ! is_multisite() && current_user_can( 'update_themes' ) ) { 213 if ( ! isset( $update_data ) ) { 214 $update_data = wp_get_update_data(); 215 } 216 217 $count = sprintf( 218 '<span class="update-plugins count-%s"><span class="theme-count">%s</span></span>', 219 $update_data['counts']['themes'], 220 number_format_i18n( $update_data['counts']['themes'] ) 221 ); 222 } 223 224 /* translators: %s: Number of available theme updates. */ 225 $submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_capability, 'themes.php' ); 226 227 if ( wp_is_block_theme() ) { 228 $submenu['themes.php'][6] = array( _x( 'Editor', 'site editor menu item' ), 'edit_theme_options', 'site-editor.php' ); 229 } else { 230 $supports_stylebook = ( current_theme_supports( 'editor-styles' ) || wp_theme_has_theme_json() ); 231 232 if ( $supports_stylebook ) { 233 $submenu['themes.php'][6] = array( _x( 'Design', 'design menu item' ), 'edit_theme_options', 'site-editor.php' ); 234 } else { 235 $submenu['themes.php'][6] = array( _x( 'Patterns', 'patterns menu item' ), 'edit_theme_options', 'site-editor.php?p=/pattern' ); 236 } 237 } 238 239 // Font Library menu item. 240 $submenu['themes.php'][9] = array( __( 'Fonts' ), 'edit_theme_options', 'font-library.php' ); 241 242 $customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' ); 243 244 // Hide Customize link on block themes unless a plugin or theme 245 // is using 'customize_register' to add a setting. 246 if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) { 247 $submenu['themes.php'][7] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' ); 248 } 249 250 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { 251 $submenu['themes.php'][10] = array( __( 'Menus' ), 'edit_theme_options', 'nav-menus.php' ); 252 } 253 254 if ( current_theme_supports( 'custom-header' ) && current_user_can( 'customize' ) ) { 255 $customize_header_url = add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url ); 256 $submenu['themes.php'][15] = array( _x( 'Header', 'custom image header' ), $appearance_capability, esc_url( $customize_header_url ), '', 'hide-if-no-customize' ); 257 } 258 259 if ( current_theme_supports( 'custom-background' ) && current_user_can( 'customize' ) ) { 260 $customize_background_url = add_query_arg( array( 'autofocus' => array( 'control' => 'background_image' ) ), $customize_url ); 261 $submenu['themes.php'][20] = array( _x( 'Background', 'custom background' ), $appearance_capability, esc_url( $customize_background_url ), '', 'hide-if-no-customize' ); 262 } 263 264 unset( $customize_url, $appearance_capability ); 265 266 // Add 'Theme File Editor' to the bottom of the Appearance (non-block themes) or Tools (block themes) menu. 267 if ( ! is_multisite() ) { 268 // Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook. 269 add_action( 'admin_menu', '_add_themes_utility_last', 101 ); 270 } 271 /** 272 * Adds the 'Theme File Editor' menu item to the bottom of the Appearance (non-block themes) 273 * or Tools (block themes) menu. 274 * 275 * @access private 276 * @since 3.0.0 277 * @since 5.9.0 Renamed 'Theme Editor' to 'Theme File Editor'. 278 * Relocates to Tools for block themes. 279 */ 280 function _add_themes_utility_last() { 281 add_submenu_page( 282 wp_is_block_theme() ? 'tools.php' : 'themes.php', 283 __( 'Theme File Editor' ), 284 __( 'Theme File Editor' ), 285 'edit_themes', 286 'theme-editor.php' 287 ); 288 } 289 290 /** 291 * Adds the 'Plugin File Editor' menu item after the 'Themes File Editor' in Tools 292 * for block themes. 293 * 294 * @access private 295 * @since 5.9.0 296 */ 297 function _add_plugin_file_editor_to_tools() { 298 if ( ! wp_is_block_theme() ) { 299 return; 300 } 301 add_submenu_page( 302 'tools.php', 303 __( 'Plugin File Editor' ), 304 __( 'Plugin File Editor' ), 305 'edit_plugins', 306 'plugin-editor.php' 307 ); 308 } 309 310 $count = ''; 311 if ( ! is_multisite() && current_user_can( 'update_plugins' ) ) { 312 if ( ! isset( $update_data ) ) { 313 $update_data = wp_get_update_data(); 314 } 315 $count = sprintf( 316 '<span class="update-plugins count-%s"><span class="plugin-count">%s</span></span>', 317 $update_data['counts']['plugins'], 318 number_format_i18n( $update_data['counts']['plugins'] ) 319 ); 320 } 321 322 /* translators: %s: Number of available plugin updates. */ 323 $menu[65] = array( sprintf( __( 'Plugins %s' ), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'dashicons-admin-plugins' ); 324 325 $submenu['plugins.php'][5] = array( __( 'Installed Plugins' ), 'activate_plugins', 'plugins.php' ); 326 327 if ( ! is_multisite() ) { 328 $submenu['plugins.php'][10] = array( __( 'Add Plugin' ), 'install_plugins', 'plugin-install.php' ); 329 if ( wp_is_block_theme() ) { 330 // Place the menu item below the Theme File Editor menu item. 331 add_action( 'admin_menu', '_add_plugin_file_editor_to_tools', 101 ); 332 } else { 333 $submenu['plugins.php'][15] = array( __( 'Plugin File Editor' ), 'edit_plugins', 'plugin-editor.php' ); 334 } 335 } 336 337 unset( $update_data ); 338 339 if ( current_user_can( 'list_users' ) ) { 340 $menu[70] = array( __( 'Users' ), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'dashicons-admin-users' ); 341 } else { 342 $menu[70] = array( __( 'Profile' ), 'read', 'profile.php', '', 'menu-top menu-icon-users', 'menu-users', 'dashicons-admin-users' ); 343 } 344 345 if ( current_user_can( 'list_users' ) ) { 346 $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php. 347 $submenu['users.php'][5] = array( __( 'All Users' ), 'list_users', 'users.php' ); 348 if ( current_user_can( 'create_users' ) ) { 349 $submenu['users.php'][10] = array( __( 'Add User' ), 'create_users', 'user-new.php' ); 350 } elseif ( is_multisite() ) { 351 $submenu['users.php'][10] = array( __( 'Add User' ), 'promote_users', 'user-new.php' ); 352 } 353 354 $submenu['users.php'][15] = array( __( 'Profile' ), 'read', 'profile.php' ); 355 } else { 356 $_wp_real_parent_file['users.php'] = 'profile.php'; 357 $submenu['profile.php'][5] = array( __( 'Profile' ), 'read', 'profile.php' ); 358 if ( current_user_can( 'create_users' ) ) { 359 $submenu['profile.php'][10] = array( __( 'Add User' ), 'create_users', 'user-new.php' ); 360 } elseif ( is_multisite() ) { 361 $submenu['profile.php'][10] = array( __( 'Add User' ), 'promote_users', 'user-new.php' ); 362 } 363 } 364 365 $site_health_count = ''; 366 if ( ! is_multisite() && current_user_can( 'view_site_health_checks' ) ) { 367 $get_issues = get_transient( 'health-check-site-status-result' ); 368 369 $issue_counts = array(); 370 371 if ( false !== $get_issues ) { 372 $issue_counts = json_decode( $get_issues, true ); 373 } 374 375 if ( ! is_array( $issue_counts ) || ! $issue_counts ) { 376 $issue_counts = array( 377 'good' => 0, 378 'recommended' => 0, 379 'critical' => 0, 380 ); 381 } 382 383 $site_health_count = sprintf( 384 '<span class="menu-counter site-health-counter count-%s"><span class="count">%s</span></span>', 385 $issue_counts['critical'], 386 number_format_i18n( $issue_counts['critical'] ) 387 ); 388 } 389 390 $menu[75] = array( __( 'Tools' ), 'edit_posts', 'tools.php', '', 'menu-top menu-icon-tools', 'menu-tools', 'dashicons-admin-tools' ); 391 $submenu['tools.php'][5] = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' ); 392 $submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' ); 393 $submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' ); 394 /* translators: %s: Number of critical Site Health checks. */ 395 $submenu['tools.php'][20] = array( sprintf( __( 'Site Health %s' ), $site_health_count ), 'view_site_health_checks', 'site-health.php' ); 396 $submenu['tools.php'][25] = array( __( 'Export Personal Data' ), 'export_others_personal_data', 'export-personal-data.php' ); 397 $submenu['tools.php'][30] = array( __( 'Erase Personal Data' ), 'erase_others_personal_data', 'erase-personal-data.php' ); 398 if ( is_multisite() && ! is_main_site() && '1' !== get_site()->deleted ) { 399 $submenu['tools.php'][35] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' ); 400 } 401 if ( ! is_multisite() && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) { 402 $submenu['tools.php'][50] = array( __( 'Network Setup' ), 'setup_network', 'network.php' ); 403 } 404 405 $menu[80] = array( __( 'Settings' ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' ); 406 $submenu['options-general.php'][10] = array( _x( 'General', 'settings screen' ), 'manage_options', 'options-general.php' ); 407 $submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' ); 408 $submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' ); 409 $submenu['options-general.php'][25] = array( __( 'Discussion' ), 'manage_options', 'options-discussion.php' ); 410 $submenu['options-general.php'][30] = array( __( 'Media' ), 'manage_options', 'options-media.php' ); 411 $submenu['options-general.php'][40] = array( __( 'Permalinks' ), 'manage_options', 'options-permalink.php' ); 412 $submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'options-privacy.php' ); 413 414 $_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group. 415 416 $menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator' ); 417 418 // Back-compat for old top-levels. 419 $_wp_real_parent_file['post.php'] = 'edit.php'; 420 $_wp_real_parent_file['post-new.php'] = 'edit.php'; 421 $_wp_real_parent_file['edit-pages.php'] = 'edit.php?post_type=page'; 422 $_wp_real_parent_file['page-new.php'] = 'edit.php?post_type=page'; 423 $_wp_real_parent_file['wpmu-admin.php'] = 'tools.php'; 424 $_wp_real_parent_file['ms-admin.php'] = 'tools.php'; 425 426 // Ensure backward compatibility. 427 $compat = array( 428 'index' => 'dashboard', 429 'edit' => 'posts', 430 'post' => 'posts', 431 'upload' => 'media', 432 'link-manager' => 'links', 433 'edit-pages' => 'pages', 434 'page' => 'pages', 435 'edit-comments' => 'comments', 436 'options-general' => 'settings', 437 'themes' => 'appearance', 438 ); 439 440 require_once ABSPATH . 'wp-admin/includes/menu.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Tue Feb 10 08:20:09 2026 | Cross-referenced by PHPXref |