Skip to content

Navigation: Let the author choose the menus a page is added to when it is published - #85771

Draft
jeryj wants to merge 18 commits into
add/navigation-auto-add-pages-publish-panelfrom
add/navigation-choose-menus-on-publish
Draft

jeryj wants to merge 18 commits into
add/navigation-auto-add-pages-publish-panelfrom
add/navigation-choose-menus-on-publish

Conversation

@jeryj

@jeryj jeryj commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What?

The pre-publish panel of a page lists every Navigation Menu with a checkbox, so the author chooses the menus the page is added to when it is published. The menus that "Auto add new pages" would add the page to start checked, a menu that already links to the page is checked and locked, and any other menu can be checked. Each menu links to its editor.

It also adds gutenberg_navigation_add_post_link( $menu_id, $post ), the public function that adds a link to a post to one menu, which the "Auto add new pages" hook now builds on and which a plugin can call.

Stacked on #85762, which is stacked on #85589 and #84508. The diff against that branch is only this change.

Why?

Part of #85156. With "Auto add new pages" on, the setting decides for every page. In #16635, @joanrho asked for a way to keep a page out of a menu at publish time (a legal page that belongs in the footer, not the header) and to add a page to a menu that does not add pages. Doing both from the publish panel saves a trip to the site editor afterwards.

The public function answers a second question: a plugin that wants a link to one of its pages in a menu, the way WooCommerce wants the Shop page in the header. Block Hooks already let a plugin hook its own block type into core/navigation, including into wp_navigation posts, and that is the right tool for a block like the Mini Cart. A plain link is a core/navigation-link, a block type every plugin shares, so the hooked_block_core/navigation-link filter cannot tell one plugin's link from another's. With this function a plugin adds its link to a menu it knows the ID of, in one call, without parsing the menu.

How?

Server

  • gutenberg_navigation_add_post_link( $menu_id, $post ) in navigation-auto-add-pages.php: parses the menu, returns false when it already links to the post, nests the link under the link to the post's parent when the menu has one and appends it otherwise, and saves. Returns a WP_Error for an unknown menu or post. The link block carries the post's type, so it works for any post type.
  • gutenberg_navigation_auto_add_page_on_publish() calls it. Its rule that a child page is skipped by a menu without its parent is unchanged.
  • navigation-choose-menus-on-publish.php registers navigation_menus on pages, a write-only REST field (a list of menu IDs). rest_pre_insert_page keeps the value for the request, and the status transition uses it in place of the setting: the page is added to exactly those menus the current user can edit, appended when the menu has no link to the parent. No menu's setting changes. A value sent with a request that does not publish is dropped on rest_after_insert_page.

Editor

  • MaybeNavigationMenusPanel renders one CheckboxControl per menu, with "Under " as its description when the link would be nested, and an "Edit" link to the menu. The section is hidden for other post types and when the site has no menu.
  • A change calls editPost( { navigation_menus: [ ...checked ids ] } ), so the choice travels with the publish request. Without a change nothing is sent and the server behaves as before.

For plugins

// Add a link to the Shop page to the menu with ID 12, under its parent's link when there is one.
gutenberg_navigation_add_post_link( 12, wc_get_page_id( 'shop' ) );

To find the menus that take new pages, query wp_navigation posts with the wp_navigation_auto_add_pages meta set.

Testing Instructions

  1. In the site editor, switch "Auto add new pages" on for one menu. Create a second menu and leave it off.
  2. Create a page and click Publish. "Menus: " expands to both menus: the first checked, the second unchecked.
  3. Check the second menu and publish. Both menus link to the page.
  4. Create another page, uncheck the first menu, and publish. Neither menu links to it. Its setting is still on, and the next page published without a change is added to it.
  5. Create a page as a child of a page the first menu links to. Its row says "Under ".
  6. Create a page, add a link to it to a menu, then publish it. That menu is checked and locked.

Automated

npm run test:unit:php:base -- --filter 'Gutenberg_Navigation_Choose_Menus_On_Publish_Test|Gutenberg_Navigation_Auto_Add_Pages_Test'
npm run test:e2e -- test/e2e/specs/editor/blocks/navigation-choose-menus-on-publish.spec.ts

