Skip to content

REST API: Add the homepage and posts page action links to pages - #14347

Closed
jorgefilipecosta wants to merge 3 commits into
WordPress:trunkfrom
jorgefilipecosta:add/rest-homepage-action-links
Closed

jorgefilipecosta wants to merge 3 commits into
WordPress:trunkfrom
jorgefilipecosta:add/rest-homepage-action-links

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Backports the homepage and posts page action links from WordPress/gutenberg#84932, part of WordPress/gutenberg#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-sticky and action-trash do for other actions:

  • Adds the https://api.w.org/action-set-homepage and https://api.w.org/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. Both change the site settings, so they require manage_options, like the settings route. The current homepage and posts page get neither.
  • Adds their link description objects to the schema of pages, like the other action links. The Gutenberg PR only adds the links.

Some notes:

  • The links reflect the settings when the page was requested, so a client that changes the homepage or the posts page needs to request the affected pages again. The Gutenberg PR does that after saving the settings.
  • Like the actions in the editor, the links don't check show_on_front, so the page stored in page_on_front gets neither while the homepage shows the latest posts.
  • The links don't check whether the theme has a front-page template, 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

  1. Create three published pages, "Page A", "Page B" and "Page C", and set "Page A" as the homepage in Settings > Reading.
  2. Open wp-admin/post-new.php as 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.
  3. Run the same request with context=view and verify no page has them.
  4. Log in as an editor, repeat step 2, and verify no page has them.
  5. Run npm run test:php -- --filter WP_Test_REST_Pages_Controller.

Gutenberg PR: WordPress/gutenberg#84932

Trac ticket: https://core.trac.wordpress.org/ticket/66327

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.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

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. Both change the site settings, so they require `manage_options`, and the current homepage and posts page get neither.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@jorgefilipecosta
jorgefilipecosta marked this pull request as ready for review October 16, 2026 15:01
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta, oandregal.

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

`update_option()` leaves the integer in the options cache, so these tests read an integer from `get_option()`, while a request reads a string from the database. Clearing the cache makes them fail when the `(int)` casts in `get_available_actions()` are removed.
…sts.

Adds `@ticket 66327` to the new tests and a failure message to every assertion. The schema tests now count each LDO with `wp_list_filter()` and `assertCount()`, like the other LDO tests, so an LDO added twice fails them.
wporg-sync pushed a commit 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
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 64433
GitHub commit: 8cad11e

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Oct 16, 2026
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants