Skip to content

Abilities API: Add the core/settings-update ability - #10892

Closed
jorgefilipecosta wants to merge 22 commits into
WordPress:trunkfrom
jorgefilipecosta:add/update-settings-ability
Closed

jorgefilipecosta wants to merge 22 commits into
WordPress:trunkfrom
jorgefilipecosta:add/update-settings-ability

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Feb 9, 2026 •

Copy link
Copy Markdown
Member

Part of: WordPress/ai#40
Inspired by the work on https://github.com/galatanovidiu/mcp-adapter-implementation-example/tree/experiment/layerd-mcp-tools/includes/Abilities by @galatanovidiu.
Follow-up to #12141, with the shape from WordPress/abilities#22.

This PR adds the core/settings-update ability to the site category, for the settings registered with show_in_abilities:

  • It takes { data }, with one property per setting to change, named as in core/settings-get, and returns the saved values of those settings.
  • A null value resets a setting to its default, and stores the default so requests that do not register the setting read it too. A setting without a default has its stored value deleted, except date_format, time_format, default_category, show_on_front, default_comment_status and default_ping_status, which refuse null because Core needs their values.
  • The input is validated against the schema before anything is saved, so a call that returns an error changes nothing.
  • A value that matches the schema but that the setting cannot use is refused with settings_invalid_value, and the error data maps each refused setting to its message under params. This covers an unknown timezone, a language that is not installed, an unknown default_post_format, a page setting that is not 0 or the ID of a page, or is a page in the trash or an auto-draft, and a default_category that is not the ID of a category.
  • Every setting registered with show_in_abilities can be updated, except the read-only ones below, including the settings a plugin exposed for core/settings-get before this ability existed. This is intended, and no separate opt-in for writing is added.
  • A setting that should stay read-only sets readonly to true in its schema: it can be read with core/settings-get, but not updated.
  • The WordPress address (url), the site address and the administration email address (email) are read-only for this ability, under whatever name a plugin exposes them. Settings > General only changes the administration email address after the new address confirms it.
  • The ability requires the manage_options capability, and changing the privacy policy page also requires manage_privacy_options.
  • src/wp-includes/abilities is added to the strict PHPStan configuration, with the existing errors in the baselines.

Updating some settings:

await wp.apiFetch( {
	path: '/wp-abilities/v1/abilities/core/settings-update/run',
	method: 'POST',
	data: {
		input: {
			data: { title: 'Launch notes', description: 'News about the launch', posts_per_page: 5 },
		},
	},
} );
{ "title": "Launch notes", "description": "News about the launch", "posts_per_page": 5 }

Going back to the default with null:

await wp.apiFetch( {
	path: '/wp-abilities/v1/abilities/core/settings-update/run',
	method: 'POST',
	data: { input: { data: { posts_per_page: null } } },
} );
{ "posts_per_page": 10 }

Trac ticket: https://core.trac.wordpress.org/ticket/64616

Follow-up work

  • Rules of single settings: the ability keeps private lists of the settings that are read-only, that refuse null and that have value rules. The long-term solution is for each setting to declare its rules when it is registered. The lists are private, so they can be removed then:
    • Read-only settings: url and email set readonly where they are registered, in register_initial_settings(), and the list of read-only options is removed from the ability. Abilities API: Allow marking a show_in_abilities object as read only #16288 adds a readonly marker to show_in_abilities, so this comes after it, with a single marker.
    • Value rules and settings that refuse null: a validate_callback argument of register_setting(), next to sanitize_callback, that core/settings-update calls before saving.
  • Page settings: a page in any status other than the trash or an auto-draft is accepted, such as a draft, pending, private or scheduled page. Settings > Reading only offers published pages, but only in its form, so the rule belongs in the Settings API, for every caller.
  • Reset values: date_format, time_format, default_category, show_on_front, default_comment_status and default_ping_status have no registered default, so they refuse null here, while the settings REST route deletes them. start_of_week has no registered default either, and null deletes it here and in the settings REST route, so the week then starts on Sunday instead of the install default (Monday in English). Registering a reset value for each would let both reset them.
  • Fixed UTC offsets: only timezone_string is exposed (timezone). A site on a fixed offset, such as UTC+2, stores it in gmt_offset and keeps timezone_string empty, so the abilities show an empty timezone and cannot change the offset. Exposing gmt_offset alone is not safe, because core calculates it from timezone_string, and only the Settings > General form keeps the two in sync.

Testing

Verify unit tests are passing:

npm run test:php -- --group 64616

Or run the examples above in the editor console as an administrator.

AI disclosure: the change and tests were drafted with AI assistance (Claude Code).

@github-actions

github-actions Bot commented Feb 9, 2026 •

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, westonruter, justlevine, gziolo.

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.

@jorgefilipecosta jorgefilipecosta changed the title initial version Add: WordPress Core update settings ability Feb 9, 2026
@github-actions

github-actions Bot commented Feb 9, 2026

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@jorgefilipecosta
jorgefilipecosta force-pushed the add/update-settings-ability branch from eb0ef04 to e582d44 Compare February 12, 2026 11:02
@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Thank you @westonruter for reviewing this PR, all your suggestions were applied.

@justlevine

Copy link
Copy Markdown

Related to https://core.trac.wordpress.org/ticket/64605, but since that got merged I'll ask here. How exactly does show_in_abilities work here?

Is show_in_abilities: bool|array{schema:array<string,mixed}, or are we in an awkward place where show_in_abilities is a bool, but we're going to infer any schemas from show_in_rest['schema'] ? I'm also not seeing anywhere in this or that PR where's we're loading/coercing the existing schema, am I missing it or was it left out for some reason?

@jorgefilipecosta
jorgefilipecosta force-pushed the add/update-settings-ability branch 2 times, most recently from 6ef6754 to d129749 Compare February 17, 2026 16:45
@gziolo gziolo mentioned this pull request Mar 9, 2026
6 of 7 tasks
@jorgefilipecosta
jorgefilipecosta force-pushed the add/update-settings-ability branch from d129749 to c20d3ff Compare November 17, 2026 22:02
@jorgefilipecosta jorgefilipecosta changed the title Add: WordPress Core update settings ability Abilities API: Add the core/settings-update ability Nov 17, 2026
@jorgefilipecosta jorgefilipecosta added the Core abilities Core abilities related tasks label Nov 19, 2026
@jorgefilipecosta jorgefilipecosta moved this from Todo to Neeeds review in Core abilities Nov 19, 2026
@jorgefilipecosta jorgefilipecosta self-assigned this Nov 20, 2026
@jorgefilipecosta
jorgefilipecosta force-pushed the add/update-settings-ability branch from c20d3ff to ad65fc0 Compare November 24, 2026 15:56
…epeated capability check in `core/settings-update`.

A false value written over a stored value no longer adds the option again, which could change its autoload value. A value equal to the default that get_option() reads is now added only when no value is stored.

The execute callback no longer checks `manage_options` again. The required capability decides who can run the ability, so a `wp_ability_permission_result` filter that grants the call, or changed required capabilities, now also allow the update. Setting the privacy policy page still requires `manage_privacy_options`.

See #64616.
…allback in `core/settings-update`.

The privacy policy page check now runs as the permission callback of the ability, so `check_permissions()` reports it before the ability runs and the `wp_ability_permission_result` filter applies to it. A refused call now returns `ability_invalid_permissions`.

A null value is now refused while the setting has a stored value that `core/settings-get` leaves out, also for a setting with a default.

A schema with a top-level `anyOf` or `oneOf` now accepts null through an `anyOf` with a null schema, and a schema whose type is already a list gets null added to that list.

The site address (`home`) is now read-only too, and the read-only and capability rules compare the option name trimmed, as the options API stores it.

An empty `default_post_format` is now accepted as the standard format, as `0` is.

Also addresses review feedback:
* The execute callback sanitizes its input, as the permission callback does.
* The value schema helper has PHPStan shapes.
* The docblocks say that a callback that runs while a value is saved can still stop the call after earlier settings were saved, and that settings exposed before become writable unless their schema sets `readonly` to true.
* A comment notes that a page in a status other than the trash or an auto-draft is still accepted.
* New tests cover the permission filter, unprepared input, the read-only options and the combining keywords.

See #64616.
…t and the default category in `core/settings-update`.

These settings have no registered default, so a null value deleted them, and without a value dates and times show as empty strings and new posts get no category. Their input schema no longer accepts null, whatever name exposes them. They can still be updated with a value.

See #64616.
…gs-update`.

When no value is stored and the sanitized value matches the default that get_option() reads, update_option() stores nothing, so requests that do not register the setting read false. The default that reads is now stored whenever a write leaves no stored value, for example `-10` for the number of posts per page.

Also addresses review feedback:
* The input schema of a setting drops the default in one place.
* The execute callback keeps the values to write apart from the input.
* The `register_setting()` docblock no longer says "including settings exposed before", and names the settings that cannot be updated or reset.
* The comment in wp_register_core_abilities() names both settings abilities.

See #64616.
…ore/settings-update`.

The read-only, reset and privacy policy page rules now compare the option name in lower case, the way the database matches it, to fix possible inconsistencies.

Also addresses review feedback:
* The ability description, the `register_setting()` docblock and a test docblock name the WordPress address as read-only.
* An invalid stored value is reported with its own message instead of "Invalid parameter(s)".
* The language and page value errors reuse existing translated strings.
* The repeated paragraphs in register() are merged.
* The value schema helpers drop the unused list type handling, and their PHPStan shapes say the type is a single type.
* The settings tests share one administrator instead of creating one per call.

See #64616.
… of `core/settings-update`.

The value rules and the `en_US` language mapping now compare the option name in lower case, the way the read-only, reset and privacy policy page rules do, to fix possible inconsistencies.

Also simplifies the tests:
* The value rule test covers each option registered in another case.
* The tests that store a core default are rows of the read-default data provider, which now also checks that no other option changes.

See #64616.
…ngs-update`.

The value schema helper now adds `null` to the type with `array_merge()`, so a type that is already a list stays a flat list instead of being nested. Its PHPStan shapes accept a single type or a list of types.

See #64616.
…e settings abilities.

The output schema helper of `WP_Abilities_Settings` is private, so no caller needs to know that it was renamed and got new parameters in 7.3.0.

See #64616.
…ttings abilities.

The array shape of an exposed setting was repeated in six `@var`, `@param` and `@return` tags of `WP_Abilities_Settings`. It is now declared once as a PHPStan type on the class. The standard tags describe a plain array, and `@phpstan-var`, `@phpstan-param` and `@phpstan-return` tags carry the exact shape.

See #64616.
…s with a verb.

Renames two private methods of `WP_Abilities_Settings`, so every method of the class starts with a verb:
* `nullable_schema()` is now `get_nullable_schema()`.
* `value_schema()` is now `get_value_schema()`.

See #64616.
The docblocks of `get_update_value_schema()`, `get_nullable_schema()` and `get_invalid_value_message()` described each step of the code, so a change to the code also meant a change to the documentation. They now keep the summary, and the reasons that are not clear from the code are inline comments next to the lines they explain.

See #64616.
…ettings-update`.

`show_on_front`, `default_comment_status` and `default_ping_status` have no registered default, so a null value deleted them. Without a value, `is_front_page()` is false on the posts home page, and new posts get an empty comment and ping status. They are now in the list of options that cannot be reset, next to `date_format`, `time_format` and `default_category`.

The description of the ability and of `data` no longer name the settings. They say that a setting whose schema does not accept null cannot be reset.

In the tests, a test setting that lists its allowed values takes the place of `default_ping_status` where a setting that can be reset is needed.

See #64616.
@jorgefilipecosta
jorgefilipecosta force-pushed the add/update-settings-ability branch from 8e15447 to 99d4a08 Compare December 1, 2026 16:06
…level.

Adds `src/wp-includes/abilities` to the paths of `phpstan-strict.neon.dist`, so that new code in the core abilities is held to rule level 10.

The 21 errors that the existing code reports at that level are added to the strict baselines with `composer phpstan:baselines`: 12 in `WP_Abilities_Content`, 4 in `WP_Abilities_Settings` and 5 in `WP_Abilities_Users`.

See #64616.
@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Hi @westonruter, thank you for checking, I added src/wp-includes/abilities to the strict config and the 21 existing errors to the baselines.

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Hi @gziolo, thank you for testing everything again 😊 I agree with the final shape, each setting should declare its rules when it is registered. I applied the NON_RESETTABLE_OPTIONS note and the style comments. For now I would keep the lists in the ability, as they are private and can be removed later, and then we work on the long term solution, I added it to the follow-up work in the PR description.

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Hi @gziolo, thank you for the reviews, I applied all the feedback or tracked it as follow-up work in the PR description.

@gziolo

gziolo commented Dec 1, 2026

Copy link
Copy Markdown
Member

@jorgefilipecosta, sounds good to me. I will do another pass tomorrow with the goal to approve with the marked follow-up task as discussed 👍🏻

@gziolo

gziolo commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks for the updates! I tested changes locally and everything works as expected. show_on_front, default_comment_status, and default_ping_status now reject null. After those calls, WordPress still recognizes the posts homepage as the front page, and new posts inherit the configured comment and ping statuses.

That addresses the remaining issue from my review. I’m happy to approve with the follow-up work listed in the PR description.

Before commit, could you copy that list to Trac #64616 and link any existing tickets there? That will give contributors one place to find the remaining work after this lands. We most likely want to keep the ticket open until all follow-up tasks are resolved.

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Thank you for the review @gziolo, the follow-up tasks are now listed at https://core.trac.wordpress.org/ticket/64616#comment:33.

wporg-sync pushed a commit that referenced this pull request Dec 2, 2026
Add a `core/settings-update` ability that updates the settings registered with `show_in_abilities`, named as in `core/settings-get`, and returns their saved values. A `null` value resets a setting to its default. Values are validated before anything is saved, and the ability requires the `manage_options` capability.

Developed in #10892.

Props jorgefilipecosta, gziolo, westonruter, justlevine.
See #64616.

git-svn-id: https://develop.svn.wordpress.org/trunk@65861 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Dec 2, 2026
Add a `core/settings-update` ability that updates the settings registered with `show_in_abilities`, named as in `core/settings-get`, and returns their saved values. A `null` value resets a setting to its default. Values are validated before anything is saved, and the ability requires the `manage_options` capability.

Developed in WordPress/wordpress-develop#10892.

Props jorgefilipecosta, gziolo, westonruter, justlevine.
See #64616.
Built from https://develop.svn.wordpress.org/trunk@65861


git-svn-id: http://core.svn.wordpress.org/trunk@64890 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@jorgefilipecosta

jorgefilipecosta commented Dec 2, 2026 •

Copy link
Copy Markdown
Member Author

Closed committed at WordPress/WordPress@29b6043.

@github-project-automation github-project-automation Bot moved this from Neeeds review to Done in Core abilities Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core abilities Core abilities related tasks

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants