Add a core/manage-settings ability#764
Conversation
Implements the write-oriented core/manage-settings ability that core's WP_Settings_Abilities reserves but does not yet ship. 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 core REST settings controller. Each accepted value is sanitized against its schema, stored, then read back and cast for the response.
Extends the settings ability test suite with coverage for the write ability: 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.
Runs the write ability through the browser Abilities API, mirroring the core/settings spec: updates blogname and posts_per_page and asserts the echoed values, reads them back through core/settings to confirm they persisted, rejects an unknown setting, and writes a setting registered by another active plugin. Each test restores the original values when done.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #764 +/- ##
=============================================
+ Coverage 76.41% 76.55% +0.13%
- Complexity 1828 1839 +11
=============================================
Files 87 87
Lines 7764 7818 +54
=============================================
+ Hits 5933 5985 +52
- Misses 1831 1833 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Drops three comments that restated information available elsewhere: the class-docblock "Plugin:" note (duplicated by the method docblock), the register_manage_settings() paragraph describing atomicity (already on execute_manage_settings()), and an e2e comment restating its own assertion.
What
Adds a write-oriented
core/manage-settingsability that updates WordPress settings, the write counterpart to the read-onlycore/settingsability added in #691.Core's
WP_Settings_Abilitiesalready reserves a slot for this (register_manage_settings()) but does not yet implement it. The plugin implements it in the sameSettingsclass, 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.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 viahas_valid_params()when any value is invalid. Accepted values are sanitized against their schema, stored, then read back and cast for the response.