Skip to content

Content Type: Add menu_icon and menu_position fields - #78285

Closed
im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/add-menu-related-fields
Closed

im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/add-menu-related-fields

Conversation

@im3dabasia

Copy link
Copy Markdown
Contributor

What?

See #77600

Adds menu_icon and menu_position fields to the user-defined post type management UI.

Why?

The issue explicitly lists "Add more fields for menu icon, menu position, rewrite, etc." as a missing capability for post type management. Without these fields, users cannot customise where their post type appears in the admin menu or what icon it uses.

Testing Instructions

  1. Ensure the content types experiment is enabled.
  2. Go to Admin → Content Types → Post Types → Add New.
  3. In the General section, confirm Menu icon and Menu position fields appear.
  4. Enter dashicons-book for icon and 25 for position, save.
  5. Verify the new post type appears in the admin menu with the correct icon and position.
  6. Run PHP tests: npm run test:unit:php:base -- --filter "WP_REST_User_Post_Types_Controller_Gutenberg_Test"

Screencast

Screen.Recording.2026-05-14.at.3.59.41.PM.mov

@im3dabasia im3dabasia self-assigned this May 14, 2026
@im3dabasia
im3dabasia requested a review from spacedmonkey as a code owner May 14, 2026 10:31
@im3dabasia
im3dabasia requested review from ntsekouras and tyxla May 14, 2026 11:02
@im3dabasia im3dabasia changed the title Feat/add menu related fields Content Type: Add menu_item and menu_position fields May 15, 2026
@im3dabasia im3dabasia mentioned this pull request May 18, 2026
23 of 49 tasks

@tyxla tyxla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @im3dabasia, this is generally looking good and working well - thanks!

BTW, the PR title says "menu_item" - I imagine you meant "menu_icon", but just confirming?

I just left a few minor suggestions and also it seems like the PHP checks are failing due to some formatting issues.

};

export const menuIconField: Field< PostTypeFormData > = {
id: 'menu_icon',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noticing we don't add a max length for the menu icon field. Considering users can put in long base64 data URI blobs, this is a problematic source of problems. One way around it is to discourage data URIs and just work with either dashicons or empty icons that they can style with CSS.

cc @ntsekouras who added some of the limits for the other fields - what limits would you put here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For start I believe we should only start with dashicons and the max length could be related to that decision. I haven't investigated the menu_icon, so I'm not sure about possible nuances with base64-encoded SVGs.

'menu_position' => array(
'type' => array( 'integer', 'null' ),
'minimum' => 1,
'maximum' => 100,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure 100 should be the practical maximum here. Technically, folks can input PHP_INT_MAX if they want. I think we should remove the upper limit, or make it something way larger than this, since folks might want to specify a custom specific order beyond 100.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we shouldn't have an upper limit if it's not enforced anywhere in PHP. Additionally we should add the same validation rules for the JS field.

'has_archive' => array( 'type' => 'boolean' ),
'show_in_rest' => array( 'type' => 'boolean' ),
'menu_icon' => array(
'type' => array( 'string', 'null' ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need some special validation here. The register_post_type documentation recognizes the special string 'none' and dashicons-* slugs. I think a pattern (e.g. dashicons slug OR data: URI OR http(s): URL OR none) would catch typos at the REST layer, in addition to the max length limit that I'm also mentioning below.

...item.config,
menu_position:
value !== '' && value !== null && value !== undefined
? Number( value )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the min/max in the REST API reflected here. We should ensure we're consistent between the UI and the REST API

Comment on lines +305 to +306
'menu_icon',
'menu_position',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this form is starting to get a bit cluttered and we might want to split it to multiple groups just like Taxonomies, so General will have just a few basic fields.

Also, should these go right at the bottom, even bellow the status field?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to split it to multiple groups

Agreed. Probably a Visibility section or an Advanced could be fine to start with and we can reorganize later.

label: __( 'Menu icon' ),
type: 'text',
description: __(
'Dashicon slug (e.g. "dashicons-book") or a data: URI for a custom icon shown in the admin menu.'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the same example of dashicon as in the placeholder?

@ntsekouras ntsekouras changed the title Content Type: Add menu_item and menu_position fields Content Type: Add menu_icon and menu_position fields Jun 3, 2026
@ntsekouras

Copy link
Copy Markdown
Contributor

Thanks for your work! I'm closing though since the experiment was removed here: #81340.

@ntsekouras ntsekouras closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants