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
Navigation: Fix creating Navigation from pages or menu with HTML in title #24673
Conversation
…itle Pages and menu items in WordPress allow HTML in the title. We should therefore not escape the menu item title when creating a Navigation block from top-level pages or an existing menu. Additionally, the menu items REST API endpoint was setting title.raw to the menu item CPT's post_title and title.rendered to the referenced post's post_title. Both title.raw and title.rendered should be set to the menu item's title, which is properly set by wp_setup_nav_menu_item(). The only difference is that title.rendered should be passed through the_title, which escapes & characters, and nav_menu_item_title, which provides plugins a chance to customise menu item titles before display. This matches what Walker_Nav_Menu does.
Size Change: +5.87 kB (0%) Total Size: 1.17 MB
ℹ️ View Unchanged
|
This looks right to me @noisysocks, can we get a phpunit test covering this? |
Done! |
Huh. The test fails in GitHub Actions but succeeds locally. I'll investigate tomorrow. |
Turns out the regular tests were passing but the multisite tests were failing. This is because administrators in a multisite do not have |
Co-authored-by: Timothy Jacobs <timothy@ironbounddesigns.com>
Fixes #23919.
Pages and menu items in WordPress allow HTML in the title. We should therefore not escape the menu item title when creating a Navigation block from top-level pages or an existing menu.
Additionally, the menu items REST API endpoint was setting
title.raw
to the menu item CPT'spost_title
($menu_item->post_title
) andtitle.rendered
to the referenced object'spost_title
(get_post( $menu_item->object_id )->post_title)
). Bothtitle.raw
andtitle.rendered
should be set to the menu item'stitle
($menu_item->title
), which is properly set bywp_setup_nav_menu_item()
.The only difference is that
title.rendered
should be passed throughthe_title
, which escapes&
characters, andnav_menu_item_title
, which provides plugins a chance to customise menu item titles before display. This matches whatWalker_Nav_Menu
does.How to test
<strong>Menu item</strong> & foo
<strong>Page</strong> & foo
.Both blocks should have bold text and a
&
in one of the links.