Skip to content

Code quality check for theme.json related APIs #45171

Closed

Description

@oandregal

This issue tracks the current state of theme.json related APIs from a quality point of view, so we can bring up, discuss and address the issues.

WordPress 6.2: shipped

Public API:

Performance:

  • wp_theme_has_theme_json: cache output #45543
  • wp_get_global_settings: cache output #45372 #45971 #45969
  • wp_get_global_stylesheet: migrate from transient to object cache #45679
  • wp_get_global_styles_svg_filters : migrate from transient to object cache #47460 (done in core as the function was removed from Gutenberg)
  • While initially the cache was implemented as persistent across requests for the above methods, concerns were brought up to make it non-persistent and keep testing: #46150

Sync WordPress core <=> Gutenberg:

WordPress 6.3: shipped

Public API

WordPress 6.4: ongoing

Performance:

Public API

Next

Algorithm:

Public API:

  • Make sure all current uses cases of WP_Theme_JSON or WP_Theme_JSON_Resolver are covered by the addition of public methods.
  • Collocate customTemplates and templateAreas metadata with the actual data they represent (templates and template parts provided by the theme as HTML) and remove them from theme.json. #42732 In testing #38984 we ran into an issue with valid HTML comments that don't belong to a block #47212
  • Deprecate/Remove the wp_theme_json_get_style_nodes filter #45172 Filters, together with methods or the theme.json datum, are all part of the public API. We should aim to not expose private implementation details in the public API that prevent us from evolving it.
  • wp_get_global_styles: resolver the reference to the value #49715

Performance

Activity

  1. added
    [Type] Code Quality
    Global Styles
    [Status] In Progress
    on Oct 20, 2022
  2. oandregal commented on Oct 21, 2022

    @oandregal
    MemberAuthor

    Added a section on experimental API that covers __experimentalSelector, __experimentalDuotone, and __experimentalStyle.

  3. added
    [Feature] Block API
    and removed
    [Status] In Progress
    on Oct 21, 2022
  4. oandregal commented on Oct 28, 2022

    @oandregal
    MemberAuthor

    #45168 is ready for review.

  5. oandregal commented on Oct 28, 2022

    @oandregal
    MemberAuthor

    Added a section about performance.

  6. added
    Needs Dev Note
    on Oct 28, 2022
  7. bph commented on Oct 28, 2022

    @bph
    Contributor

    Added the 'needs-dev-note` to this tracking issue, to make sure we cover all relevant changes for the WordPress 6.2 release.

  8. spacedmonkey commented on Nov 2, 2022

    @spacedmonkey
    Member
  9. spacedmonkey commented on Nov 2, 2022

    @spacedmonkey
    Member

    Key goals of this refactor.

    • Do no run logic on themes that do not support theme.json ( have this file ).
    • Only run the logic once.
    • Add set of developer focus functions that stop them from running code again.
    • Add unit tests.
    • Make code standard with rest of core.
    • Make code easier to test.
  10. oandregal commented on Nov 3, 2022

    @oandregal
    MemberAuthor

    Key goals of this refactor.

    Hey @spacedmonkey your comment may induce people to think this is about a refactor, that code does not have unit test, etc.
    That's not true.

    The issue description should be clear enough, though reiterating never hurts for expectations to be clear for everyone. This is about coordinating work among the dozens of people working on this area by highlighting actionable issues that will have an impact on user experience and/or code longevity.

  11. oandregal commented on Nov 3, 2022

    @oandregal
    MemberAuthor

    WordPress/wordpress-develop#3556 backports to core the wp_theme_has_theme_json method.

  12. spacedmonkey commented on Nov 3, 2022

    @spacedmonkey
    Member

    Hey @spacedmonkey your comment may induce people to think this is about a refactor, that code does not have unit test, etc. That's not true.

    Confused by this comment. I am just expanding on all this work should include refactoring to improve code quality and testability. A goal we should always keep in mind for any change to code.

  13. 26 remaining items

  14. oandregal commented on Feb 13, 2023

    @oandregal
    MemberAuthor

    Now that WordPress 6.2 beta is over, I've taken some time to reorganize the issue description so it's clear what has been shipped, what's ongoing, and what's next.

    Shipped in WordPress 6.2

    Public API:

    Performance:

    • wp_theme_has_theme_json: cache output #45543
    • wp_get_global_settings: cache output #45372 #45971 #45969
    • wp_get_global_stylesheet: migrate from transient to object cache #45679
    • wp_get_global_styles_svg_filters : migrate from transient to object cache #47460 (done in core as the function was removed from Gutenberg)
    • While initially the cache was implemented as persistent across requests for the above methods, concerns were brought up to make it non-persistent and keep testing: #46150

    Sync WordPress core <=> Gutenberg:

    It has seen some progress

    Public API:

    • In trying to extract template metadata from HTML files at #38984 we ran into a parser error with valid HTML comments that don't belong to a block #47212.
    • Stabilizing block selectors #45194. There's a PR that is mostly ready at #46496.

    Performance:

    • Conversation about how to allow theme.json caches to be made persistent across requests #45912

    Next

    See issue description.

  15. oandregal commented on Mar 23, 2023

    @oandregal
    MemberAuthor

    Created a section for ongoing 6.3 work.

  16. jsnajdr commented on May 4, 2023

    @jsnajdr
    Member

    Looking at the three wp_get_global_styles issues, they all want to resolve something, or convert it to a "canonical" value, so maybe the best API is not to create separate wp_get_global_styles_resolve_x functions, but to add an options parameter:

    wp_get_global_styles( $path, $context, $options )
    

    where the options is an object with fields like resolve_refs, resolve_css_vars etc.

    With the "resolve internal CSS var format to standard" and "resolve refs" options, it seems to me they should be resolved by default. Only the "resolve CSS variables into real values" should 100% be an option.

  17. oandregal commented on May 5, 2023

    @oandregal
    MemberAuthor

    With the "resolve internal CSS var format to standard" and "resolve refs" options, it seems to me they should be resolved by default. Only the "resolve CSS variables into real values" should 100% be an option.

    Agreed with the "internal CSS var", it should always be resolved: this is the easiest and @samnajian is looking into that.

    Also agreed on "resolve CSS variables" being not the default behavior. It's only a few setups (different rendering pipelines such as mobile, mails, RSS feed) that would need this one.

    I'm not sure about the "resolve refs": as far as my understanding goes, this aims to "declare links" between different style tokens. It may or may not be important for consumers to know those links exist, depending on what they want to do. See conversation at #49715 (comment)

  18. oandregal commented on May 12, 2023

    @oandregal
    MemberAuthor

    Relevant thread for the conversation about "transforming/resolving" references and variables in style values https://github.com/WordPress/gutenberg/pull/50484/files#r1192502874

  19. spacedmonkey commented on May 19, 2023

    @spacedmonkey
    Member

    This PR is still awaiting review - #45831

    There is also WordPress/wordpress-develop#3860 to look at as well.

  20. dd32 commented on Jun 19, 2023

    @dd32
    Member

    Syncing my comment from https://core.trac.wordpress.org/ticket/58460 over here:

    The name wp_get_remote_theme_patterns() feels a bit close to the wp_remote_*() and wp_safe_remote_*() methods to me. The inclusion of remote when it's not actually performing a remote-request seems weird too (I get that it's to say "This returns something that needs to be fetched remotely")

    I would suggest that something along the lines of wp_theme_required_patterns() or ...pattern_slugs() is maybe a little more understandable as to what it means? ie. wp_ (it's a WP function) theme_ (It's related to the themes component) required_ (It might not be required, and rather suggested?) pattern_slugs() what's being queried for.

    Looking at the rest of this PR, wp_get_... works as the next component is wp_get_global_..., but for wp_get_remote_theme_patterns() I still feel like the above comments make sense.

  21. oandregal commented on Jun 19, 2023

    @oandregal
    MemberAuthor

    Looking at the rest of this PR, wp_get_... works as the next component is wp_get_global_..., but for wp_get_remote_theme_patterns() I still feel like the above comments make sense.

    I've prepared WordPress/wordpress-develop#4640 to follow-up on this.

  22. oandregal commented on Aug 7, 2023

    @oandregal
    MemberAuthor

    PR for adding wp_get_theme_template_part_metadata WordPress/wordpress-develop#4971

  23. oandregal commented on Aug 7, 2023

    @oandregal
    MemberAuthor

    I've also updated the issue description with what we shipped in 6.3 and ongoing work for 6.4.

  24. felixarntz commented on Sep 7, 2023

    @felixarntz
    Member

    @oandregal Just checking in here for whether the issue description is still accurate? Is there any other work related to this that you intend to get into 6.4? Happy to help where I can!

  25. oandregal commented on Sep 18, 2023

    @oandregal
    MemberAuthor

    Just checking in here for whether the issue description is still accurate? Is there any other work related to this that you intend to get into 6.4? Happy to help where I can!

    @felixarntz yeah, it is. The two opened PRs related to performance are in draft at the moment, I don't think I'll be able to get them ready on time before beta. I'd like to revisit this work for the next cycles.

  26. youknowriad commented on Aug 5, 2026

    @youknowriad
    Contributor

    Closing as a stale tracking issue that seems to have served well. Let me know if I'm missing anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global StylesNeeds Dev Note[Feature] Block API[Type] Code Quality[Type] Tracking Issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions