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