Repository navigation
REST API: Limit the show_on_front and start_of_week settings to the values they accept - #16207
Conversation
…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.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
westonruter
left a comment
There was a problem hiding this comment.
Just some type improvements for tests, but LGTM
| * @return array<string, array{0: string, 1: mixed}> | ||
| */ | ||
| public function data_update_item_with_value_inside_schema() { |
There was a problem hiding this comment.
| * @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 { |
| * @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 ) { |
There was a problem hiding this comment.
| * @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 ) { |
| * @return array<string, array{0: string, 1: mixed}> | ||
| */ | ||
| public function data_update_item_with_value_outside_schema() { |
There was a problem hiding this comment.
| * @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 { |
| * @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 ) { |
There was a problem hiding this comment.
| * @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 ) { |
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_frontgets anenumwithpostsandpage.start_of_weekgets aminimumof 0 and amaximumof 6.Before, a value outside them got a successful response:
show_on_front: "banana"was saved asposts, andstart_of_week: 99was saved as sent. Now the request fails withrest_invalid_paramand nothing is saved, as it already does fordefault_ping_statusanddefault_comment_status.A value outside them that is already stored is returned as
nullby the settings route and left out bycore/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:
Or run this in the editor console as an administrator, and verify it fails with
rest_invalid_param:AI disclosure: the change and tests were drafted with AI assistance (Claude Code).