The spec from #85762 is folded into the new one, since the panel it tested is now the checkbox list.

Notes

  • The choice applies to the publish transition it is sent with, like the setting itself. Nothing is stored on the page, so a page unpublished and published again starts from the default again.
  • The function is prefixed gutenberg_ and would become wp_navigation_add_post_link() in Core.

🤖 Generated with Claude Code

https://claude.ai/code/session_0199oMWAas4xDSnjTYeDtPxL

@jeryj jeryj added [Type] Enhancement A suggestion for improvement. REST API Interaction Related to REST API [Package] Editor /packages/editor [Block] Navigation Affects the Navigation Block labels Oct 27, 2026
@jeryj
jeryj requested a review from spacedmonkey as a code owner October 27, 2026 18:11
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jeryj <jeryj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +746 B (+0.01%)

Total Size: 8.73 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 575 kB +652 B (+0.11%)
build/styles/editor/style-rtl.css 32.6 kB +24 B (+0.07%)
build/styles/editor/style-rtl.min.css 28.2 kB +22 B (+0.08%)
build/styles/editor/style.css 32.7 kB +26 B (+0.08%)
build/styles/editor/style.min.css 28.2 kB +22 B (+0.08%)

4087cfc Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 157b88e add/navigation-auto-add-pages-publish-panel % Change
timeToFirstByte 47.05 ms +2.13% -4.14% 45.75 ms +5.46% -4.48% 2.84%
largestContentfulPaint 76 ms +7.89% -5.26% 74 ms +10.81% -2.7% 2.7%
lcpMinusTtfb 27.8 ms +18.71% -3.24% 28 ms +32.86% -6.25% -0.71%
wpBeforeTemplate 23.74 ms +4.72% -2.78% 22.96 ms +7.19% -2.79% 3.4%
wpTemplate 19.1 ms +4.92% -5.39% 18.55 ms +5.23% -6.36% 2.96%
wpTotal 42.88 ms +2.78% -3.71% 41.95 ms +5.63% -4.7% 2.22%
wpMemoryUsage 7.77 MB +0% -0% 7.77 MB +0% -0% 0.01%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 157b88e add/navigation-auto-add-pages-publish-panel % Change
timeToFirstByte 39.4 ms +2.41% -4.19% 38.35 ms +1.17% -3.39% 2.74%
largestContentfulPaint 72 ms +0% -0% 70 ms +2.86% -2.86% 2.86%
lcpMinusTtfb 32.6 ms +4.6% -4.14% 31.3 ms +8.47% -3.67% 4.15%
wpBeforeTemplate 20.77 ms +3.13% -1.35% 20.24 ms +4.59% -0.64% 2.62%
wpTemplate 14.25 ms +8.28% -2.95% 14.3 ms +5.59% -3.99% -0.35%
wpTotal 35.88 ms +3.18% -3.37% 34.81 ms +2.13% -2.79% 3.07%
wpMemoryUsage 6.46 MB +0% -0% 6.45 MB +0% -0% 0.01%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 157b88e add/navigation-auto-add-pages-publish-panel % Change
mediaProcessingJpeg 344.53 ms +0.64% -0.26% 343.12 ms +0.96% -0% 0.41%
mediaProcessingAvif 4889.77 ms +0.91% -0.2% 4871.43 ms +0.34% -1.1% 0.38%
mediaProcessingJpegToAvif 3315.71 ms +0.86% -0.19% 3302.16 ms +1.14% -0.55% 0.41%

media-upload

Metric 157b88e add/navigation-auto-add-pages-publish-panel % Change
jpegUploadProcessing 1485.95 ms +1.82% -1.03% 1477.8 ms +1.27% -1.07% 0.55%
pngUploadProcessing 246.67 ms +3.01% -1.36% 248.55 ms +4.83% -4.71% -0.76%
largeJpegUploadProcessing 1465.85 ms +0.3% -0.51% 1474.59 ms +0.29% -0.94% -0.59%
multipleImageUploadProcessing 1557.14 ms +0.68% -0.45% 1559.91 ms +1.88% -0.81% -0.18%

post-editor

