Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#39033 closed enhancement (fixed)

WP REST API: Add `supports` object to `/types` response

Reported by: timmydcrawford's profile timmydcrawford Owned by: rachelbaker's profile rachelbaker
Milestone: 4.8 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description

While working on a Calypso [pull request](https://github.com/Automattic/wp-calypso/pull/9751) to utilize the post types endpoint on WordPress.com, I hit a bit of a stumbling block with the current implementation.

In the [WordPress.com API](https://github.com/Automattic/jetpack/blob/master/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php#L61), the output of [get_all_post_type_supports](https://developer.wordpress.org/reference/functions/get_all_post_type_supports/) is returned in a supports object for each post type.

Adding this object to the response stream was easy enough to do as a plugin via register_rest_field, but I figured it might be worth considering including in the core endpoint.

Attachments (2)

39033.diff (3.0 KB) - added by tyxla 7 years ago.
Include supports in the output of the post types REST API endpoint (for edit context only). Includes tests.
39033.1.diff (3.0 KB) - added by rachelbaker 7 years ago.
Moves the supports key above taxonomies to keep the alpha order

Download all attachments as: .zip

Change History (7)

#1 @rachelbaker
7 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to 4.8
  • Summary changed from WP REST API: Consider adding `supports` object to `/types` response to WP REST API: Add `supports` object to `/types` response

Sounds reasonable to me. I don't know if this is something we would want to expose without authentication. @timmydcrawford what do you think about only including if the context is edit?

#2 @timmydcrawford
7 years ago

what do you think about only including if the context is edit?

Seems like a good idea. Shall I work on a patch?

@tyxla
7 years ago

Include supports in the output of the post types REST API endpoint (for edit context only). Includes tests.

#3 @tyxla
7 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

39033.diff adds supports with all of the supported features to each of the post types, only for edit context. The patch also includes tests.

@rachelbaker
7 years ago

Moves the supports key above taxonomies to keep the alpha order

#4 @rachelbaker
7 years ago

  • Keywords commit added

@tyxla Your patch looked great, thank you for the unit tests as well. We have the item response properties in alphabetical order - minus a special exception for rest_base which is the last property in the Post Type response object.

In 39033.1.diff I moved the supports property above taxonomies in the response object to keep the semi-alpha order. Marking this for commit.

#5 @rachelbaker
7 years ago

  • Owner set to rachelbaker
  • Resolution set to fixed
  • Status changed from new to closed

In 39647:

REST API: Add the supports property to the Post Type response object.

Includes a new supports property in the response object and schema for the /types endpoints for users with the edit_posts capability for the given post type. The supports property returns an object of the features the given post type *supports*.

Props timmydcrawford, tyxla.
Fixes #39033.

Note: See TracTickets for help on using tickets.