-
Notifications
You must be signed in to change notification settings - Fork 383
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
Add REST endpoint providing post types, taxonomies, blocks, and widgets registered by the theme #5751
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #5751 +/- ##
=============================================
+ Coverage 74.14% 74.40% +0.26%
- Complexity 5498 5517 +19
=============================================
Files 201 202 +1
Lines 16653 16716 +63
=============================================
+ Hits 12347 12438 +91
+ Misses 4306 4278 -28
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Plugin builds for ac3a475 are ready 🛎️!
|
Interesting approach! Curious: what happens if a theme enables a post type configured by a plugin using |
Interesting. In this case, I think the end result is largely the same, at least for the Reader themes that we support out of the box (the core themes), since none of the core themes would add theme support for any particular post types. In that case, the registered entities request with the theme disabled would return with any such post types omitted, meaning they would not be available in a Reader theme.
Come to think of it, we can avoid the nested request to simplify things. We can just have the client make two requests: one with the theme enabled, and one with the theme disabled, and it can then compute the difference itself. Then we wouldn't need to worry about authenticating the loopback request. Also we in general have had problems with loopback requests failing for sites (see #4979), so the more we can eliminate them the better. (Then we won't need #3789.) |
As an alternative to the REST API request disabling the theme, we could also provide a parameter to switch the theme, as the Customizer does. In that case, we could see if a particular Reader theme would be problematic alongside an active primary theme. So instead of checking theme compatibility once when showing the list of Reader themes, we could eventually check the theme compatibility when selecting an individual Reader theme. This would be useful as more themes become AMP-compatible and are listed in Reader mode. This could be done as a future improvement. |
I've given this some thought and I've realized that I think we can take a different approach which will allow us to detect the entities which were registered not only be the theme but by the plugins as well. And this can be done in a single request without having to turn off a theme/plugin. See #6516. So I'm closing this PR for now, although it may make sense to re-open if it turns out that the logic could serve as a starting point. |
Summary
Related to #4795 but does not resolve this issue because it doesn't provide any of the UI for the settings screen or onboarding wizard.
This sets up a REST endpoint,
amp/v1/theme-entities
. When in the admin with a logged-in user with dev tools turned on, a request toamp/v1/theme-entities
will return an object that looks something like this:Each of these fields will contain a list of names/slugs for any blocks, post types, taxonomies, widgets, registered by the theme.
How it works
The REST endpoint callback first gets all entities active on the site. Then it makes a nested request to the same endpoint with a context flag that disables the theme. Within that nested request all entities are again retrieved while the theme is disabled. Then
array_diff
is used to find the items that only exist when the theme is active. The result is cached using a cache key from the theme name and version.Checklist