Make WordPress Core

Opened 11 months ago

Closed 8 months ago

Last modified 8 months ago

#58123 closed enhancement (fixed)

Indicate when a theme supports the Site editor in the Themes REST API response

Reported by: grantmkin's profile grantmkin Owned by: audrasjb's profile audrasjb
Milestone: 6.3 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch has-unit-tests has-testing-info has-screenshots add-to-field-guide
Focuses: rest-api Cc:

Description

I currently can't find a way to know if the active theme supports the Site editor based on the /themes REST API response for that theme.

We have theme supports data for block-template-parts in the response, which can be an indication of Site editor support, but use of this doesn't seem consistent. For example, Twenty Twenty-Two doesn't declare block-template-parts support, but it supports using the Site editor.

One way to know would be to surface the result of WP_Theme::is_block_theme for each theme (or at least for the active theme) in the API response.

Attachments (1)

gutenberg.16.0.0.zip (8.3 MB) - added by zunaid321 9 months ago.

Change History (12)

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


11 months ago
#1

  • Keywords has-patch has-unit-tests added

Adds a is_block_theme property to each theme in the wp/v2/themes API response, which uses WP_Theme::is_block_theme.

This helps to indicate if a theme supports the Site editor, or not.

Trac ticket: https://core.trac.wordpress.org/ticket/58123

#2 @ironprogrammer
9 months ago

  • Keywords has-testing-info needs-testing has-screenshots added
  • Milestone changed from Awaiting Review to 6.3

Welcome back to Trac, and thanks for the ticket and PR, @grantmkin!

This LGTM 👍🏻 Moving into the 6.3 milestone for consideration.

Test Report

Patch tested: https://github.com/WordPress/wordpress-develop/pull/4323

Steps to Test

  1. Activate Gutenberg. This conveniently makes use of Core's wp/v2/themes endpoint.
  2. Activate a block theme. This is needed to make the Editor available.
  3. Navigate to Appearance > Editor (/wp-admin/site-editor.php).
  4. In the browser console, inspect the network connections (in Chrome this is the Network tab), and filter results by "themes" and/or fetch/XHR requests. Reload the page if nothing is there the first try.
  5. Locate the request for themes?context=edit... and preview/inspect the response.
  6. 👀 Expand and inspect the data for each theme.
  7. 🩹 Apply patch.
  8. Refresh the page, and repeat Step 5.
  9. 👀 Expand and inspect the data for each theme again.

Expected Results

After applying the patch:

  • ✅ Observe that for block themes, the theme data includes is_block_theme: true.
  • ✅ Observe that for classic themes, the theme data includes is_block_theme: false.

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 13.4
  • Browser: Google Chrome 114.0.5735.106
  • Server: nginx/1.25.0
  • PHP: 7.4.33
  • WordPress: 6.3-alpha-55505-src
  • Theme: twentytwentythree v1.1
  • Active Plugins:
    • gutenberg v16.0.0

Actual Results

  • ✅ Block themes (like TT3) include is_block_theme: true.
  • ✅ Classic themes (like TT) include is_block_theme: false.

Supplemental Artifacts

Figure 1: Chrome DevTools Network tab themes endpoint response data for block theme.

https://cldup.com/pW9NFLc0lD.png

Figure 2: Chrome DevTools Network tab themes endpoint response data for classic theme.

https://cldup.com/spo24yaSEB.png

This ticket was mentioned in Slack in #core by zunaid321. View the logs.


9 months ago

#4 @zunaid321
9 months ago

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/4323

Environment

  • OS: Windows 11 (22H2)
  • Web Server: nginx/1.23.4
  • PHP: 7.4.33
  • WordPress: 6.3-alpha-55505-src
  • Browser: Chrome Version 114.0.5735.110 (Official Build) (64-bit)
  • Theme: Twenty Twenty-Three

Before Applying The Patch

  • Followed the instructions of @ironprogrammer
  • ❌ is_block_theme - was not available

After Applying The Patch

  • Followed the same instructions
  • ✅ is_block_theme was displaying the correct info for both classic and block based themes.

Plugins Used

  • Attached: gutenberg.16.0.0.zip

Screenshots

#5 @azaozz
9 months ago

  • Keywords commit added

surface the result of WP_Theme::is_block_theme

Makes sense imho. The patch also looks good. Not sure if it needs two new tests for one boolean value, could they be combined? But the more-the merrier :)

#6 @spacedmonkey
9 months ago

Looks good to me. Marking as ready to commit.

#7 @audrasjb
9 months ago

  • Keywords needs-testing commit removed
  • Owner set to audrasjb
  • Status changed from new to reviewing

Removing commit since I added a request to add the ticket number in the related unit tests functions.

#8 @grantmkin
8 months ago

Not sure if it needs two new tests for one boolean value, could they be combined?

Tests combined in https://github.com/WordPress/wordpress-develop/pull/4323/commits/a66c9f54db7ce63c2756b013bb37b1487078017b

Removing commit since I added a request to add the ticket number in the related unit tests functions.

Added in https://github.com/WordPress/wordpress-develop/pull/4323/commits/91750e63e3edd38a613a40f7ef07b9e8dfc76228

---

Let me know if there's anything else needed!

#9 @audrasjb
8 months ago

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

In 55951:

REST API: Indicate when a theme supports the Site editor in the Themes REST API response.

This changeset adds a is_block_theme property to each theme in the wp/v2/themes API response, which uses WP_Theme::is_block_theme to determinate whether
the theme is block theme or not.

Props grantmkin, ironprogrammer, zunaid321, azaozz, spacedmonkey, audrasjb, costdev.
Fixes #58123.

#11 @milana_cap
8 months ago

  • Keywords add-to-field-guide added
Note: See TracTickets for help on using tickets.