Make WordPress Core

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's profile danielbachhuber Owned by: desrosj's profile 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)

45016.diff (20.6 KB) - added by desrosj 6 years ago.
45016.2.diff (20.6 KB) - added by desrosj 6 years ago.
Fix inline documentation description for WP_REST_Themes_Controller_Test::$themes_route
45016.3.diff (20.6 KB) - added by desrosj 6 years ago.
Remove gutenberg text domain.
45016.4.diff (3.7 KB) - added by desrosj 6 years ago.

Download all attachments as: .zip

Change History (27)

#1 @danielbachhuber
6 years ago

#43817 was marked as a duplicate.

#2 follow-up: @kadamwhite
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 @danielbachhuber
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 @kadamwhite
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

#6 @kadamwhite
6 years ago

Renamed based on discussion above & in slack clarifying the desired approach.

#7 @danielbachhuber
6 years ago

  • Owner set to desrosj
  • Status changed from new to assigned

@desrosj said he'd pick this up today in Slack.

#8 @danielbachhuber
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 @kadamwhite
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.

@desrosj
6 years ago

#11 @desrosj
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 @adamsilverstein
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.

@desrosj
6 years ago

Fix inline documentation description for WP_REST_Themes_Controller_Test::$themes_route

@desrosj
6 years ago

Remove gutenberg text domain.

#15 @kadamwhite
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 43734:

REST API: Introduce themes endpoint to expose theme-supports values for the active theme.

In order to correctly render parts of its UI, the new editor needs to be aware of the active theme's post-formats and post-thumbnails support. This data is exposed by querying for the active theme on a new /wp/v2/themes endpoint for sufficiently privileged users.

props desrosj.
Fixes #45016.

#16 @kadamwhite
6 years ago

  • Keywords fixed-5.0 added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for trunk.

#17 @kadamwhite
6 years ago

In 43735:

REST API: Add new class file and tests missed in [43734].

See #45016.

This ticket was mentioned in Slack in #core-restapi by aduth. View the logs.


6 years ago

#19 follow-up: @desrosj
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

@desrosj
6 years ago

This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.


6 years ago

#21 in reply to: ↑ 19 @danielbachhuber
6 years ago

Replying to desrosj:

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.

Related #45125

#22 @desrosj
6 years ago

Ignore 45016.4.diff. I included it in the patch on #45125.

#23 @jeremyfelt
6 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 43985:

REST API: Introduce themes endpoint to expose theme-supports values for the active theme.

In order to correctly render parts of its UI, the new editor needs to be aware of the active theme's post-formats and post-thumbnails support. This data is exposed by querying for the active theme on a new /wp/v2/themes endpoint for sufficiently privileged users.

Merges [43734], [43735] to trunk.

props desrosj.
Fixes #45016.

Note: See TracTickets for help on using tickets.