Skip to content
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

Fix menu ordering on item update #502

Closed

Conversation

nateinaction
Copy link

@nateinaction nateinaction commented May 16, 2024

Fixes #463

This PR reorders menu items when using wp menu item update command with the --position flag

Previous behavior is described in #463

New behavior:

$ wp menu item list sample-menu --format=csv
db_id,type,title,link,position
4,custom,Alpha,https://alpha.com,1
5,custom,Beta,https://beta.com,2

$ wp menu item update 5 --position=1
Success: Menu item updated.

$ wp menu item list sample-menu --format=csv
db_id,type,title,link,position
5,custom,Beta,https://beta.com,1
4,custom,Alpha,https://alpha.com,2

$ wp menu item update 5 --position=2        
Success: Menu item updated.

$ wp menu item list sample-menu --format=csv
db_id,type,title,link,position
4,custom,Alpha,https://alpha.com,1
5,custom,Beta,https://beta.com,2

While this fix works, it utilizes reorder_menu_items() which I believe is potentially error prone in situations where there are gaps in menu item ordering. Menu ordering gaps can be introduced using the same wp menu item update command and can cause abnormal behavior when reordering position. I'm curious about the maintainer's interest in enforcing menu item ordering without allowing gaps?

Another potential bug could be the position shown when listing the menu does not match the menu_order column in the posts table. By not displaying the exact menu_order value we can cause confusion like I had when investigating this issue.

@nateinaction nateinaction requested a review from a team as a code owner May 16, 2024 21:20
@nateinaction nateinaction force-pushed the fix/menu-ordering-on-update branch from a55a71b to d87a666 Compare May 16, 2024 21:24
@nateinaction
Copy link
Author

This is close but we need slightly more complex logic for reordering. Still seeing odd ordering issues on top of problems when gaps exist in menu item order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Position is not updated in wp menu item update command
2 participants