Metric 157b88e add/navigation-auto-add-pages-publish-panel % Change
serverResponse 458.34 ms +2.96% -7.35% 468.71 ms +0.59% -9.24% -2.21%
firstPaint 387.51 ms +4.38% -2.54% 438.09 ms +1.08% -10.64% -11.55%
domContentLoaded 806.53 ms +4.17% -0.79% 799.99 ms +2.01% -1.02% 0.82%
loaded 807.41 ms +4.16% -0.78% 800.98 ms +2.02% -1.01% 0.8%
firstContentfulPaint 456.44 ms +6.68% -2.38% 447.04 ms +1.84% -1.18% 2.1%
firstBlock 2206.33 ms +5.76% -1.49% 2168.8 ms +1.18% -1.04% 1.73%
type 18.18 ms +5.12% -7.32% 17.99 ms +4.5% -12.17% 1.06%
typeWithoutInspector 16.32 ms +5.27% -4.17% 16.56 ms +10.33% -7.37% -1.45%
typeWithTopToolbar 22.51 ms +8.26% -5.38% 22.4 ms +5.94% -10.54% 0.49%
typeContainer 8.49 ms +8.72% -8.6% 8.06 ms +16.63% -2.61% 5.33%
focus 105.9 ms +2.71% -3.94% 105.06 ms +2.37% -7.02% 0.8%
firstFocus 276.69 ms +0% -0% 251.62 ms +0% -0% 9.96%
selectAll 395.37 ms +0.99% -3.5% 391.85 ms +3.98% -0.17% 0.9%
undo 28.77 ms +4.17% -5.77% 28.67 ms +2.55% -5.72% 0.35%
listViewOpen 37.7 ms +5.94% -5.31% 39.79 ms +15.66% -9.47% -5.25%
inserterOpen 40.66 ms +6.2% -6.62% 38.92 ms +7.68% -7.35% 4.47%
inserterHover 10.78 ms +5.29% -11.13% 11.16 ms +5.91% -7.71% -3.41%
inserterSearch 8.16 ms +4.04% -5.51% 8.27 ms +10.04% -7.74% -1.33%
loadPatterns 602.91 ms +2.78% -1.25% 615.8 ms +5.74% -2.74% -2.09%
wpTotal 448.04 ms +3.2% -7.37% 459.14 ms +0.59% -9.42% -2.42%
wpMemoryUsage 14.82 MB +0% -0% 14.82 MB +0% -0% 0.03%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 157b88e add/navigation-auto-add-pages-publish-panel % Change
serverResponse 487.5 ms +0.64% -8.13% 467.72 ms +9.26% -5.49% 4.23%
firstPaint 464.44 ms +10.34% -13.43% 472.69 ms +3.16% -17.22% -1.75%
domContentLoaded 886.12 ms +1.63% -2.22% 873.84 ms +0.53% -1.17% 1.41%
loaded 887.15 ms +1.62% -2.19% 875.02 ms +0.51% -1.16% 1.39%
firstContentfulPaint 500.89 ms +2.57% -2.63% 483.01 ms +1.07% -0.61% 3.7%
firstBlock 2775.53 ms +0.84% -1.41% 2707.45 ms +1.01% -1.31% 2.51%
type 19.92 ms +9.44% -8.23% 19.33 ms +5.74% -13.55% 3.05%
navigate 120.68 ms +5.54% -1.29% 122.14 ms +4.85% -4.7% -1.2%
loadPatterns 1606.33 ms +4.6% -7.46% 1666.15 ms +3.3% -17.75% -3.59%
loadPages 969.66 ms +3.39% -1.03% 1002.28 ms +1.81% -1.02% -3.25%
wpTotal 477.78 ms +0.58% -8.29% 457.48 ms +9.57% -5.5% 4.44%
wpMemoryUsage 12.86 MB +0% -0% 12.85 MB +0% -0% 0.04%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

4087cfc Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

should give the image its context menu while selected @WebKit @Firefox in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Test timeout of 100000ms exceeded.

4087cfc Run

