Abilities API: Add a core/manage-settings ability#90
Open
jorgefilipecosta wants to merge 2 commits into
Open
Conversation
Implements the write-oriented `core/manage-settings` ability that WP_Settings_Abilities reserved a slot for. It reuses the exposed-settings snapshot built for `core/settings`, so every setting flagged with `show_in_abilities` is both readable (`core/settings`) and writable (`core/manage-settings`), and the input/output schemas reuse the same per-setting schemas. The Abilities API validates the input against those schemas (with `additionalProperties` disabled) before execution, so an invalid or unknown value aborts the whole call before any option is written -- matching the all-or-nothing behavior of the REST settings controller. Each accepted value is sanitized against its schema, stored, then read back and cast for the response.
Covers registration and writable annotations, an input schema that mirrors the exposed settings with additionalProperties disabled, updating and returning correctly typed values, all-or-nothing aborting on an invalid value (the valid sibling must not persist), rejection of unknown keys and empty input, the manage_options permission gate, and writing a setting registered by another plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a write-oriented
core/manage-settingsability to the Abilities API, the write counterpart to the read-onlycore/settingsability from WordPress#12141.WP_Settings_Abilitiesalready reserved aregister_manage_settings()slot; this fills it in, reusing the exposed-settings snapshot and the shared helpers (get_exposed_settings(),value_schema(),cast_value()).additionalProperties: false.manage_options(shared withcore/settings).readonly: false,destructive: false,idempotent: true.Read = write
A truthy
show_in_abilitiesflag grants both read (viacore/settings) and write (viacore/manage-settings); there is no separatewritableflag. No changes tooption.phpor the exposed-settings helpers are needed.Atomic, all-or-nothing
The Abilities API validates the input against the registered input schema before
execute_manage_settings()runs, so an invalid or unknown value aborts the whole call before anyupdate_option()fires — matchingWP_REST_Settings_Controller::update_item(), which rejects the entire request when any value is invalid. Accepted values are sanitized against their schema, stored, then read back and cast for the response.Tests
Adds
Tests_Abilities_API_WpRegisterCoreManageSettingsAbilitycovering registration/annotations, the mirrored input schema, updating and returning typed values, all-or-nothing aborting on an invalid value, rejection of unknown keys and empty input, themanage_optionsgate, and writing a setting registered by another plugin. Full--group abilities-apirun: 351 tests passing.Stacked PR
Stacked on WordPress#12141 (base branch
add/core-settings-ability); that PR was rebased on latesttrunkfirst. Intended to open againstWordPress/wordpress-develop:trunkonce WordPress#12141 lands.