[wp-trac] [WordPress Trac] #43817: REST API: Include 'formats' attribute on Post Type resource

WordPress Trac noreply at wordpress.org
Sat Apr 21 11:11:29 UTC 2018


#43817: REST API: Include 'formats' attribute on Post Type resource
--------------------------------------+-----------------------
 Reporter:  pento                     |       Owner:  flixos90
     Type:  enhancement               |      Status:  assigned
 Priority:  normal                    |   Milestone:  5.0
Component:  Post Formats              |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  rest-api
--------------------------------------+-----------------------
Changes (by flixos90):

 * keywords:  needs-patch needs-unit-tests => has-patch has-unit-tests


Comment:

 [attachment:43817.diff] adds a `formats` field to post type objects.

 @pento I mostly followed your approach from the GitHub PR, with a few
 adjustments:

 * When fetching the post formats, I added support for the case where
 someone does `add_theme_support( 'post-formats )`. In that case, all post
 formats are supported.
 * When fetching all post formats, I added a whitelist check against the
 available post formats, so that random strings defined as post formats are
 stripped from the list.
 * In the schema description, I added a note that these post formats depend
 on the post type ''and'' the current theme.
 * In the schema, I added definition for the items in the post formats
 array.
 * I added three tests: One for `add_theme_support()` being called without
 extra parameters, one for `add_theme_support()` being called with a subset
 of post formats, and one for a post type that doesn't support post
 formats.

 A few additional thoughts from my end:
 * I don't really like that we put theme-specific data into a post type
 controller, but we don't have a themes controller, and even if we did, it
 would be inconvenient to make two database requests for this matter. Since
 one can still check for ''only'' the post type support for post formats as
 necessary (via the `supports` field), I can accept this as a necessary
 evil. :)
 * I'm not sure about how the `standard` post format. I went with the same
 approach like your PR for now, but I'd prefer if we never included it in
 that list or alternatively also include this when the post type doesn't
 support formats (as sole value in the array). Because that format is
 always supported. The UI could still make a check like "only show post
 formats UI component if more than 1 format are supported), so it would
 still be feasible from a usage standpoint, but more logical from a data
 standpoint.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43817#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list