Repository navigation
Content Type: Add menu_icon and menu_position fields - #78285
im3dabasia wants to merge 2 commits into
Conversation
menu_item and menu_position fields
tyxla
left a comment
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
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 ) |
There was a problem hiding this comment.
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
| 'menu_icon', | ||
| 'menu_position', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.' |
There was a problem hiding this comment.
Should we use the same example of dashicon as in the placeholder?
menu_item and menu_position fieldsmenu_icon and menu_position fields
|
Thanks for your work! I'm closing though since the experiment was removed here: #81340. |
What?
See #77600
Adds
menu_iconandmenu_positionfields 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
dashicons-bookfor icon and25for position, save.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