Make WordPress Core

Opened 17 months ago

Last modified 16 months ago

#63253 new enhancement

Theme REST API: expose "has_theme_json" field

Reported by: wildworks Owned by:
Priority: normal Milestone: Awaiting Review
Component: REST API Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

Currently, there is no official way to detect whether the active theme has theme.json or not via REST API.

We needed to check for the existence of theme.json to conditionally expose Stylebook for the classic theme. As a temporary approach, we used the supportsLayout setting, which is the equivalent of the wp_theme_has_theme_json() function:

https://github.com/WordPress/gutenberg/blob/a4a5b07b4432d28ad4eb3646435bbaf9a8f9796e/packages/edit-site/src/components/site-editor-routes/utils.js#L11-L12

However, there is no guarantee that this setting will remain equivalent to wp_theme_has_theme_json() in the future.

We should expose the new "has_theme_json" field via the theme REST API.

Change History (5)

#1 @wildworks
17 months ago

  • Type defect (bug)enhancement

This ticket was mentioned in PR #8665 on WordPress/wordpress-develop by @wildworks.


17 months ago
#2

  • Keywords has-patch has-unit-tests added

#3 @wildworks
17 months ago

Testing Instructions

  • Open the post editor or the site editor
  • Open the console panel of your browser
  • Run wp.data.select('core').getCurrentTheme()
  • Confirm that the response includes the has_theme_json field

@ankitkumarshah commented on PR #8665:


17 months ago
#4

Hey @t-hamano,

I have tested the PR, and it works well and adds the has_theme_json field in the themes REST API

## Screenshot:

#### Trunk:
https://github.com/user-attachments/assets/df562ce1-e83d-4ec3-920f-ed22b4b6e643

#### This PR with no theme.json:
https://github.com/user-attachments/assets/c12537f6-1443-4e3b-ad99-f166c2151a2c

#### This PR with theme.json:
https://github.com/user-attachments/assets/ec95ed12-c2b4-4b05-b647-abcb6f64a0f7

#5 @wildworks
16 months ago

Update: I realized that using wp_theme_has_theme_json() in the REST API response isn't correct. Because the wp_theme_has_theme_json() function returns results based on the active theme.

See https://github.com/WordPress/gutenberg/pull/69857#issuecomment-2801814369 for more details.

I think we need to add a new has_theme_json method to the WP_Theme class first, so I submitted #63299.

Note: See TracTickets for help on using tickets.