Repository navigation
Options, Meta APIs: Add a validate_callback argument to register_setting() - #16384
Draft
jorgefilipecosta wants to merge 3 commits into
Draft
jorgefilipecosta wants to merge 3 commits into
jorgefilipecosta wants to merge 3 commits into
Conversation
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. |
…etting()`. A setting can be registered with a callback that checks whether it can use a value. The callback receives the value and the option name, and returns true or a `WP_Error`. It is kept with the registered setting and listed by `get_registered_settings()`; saving the option with `update_option()` does not call it. The `core/settings-update` ability calls the callback of each named setting before the first write, so a refused call still changes nothing, and returns the same `settings_invalid_value` error. The value rules of the timezone, language, default post format, default category and page settings move from the ability into callbacks registered in `register_initial_settings()`, so plugins can add rules for their own settings the same way. The front page and the page for posts now accept 0 or a published page, and the privacy policy page 0 or a published or draft page, the statuses the Settings screens offer for them. See #64616.
…d again. Registering a setting again without a `validate_callback` now keeps the callback it was registered with, so a plugin that registers a core setting again keeps the rule of Core. The language error no longer names the option. See #64616.
jorgefilipecosta
force-pushed
the
add/register-setting-validate-callback
branch
from
December 2, 2026 16:18
d66de43 to
49f5d0c
Compare
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.
Follow-up to #10892.
Currently, core/settings-update validates the values of seven core settings in a private method of the ability, and plugins have no way to add similar rules to their own settings.
This PR implements the following changes:
Trac ticket: https://core.trac.wordpress.org/ticket/66900
Testing
Verify unit tests are passing:
AI disclosure: the change and tests were drafted with AI assistance (Claude Code).