Skip to content
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

Deprecate/Remove the wp_theme_json_get_style_nodes filter #45172

Open
oandregal opened this issue Oct 20, 2022 · 3 comments
Open

Deprecate/Remove the wp_theme_json_get_style_nodes filter #45172

oandregal opened this issue Oct 20, 2022 · 3 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Code Quality Issues or PRs that relate to code quality

Comments

@oandregal
Copy link
Member

oandregal commented Oct 20, 2022

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.

@oandregal
Copy link
Member Author

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.

@oandregal oandregal added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json and removed [Type] Enhancement A suggestion for improvement. [Feature] Full Site Editing labels Oct 20, 2022
@ramonjd
Copy link
Member

ramonjd commented Oct 20, 2022

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()

@oandregal
Copy link
Member Author

oandregal commented Oct 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

No branches or pull requests

3 participants