Skip to content

Actions API: Register the homepage and posts page actions using REST links - #84932

Merged
jorgefilipecosta merged 10 commits into
trunkfrom
try/homepage-actions-rest-links
Oct 16, 2026
Merged

jorgefilipecosta merged 10 commits into
trunkfrom
try/homepage-actions-rest-links

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

Part of #83537.

Fixes #76668.

Alternative to #84646.

Right now "Set as homepage" and "Set as posts page" are not entity actions. usePostActions() creates them with hooks that read the site settings and the templates, and adds them to the actions the server returns, so a plugin can't remove them with wp_unregister_entity_actions(). They are hooks because whether a page can be set as the homepage depends on data outside the page: the current homepage and posts page, whether the user can change the site settings, and whether the theme has a front-page template.

#84646 solves this by passing the registry to isEligible. This PR keeps isEligible( item ) as it is, and lets the server say which pages the actions apply to with REST links, as the core fields already do with wp:action-publish and wp:action-sticky, and the trash actions with wp:action-trash (#84045):

  • Adds the wp:action-set-homepage and wp:action-set-posts-page links to the published pages the current user can set as the homepage or as the posts page, in the edit context. The user needs manage_options, like the settings route, and the current homepage and posts page don't get them.
  • Moves the two actions to a new @wordpress/core-actions/page script module, and registers them on the server for pages when the user can manage the options and the theme has no front-page template.
  • Makes their isEligible check the link of the action and that the page is published, without reading any store.
  • Makes their modals request the new and the previous homepage or posts page again after saving the settings, so the links, and the menus, follow the change without a reload.
  • Removes the hooks from usePostActions().

Some notes:

  • The links reflect the settings when the page was requested, so whatever changes the homepage or the posts page needs to request the affected pages again. Right now only these two modals change them without a reload (the "Reading settings" field links to wp-admin), and it's one GET /wp/v2/pages?include=… request per change.
  • I considered adding the front-page template check to the links too, but it's the same for every page, so I opted for checking it once when the actions are registered.
  • Compared to Actions API: Register the homepage and posts page actions as entity actions #84646, DataViews and the type of isEligible don't change, the eligibility doesn't add work when the stores change, and the pages list no longer makes the OPTIONS /wp/v2/settings (v1) and GET /wp/v2/templates/lookup?slug=front-page (v2) requests. The menus are the same as on trunk in both site editors and in the inspector.
  • The status is still checked in JavaScript, as the inspector shows the actions of the edited page, which can have an unsaved status.
  • Plugin actions registered for pages now come after these two, as they're registered with the core actions. On trunk they came before.
  • The text of the modals is now in a script module, so it isn't translated until Script Modules: Fix missing translations of script modules #84651 lands, like the rest of @wordpress/core-actions.
  • The links need a core backport to WP_REST_Posts_Controller::get_available_actions(), like action-trash. I'll open it if we go with this approach.

Testing Instructions

  1. Start wp-env with a block theme that has no front-page template (e.g. Twenty Twenty-Four), and create three published pages, "Page A", "Page B" and "Page C".
  2. Go to http://localhost:8888/wp-admin/site-editor.php?p=%2Fpage, open the actions of "Page A", and verify "Set as homepage…" and "Set as posts page…" show, as on trunk.
  3. Set "Page A" as the homepage. Without reloading, verify the actions of "Page A" show neither action, while "Page B" still shows both.
  4. Set "Page B" as the homepage. Without reloading, verify "Page A" shows both actions again and "Page B" shows neither.
  5. Run ( await wp.apiFetch( { path: '/wp/v2/pages?context=edit' } ) ).map( ( page ) => [ page.title.raw, Object.keys( page._links ).filter( ( rel ) => rel.startsWith( 'wp:action-set' ) ) ] ) in the browser console, and verify every published page has both links except "Page B".
  6. Open "Page C" in the post editor, set it as the posts page from the actions menu of the inspector, and verify that, without reloading, the menu no longer shows either action.
  7. Add an mu-plugin that removes "Set as homepage…", and verify the pages list only shows "Set as posts page…":
    <?php
    add_action( 'wp_entity_actions_api_init', function () {
    	wp_unregister_entity_actions( 'postType', 'page', array( 'set-as-homepage' ) );
    } );
    
  8. Log in as an editor, open a page in the post editor, and verify the inspector shows neither action.
  9. Enable the "Extensible Site Editor" experiment in Gutenberg > Experiments, and repeat steps 2 to 4 in http://localhost:8888/wp-admin/admin.php?page=site-editor-v2&p=%2Ftypes%2Fpage.

AI usage disclosure: fix and description drafted with AI assistance and reviewed by me.

@jorgefilipecosta jorgefilipecosta added [Type] Enhancement A suggestion for improvement. [Feature] Extensibility The ability to extend blocks or the editing experience (e.g. by plugins and themes) REST API Interaction Related to REST API [Package] Editor /packages/editor [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Oct 16, 2026
@github-actions github-actions Bot added the [Package] Fields /packages/fields label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 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: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: chihsuan <chihsuan@git.wordpress.org>

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

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

📦 Bundle size

Size Change: +779 B (+0.01%)

Total Size: 8.85 MB

📦 View Changed
Filename Size Change
build/modules/core-actions/page.min.js 1.83 kB +1.83 kB (new file) 🆕
build/scripts/editor/index.min.js 608 kB -1.05 kB (-0.17%)

c12df43 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric a572b60 trunk % Change
timeToFirstByte 57.1 ms +6.22% -2.89% 56.6 ms +6.8% -6.01% 0.88%
largestContentfulPaint 100 ms +2% -6% 98 ms +2.04% -6.12% 2.04%
lcpMinusTtfb 39.85 ms +13.43% -12.17% 39.5 ms +12.66% -10.76% 0.89%
wpBeforeTemplate 29.84 ms +13.24% -2.48% 29.44 ms +11.38% -2.79% 1.36%
wpTemplate 22.75 ms +4.4% -3.03% 22.11 ms +5.25% -4.34% 2.89%
wpTotal 53.29 ms +6.74% -3.04% 52.85 ms +6.58% -6.36% 0.83%
wpMemoryUsage 7.62 MB +0% -0% 7.58 MB +0% -0% 0.48%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric a572b60 trunk % Change
timeToFirstByte 43.5 ms +5.86% -1.95% 43.15 ms +8.11% -1.27% 0.81%
largestContentfulPaint 96 ms +0% -4.17% 92 ms +4.35% -0% 4.35%
lcpMinusTtfb 50.25 ms +4.48% -2.59% 49.15 ms +1.63% -1.53% 2.24%
wpBeforeTemplate 27.41 ms +7.04% -0.99% 27.22 ms +4.92% -1.91% 0.7%
wpTemplate 12.79 ms +4.85% -3.05% 12.83 ms +2.26% -3.04% -0.31%
wpTotal 40.7 ms +5.7% -2.58% 40.28 ms +6.9% -1.39% 1.04%
wpMemoryUsage 6.17 MB +0% -0% 6.13 MB +0% -0% 0.61%
wpDbQueries 10 +0% -0% 10 +0% -0% 0%

media-processing

Metric a572b60 trunk % Change
mediaProcessingJpeg 404.27 ms +2.17% -0.88% 404.76 ms +0.54% -1.08% -0.12%
mediaProcessingAvif 6062.97 ms +0.2% -0.24% 6078.66 ms +0.19% -0.27% -0.26%
mediaProcessingJpegToAvif 4185.49 ms +0.27% -0.15% 4185.95 ms +0.09% -0.22% -0.01%

media-upload

Metric a572b60 trunk % Change
jpegUploadProcessing 1456.94 ms +34.66% -1.7% 1420.42 ms +0.76% -0.1% 2.57%
pngUploadProcessing 215.94 ms +5.61% -14.19% 210.28 ms +11.26% -9.5% 2.69%
largeJpegUploadProcessing 1419.12 ms +0.49% -1.1% 1417.08 ms +0.98% -0.49% 0.14%
multipleImageUploadProcessing 1586.7 ms +8.01% -1.13% 1581.58 ms +0.61% -0.65% 0.32%

post-editor

Metric a572b60 trunk % Change
serverResponse 327.27 ms +5.44% -3% 318.1 ms +3.82% -7.55% 2.88%
firstPaint 292.57 ms +36.3% -28.82% 238.61 ms +60.56% -28.13% 22.61%
domContentLoaded 895.56 ms +3.16% -2.3% 894.7 ms +2.31% -2.28% 0.1%
loaded 896.76 ms +3.12% -2.34% 895.65 ms +2.33% -2.27% 0.12%
firstContentfulPaint 393.72 ms +4.6% -6.66% 391.76 ms +2.46% -2.92% 0.5%
firstBlock 2640.74 ms +0.88% -1.15% 2601.85 ms +1.19% -1.62% 1.49%
type 15.79 ms +1.27% -2.91% 15.96 ms +8.15% -2.13% -1.07%
typeWithoutInspector 15.98 ms +7.38% -2.13% 15.24 ms +5.38% -3.74% 4.86%
typeWithTopToolbar 19.7 ms +6.75% -5.89% 20.02 ms +10.79% -7.39% -1.6%
typeContainer 6.96 ms +7.9% -6.32% 7.12 ms +5.48% -4.78% -2.25%
focus 95.68 ms +5.82% -5.2% 87.91 ms +2.45% -2.71% 8.84%
firstFocus 197.98 ms +0% -0% 171.9 ms +0% -0% 15.17%
selectAll 458.22 ms +0.74% -0.82% 449.2 ms +1.63% -0.61% 2.01%
listViewOpen 57.67 ms +5.32% -4.79% 61.37 ms +5.96% -7.66% -6.03%
inserterOpen 33.31 ms +4.26% -3.72% 29.56 ms +13.57% -3.42% 12.69%
inserterHover 9.67 ms +6.83% -3.41% 10.25 ms +2.93% -5.17% -5.66%
inserterSearch 7.19 ms +8.48% -4.45% 6.4 ms +10.62% -5.63% 12.34%
loadPatterns 522.14 ms +4.95% -5.37% 499.05 ms +4.02% -2.13% 4.63%
wpTotal 318.52 ms +5.56% -3.1% 309.42 ms +3.8% -7.76% 2.94%
wpMemoryUsage 13.51 MB +0% -0% 13.47 MB +0% -0% 0.31%
wpDbQueries 55 +0% -0% 54 +0% -0% 1.85%

site-editor

Metric a572b60 trunk % Change
serverResponse 342.64 ms +5.45% -3.2% 335.93 ms +2.03% -2.12% 2%
firstPaint 210.17 ms +17.11% -7.59% 224.73 ms +7.95% -17.3% -6.48%
domContentLoaded 979.33 ms +0.62% -3.67% 944.81 ms +1.95% -0.84% 3.65%
loaded 980.06 ms +0.64% -3.67% 945.63 ms +1.95% -0.83% 3.64%
firstContentfulPaint 412 ms +2.46% -23.62% 408.3 ms +3.43% -18.09% 0.91%
firstBlock 3546.58 ms +1.53% -0.86% 3506.05 ms +0.76% -0.56% 1.16%
type 15.9 ms +4.53% -2.89% 16.05 ms +2.24% -3.55% -0.93%
navigate 99.78 ms +4.16% -4.44% 96.41 ms +3.96% -4.41% 3.5%
loadPatterns 1082.03 ms +11.74% -4.12% 1073.97 ms +9.2% -13.25% 0.75%
loadPages 995.55 ms +7.7% -1.81% 1090.59 ms +1.55% -9.85% -8.71%
wpTotal 334.04 ms +5.57% -3.32% 327.01 ms +2.23% -2.16% 2.15%
wpMemoryUsage 12.57 MB +0% -0% 12.53 MB +0% -0% 0.33%
wpDbQueries 44 +2.27% -0% 43 +2.33% -0% 2.33%

c12df43 Run

WordPress 7.2 adds the links in `get_available_actions()` once the backport lands, and Gutenberg's PHP tests run against WordPress trunk, so the filter now skips the links a response already has.
@jorgefilipecosta
jorgefilipecosta force-pushed the try/homepage-actions-rest-links branch from cadc1f7 to 436eb12 Compare October 16, 2026 12:49
@jorgefilipecosta
jorgefilipecosta marked this pull request as ready for review October 16, 2026 14:46

@oandregal oandregal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice work, thanks!

@jorgefilipecosta
jorgefilipecosta merged commit 55ccf8a into trunk Oct 16, 2026
129 checks passed
@jorgefilipecosta
jorgefilipecosta deleted the try/homepage-actions-rest-links branch October 16, 2026 15:01
wporg-sync pushed a commit to WordPress/wordpress-develop that referenced this pull request Oct 16, 2026
Adds the `action-set-homepage` and `action-set-posts-page` links to the published pages the current user can set as the homepage or as the posts page, in the `edit` context, and their link description objects to the pages schema. Both change the site settings, so they require `manage_options`, and the current homepage and posts page get neither. The editor uses them for its "Set as homepage" and "Set as posts page" actions.

Developed in #14347 and WordPress/gutenberg#84932.

Follow-up to [64343].

Props jorgefilipecosta, oandregal, chihsuan.
Fixes #66327.

git-svn-id: https://develop.svn.wordpress.org/trunk@64433 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 16, 2026
Adds the `action-set-homepage` and `action-set-posts-page` links to the published pages the current user can set as the homepage or as the posts page, in the `edit` context, and their link description objects to the pages schema. Both change the site settings, so they require `manage_options`, and the current homepage and posts page get neither. The editor uses them for its "Set as homepage" and "Set as posts page" actions.

Developed in WordPress/wordpress-develop#14347 and WordPress/gutenberg#84932.

Follow-up to [64343].

Props jorgefilipecosta, oandregal, chihsuan.
Fixes #66327.
Built from https://develop.svn.wordpress.org/trunk@64433


git-svn-id: http://core.svn.wordpress.org/trunk@63583 1a063a9b-81f0-0310-95a4-ce76da25c4cd
arshidkv12 pushed a commit to arshidkv12/wordpress-develop that referenced this pull request Nov 21, 2026
Adds the `action-set-homepage` and `action-set-posts-page` links to the published pages the current user can set as the homepage or as the posts page, in the `edit` context, and their link description objects to the pages schema. Both change the site settings, so they require `manage_options`, and the current homepage and posts page get neither. The editor uses them for its "Set as homepage" and "Set as posts page" actions.

Developed in WordPress#14347 and WordPress/gutenberg#84932.

Follow-up to [64343].

Props jorgefilipecosta, oandregal, chihsuan.
Fixes #66327.

git-svn-id: https://develop.svn.wordpress.org/trunk@64433 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Feature] Extensibility The ability to extend blocks or the editing experience (e.g. by plugins and themes) [Package] Editor /packages/editor [Package] Fields /packages/fields 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.

Register set-as-homepage and set-as-posts-page as entity actions

2 participants