@jeryj
jeryj force-pushed the add/navigation-auto-add-pages-publish-panel branch from c69f8b8 to 39587eb Compare October 27, 2026 18:29
@jeryj
jeryj force-pushed the add/navigation-choose-menus-on-publish branch from bc0ec2e to ade55fe Compare October 27, 2026 18:29
@jeryj
jeryj force-pushed the add/navigation-auto-add-pages-publish-panel branch from 39587eb to 7b923be Compare October 27, 2026 18:59
@jeryj
jeryj requested a review from fabiankaegy as a code owner October 27, 2026 18:59
@jeryj
jeryj force-pushed the add/navigation-choose-menus-on-publish branch from ade55fe to 21159ab Compare October 27, 2026 18:59
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Oct 27, 2026
jeryj and others added 2 commits October 27, 2026 14:00
…t is published

The pre-publish panel of a page lists every Navigation Menu with a checkbox. The menus that "Auto add pages" would add the page to start checked, a menu that already links to the page is checked and locked, and any other menu can be checked. A change is sent with the page as a write-only `navigation_menus` REST field, which the status transition uses instead of the setting for that page only: an unchecked menu keeps its setting and still gets the next page.

The hook now builds on gutenberg_navigation_add_post_link( $menu_id, $post ), a public function that adds a link to a post to one menu, nested under the link to its parent when there is one and appended otherwise, so a plugin can add a link to one of its pages to a menu it knows the ID of.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0199oMWAas4xDSnjTYeDtPxL
Each menu row links to the menu's screen in the site editor with a "View" link that opens in a new tab, so the author can look at the menu without leaving the publish flow. The link replaces the "Edit" one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0199oMWAas4xDSnjTYeDtPxL
@jeryj
jeryj force-pushed the add/navigation-auto-add-pages-publish-panel branch from 7b923be to ce97ed6 Compare October 27, 2026 19:00
@jeryj
jeryj force-pushed the add/navigation-choose-menus-on-publish branch from 21159ab to 7b7ffa1 Compare October 27, 2026 19:01
@github-actions github-actions Bot removed the [Package] Block library /packages/block-library label Oct 27, 2026
jeryj and others added 6 commits October 27, 2026 14:10
The selector built a new object and rows array on every call, which trips the `useSelect` consistency check and failed the pre-publish panel's unit test. It now returns the records array and primitives, and the rows derive from them in a memo.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0199oMWAas4xDSnjTYeDtPxL
…avigation-choose-menus-on-publish

# Conflicts:
#	lib/compat/wordpress-7.2/navigation-auto-add-pages.php
#	packages/editor/src/components/post-publish-panel/maybe-navigation-menus-panel.tsx
…avigation-choose-menus-on-publish

# Conflicts:
#	lib/compat/wordpress-7.2/navigation-auto-add-pages.php
jeryj and others added 2 commits November 24, 2026 13:44
The site editor's Duplicate action copied only the title and content, so
the copy of a menu with the setting on had it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1u1vfDfpUYw8PAkEUWnB7
@github-actions github-actions Bot added the [Package] Edit Site /packages/edit-site label Nov 24, 2026
jeryj added a commit that referenced this pull request Nov 24, 2026
jeryj and others added 2 commits November 24, 2026 14:44
…avigation-choose-menus-on-publish

# Conflicts:
#	test/e2e/specs/editor/blocks/navigation-auto-add-pages-publish-panel.spec.ts
Trunk now requires new files in the e2e tests to be TypeScript (#84829). Menus with "Auto add new pages" on are created through the REST API, since `createNavigationMenu()` takes only a title and content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the [Package] Edit Site /packages/edit-site label Nov 24, 2026
jeryj and others added 5 commits December 1, 2026 13:23
…avigation-choose-menus-on-publish

# Conflicts:
#	lib/load.php
#	packages/editor/CHANGELOG.md
… compat folder

WordPress 7.2 has branched, so new features now target 7.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…avigation-choose-menus-on-publish

# Conflicts:
#	lib/compat/wordpress-7.3/navigation-auto-add-pages.php
#	packages/editor/CHANGELOG.md
The WordPress 7.3 compat folder is analyzed at PHPStan's strict level. Read the request's menu IDs with `wp_parse_id_list()`, read the page ID only when it is numeric, type the stored choices, and state the void returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeryj
jeryj marked this pull request as draft December 1, 2026 21:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block [Package] Editor /packages/editor REST API Interaction Related to REST API [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant