Repository navigation
Abilities API: Read the schema default in core/settings-get - #16062
mukeshpanchal27 wants to merge 3 commits into
Conversation
A setting can declare its default in `show_in_rest.schema.default` or `show_in_abilities.schema.default`. The settings endpoint reads that default for a setting that was never saved, but `core/settings-get` only read the registered `default` argument. As a result, the ability left out a setting that `/wp/v2/settings` returned. This change uses the exposure schema's default when it declares one, and falls back to the registered default otherwise, matching the settings endpoint. See #64605. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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. |
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the change to settings-default precedence.
No open issues 🎉
What changed in this PR
Fixes core/settings-get so unsaved settings use the selected exposure schema’s default, falling back to the registered default when none is declared.
Changes:
- Updates default selection and its documentation.
- Adds regression cases for REST and abilities schema defaults, plus a direct comparison with
/wp/v2/settings.
| File | Description |
|---|---|
tests/phpunit/tests/abilities-api/wpRegisterCoreSettingsGetAbility.php |
Tests schema defaults, registered-default overrides, and REST endpoint parity. |
src/wp-includes/abilities/class-wp-abilities-settings.php |
Gives exposure schema defaults precedence over registered defaults. |
Review effort: Balanced
A setting can declare its default in
show_in_rest.schema.default, or inshow_in_abilities.schema.default. For a setting that was never saved,/wp/v2/settingsreturns that default.core/settings-getdoes not.The cause is in
WP_Abilities_Settings::get_exposed_settings(), which stores only the registereddefaultargument. The settings endpoint instead reads$args['schema']['default']inWP_REST_Settings_Controller::get_item(), and that value includes the schema override.This PR uses the exposure schema's default when it declares one. Otherwise it falls back to the registered default, as the settings endpoint does.
Steps to reproduce
Do not save the option. As an admin:
GET /wp/v2/settingsreturns"my_option": "from-schema".wp_get_ability( 'core/settings-get' )->execute( array( 'fields' => array( 'my_option' ) ) )leavesmy_optionout.With this PR, both return
from-schema.Tests
data_never_saved_settings: a REST API schema default, a REST API schema default that overrides the registered default, and an abilities schema default.test_core_settings_get_matches_the_settings_endpoint_for_a_schema_default(), which compares the ability with/wp/v2/settingsdirectly.abilities-apigroup passes: 902 tests. PHPCS passes on both changed files.core/settings-getis new in 7.2, so this fixes a bug before release.Trac ticket: https://core.trac.wordpress.org/ticket/64605
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the bug while reviewing 7.2 changes, drafting the fix and tests, and running the test suite. I reviewed the final code and tests.
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.
🤖 Generated with Claude Code