REST API: Include `taxonomies` as an attribute of post types.
Add the taxonomies for a post type to the `/wp/v2/types` endpoint, so clients know which taxonomies are available for which post types. Props danielbachhuber. Fixes #38438, #38631. Built from https://develop.svn.wordpress.org/trunk@39097 git-svn-id: http://core.svn.wordpress.org/trunk@39039 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
37858faf96
commit
5666292dda
|
@ -146,6 +146,8 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
* @return WP_REST_Response Response object.
|
||||
*/
|
||||
public function prepare_item_for_response( $post_type, $request ) {
|
||||
$taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
|
||||
$taxonomies = wp_list_pluck( $taxonomies, 'name' );
|
||||
$data = array(
|
||||
'capabilities' => $post_type->cap,
|
||||
'description' => $post_type->description,
|
||||
|
@ -153,6 +155,7 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
'labels' => $post_type->labels,
|
||||
'name' => $post_type->label,
|
||||
'slug' => $post_type->name,
|
||||
'taxonomies' => array_values( $taxonomies ),
|
||||
);
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
|
@ -203,6 +206,9 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
'capabilities' => array(
|
||||
'description' => __( 'All capabilities used by the resource.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
|
@ -236,6 +242,15 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'taxonomies' => array(
|
||||
'description' => __( 'Taxonomies associated with resource.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7-beta1-39096';
|
||||
$wp_version = '4.7-beta1-39097';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue