wp/wp-admin/menu.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    61 
    61 
    62 $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
    62 $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
    63 
    63 
    64 // $menu[5] = Posts.
    64 // $menu[5] = Posts.
    65 
    65 
    66 $menu[10]                     = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' );
    66 $menu[10]                      = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' );
    67 	$submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' );
    67 	$submenu['upload.php'][5]  = array( __( 'Library' ), 'upload_files', 'upload.php' );
    68 	/* translators: Add new file. */
    68 	$submenu['upload.php'][10] = array( __( 'Add New Media File' ), 'upload_files', 'media-new.php' );
    69 	$submenu['upload.php'][10] = array( _x( 'Add New', 'file' ), 'upload_files', 'media-new.php' );
       
    70 	$i                         = 15;
    69 	$i                         = 15;
    71 foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) {
    70 foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) {
    72 	if ( ! $tax->show_ui || ! $tax->show_in_menu ) {
    71 	if ( ! $tax->show_ui || ! $tax->show_in_menu ) {
    73 		continue;
    72 		continue;
    74 	}
    73 	}
    75 
    74 
    76 	$submenu['upload.php'][ $i++ ] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=attachment' );
    75 	$submenu['upload.php'][ $i++ ] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=attachment' );
    77 }
    76 }
    78 	unset( $tax, $i );
    77 	unset( $tax, $i );
    79 
    78 
    80 $menu[15]                           = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' );
    79 $menu[15]                            = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' );
    81 	$submenu['link-manager.php'][5] = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' );
    80 	$submenu['link-manager.php'][5]  = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' );
    82 	/* translators: Add new links. */
    81 	$submenu['link-manager.php'][10] = array( __( 'Add New Link' ), 'manage_links', 'link-add.php' );
    83 	$submenu['link-manager.php'][10] = array( _x( 'Add New', 'link' ), 'manage_links', 'link-add.php' );
       
    84 	$submenu['link-manager.php'][15] = array( __( 'Link Categories' ), 'manage_categories', 'edit-tags.php?taxonomy=link_category' );
    82 	$submenu['link-manager.php'][15] = array( __( 'Link Categories' ), 'manage_categories', 'edit-tags.php?taxonomy=link_category' );
    85 
    83 
    86 // $menu[20] = Pages.
    84 // $menu[20] = Pages.
    87 
    85 
    88 // Avoid the comment count query for users who cannot edit_posts.
    86 // Avoid the comment count query for users who cannot edit_posts.
   127 	$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.
   125 	$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.
   128 	$ptype_for_id        = sanitize_html_class( $ptype );
   126 	$ptype_for_id        = sanitize_html_class( $ptype );
   129 
   127 
   130 	$menu_icon = 'dashicons-admin-post';
   128 	$menu_icon = 'dashicons-admin-post';
   131 	if ( is_string( $ptype_obj->menu_icon ) ) {
   129 	if ( is_string( $ptype_obj->menu_icon ) ) {
   132 		// Special handling for data:image/svg+xml and Dashicons.
   130 		// Special handling for an empty div.wp-menu-image, data:image/svg+xml, and Dashicons.
   133 		if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) {
   131 		if ( 'none' === $ptype_obj->menu_icon || 'div' === $ptype_obj->menu_icon
       
   132 			|| str_starts_with( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' )
       
   133 			|| str_starts_with( $ptype_obj->menu_icon, 'dashicons-' )
       
   134 		) {
   134 			$menu_icon = $ptype_obj->menu_icon;
   135 			$menu_icon = $ptype_obj->menu_icon;
   135 		} else {
   136 		} else {
   136 			$menu_icon = esc_url( $ptype_obj->menu_icon );
   137 			$menu_icon = esc_url( $ptype_obj->menu_icon );
   137 		}
   138 		}
   138 	} elseif ( in_array( $ptype, $builtin, true ) ) {
   139 	} elseif ( in_array( $ptype, $builtin, true ) ) {
   161 	 * If $ptype_menu_position is already populated or will be populated
   162 	 * If $ptype_menu_position is already populated or will be populated
   162 	 * by a hard-coded value below, increment the position.
   163 	 * by a hard-coded value below, increment the position.
   163 	 */
   164 	 */
   164 	$core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 );
   165 	$core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 );
   165 	while ( isset( $menu[ $ptype_menu_position ] ) || in_array( $ptype_menu_position, $core_menu_positions, true ) ) {
   166 	while ( isset( $menu[ $ptype_menu_position ] ) || in_array( $ptype_menu_position, $core_menu_positions, true ) ) {
   166 		$ptype_menu_position++;
   167 		++$ptype_menu_position;
   167 	}
   168 	}
   168 
   169 
   169 	$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 );
   170 	$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 );
   170 	$submenu[ $ptype_file ][5]    = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file );
   171 	$submenu[ $ptype_file ][5]    = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file );
   171 	$submenu[ $ptype_file ][10]   = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, $post_new_file );
   172 	$submenu[ $ptype_file ][10]   = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, $post_new_file );
   201 
   202 
   202 	/* translators: %s: Number of available theme updates. */
   203 	/* translators: %s: Number of available theme updates. */
   203 	$submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_cap, 'themes.php' );
   204 	$submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_cap, 'themes.php' );
   204 
   205 
   205 if ( wp_is_block_theme() ) {
   206 if ( wp_is_block_theme() ) {
   206 	$submenu['themes.php'][6] = array(
   207 	$submenu['themes.php'][6] = array( _x( 'Editor', 'site editor menu item' ), 'edit_theme_options', 'site-editor.php' );
   207 		sprintf(
   208 } else {
   208 			/* translators: %s: "beta" label */
   209 	$submenu['themes.php'][6] = array( _x( 'Patterns', 'patterns menu item' ), 'edit_theme_options', 'site-editor.php?path=/patterns' );
   209 			__( 'Editor %s' ),
       
   210 			'<span class="awaiting-mod">' . __( 'beta' ) . '</span>'
       
   211 		),
       
   212 		'edit_theme_options',
       
   213 		'site-editor.php',
       
   214 	);
       
   215 }
   210 }
   216 
   211 
   217 $customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
   212 $customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
   218 
   213 
   219 // Hide Customize link on block themes unless a plugin or theme
   214 // Hide Customize link on block themes unless a plugin or theme
   220 // is using 'customize_register' to add a setting.
   215 // is using 'customize_register' to add a setting.
   221 if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) {
   216 if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) {
   222 	$position = wp_is_block_theme() ? 7 : 6;
   217 	$submenu['themes.php'][7] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' );
   223 
       
   224 	$submenu['themes.php'][ $position ] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' );
       
   225 }
   218 }
   226 
   219 
   227 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
   220 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
   228 	$submenu['themes.php'][10] = array( __( 'Menus' ), 'edit_theme_options', 'nav-menus.php' );
   221 	$submenu['themes.php'][10] = array( __( 'Menus' ), 'edit_theme_options', 'nav-menus.php' );
   229 }
   222 }
   230 
   223 
   231 if ( current_theme_supports( 'custom-header' ) && current_user_can( 'customize' ) ) {
   224 if ( current_theme_supports( 'custom-header' ) && current_user_can( 'customize' ) ) {
   232 	$customize_header_url      = add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url );
   225 	$customize_header_url      = add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url );
   233 	$submenu['themes.php'][15] = array( __( 'Header' ), $appearance_cap, esc_url( $customize_header_url ), '', 'hide-if-no-customize' );
   226 	$submenu['themes.php'][15] = array( _x( 'Header', 'custom image header' ), $appearance_cap, esc_url( $customize_header_url ), '', 'hide-if-no-customize' );
   234 }
   227 }
   235 
   228 
   236 if ( current_theme_supports( 'custom-background' ) && current_user_can( 'customize' ) ) {
   229 if ( current_theme_supports( 'custom-background' ) && current_user_can( 'customize' ) ) {
   237 	$customize_background_url  = add_query_arg( array( 'autofocus' => array( 'control' => 'background_image' ) ), $customize_url );
   230 	$customize_background_url  = add_query_arg( array( 'autofocus' => array( 'control' => 'background_image' ) ), $customize_url );
   238 	$submenu['themes.php'][20] = array( __( 'Background' ), $appearance_cap, esc_url( $customize_background_url ), '', 'hide-if-no-customize' );
   231 	$submenu['themes.php'][20] = array( _x( 'Background', 'custom background' ), $appearance_cap, esc_url( $customize_background_url ), '', 'hide-if-no-customize' );
   239 }
   232 }
   240 
   233 
   241 unset( $customize_url );
   234 unset( $customize_url );
   242 
   235 
   243 unset( $appearance_cap );
   236 unset( $appearance_cap );
   302 $menu[65] = array( sprintf( __( 'Plugins %s' ), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'dashicons-admin-plugins' );
   295 $menu[65] = array( sprintf( __( 'Plugins %s' ), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'dashicons-admin-plugins' );
   303 
   296 
   304 $submenu['plugins.php'][5] = array( __( 'Installed Plugins' ), 'activate_plugins', 'plugins.php' );
   297 $submenu['plugins.php'][5] = array( __( 'Installed Plugins' ), 'activate_plugins', 'plugins.php' );
   305 
   298 
   306 if ( ! is_multisite() ) {
   299 if ( ! is_multisite() ) {
   307 	/* translators: Add new plugin. */
   300 	$submenu['plugins.php'][10] = array( __( 'Add New Plugin' ), 'install_plugins', 'plugin-install.php' );
   308 	$submenu['plugins.php'][10] = array( _x( 'Add New', 'plugin' ), 'install_plugins', 'plugin-install.php' );
       
   309 	if ( wp_is_block_theme() ) {
   301 	if ( wp_is_block_theme() ) {
   310 		// Place the menu item below the Theme File Editor menu item.
   302 		// Place the menu item below the Theme File Editor menu item.
   311 		add_action( 'admin_menu', '_add_plugin_file_editor_to_tools', 101 );
   303 		add_action( 'admin_menu', '_add_plugin_file_editor_to_tools', 101 );
   312 	} else {
   304 	} else {
   313 		$submenu['plugins.php'][15] = array( __( 'Plugin File Editor' ), 'edit_plugins', 'plugin-editor.php' );
   305 		$submenu['plugins.php'][15] = array( __( 'Plugin File Editor' ), 'edit_plugins', 'plugin-editor.php' );
   324 
   316 
   325 if ( current_user_can( 'list_users' ) ) {
   317 if ( current_user_can( 'list_users' ) ) {
   326 	$_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
   318 	$_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
   327 	$submenu['users.php'][5]             = array( __( 'All Users' ), 'list_users', 'users.php' );
   319 	$submenu['users.php'][5]             = array( __( 'All Users' ), 'list_users', 'users.php' );
   328 	if ( current_user_can( 'create_users' ) ) {
   320 	if ( current_user_can( 'create_users' ) ) {
   329 		$submenu['users.php'][10] = array( _x( 'Add New', 'user' ), 'create_users', 'user-new.php' );
   321 		$submenu['users.php'][10] = array( __( 'Add New User' ), 'create_users', 'user-new.php' );
   330 	} elseif ( is_multisite() ) {
   322 	} elseif ( is_multisite() ) {
   331 		$submenu['users.php'][10] = array( _x( 'Add New', 'user' ), 'promote_users', 'user-new.php' );
   323 		$submenu['users.php'][10] = array( __( 'Add New User' ), 'promote_users', 'user-new.php' );
   332 	}
   324 	}
   333 
   325 
   334 	$submenu['users.php'][15] = array( __( 'Profile' ), 'read', 'profile.php' );
   326 	$submenu['users.php'][15] = array( __( 'Profile' ), 'read', 'profile.php' );
   335 } else {
   327 } else {
   336 	$_wp_real_parent_file['users.php'] = 'profile.php';
   328 	$_wp_real_parent_file['users.php'] = 'profile.php';
   340 	} elseif ( is_multisite() ) {
   332 	} elseif ( is_multisite() ) {
   341 		$submenu['profile.php'][10] = array( __( 'Add New User' ), 'promote_users', 'user-new.php' );
   333 		$submenu['profile.php'][10] = array( __( 'Add New User' ), 'promote_users', 'user-new.php' );
   342 	}
   334 	}
   343 }
   335 }
   344 
   336 
       
   337 $site_health_count = '';
       
   338 if ( ! is_multisite() && current_user_can( 'view_site_health_checks' ) ) {
       
   339 	$get_issues = get_transient( 'health-check-site-status-result' );
       
   340 
       
   341 	$issue_counts = array();
       
   342 
       
   343 	if ( false !== $get_issues ) {
       
   344 		$issue_counts = json_decode( $get_issues, true );
       
   345 	}
       
   346 
       
   347 	if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
       
   348 		$issue_counts = array(
       
   349 			'good'        => 0,
       
   350 			'recommended' => 0,
       
   351 			'critical'    => 0,
       
   352 		);
       
   353 	}
       
   354 
       
   355 	$site_health_count = sprintf(
       
   356 		'<span class="menu-counter site-health-counter count-%s"><span class="count">%s</span></span>',
       
   357 		$issue_counts['critical'],
       
   358 		number_format_i18n( $issue_counts['critical'] )
       
   359 	);
       
   360 }
       
   361 
   345 $menu[75]                     = array( __( 'Tools' ), 'edit_posts', 'tools.php', '', 'menu-top menu-icon-tools', 'menu-tools', 'dashicons-admin-tools' );
   362 $menu[75]                     = array( __( 'Tools' ), 'edit_posts', 'tools.php', '', 'menu-top menu-icon-tools', 'menu-tools', 'dashicons-admin-tools' );
   346 	$submenu['tools.php'][5]  = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' );
   363 	$submenu['tools.php'][5]  = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' );
   347 	$submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' );
   364 	$submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' );
   348 	$submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' );
   365 	$submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' );
   349 	$submenu['tools.php'][20] = array( __( 'Site Health' ), 'view_site_health_checks', 'site-health.php' );
   366 	/* translators: %s: Number of critical Site Health checks. */
       
   367 	$submenu['tools.php'][20] = array( sprintf( __( 'Site Health %s' ), $site_health_count ), 'view_site_health_checks', 'site-health.php' );
   350 	$submenu['tools.php'][25] = array( __( 'Export Personal Data' ), 'export_others_personal_data', 'export-personal-data.php' );
   368 	$submenu['tools.php'][25] = array( __( 'Export Personal Data' ), 'export_others_personal_data', 'export-personal-data.php' );
   351 	$submenu['tools.php'][30] = array( __( 'Erase Personal Data' ), 'erase_others_personal_data', 'erase-personal-data.php' );
   369 	$submenu['tools.php'][30] = array( __( 'Erase Personal Data' ), 'erase_others_personal_data', 'erase-personal-data.php' );
   352 if ( is_multisite() && ! is_main_site() ) {
   370 if ( is_multisite() && ! is_main_site() ) {
   353 	$submenu['tools.php'][35] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' );
   371 	$submenu['tools.php'][35] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' );
   354 }
   372 }