Changeset 61200
- Timestamp:
- 11/10/2025 10:57:40 PM (2 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/menu.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/menu.php
r60358 r61200 41 41 if ( ! is_multisite() ) { 42 42 if ( current_user_can( 'update_core' ) ) { 43 $cap = 'update_core';43 $capability = 'update_core'; 44 44 } elseif ( current_user_can( 'update_plugins' ) ) { 45 $cap = 'update_plugins';45 $capability = 'update_plugins'; 46 46 } elseif ( current_user_can( 'update_themes' ) ) { 47 $cap = 'update_themes';47 $capability = 'update_themes'; 48 48 } else { 49 $cap = 'update_languages'; 50 } 49 $capability = 'update_languages'; 50 } 51 51 52 $submenu['index.php'][10] = array( 52 53 sprintf( … … 59 60 ) 60 61 ), 61 $cap ,62 $capability, 62 63 'update-core.php', 63 64 ); 64 unset( $cap ); 65 66 unset( $capability ); 65 67 } 66 68 … … 69 71 // $menu[5] = Posts. 70 72 71 $menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' ); 73 $menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' ); 74 72 75 $submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' ); 73 76 $submenu['upload.php'][10] = array( __( 'Add Media File' ), 'upload_files', 'media-new.php' ); 74 $i = 15; 75 foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) { 76 if ( ! $tax->show_ui || ! $tax->show_in_menu ) { 77 continue; 78 } 79 80 $submenu['upload.php'][ $i++ ] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=attachment' ); 81 } 82 unset( $tax, $i ); 83 84 $menu[15] = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' ); 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 85 91 $submenu['link-manager.php'][5] = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' ); 86 92 $submenu['link-manager.php'][10] = array( __( 'Add Link' ), 'manage_links', 'link-add.php' ); … … 91 97 // Avoid the comment count query for users who cannot edit_posts. 92 98 if ( current_user_can( 'edit_posts' ) ) { 93 $awaiting_mod = wp_count_comments();94 $awaiting_mod = $awaiting_mod->moderated;95 $awaiting_mod _i18n = number_format_i18n( $awaiting_mod);99 $awaiting_moderation = wp_count_comments(); 100 $awaiting_moderation = $awaiting_moderation->moderated; 101 $awaiting_moderation_i18n = number_format_i18n( $awaiting_moderation ); 96 102 /* translators: %s: Number of comments. */ 97 $awaiting_mod _text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), $awaiting_mod_i18n );103 $awaiting_moderation_text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_moderation ), $awaiting_moderation_i18n ); 98 104 99 105 $menu[25] = array( 100 106 /* translators: %s: Number of comments. */ 101 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>' ),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>' ), 102 108 'edit_posts', 103 109 'edit-comments.php', … … 107 113 'dashicons-admin-comments', 108 114 ); 109 unset( $awaiting_mod ); 115 116 unset( $awaiting_moderation ); 110 117 } 111 118 … … 114 121 $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group. 115 122 116 $ types= (array) get_post_types(123 $post_types = (array) get_post_types( 117 124 array( 118 125 'show_ui' => true, … … 121 128 ) 122 129 ); 123 $builtin = array( 'post', 'page' ); 124 foreach ( array_merge( $builtin, $types ) as $ptype ) { 125 $ptype_obj = get_post_type_object( $ptype ); 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 126 135 // Check if it should be a submenu. 127 if ( true !== $p type_obj->show_in_menu ) {136 if ( true !== $post_type_obj->show_in_menu ) { 128 137 continue; 129 138 } 130 $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. 131 $ptype_for_id = sanitize_html_class( $ptype ); 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 ); 132 144 133 145 $menu_icon = 'dashicons-admin-post'; 134 if ( is_string( $p type_obj->menu_icon ) ) {146 if ( is_string( $post_type_obj->menu_icon ) ) { 135 147 // Special handling for an empty div.wp-menu-image, data:image/svg+xml, and Dashicons. 136 if ( 'none' === $p type_obj->menu_icon || 'div' === $ptype_obj->menu_icon137 || str_starts_with( $p type_obj->menu_icon, 'data:image/svg+xml;base64,' )138 || str_starts_with( $p type_obj->menu_icon, '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-' ) 139 151 ) { 140 $menu_icon = $p type_obj->menu_icon;152 $menu_icon = $post_type_obj->menu_icon; 141 153 } else { 142 $menu_icon = esc_url( $p type_obj->menu_icon );154 $menu_icon = esc_url( $post_type_obj->menu_icon ); 143 155 } 144 } elseif ( in_array( $p type, $builtin, true ) ) {145 $menu_icon = 'dashicons-admin-' . $p type;146 } 147 148 $menu_class = 'menu-top menu-icon-' . $p type_for_id;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; 149 161 // 'post' special case. 150 if ( 'post' === $p type ) {162 if ( 'post' === $post_type ) { 151 163 $menu_class .= ' open-if-no-js'; 152 $p type_file= 'edit.php';164 $post_type_file = 'edit.php'; 153 165 $post_new_file = 'post-new.php'; 154 166 $edit_tags_file = 'edit-tags.php?taxonomy=%s'; 155 167 } else { 156 $p type_file = "edit.php?post_type=$ptype";157 $post_new_file = "post-new.php?post_type=$p type";158 $edit_tags_file = "edit-tags.php?taxonomy=%s&post_type=$p type";159 } 160 161 if ( in_array( $p type, $builtin, true ) ) {162 $p type_menu_id = 'menu-' . $ptype_for_id . 's';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'; 163 175 } else { 164 $ptype_menu_id = 'menu-posts-' . $ptype_for_id; 165 } 176 $post_type_menu_id = 'menu-posts-' . $post_type_for_id; 177 } 178 166 179 /* 167 * If $p type_menu_position is already populated or will be populated180 * If $post_type_menu_position is already populated or will be populated 168 181 * by a hard-coded value below, increment the position. 169 182 */ 170 183 $core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 ); 171 while ( isset( $menu[ $ptype_menu_position ] ) || in_array( $ptype_menu_position, $core_menu_positions, true ) ) { 172 ++$ptype_menu_position; 173 } 174 175 $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 ); 176 $submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file ); 177 $submenu[ $ptype_file ][10] = array( $ptype_obj->labels->add_new_item, $ptype_obj->cap->create_posts, $post_new_file ); 178 179 $i = 15; 180 foreach ( get_taxonomies( array(), 'objects' ) as $tax ) { 181 if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array( $ptype, (array) $tax->object_type, true ) ) { 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 ) ) { 182 196 continue; 183 197 } 184 198 185 $submenu[ $ptype_file ][ $i++ ] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, sprintf( $edit_tags_file, $tax->name ) ); 186 } 187 } 188 unset( $ptype, $ptype_obj, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax, $post_new_file ); 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 ); 189 204 190 205 $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); 191 206 192 $appearance_cap = current_user_can( 'switch_themes' ) ? 'switch_themes' : 'edit_theme_options';193 194 $menu[60] = array( __( 'Appearance' ), $appearance_cap , 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'dashicons-admin-appearance' );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' ); 195 210 196 211 $count = ''; … … 199 214 $update_data = wp_get_update_data(); 200 215 } 216 201 217 $count = sprintf( 202 218 '<span class="update-plugins count-%s"><span class="theme-count">%s</span></span>', … … 207 223 208 224 /* translators: %s: Number of available theme updates. */ 209 $submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_cap , 'themes.php' );225 $submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_capability, 'themes.php' ); 210 226 211 227 if ( wp_is_block_theme() ) { … … 235 251 if ( current_theme_supports( 'custom-header' ) && current_user_can( 'customize' ) ) { 236 252 $customize_header_url = add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url ); 237 $submenu['themes.php'][15] = array( _x( 'Header', 'custom image header' ), $appearance_cap , esc_url( $customize_header_url ), '', 'hide-if-no-customize' );253 $submenu['themes.php'][15] = array( _x( 'Header', 'custom image header' ), $appearance_capability, esc_url( $customize_header_url ), '', 'hide-if-no-customize' ); 238 254 } 239 255 240 256 if ( current_theme_supports( 'custom-background' ) && current_user_can( 'customize' ) ) { 241 257 $customize_background_url = add_query_arg( array( 'autofocus' => array( 'control' => 'background_image' ) ), $customize_url ); 242 $submenu['themes.php'][20] = array( _x( 'Background', 'custom background' ), $appearance_cap, esc_url( $customize_background_url ), '', 'hide-if-no-customize' ); 243 } 244 245 unset( $customize_url ); 246 247 unset( $appearance_cap ); 258 $submenu['themes.php'][20] = array( _x( 'Background', 'custom background' ), $appearance_capability, esc_url( $customize_background_url ), '', 'hide-if-no-customize' ); 259 } 260 261 unset( $customize_url, $appearance_capability ); 248 262 249 263 // Add 'Theme File Editor' to the bottom of the Appearance (non-block themes) or Tools (block themes) menu.
Note: See TracChangeset
for help on using the changeset viewer.