<?php /** * Build Administration Menu. * * @package WordPress * @subpackage Administration */ /** * Constructs the admin menu. * * The elements in the array are: * 0: Menu item name. * 1: Minimum level or capability required. * 2: The URL of the item's file. * 3: Page title. * 4: Classes. * 5: ID. * 6: Icon for top level menu. * * @global array $menu */ $menu[2] = array( __( 'Dashboard' ), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'dashicons-dashboard' ); $submenu['index.php'][0] = array( __( 'Home' ), 'read', 'index.php' ); if ( is_multisite() ) { $submenu['index.php'][5] = array( __( 'My Sites' ), 'read', 'my-sites.php' ); } if ( ! is_multisite() || current_user_can( 'update_core' ) ) { $update_data = wp_get_update_data(); } if ( ! is_multisite() ) { if ( current_user_can( 'update_core' ) ) { $cap = 'update_core'; } elseif ( current_user_can( 'update_plugins' ) ) { $cap = 'update_plugins'; } elseif ( current_user_can( 'update_themes' ) ) { $cap = 'update_themes'; } else { $cap = 'update_languages'; } $submenu['index.php'][10] = array( sprintf( /* translators: %s: Number of pending updates. */ __( 'Updates %s' ), sprintf( '<span class="update-plugins count-%s"><span class="update-count">%s</span></span>', $update_data['counts']['total'], number_format_i18n( $update_data['counts']['total'] ) ) ), $cap, 'update-core.php', ); unset( $cap ); } $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); // $menu[5] = Posts. $menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' ); $submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' ); $submenu['upload.php'][10] = array( __( 'Add New Media File' ), 'upload_files', 'media-new.php' ); $i = 15; foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) { if ( ! $tax->show_ui || ! $tax->show_in_menu ) { continue; } $submenu['upload.php'][ $i++ ] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&amp;post_type=attachment' ); } unset( $tax, $i ); $menu[15] = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' ); $submenu['link-manager.php'][5] = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' ); $submenu['link-manager.php'][10] = array( __( 'Add New Link' ), 'manage_links', 'link-add.php' ); $submenu['link-manager.php'][15] = array( __( 'Link Categories' ), 'manage_categories', 'edit-tags.php?taxonomy=link_category' ); // $menu[20] = Pages. // Avoid the comment count query for users who cannot edit_posts. if ( current_user_can( 'edit_posts' ) ) { $awaiting_mod = wp_count_comments(); $awaiting_mod = $awaiting_mod->moderated; $awaiting_mod_i18n = number_format_i18n( $awaiting_mod ); /* translators: %s: Number of comments. */ $awaiting_mod_text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), $awaiting_mod_i18n ); $menu[25] = array( /* translators: %s: Number of comments. */ sprintf( __( 'Comments %s' ), '<span class="awaiting-mod count-' . absint( $awaiting_mod ) . '"><span class="pending-count" aria-hidden="true">' . $awaiting_mod_i18n . '</span><span class="comments-in-moderation-text screen-reader-text">' . $awaiting_mod_text . '</span></span>' ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'dashicons-admin-comments', ); unset( $awaiting_mod ); } $submenu['edit-comments.php'][0] = array( __( 'All Comments' ), 'edit_posts', 'edit-comments.php' ); $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group. $types = (array) get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true, ) ); $builtin = array( 'post', 'page' ); foreach ( array_merge( $builtin, $types ) as $ptype ) { $ptype_obj = get_post_type_object( $ptype ); // Check if it should be a submenu. if ( true !== $ptype_obj->show_in_menu ) { continue; } $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first. $ptype_for_id = sanitize_html_class( $ptype ); $menu_icon = 'dashicons-admin-post'; if ( is_string( $ptype_obj->menu_icon ) ) { // Special handling for an empty div.wp-menu-image, data:image/svg+xml, and Dashicons. if ( 'none' === $ptype_obj->menu_icon || 'div' === $ptype_obj->menu_icon || str_starts_with( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || str_starts_with( $ptype_obj->menu_icon, 'dashicons-' ) ) { $menu_icon = $ptype_obj->menu_icon; } else { $menu_icon = esc_url( $ptype_obj->menu_icon ); } } elseif ( in_array( $ptype, $builtin, true ) ) { $menu_icon = 'dashicons-admin-' . $ptype; } $menu_class = 'menu-top menu-icon-' . $ptype_for_id; // 'post' special case. if ( 'post' === $ptype ) { $menu_class .= ' open-if-no-js'; $ptype_file = 'edit.php'; $post_new_file = 'post-new.php'; $edit_tags_file = 'edit-tags.php?taxonomy=%s'; } else { $ptype_file = "edit.php?post_type=$ptype"; $post_new_file = "post-new.php?post_type=$ptype"; $edit_tags_file = "edit-tags.php?taxonomy=%s&amp;post_type=$ptype"; } if ( in_array( $ptype, $builtin, true ) ) { $ptype_menu_id = 'menu-' . $ptype_for_id . 's'; } else { $ptype_menu_id = 'menu-posts-' . $ptype_for_id; } /* * If $ptype_menu_position is already populated or will be populated * by a hard-coded value below, increment the position. */ $core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 ); while ( isset( $menu[ $ptype_menu_position ] ) || in_array( $ptype_menu_position, $core_menu_positions, true ) ) { ++$ptype_menu_position; } $menu[ $ptype_menu_position ] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon ); $submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file ); $submenu[ $ptype_file ][10] = array( $ptype_obj->labels->add_new_item, $ptype_obj->cap->create_posts, $post_new_file ); $i = 15; foreach ( get_taxonomies( array(), 'objects' ) as $tax ) { if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array( $ptype, (array) $tax->object_type, true ) ) { continue; } $submenu[ $ptype_file ][ $i++ ] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, sprintf( $edit_tags_file, $tax->name ) ); } } unset( $ptype, $ptype_obj, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax, $post_new_file ); $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); $appearance_cap = current_user_can( 'switch_themes' ) ? 'switch_themes' : 'edit_theme_options'; $menu[60] = array( __( 'Appearance' ), $appearance_cap, 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'dashicons-admin-appearance' ); $count = ''; if ( ! is_multisite() && current_user_can( 'update_themes' ) ) { if ( ! isset( $update_data ) ) { $update_data = wp_get_update_data(); } $count = sprintf( '<span class="update-plugins count-%s"><span class="theme-count">%s</span></span>', $update_data['counts']['themes'], number_format_i18n( $update_data['counts']['themes'] ) ); } /* translators: %s: Number of available theme updates. */ $submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_cap, 'themes.php' ); if ( wp_is_block_theme() ) { $submenu['themes.php'][6] = array( _x( 'Editor', 'site editor menu item' ), 'edit_theme_options', 'site-editor.php' ); } else { $submenu['themes.php'][6] = array( _x( 'Patterns', 'patterns menu item' ), 'edit_theme_options', 'site-editor.php?path=/patterns' ); } $customize_url = add_query_arg( 'return', u