Add a core/settings ability#691
Conversation
|
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. |
4c74702 to
413c6a4
Compare
413c6a4 to
7d9a1b2
Compare
Add the core/settings ability, matching the equivalent WordPress core change. Read-only; returns settings flagged show_in_abilities as a flat name => value map, filterable by group or by name, gated on manage_options. The Settings class is kept near-identical to core's WP_Settings_Abilities and registers at priority 11, unregistering any core-provided copy first so the plugin wins when both are present. A generic Show_In_Abilities component seeds the show_in_abilities flag onto a curated set of core settings so the ability returns data on a stock site. Includes a Playwright e2e spec that drives the ability through the @wordpress/abilities client. Keeps the output schema free of unsupported formats and per-property defaults so the client-side validator accepts it and does not inject defaults into filtered results.
…ent enabled The @wordpress/abilities client modules are only added to the editor's import map when an AI experiment is enabled (its script declares them as module_dependencies). Enable Excerpt Generation and drive the test from a new post instead of skipping when the client is unavailable.
52920c8 to
a431013
Compare
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
'settings' reads more naturally than 'slugs' for an ability about settings:
executeAbility( 'core/settings', { settings: [ 'blogname' ] } ).
Add an e2e sample plugin that registers a setting with show_in_abilities, map it in .wp-env.test.json, and assert the core/settings ability returns it.
|
@jeffpaul or @dkotter, what are the conditions for this new (and other planned) ability to get included in the AI plugin? Code-wise it's shaping up nicely according to what we discussed in #40 and in https://core.trac.wordpress.org/ticket/64605. The idea would be to land it in the plugin first for early testing, and then put it in WordPress core. |
| */ | ||
| public static function settings_map(): array { | ||
| return array( | ||
| // General. |
There was a problem hiding this comment.
Noting that some settings will get duplicated between core/get-site-info and core/settings.
It seems like we will have to follow up in WP core to replicate show_in_abilities check inside core/get-site-info once that concept is there.
More broadly, show_in_abilities might probably need more variety, for example:
`show_in_abilities` => true,
`show_in_abilities` => false,
`show_in_abilities` => 'read',
`show_in_abilities` => 'write',There was a problem hiding this comment.
Yah show_in_abilities will pass by some evolution in some cases like show_in_rest it may also need to pass schema information, and read/write distinction may also be a good approach. Would you want me to already include read/write distinction as part of this PR or do you think this is something for the future?
- Simplify the input schema: replace the group-XOR-name `oneOf` with optional,
combinable `group` and `fields` filters (rename `settings` -> `fields`, matching
core/get-site-info). Default to an empty object so the type:object schema default
serializes as {}.
- Memoize the exposed settings so the input/output schema and execute() derive from a
single walk of get_registered_settings().
- Cast object-typed values to objects so they serialize as {} (not []) and satisfy the
output schema validated by execute().
- Drop the redundant `site` ability-category fallback (core registers it and the plugin
requires WP 7.0).
- Use __() instead of esc_html__() for ability strings, and @SInCE x.x.x per CONTRIBUTING.md.
- Harden value handling so the new code passes PHPStan at the strictest level.
- Tests: assert keys order-insensitively and cover combined group+fields filtering.
a9811cb to
66c05ed
Compare
Mirrors the fixes from the core/settings review (#691) that also apply here: - Memoize the exposed post types so the input schema and the permission/execute callbacks derive from a single walk of the registered post types. - Default the input schema to an empty object so the type:object default serializes as {}. - Use __() instead of esc_html__(), and @SInCE x.x.x per CONTRIBUTING.md. - Harden input/value handling (type guards, capability resolver, non-negative int helper) so the new code passes PHPStan at the strictest level. The `content` ability-category fallback is kept on purpose: unlike `site`, `content` is a new category not present on the plugin's minimum WordPress (7.0).
|
Hi @gziolo, thank you a lot for the review I think I applied/answered all the feedback. |
No real condition here, other than we typically like to utilize the things we're adding within the AI plugin (instead of just adding something others can use). But that said, if the goal here is to help prove this concept out so we can get movement upstream, that's also a fine goal and works for me. I've held off on reviewing things here as it seemed like it was till a work in progress but let me know when things are settled and I'm happy to review and get this moving along for our next release. |
Summary
Adds the
core/settingsability to the plugin, matching the equivalent WordPress core change in WordPress/wordpress-develop#12141. Read-only; returns settings flaggedshow_in_abilitiesas a flatname => valuemap (metadata in the output schema), filterable bygrouporslugs(mutually exclusive). Requiresmanage_options.Settings— registerscore/settings. Kept near-identical to core'sWP_Settings_Abilities(differences marked with// Plugin:comments). It registers at priority 11 and unregisters any core-provided copy first, so the plugin's version wins when both are present.Show_In_Abilities— seeds theshow_in_abilitiesflag onto a curated set of core settings via theregister_setting_argsfilter, so the ability returns data on a stock site before core ships the flag. Object-type-agnostic, for future reuse (post types, meta).Test plan
Prerequisite: the client-side Abilities API (
@wordpress/abilities) is only loaded in the block editor once an AI experiment is enabled — the experiment's editor script declares the@wordpress/abilities+@wordpress/core-abilitiesmodules as dependencies, which adds them to the editor's import map. So first enable an experiment such as Excerpt Generation and open a new post (post-new.php). Then, in the browser console:name => valuemap with typed valuesgroup/slugsfilters work; supplying both is rejectedmanage_options) is deniedIntegration tests added under
tests/Integration/Includes/Abilities/. An end-to-end test (tests/e2e/specs/abilities/core-settings.spec.js) drives the ability through the client-side Abilities API from the editor (with an experiment enabled).Core PR: WordPress/wordpress-develop#12141