Skip to content

REST API: Limit the show_on_front and start_of_week settings to the values they accept - #16207

Closed
jorgefilipecosta wants to merge 3 commits into
WordPress:trunkfrom
jorgefilipecosta:update/settings-schema-show-on-front-start-of-week
Closed

jorgefilipecosta wants to merge 3 commits into
WordPress:trunkfrom
jorgefilipecosta:update/settings-schema-show-on-front-start-of-week

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Related to #10892.

This PR limits two settings to the values they accept, in the schema shared by the settings REST route and the settings abilities:

  • show_on_front gets an enum with posts and page.
  • start_of_week gets a minimum of 0 and a maximum of 6.

Before, a value outside them got a successful response: show_on_front: "banana" was saved as posts, and start_of_week: 99 was saved as sent. Now the request fails with rest_invalid_param and nothing is saved, as it already does for default_ping_status and default_comment_status.

A value outside them that is already stored is returned as null by the settings route and left out by core/settings-get, like any stored value that does not match its schema.

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

Testing

Verify unit tests are passing:

npm run test:php -- --filter WP_Test_REST_Settings_Controller

Or run this in the editor console as an administrator, and verify it fails with rest_invalid_param:

await wp.apiFetch( { path: '/wp/v2/settings', method: 'POST', data: { show_on_front: 'banana' } } );

AI disclosure: the change and tests were drafted with AI assistance (Claude Code).

@github-actions

github-actions Bot commented Nov 24, 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.

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

Props jorgefilipecosta, westonruter.

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 or WordPress.org 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.

@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.

@westonruter westonruter 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.

Just some type improvements for tests, but LGTM

…he values they accept.

Adds an `enum` to the schema of `show_on_front` and a `minimum` and a `maximum` to the schema of `start_of_week`. A value outside them is now refused when the request is validated. Before, the request succeeded: `show_on_front` was saved as `posts` and `start_of_week` was saved as sent.

The schema is shared with the settings abilities, which get the same limits.
@jorgefilipecosta
jorgefilipecosta force-pushed the update/settings-schema-show-on-front-start-of-week branch from 15c660d to 79eb0e1 Compare November 30, 2026 14:14
@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Thank you for the review @westonruter, all the type suggestions were applied 😊

wporg-sync pushed a commit that referenced this pull request Nov 30, 2026
…he values they accept.

Adds an `enum` with `posts` and `page` to the schema of the `show_on_front` setting, and a `minimum` of 0 and a `maximum` of 6 to the schema of the `start_of_week` setting. A value outside them now fails with `rest_invalid_param` and nothing is saved. Before, the request succeeded: `show_on_front` was saved as `posts` and `start_of_week` was saved as sent.
A stored value outside them is returned as `null` by the settings route, like any stored value that does not match its schema. The schema is shared with the settings abilities, which get the same limits.

Developed in #16207.

Props jorgefilipecosta, westonruter, abhishekfdd.
Fixes #66804.

git-svn-id: https://develop.svn.wordpress.org/trunk@65828 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: 65828
GitHub commit: f06f375

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 Nov 30, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 30, 2026
…he values they accept.

Adds an `enum` with `posts` and `page` to the schema of the `show_on_front` setting, and a `minimum` of 0 and a `maximum` of 6 to the schema of the `start_of_week` setting. A value outside them now fails with `rest_invalid_param` and nothing is saved. Before, the request succeeded: `show_on_front` was saved as `posts` and `start_of_week` was saved as sent.
A stored value outside them is returned as `null` by the settings route, like any stored value that does not match its schema. The schema is shared with the settings abilities, which get the same limits.

Developed in WordPress/wordpress-develop#16207.

Props jorgefilipecosta, westonruter, abhishekfdd.
Fixes #66804.
Built from https://develop.svn.wordpress.org/trunk@65828


git-svn-id: http://core.svn.wordpress.org/trunk@64857 1a063a9b-81f0-0310-95a4-ce76da25c4cd
*
* @return array<non-falsy-string, array{ 0: non-falsy-string, 1: mixed }>
*/
public function data_update_item_with_value_outside_schema(): array {

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.

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.

3 participants