Skip to content

Abilities API: Read the schema default in core/settings-get - #16062

Open
mukeshpanchal27 wants to merge 3 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/abilities-settings-get-schema-default
Open

mukeshpanchal27 wants to merge 3 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/abilities-settings-get-schema-default

Conversation

@mukeshpanchal27

Copy link
Copy Markdown
Member

A setting can declare its default in show_in_rest.schema.default, or in show_in_abilities.schema.default. For a setting that was never saved, /wp/v2/settings returns that default. core/settings-get does not.

The cause is in WP_Abilities_Settings::get_exposed_settings(), which stores only the registered default argument. The settings endpoint instead reads $args['schema']['default'] in WP_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

register_setting(
	'general',
	'my_option',
	array(
		'type'              => 'string',
		'show_in_rest'      => array( 'schema' => array( 'default' => 'from-schema' ) ),
		'show_in_abilities' => true,
	)
);

Do not save the option. As an admin:

  • GET /wp/v2/settings returns "my_option": "from-schema".
  • wp_get_ability( 'core/settings-get' )->execute( array( 'fields' => array( 'my_option' ) ) ) leaves my_option out.

With this PR, both return from-schema.

Tests

  • I added three cases to data_never_saved_settings: a REST API schema default, a REST API schema default that overrides the registered default, and an abilities schema default.
  • I added test_core_settings_get_matches_the_settings_endpoint_for_a_schema_default(), which compares the ability with /wp/v2/settings directly.
  • All four new tests fail without the fix and pass with it.
  • The abilities-api group passes: 902 tests. PHPCS passes on both changed files.

core/settings-get is 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

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

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

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