WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 4 months ago

#39033 closed enhancement (fixed)

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

Reported by: timmydcrawford Owned by: 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 5 months 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 4 months ago.
Moves the supports key above taxonomies to keep the alpha order

Download all attachments as: .zip

Change History (7)

#1 @rachelbaker
5 months 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
5 months 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
5 months ago

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

#3 @tyxla
5 months 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
4 months ago

Moves the supports key above taxonomies to keep the alpha order

#4 @rachelbaker
4 months 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
4 months 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.