-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign a unique slug to navigation blocks and wp_navigation posts #36828
Conversation
I'm fine with using IDs in the first rollout and switch to slugs down the road. The uniqueness of a slug based on a name should be enforced by the post type APIs when the menu is saved server-side, though. |
Thank you for proposing this and thinking carefully about the longer term health of the block 👏
So the benefit of this is that it's a DB attribute and thus if necessary we can write a migration for it in the future? I'm trying to get at why using |
4c048f5
to
c596381
Compare
Prompted by your comments, I did some more thinking and it turned out that title-based slug is already available at the same time as ID. I refactored this PR from merely a migration path to a decent and potentially long-term solution. |
Size Change: +21 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this and the slug was auto generated correctly.
However I found a bug.
- Delete all menus.
- Site Editor.
- Create Nav block and create a Menu adding 1 item.
- Save.
- Go back to Nav block and
Select menu -> Create new
. - Add some items to this new Menu.
- Save.
- Notice how both menus are now marked as dirty.
- Saving causes the original / first menu to loose all its items.
@getdave good catch! It is a bug in trunk, let's address it separately. |
c596381
to
034ab76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this worked apart from the bug I noticed which we will address in a separate PR as it's unrelated.
After some more discussion, it will be easy for the two values to go out of sync. I could change the ID in the code editor, for example. This would only create more trouble in the future. Let's close this one for now and stick to numeric IDs. The migration will still be possible, and maybe even easier than if there were two sources of truth instead of just one. |
Sounds logical. Small steps. Thank you for exploring though. |
Description
Related to #36524.
This PR sets the ground for using slugs in the navigation block in WordPress 6.0. Right now, the navigation block refers to the underlying data using a numerical ID, like
684
:<!-- wp:navigation {"menuId": 642 } /-->
With slugs, it would refer to it using a string:
<!-- wp:navigation {"slug": "header-menu" } /-->
This would enable an automated transfer of menus between themes. It's the same idea as in template parts.
The problem is that WP 5.9 will use numerical IDs, which means there will be many "legacy" blocks created by the time WP 6.0 is released. How could they be migrated to slugs in 6.0? Enter this PR.
I propose setting
post_name
of every createdwp_navigation
post to the slug fetched from the backend on wp_navigation post creation. This way, in WP 6.0 we could migrate this:<!-- wp:navigation {"menuId": 642, "slug": "header-navigation" } /-->
to this:
<!-- wp:navigation {"slug": "header-navigation" } /-->
Even if slugs won't be shipped in the end, that's okay – the migration would just go in this direction insted:
<!-- wp:navigation {"menuId": 642 } /-->
Test plan
cc @getdave @tellthemachines @talldan @noisysocks @mtias @draganescu