Skip to content

Conversation

@jorgefilipecosta
Copy link
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.

Summary

This PR adds a core/get-settings ability to the WordPress Abilities API. This ability dynamically discovers and exposes all WordPress settings. For now all abilities that are register show_in_rest = true are exposed. We should probably have a setting related to the ability exposition but can be a follow.

Organization

Following the pattern established in #10665, this PR adds a new class WP_Settings_Abilities in src/wp-includes/abilities/class-wp-settings-abilities.php. The class is organized into:

  • Initialization: init() method that collects available groups and builds the output schema
  • Schema Building: build_output_schema() creates a rich JSON Schema from registered settings metadata
  • Ability Registration: register_get_settings() registers the ability with dynamic schemas
  • Execution: execute_get_settings() retrieves and returns settings grouped by their registration group
  • Utilities: Helper methods for permission checking and value type casting

Test plan

  • Open http://localhost:6888/site-wp-dev-1/wp-admin/post-new.php
  • Open the browser console and run the following examples:
// Get all settings
await wp.apiFetch({
  path: '/wp-abilities/v1/abilities/core/get-settings/run',
  method: 'POST',
  data: { input: {} }
});
  • Verify all settings are returned grouped by their registration group (general, reading, writing, discussion)
// Get only general settings
await wp.apiFetch({
  path: '/wp-abilities/v1/abilities/core/get-settings/run',
  method: 'POST',
  data: { input: { group: 'general' } }
});
  • Verify only general settings are returned when filtering by group
// Check the ability schema
await wp.apiFetch({
  path: '/wp-abilities/v1/abilities/core/get-settings',
  method: 'GET'
});
  • Verify the input schema includes a dynamic enum of available groups

  • Verify the output schema documents each group and its settings with types, descriptions, and defaults

  • Test permission check: Verify non-admin users cannot access the ability (requires manage_options capability)

@github-actions
Copy link

github-actions bot commented Jan 16, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta, mukesh27, justlevine, jason_the_adams.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@jorgefilipecosta jorgefilipecosta changed the title Initial implementation Add: WordPress Core get settings ability Jan 16, 2026
@github-actions
Copy link

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/get-settings-ability branch 2 times, most recently from c7d29ed to 5881244 Compare January 21, 2026 16:05
jorgefilipecosta and others added 15 commits January 21, 2026 17:48
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Dovid Levine <justlevine@gmail.com>
Addresses review feedback to add support for filtering settings by
specific setting slugs. The input schema now supports both `group`
and `slugs` parameters with a oneOf relationship making them
mutually exclusive.

- Add $available_slugs static property
- Add get_available_slugs() method to collect setting slugs
- Update input_schema with slugs parameter and oneOf constraint
- Update execute_get_settings() to filter by slugs when provided
Use explicit union type (string|bool|int|float|array) instead of
mixed for better type safety and documentation.
@jorgefilipecosta jorgefilipecosta force-pushed the add/get-settings-ability branch from f7bc83e to 00a6bbd Compare January 21, 2026 17:48
@github-actions
Copy link

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

@jorgefilipecosta
Copy link
Member Author

Hi @justlevine, @mukeshpanchal27, thank you both for the reviews, I tried to address or answerer them all. I think it is ready for another pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgefilipecosta Out of curiosity, why are we coupling this to the REST API? Why would this Ability limit itself to settings that are configured to work with REST? Or am I misunderstanding something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm inclined away from using a preexisting configuration in an unexpected way.

@JasonTheAdams
Copy link
Member

I guess I'm also not understanding the purpose of this Ability. Why would someone use this over the get_option() function? What's this for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants