-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REST API: Sync /themes endpoint with Core's #23321
Conversation
Size Change: +35 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this on 5.4 and master, the theme preview works as expected. Although I noticed this still works on current Gutenberg master branch, so this isn't fixing the theme preview? That's more of a smoke test to ensure the endpoint is still working?
Uh, you're right, there was a mistake in my instructions 😅 I've updated them now, I hope they make more sense now. They're still a bit complex -- we're basically comparing the output
|
Related: WordPress/wordpress-develop#264 |
@@ -31,7 +31,7 @@ function ThemePreview( { | |||
alt={ 'Theme Preview' } | |||
/> | |||
<div className="edit-site-template-switcher__theme-preview-description"> | |||
{ truncate( description, { | |||
{ truncate( description.raw, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this the rendered version? The rendered version has wptexturize
applied which handles things like curly quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was that the rendered version might contain HTML markup (stuff like <a />
or <em />
) and would thus require us to __dangerouslySetInnerHtml
to render it in React, which I wanted to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could, but it has wp_kses
applied to be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, okay. I can see that for name
, but with description
here, there's an extra complication -- I'm truncate()
ing, so we might end up with an opening HTML tag that messes up the rest of the markup 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this could be possible with https://github.com/arendjr/text-clipper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I wasn't aware of that! I think it's worth considering, but since we'd require an extra dependency for truncating the theme description down to ~120 chars, it might be controversial, so I'd rather not block this PR on it. We can open a separate issue/PR tho!
} ) { | ||
return ( | ||
<div className="edit-site-template-switcher__theme-preview"> | ||
<span className="edit-site-template-switcher__theme-preview-name"> | ||
{ name } | ||
{ name.raw } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not rendered
here as well? We get a safe fallback if the theme doesn't have a proper name listed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(see)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should, that matches core's behavior see wp_prepare_themes_for_js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. I think we also need to consider the value of I am somewhat worried about making sure these stay in sync with Core. Have we ruled out requiring trunk for experimental features like this? |
Ah yeah, good point. I'll modify it to that effect 👍
I haven't really been in any conversation regarding that. TBH I'd rather avoid that -- I think it's fair to require a rock-solid implementation of e.g. a REST API endpoint in Core, but I was happy that it wasn't a blocker for developing some code on the client side that depended on it. Getting a preliminary version of the endpoint additions into Gutenberg allowed me (and others) to iterate quickly on the client-side code, while I was at the same time refining the Core implementation of the endpoint (in accordance with feedback). Overall, it took about 8 weeks until the latter was ready to be merged; that's the amount of time I would've had to wait if we had required those changes to be in Core's trunk for Gutenberg to use it. |
I think I did a bad job of explaining what I meant. The idea would still be that code lives in Gutenberg first, but once it is merged to trunk, trunk would be required. That way we don't have to worry about any future changes to trunk making it back to the Gutenberg plugin or the syncing back to Gutenberg from Core was incorrect. So the development flow would be...
|
Right, thanks for clarifying! But wouldn't that mean that once a new version of the Gutenberg plugin is released after 3., it could no longer be tested on a stable WordPress Core install? |
we still need to maintain compatibility in the Gutenberg plugin with 5.4 even after 5.5 lands. |
I just tested adding some |
@TimothyBJacobs I think I addressed your feedback, would you mind giving this another look? 😊 🙏 |
I'll move this to a separate issue, but I think doing this for some things will be completely impossible, like the navigation screen due to how batch requests need to be implemented in Core. I also think its going to prove difficult to keep the larger REST API changes in sync.
Looks good. I still wish we'd use the same data ( rendered description ) that we do in wp-admin, but I can see how that complicates things. |
I might be missing something here, but is this related to the changes in this PR? The way we're adding fields to the
Thank you! In #23321 (comment), I'm suggesting a follow-up issue/PR to further look into that 🙂 |
The test setup has changed and tests seem to be stuck. I'll rebase. |
ec6f16d
to
870324e
Compare
Description
In #21578, I added a few fields to Core's
/themes
endpoint, for use by the Site Editor's Template Switcher (see both #21578 and #21768). I then submitted those changes as a PR against Core. That PR underwent a number of modifications and was eventually merged; the new fields will be part of the/themes
endpoint exposed by Core starting from the next WP release.This PR updates the fields added by Gutenberg to follow the same semantics, as well as the callsites that use that endpoint.
Fixes #23054.
How has this been tested?
Test the template switcher's theme preview as described in #21768. You need to do this both with WP 5.4, and WordPress' current
master
branch. Verify that the theme preview works in both cases.Alternatively:
master
branch, and make sure you're using it with WordPress' latestmaster
branch./themes
endpoint, and to suppress Gutenberg's addition of fields to the/themes
endpoint (so that we get the/themes
endpoint to reply with the fields that are defined in Core):/themes
endpoint's response, and copy it (in JSON format) to a text editor.lib/rest-api.php
patch, but keep thelib/edit-site-page.php
patch.theme_supports
, which predates REST API: Themes: Expose some additional basic fields wordpress-develop#222) in order to rely on Gutenberg to add those fields:Types of changes
Update to sync with Core.
Checklist: