Skip to content

Deprecate/Remove the wp_theme_json_get_style_nodes filter #45172

Closed

Description

@oandregal

Part of #45171 (an effort to maintain our codebase in a healthy state)

What

Remove the existing wp_theme_json_get_style_nodes filter.

Why

The wp_theme_json_get_style_nodes filter was introduced #41160 (different name back then) and allows consumers to hook into the implementation of the WP_Theme_JSON::get_style_nodes method.

It allows consumers to filter a private method of a private class, converting into public API something that was private.

Unlike the merge algorithm, how we read and process a theme.json is not part of the public API. We should be able to change the implementation if we find a performance bottleneck, for example. That we have at some point in time all the style nodes in one place is a very low-level detail that can change if we modify the parser. By exposing this implementation detail, we are creating the expectation that it won't ever change.

How

To be explored via PRs.

Activity

  1. added
    [Type] Enhancement
    [Type] Code Quality
    on Oct 20, 2022
  2. oandregal commented on Oct 20, 2022

    @oandregal
    MemberAuthor

    cc @scruffian @adamziel @draganescu @ramonjd as the original authors/reviewers of the PR.

    I wish I had had the opportunity to offer this feedback at the time it was created, but I was not. I still find this problematic, and I'd like us to act preemptively rather than reactively.

  3. added
    Global Styles
    and removed
    [Type] Enhancement
    on Oct 20, 2022
  4. ramonjd commented on Oct 20, 2022

    @ramonjd
    Member

    Looking at where WP_Theme_JSON::get_style_nodes is called, it appears in two publicly declared functions:

    public function get_stylesheet
    public static function remove_insecure_properties

    Could we move the apply_filters to these functions? And do we really need it in the latter function?

    I'm not sure if it's in keeping with the intentions behind #41160

    The only place I see the filter being hooked into is in function wp_enqueue_global_styles()

  5. oandregal commented on Oct 21, 2022

    @oandregal
    MemberAuthor

    Could we move the apply_filters to these functions? And do we really need it in the latter function?

    I'm more concerned with the fact that how we read a theme.json should be a private implementation detail, and the filter makes it public. Firing the filter from a public function doesn't solve the core issue.

    The only place I see the filter being hooked into is in function wp_enqueue_global_styles()

    Yeah, true in the realm of WordPress codebase. Though because it is a filter, anyone can potentially use it: plugins, themes, building tools, etc.

  6. jorgefilipecosta commented on Jul 24, 2026

    @jorgefilipecosta
    Member

    Hi @oandregal us this issue still valid and we should deprecate wp_theme_json_get_style_nodes ?

  7. oandregal commented on Jul 24, 2026

    @oandregal
    MemberAuthor

    It's been almost 4 years since this issue. While the rationale still stands, I'm not sure this is longer a goal for us. I'm going to close, but happy if anyone wants to own/reopen it.

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 Styles[Type] Code Quality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions