Repository navigation
Actions API: Register the homepage and posts page actions as entity actions - #84646
Closed
jorgefilipecosta wants to merge 8 commits into
Closed
jorgefilipecosta wants to merge 8 commits into
jorgefilipecosta wants to merge 8 commits into
Conversation
🤖 PR meta 🤖📦 Bundle sizeSize Change: +785 B (+0.01%) Total Size: 8.85 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
This was referenced Oct 13, 2026
Member
Author
|
Although I think isEligible should receive the registry like callback does, as in multiple cases checking information outside the item itself is required to know if the action is eligible or not, like deleting a product may require checking that there are no pending orders with that product. I'm giving a try to an alternative implementation relying on REST link information avoid us the need to do the change here. |
Draft
…elect`
`callback` receives the data registry, but `isEligible` only received
the item, so an action whose eligibility depends on the data of the
stores had to read that data in a hook and be recreated when it
changed. Pass `{ registry }` to `isEligible` too, and evaluate it in
`useSelect` where DataViews filters the actions: the item actions, the
list and activity layouts, the bulk actions and the picker footer.
`useSelect` subscribes to the stores `isEligible` reads, so the
eligibility is evaluated again when their data changes.
The picker footer evaluates the eligibility per action, so each of its
buttons moves to its own component. The table and grid layouts pass
the registry to the check that decides whether a row can be selected.
`PostActions`, the actions menu of the editor inspector, filters the
actions of the post with `isEligible`. Pass `{ registry }` as DataViews
does, and evaluate it in `useSelect`, so the menu is updated when the
data an action reads changes.
`usePostActions()` added "Set as homepage" and "Set as posts page" to the actions it read from the registry, so `unregisterEntityAction()` could not remove them. Make them plain actions whose `isEligible` reads the site settings and the front page template through the registry, and register them in `registerPostTypeSchema()` for pages when the user can update the site settings. They are registered last, so the menus keep the order they had.
`useSelect` calls its callback with `( select, registry )`, so pass that registry to `isEligible` instead of the one `useRegistry()` returns, and drop it from the dependencies. A component that still calls `useRegistry()` for the action callbacks can't name the callback parameter `registry` (`no-shadow`), so the filters move to two DataViews hooks: `useEligibleActions()` for the item actions and the list and activity layouts, and `useEligibleItems()` for the bulk actions and picker footer buttons. The `useSelect` mock of the post actions test passes the registry too.
jorgefilipecosta
force-pushed
the
add/homepage-entity-actions
branch
from
October 16, 2026 11:31
ed0ad29 to
f3390f8
Compare
…e` collection of `@wordpress/core-actions`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #83537.
Fixes #76668.
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 adds them to the actions the server returns, sowp_unregister_entity_actions( 'postType', 'page', array( 'set-as-homepage' ) )doesn't remove them. They are hooks because their eligibility depends on the data of the stores (the homepage, the posts page and the front page template), whileisEligibleonly receives the item.This PR follows Approach C of #76668:
isEligiblereceive{ registry }as its second argument, ascallbackalready does.isEligibleinuseSelectin the item actions, the list and activity layouts, the bulk actions and the picker footer, so the eligibility is evaluated again when the data it reads through the registry changes. The table and grid layouts also pass the registry to the check that decides if a row can be selected.PostActions, the actions menu of the editor inspector.set-as-homepageandset-as-posts-pageto a newpagecollection of@wordpress/core-actionsas plain actions, with their label and modal options inaction.phpand theirisEligibleand modal inaction.tsx. TheirisEligiblekeeps the checks the hooks did: the page is published, it isn't the homepage or the posts page already, and the theme has nofront-pagetemplate.manage_options, the capability behindcanUser( 'update', { kind: 'root', name: 'site' } ), and removes them fromusePostActions(). They are registered after the other core actions, so the core actions keep the order they have on trunk.Some notes:
useSelectonly subscribes to the stores its callback reads. On wp-env, with 20 pages in the pages list, I dispatched 500 changes to the core store that no action reads (median of 7 runs): a change took 186 µs on trunk, 369 µs with this PR, and 183 µs with this PR and the two homepage actions unregistered. So the extra cost, about 9 µs per row, comes from the two actions reading the site settings and the templates, and the actions that only check the item cost the same as before. Loading the pages list until the action menus show took about 1.47 s in both.callback, so I opted for passing it toisEligibletoo, which keeps both functions symmetric. The actions read the stores through that registry, not the globalselect(), which was the concern in Data Views: Add action for pages to set site homepage #65426.isEligibleimplementations that only take the item keep working. Code that callsisEligibleoutside DataViews should pass the registry, as it does forcallback.canUser( 'update', { kind: 'root', name: 'site' } )before showing them.usePostActions()adds them after every action the server returns.Testing Instructions
Start wp-env with a block theme that has no
front-pagetemplate (e.g. Twenty Twenty-Four), and create two published pages, "Page A" and "Page B".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 after the other actions, as on trunk.
Set "Page A" as the homepage. Without reloading, open its actions again and verify neither action shows, while "Page B" still has both.
Open "Page B" 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.
Add this mu-plugin, reload the pages list, and verify the actions of "Sample Page" no longer show "Set as homepage…" and still show "Set as posts page…". On trunk, "Set as homepage…" stays.
Log in as an editor and verify neither action shows in the pages list or in the inspector.
Enable the "Extensible Site Editor" experiment in Gutenberg > Experiments, and repeat steps 2, 3 and 5 with two new pages 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.