-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add: WordPress Core update settings ability #10892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Add: WordPress Core update settings ability #10892
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * @var array | ||
| */ | ||
| private static $output_schema; | ||
| private static $settings_schema; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to PHP 7.4:
| private static $settings_schema; | |
| private static array $settings_schema; |
| * Schema for settings grouped by registration group. | ||
| * | ||
| * @since 7.0.0 | ||
| * @var array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @var array | |
| * @var array<string, mixed> |
| * @since 7.0.0 | ||
| * @var string[] | ||
| */ | ||
| private static $available_slugs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private static array $available_slugs; |
| * @since 7.0.0 | ||
| * | ||
| * @return array JSON Schema for the output. | ||
| * @return array JSON Schema for settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @return array JSON Schema for settings. | |
| * @return array<string, mixed> JSON Schema for settings. |
| * | ||
| * @return void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Core doesn't use @return void generally. (cf. r61599)
| * | |
| * @return void |
| } | ||
|
|
||
| return array( | ||
| 'updated_settings' => ! empty( $updated_settings ) ? $updated_settings : (object) array(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is (object) array() correct given that $updated_settings is an array? I suppose this forces JSON to be encoded as {} instead of []?
| * | ||
| * @type array $settings Settings to update, grouped by registration group. | ||
| * } | ||
| * @return array|WP_Error Updated settings on success, WP_Error on failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @return array|WP_Error Updated settings on success, WP_Error on failure. | |
| * @return array<string, array<string, mixed>|object>|WP_Error Updated settings on success, WP_Error on failure. |
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.
Ticket: https://core.trac.wordpress.org/ticket/64616
This PR adds a
core/update-settingsability to the WordPress Abilities API. This ability allows updating WordPress settings that haveshow_in_abilities = true. It complements the existingcore/get-settingsability by providing a symmetric API for reading and writing settings.The input and output structures are designed for symmetry with
core/get-settings:core/get-settings)updated_settings(with updated values) andvalidation_errors(with error messages) in the same grouped structureOrganization
Following the pattern established in #10747, this PR extends the
WP_Settings_Abilitiesclass insrc/wp-includes/abilities/class-wp-settings-abilities.php. The implementation maximizes code reuse:get_allowed_settings(),check_manage_options(), andcast_value()from the existing implementationregister_update_settings()registers the ability with appropriate annotations (readonly: false,destructive: false,idempotent: true)execute_update_settings()validates, sanitizes, and updates settings, returning both successful updates and validation errorsTest plan
/wp-admin/post-new.phpupdated_settingsandvalidation_errorsVerify
blognameis inupdated_settingsandunknown_settingis invalidation_errorsTest permission check: Verify non-admin users cannot access the ability (requires
manage_optionscapability)Verify settings without
show_in_abilitiescannot be modifiedVerify settings placed in wrong groups are rejected with appropriate error messages
Test plan with Gutenberg
/wp-admin/post-new.phpSet abilitiesAPI:
Run the following examples: