Opened 10 hours ago
Closed 3 hours ago
#66327 closed enhancement (fixed)
REST API: Add action-set-homepage and action-set-posts-page links to pages
| Reported by: | jorgefilipecosta | Owned by: | jorgefilipecosta |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Adds the https://api.w.org/action-set-homepage and https://api.w.org/action-set-posts-page links to pages in the edit context, like action-trash (#63670). Published pages get them when the current user can manage_options, except the current homepage and posts page.
The editor uses these links for its "Set as homepage" and "Set as posts page" actions, so it no longer has to read the site settings. And the actions can just rely on the current self contained item information without additional API changes or requests.
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/84932
Change History (2)
This ticket was mentioned in PR #14347 on WordPress/wordpress-develop by @jorgefilipecosta.
10 hours ago
#1
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Backports the homepage and posts page action links from https://github.com/WordPress/gutenberg/pull/84932, part of https://github.com/WordPress/gutenberg/issues/83537.
Right now a client that wants to know whether a page can be set as the homepage or as the posts page needs the site settings on top of the page, and whether the user can read them. The editor reads them for its "Set as homepage" and "Set as posts page" actions. This PR lets the server say it with links, as
action-publish,action-stickyandaction-trashdo for other actions:https://api.w.org/action-set-homepageandhttps://api.w.org/action-set-posts-pagelinks to the published pages the current user can set as the homepage or as the posts page, in theeditcontext. Both change the site settings, so they requiremanage_options, like the settings route. The current homepage and posts page get neither.Some notes:
show_on_front, so the page stored inpage_on_frontgets neither while the homepage shows the latest posts.front-pagetemplate, which makes the homepage setting have no effect. It's the same for every page, so the Gutenberg PR checks it once, when it registers the actions.Testing Instructions
wp-admin/post-new.phpas an administrator. In the console, 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' ) ) ] )and verify "Page B" and "Page C" have both links and "Page A" has neither.context=viewand verify no page has them.npm run test:php -- --filter WP_Test_REST_Pages_Controller.Gutenberg PR: https://github.com/WordPress/gutenberg/pull/84932
Use of AI Tools
AI assistance: Yes
Used for: porting the code and the tests from the Gutenberg PR, and drafting this description; reviewed and edited by me.