WordPress.org

Make WordPress Core

Opened 5 weeks ago

Last modified 6 hours ago

#49037 new enhancement

Expose all theme supports in /themes endpoint

Reported by: adamboro Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 5.0
Component: REST API Keywords: needs-patch good-first-bug
Focuses: rest-api Cc:
PR Number:

Description

The /themes endpoint exposes just three of values stored in $_wp_theme_features:
https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php#L108

This is different than how get_theme_support (https://developer.wordpress.org/reference/functions/get_theme_support) function works, which exposes all of them.
As it is now, In order to retrieve a theme support - which is not one of the three values - via REST API, a custom endpoint has to be created. This is pretty cumbersome - why shouldn't /themes expose all theme features?

Related: #45016, #48798

Attachments (8)

49037.patch (11.0 KB) - added by apieschel 6 days ago.
exposes automatic-feed-links feature
48937.2.diff (2.2 KB) - added by apieschel 6 days ago.
exposes custom-logo feature with unit tests
49037.2.patch (12.9 KB) - added by apieschel 6 days ago.
exposes custom-logo feature with unit tests (correct file)
49037.3.patch (20.7 KB) - added by apieschel 6 days ago.
exposed remaining features from https://developer.wordpress.org/reference/functions/add_theme_support/
49037.4.patch (21.8 KB) - added by apieschel 2 days ago.
changed format of child properties and adjusted unit test for 'title-tag'
49037.5.patch (27.2 KB) - added by apieschel 2 days ago.
added editor-styles, dark-editor-style, align-wide, and wp-block-styles
49037.diff (28.1 KB) - added by spacedmonkey 25 hours ago.
49037.2.diff (25.9 KB) - added by spacedmonkey 24 hours ago.

Download all attachments as: .zip

Change History (23)

#1 @SergeyBiryukov
5 weeks ago

  • Component changed from REST API to Themes

#2 @spacedmonkey
5 weeks ago

  • Component changed from Themes to REST API
  • Keywords needs-patch added
  • Version changed from 5.3.1 to 5.0

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


5 weeks ago

#4 @TimothyBlynJacobs
5 weeks ago

  • Milestone changed from Awaiting Review to 5.4

Based on discussion in #core-restapi, I think we are going to start by extending this to register all WordPress Core Theme Support. 3rd party theme support might come at a later point. Provisionally milestoning for 5.4.

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


7 days ago

#6 @TimothyBlynJacobs
7 days ago

  • Keywords good-first-bug added

Going to mark this as a good first bug. You can find a similar ticket for guidance in #48798.

@apieschel
6 days ago

exposes automatic-feed-links feature

#7 @apieschel
6 days ago

@TimothyBlynJacobs I started on this. If you have time, would you mind checking to see if it's on the right track? I moved over all the code from #48798, and added all the lines related to "automatic-feed-links" and "custom-logo".

Last edited 6 days ago by apieschel (previous) (diff)

@apieschel
6 days ago

exposes custom-logo feature with unit tests

@apieschel
6 days ago

exposes custom-logo feature with unit tests (correct file)

#8 @spacedmonkey
6 days ago

Thinking this ticket over, I wonder if we should add an api to register theme supports.

This would define the key name, description, show in rest etc. That would allow third party developers to also register their own supports. It would also mean that this definitions could be reused elsewhere. Thoughts @TimothyBlynJacobs ?

#9 @apieschel
6 days ago

Went ahead and added the remaining supports from https://developer.wordpress.org/reference/functions/add_theme_support/.

I guess I also need to add the ones from here: https://developer.wordpress.org/block-editor/developers/themes/theme-support/ ?

Is there a better place to look at a list of all possible theme supports? The documentation is a little confusing!

All new unit tests are passing except test_theme_can_manage_title_tag(). Can't figure out why this line:

$result[0]['theme_supports']['title-tag']

keeps returning false.

Last edited 6 days ago by apieschel (previous) (diff)

#10 @TimothyBlynJacobs
2 days ago

#48798 was marked as a duplicate.

#11 follow-up: @TimothyBlynJacobs
2 days ago

Thinking this ticket over, I wonder if we should add an api to register theme supports.

From my perspective, such an API would make a lot of sense. I think we should open a separate ticket for it and work with the Themes component on it.

Thanks for working on these patches @apieschel! Going to take a more in-depth look later, but one thing that I saw in my initial review is that the schema format for the child properties is wrong. See the first part of my comment here: https://core.trac.wordpress.org/ticket/48798#comment:11

Also, for html5 instead of listing those as properties, they should be an enum. So

'items' => [
 	 'type'   => 'string',
 	 'enum' => array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style' ),
],

All new unit tests are passing except test_theme_can_manage_title_tag(). Can't figure out why this line:

This may be because add_theme_support checks if wp_loaded has fired, and if so, prevents the theme support from being registered. In this case, it may be find to add the support manually to the $_wp_theme_features global.

@apieschel
2 days ago

changed format of child properties and adjusted unit test for 'title-tag'

@apieschel
2 days ago

added editor-styles, dark-editor-style, align-wide, and wp-block-styles

#12 in reply to: ↑ 11 @apieschel
2 days ago

Replying to TimothyBlynJacobs:

Going to take a more in-depth look later, but one thing that I saw in my initial review is that the schema format for the child properties is wrong. See the first part of my comment here: https://core.trac.wordpress.org/ticket/48798#comment:11

Thanks for this! I read that comment, but didn't get it at first for some reason. Added a patch with the schema format for child properties adjusted, and 'title-tag' support manually added to the $_wp_theme_features global in the relevant unit test. I also added supports and tests for editor-styles, dark-editor-style, align-wide, and wp-block-styles from https://developer.wordpress.org/block-editor/developers/themes/theme-support/. Let me know what else I need to change!

#13 @spacedmonkey
33 hours ago

I have created a possiblity useful and related ticket for formatting color at #49270

@spacedmonkey
25 hours ago

#14 @spacedmonkey
24 hours ago

In 49037.2.diff, there are number of improvements.

  • Lints now pass
  • Unit tests now pass.
  • Repeated logic removed and replaced with loop
  • Make sure all array types also have items key to stop php notice.

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


6 hours ago

Note: See TracTickets for help on using tickets.