Repository navigation
REST API: Limit the show_on_front and start_of_week settings to the values they accept - #16207
jorgefilipecosta wants to merge 3 commits into
Conversation
|
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
…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.
15c660d to
79eb0e1
Compare
|
Thank you for the review @westonruter, all the type suggestions were applied 😊 |
…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
…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 { |
There was a problem hiding this comment.
@jorgefilipecosta Per https://core.trac.wordpress.org/ticket/66755, Make data providers static.
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).