-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Abilities API: Support schema in show_in_abilities for settings #10954
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
Open
jorgefilipecosta
wants to merge
4
commits into
WordPress:trunk
Choose a base branch
from
jorgefilipecosta:update/support-setting-schema-on-get-settings
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5fb3965
Update: Support settings schema on get settings.
jorgefilipecosta fc9b98f
Test invalid output shcema validation
jorgefilipecosta daebd4b
remove schema duplocation
jorgefilipecosta 9051fa5
Docs: Clarify register_setting show_in_abilities schema arg
jorgefilipecosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2768,35 +2768,37 @@ function register_initial_settings() { | |
| ); | ||
|
|
||
| if ( ! is_multisite() ) { | ||
| $uri_schema = array( 'format' => 'uri' ); | ||
| register_setting( | ||
| 'general', | ||
| 'siteurl', | ||
| array( | ||
| 'show_in_rest' => array( | ||
| 'name' => 'url', | ||
| 'schema' => array( | ||
| 'format' => 'uri', | ||
| ), | ||
| 'schema' => $uri_schema, | ||
| ), | ||
| 'show_in_abilities' => array( | ||
| 'schema' => $uri_schema, | ||
| ), | ||
| 'show_in_abilities' => true, | ||
| 'type' => 'string', | ||
| 'description' => __( 'Site URL.' ), | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| if ( ! is_multisite() ) { | ||
| $email_schema = array( 'format' => 'email' ); | ||
| register_setting( | ||
| 'general', | ||
| 'admin_email', | ||
| array( | ||
| 'show_in_rest' => array( | ||
| 'name' => 'email', | ||
| 'schema' => array( | ||
| 'format' => 'email', | ||
| ), | ||
| 'schema' => $email_schema, | ||
| ), | ||
| 'show_in_abilities' => array( | ||
| 'schema' => $email_schema, | ||
| ), | ||
| 'show_in_abilities' => true, | ||
| 'type' => 'string', | ||
| 'description' => __( 'This address is used for admin purposes, like new user notification.' ), | ||
| ) | ||
|
|
@@ -2945,16 +2947,18 @@ function register_initial_settings() { | |
| ) | ||
| ); | ||
|
|
||
| $open_closed_enum_schema = array( 'enum' => array( 'open', 'closed' ) ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (If https://github.com/WordPress/wordpress-develop/pull/10954/files#r2816934895, I would reuse the enum sand make it |
||
|
|
||
| register_setting( | ||
| 'discussion', | ||
| 'default_ping_status', | ||
| array( | ||
| 'show_in_rest' => array( | ||
| 'schema' => array( | ||
| 'enum' => array( 'open', 'closed' ), | ||
| ), | ||
| 'schema' => $open_closed_enum_schema, | ||
| ), | ||
| 'show_in_abilities' => array( | ||
| 'schema' => $open_closed_enum_schema, | ||
| ), | ||
| 'show_in_abilities' => true, | ||
| 'type' => 'string', | ||
| 'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ), | ||
| ) | ||
|
|
@@ -2965,11 +2969,11 @@ function register_initial_settings() { | |
| 'default_comment_status', | ||
| array( | ||
| 'show_in_rest' => array( | ||
| 'schema' => array( | ||
| 'enum' => array( 'open', 'closed' ), | ||
| ), | ||
| 'schema' => $open_closed_enum_schema, | ||
| ), | ||
| 'show_in_abilities' => array( | ||
| 'schema' => $open_closed_enum_schema, | ||
| ), | ||
| 'show_in_abilities' => true, | ||
| 'type' => 'string', | ||
| 'label' => __( 'Allow comments on new posts' ), | ||
| 'description' => __( 'Allow people to submit comments on new posts.' ), | ||
|
|
@@ -3006,8 +3010,9 @@ function register_initial_settings() { | |
| * @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API. | ||
| * When registering complex settings, this argument may optionally be an | ||
| * array with a 'schema' key. | ||
| * @type bool $show_in_abilities Whether this setting should be exposed through the Abilities API. | ||
| * Default false. | ||
| * @type bool|array $show_in_abilities Whether this setting should be exposed through the Abilities API. | ||
| * When registering complex settings, this argument may optionally be an | ||
| * array with a 'schema' key. Default false. | ||
| * @type mixed $default Default value when calling `get_option()`. | ||
| * } | ||
| */ | ||
|
|
||
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
Oops, something went wrong.
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.
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.
I think we just inline this . Conceptually, the schemas are different (or we'd be abstracting to a top-level
schemaprop, instead of nesting), so this a convenience helper. and since it's a 1-line array that makes this block longer, it doesnt feel like its that "convenient" imo