mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Try: Set show_in_rest
to true
by default when label
argument is defined
#7302
Closed
SantosGuillamot
wants to merge
8
commits into
WordPress:trunk
from
SantosGuillamot:add/inherit-show-in-rest-from-label
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
696b3f1
Add `label` arg to `register_meta`
SantosGuillamot 7593c51
Add label to REST API schema
SantosGuillamot edc444c
Adapt unit tests
SantosGuillamot c307b4f
Use 'title' instead of 'label' in schema
SantosGuillamot 74e3465
Add unit test to check title in schema
SantosGuillamot 0abab55
Add since tag
SantosGuillamot 7211ec9
Inherit `show_in_rest` from `label`
SantosGuillamot 41ae82b
Add unit test
SantosGuillamot 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 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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1368,6 +1368,7 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = | |||||||||||||||||
* @since 5.3.0 Valid meta types expanded to include "array" and "object". | ||||||||||||||||||
* @since 5.5.0 The `$default` argument was added to the arguments array. | ||||||||||||||||||
* @since 6.4.0 The `$revisions_enabled` argument was added to the arguments array. | ||||||||||||||||||
* @since 6.7.0 The `label` argument was added to the arguments array. | ||||||||||||||||||
* | ||||||||||||||||||
* @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', | ||||||||||||||||||
* or any other object type with an associated meta table. | ||||||||||||||||||
|
@@ -1379,6 +1380,7 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = | |||||||||||||||||
* the meta key will be registered on the entire object type. Default empty. | ||||||||||||||||||
* @type string $type The type of data associated with this meta key. | ||||||||||||||||||
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'. | ||||||||||||||||||
* @type string $label A human-readable label of the data attached to this meta key. | ||||||||||||||||||
* @type string $description A description of the data attached to this meta key. | ||||||||||||||||||
* @type bool $single Whether the meta key has one value per object, or an array of values per object. | ||||||||||||||||||
* @type mixed $default The default value returned from get_metadata() if no value has been set yet. | ||||||||||||||||||
|
@@ -1411,6 +1413,7 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { | |||||||||||||||||
$defaults = array( | ||||||||||||||||||
'object_subtype' => '', | ||||||||||||||||||
'type' => 'string', | ||||||||||||||||||
'label' => '', | ||||||||||||||||||
'description' => '', | ||||||||||||||||||
'default' => '', | ||||||||||||||||||
'single' => false, | ||||||||||||||||||
|
@@ -1451,6 +1454,9 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { | |||||||||||||||||
* @param string $meta_key Meta key. | ||||||||||||||||||
*/ | ||||||||||||||||||
$args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key ); | ||||||||||||||||||
if ( isset( $args['label'] ) && ! isset( $args['show_in_rest'] ) ) { | ||||||||||||||||||
$args['show_in_rest'] = true; | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+1457
to
+1459
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.
Suggested change
Just adding some spacing for clarity. |
||||||||||||||||||
unset( $defaults['default'] ); | ||||||||||||||||||
$args = wp_parse_args( $args, $defaults ); | ||||||||||||||||||
|
||||||||||||||||||
|
This file contains 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 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 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 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.
This should change before the filter so 3rd party code can still change it.
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.
What happens when the filter adds a label without setting
show_in_rest
? Shouldn't that follow the same behavior?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.
Maybe it is safer to move it before the filter as you say to ensure people can change this behavior.