diff options
author | K. Adam White <kadamwhite@git.wordpress.org> | 2018-06-21 21:06:50 +0000 |
---|---|---|
committer | K. Adam White <kadamwhite@git.wordpress.org> | 2018-06-21 21:06:50 +0000 |
commit | a830dbcab3147e67b3076d3d15c89975df675fbb (patch) | |
tree | 572cb4ca0a22e8f8b7158f3d6c27eb1e94a0dcd4 /src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php | |
parent | cdd9910f01997d87d052289b56b3e0ba652da05a (diff) | |
download | wordpress-a830dbcab3147e67b3076d3d15c89975df675fbb.tar.gz wordpress-a830dbcab3147e67b3076d3d15c89975df675fbb.zip |
REST API: Support meta registration for specific object subtypes.
Introduce an `object_subtype` argument to the args array for `register_meta()` which can be used to limit meta registration to a single subtype (e.g. a custom post type or taxonomy, vs all posts or taxonomies).
Introduce `register_post_meta()` and `register_term_meta()` wrapper methods for `register_meta` to provide a convenient interface for the common case of registering meta for a specific taxonomy or post type. These methods work the way plugin developers have often expected `register_meta` to function, and should be used in place of direct `register_meta` where possible.
Props flixos90, tharsheblows, spacedmonkey.
Fixes #38323.
git-svn-id: https://develop.svn.wordpress.org/trunk@43378 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php')
-rw-r--r-- | src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php b/src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php index e15364246e..d1c3ad6ad9 100644 --- a/src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php +++ b/src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php @@ -47,6 +47,17 @@ class WP_REST_Post_Meta_Fields extends WP_REST_Meta_Fields { } /** + * Retrieves the object meta subtype. + * + * @since 5.0.0 + * + * @return string Subtype for the meta type, or empty string if no specific subtype. + */ + protected function get_meta_subtype() { + return $this->post_type; + } + + /** * Retrieves the type for register_rest_field(). * * @since 4.7.0 |