Skip to content

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

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

jorgefilipecosta wants to merge 2 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).

…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.
@github-actions

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.

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

Comment on lines +779 to +781
* @return array<string, array{0: string, 1: mixed}>
*/
public function data_update_item_with_value_inside_schema() {

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.

Suggested change
* @return array<string, array{0: string, 1: mixed}>
*/
public function data_update_item_with_value_inside_schema() {
* @return array<non-falsy-string, array{ 0: non-falsy-string, 1: mixed }>
*/
public function data_update_item_with_value_inside_schema(): array {

Comment on lines +762 to +765
* @param string $setting The name of the setting.
* @param mixed $value The value to send.
*/
public function test_update_item_with_value_inside_schema( $setting, $value ) {

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.

Suggested change
* @param string $setting The name of the setting.
* @param mixed $value The value to send.
*/
public function test_update_item_with_value_inside_schema( $setting, $value ) {
* @param non-falsy-string $setting The name of the setting.
* @param mixed $value The value to send.
*/
public function test_update_item_with_value_inside_schema( string $setting, $value ) {

Comment on lines +744 to +746
* @return array<string, array{0: string, 1: mixed}>
*/
public function data_update_item_with_value_outside_schema() {

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.

Suggested change
* @return array<string, array{0: string, 1: mixed}>
*/
public function data_update_item_with_value_outside_schema() {
* @return array<non-falsy-string, array{ 0: non-falsy-string, 1: mixed }>
*/
public function data_update_item_with_value_outside_schema(): array {

Comment on lines +726 to +729
* @param string $setting The name of the setting, which is also the name of its option.
* @param mixed $value The value to send.
*/
public function test_update_item_with_value_outside_schema( $setting, $value ) {

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.

Suggested change
* @param string $setting The name of the setting, which is also the name of its option.
* @param mixed $value The value to send.
*/
public function test_update_item_with_value_outside_schema( $setting, $value ) {
* @param non-falsy-string $setting The name of the setting, which is also the name of its option.
* @param mixed $value The value to send.
*/
public function test_update_item_with_value_outside_schema( string $setting, $value ) {

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