Opened 6 years ago
Closed 6 years ago
#45016 closed enhancement (fixed)
REST API: Expose theme_supports data through a minimal theme controller
Reported by: | danielbachhuber | Owned by: | desrosj |
---|---|---|---|
Milestone: | 5.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch has-unit-tests fixed-5.0 |
Focuses: | rest-api | Cc: |
Description
In order to correctly render parts of its UI, Gutenberg needs access to the data from post-formats
and post-thumbnails
:
$formats = get_theme_support( 'post-formats' ); $formats = is_array( $formats ) ? array_values( $formats[0] ) : array(); $formats = array_merge( array( 'standard' ), $formats ); $site_info['theme_supports']['formats'] = $formats;
$post_thumbnails = get_theme_support( 'post-thumbnails' ); if ( $post_thumbnails ) { // $post_thumbnails can contain a nested array of post types. // e.g. array( array( 'post', 'page' ) ). $site_info['theme_supports']['post-thumbnails'] = is_array( $post_thumbnails ) ? $post_thumbnails[0] : true; }
In wordpress/gutenberg#6318, this data landed on the REST API index.
As mentioned by @pento in https://core.trac.wordpress.org/ticket/43817#comment:4, the ideal location for this data would be a read-only Theme object. However, we may or may not have the time to accomplish this by our deadline.
Attachments (4)
Change History (27)
#2
follow-up:
↓ 3
@
6 years ago
I'd be very hesitant to add this to the index as a matter of expediency. If we need another endpoint for theme settings, let's absolutely do that mindfully. 5.0 and Gutenberg are meant to be the foundation for stable future iteration, we need to make that foundation solid.
#3
in reply to:
↑ 2
@
6 years ago
Replying to kadamwhite:
I'd be very hesitant to add this to the index as a matter of expediency. If we need another endpoint for theme settings, let's absolutely do that mindfully. 5.0 and Gutenberg are meant to be the foundation for stable future iteration, we need to make that foundation solid.
What do you think is realistic to do in the next 4-6 weeks? We need something in core, as all PHP files will be removed from the Gutenberg plugin before this is finalized.
Personally, I would prefer a stripped-down, read-only Themes controller if we can track down engineering resources to put it together. Putting the data on the index would be the worst-case path of least resistance.
This ticket was mentioned in Slack in #core-restapi by danielbachhuber. View the logs.
6 years ago
#5
@
6 years ago
- Summary changed from REST API: Expose theme_supports data on the index or similar to REST API: Expose theme_supports data through a minimal theme controller
#7
@
6 years ago
- Owner set to desrosj
- Status changed from new to assigned
@desrosj said he'd pick this up today in Slack.
#8
@
6 years ago
Worth noting too: we may be able to steal some code from https://github.com/WP-API/wp-api-plugins-themes-endpoints.
The ideal endpoint is something like /wp/v2/themes/current
(I don't have a strong preference on the naming of 'current' or otherwise), and it would only expose the limited fields we need right now.
This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.
6 years ago
#10
@
6 years ago
Updates from discussion in Slack and on GitHub (https://github.com/wordPress/gutenberg/pull/10518):
- For 5.0, the theme controller need not expose anything but the active theme, and whether that theme supports post formats and thumbnails.
- The only new endpoint will be
/wp/v2/themes
. We will query for active theme by passing a?status=active
query parameter.themes?status=active
will return an array containing an object representing the active theme. - For 5.0, we will not return any response on
/wp/v2/themes
if the?status=active
query is omitted, and no other themes than the active one will be represented in the endpoint. - Endpoint access is limited to authenticated users with
edit_posts
.
The PR linked above implements this endpoint for Gutenberg; after merge, it can be moved here for core merge.
#11
@
6 years ago
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
The theme controller was merged in de2fab7. 45016.diff is a patch for moving the bare-bones theme endpoint into Core against the 5.0 branch. It should also apply to trunk
cleanly.
I wasn't sure about including the tests/qunit/fixtures/wp-api-generated.js
changes in the patch vs. those being made pre-commit. That file was automatically updated.
This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.
6 years ago
This ticket was mentioned in Slack in #core-restapi by adamsilverstein. View the logs.
6 years ago
#14
@
6 years ago
I wasn't sure about including the tests/qunit/fixtures/wp-api-generated.js changes in the patch vs. those being made pre-commit. That file was automatically updated.
The updates to this file look correct and can be included in the commit. These are generated during the phpunit run and later used by the REST API tests to provide mocked responses. Since you added an endpoint it is expected the fixture would be updated.
@
6 years ago
Fix inline documentation description for WP_REST_Themes_Controller_Test::$themes_route
#16
@
6 years ago
- Keywords fixed-5.0 added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for trunk.
This ticket was mentioned in Slack in #core-restapi by aduth. View the logs.
6 years ago
#19
follow-up:
↓ 21
@
6 years ago
https://github.com/WordPress/gutenberg/pull/10477 adds responsive-embeds
to the theme_supports
property of the themes endpoint. Incoming patch to add this to core.
Test build on Travis: https://travis-ci.org/desrosj/wordpress-develop/builds/443413062
#43817 was marked as a duplicate.