-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 filters to shortcircuit the public API of global styles #36909
Conversation
We've been wary of introducing filters for the internals of the global styles lifecycle and its data structure. The rationale is that the API needs room for consolidation/maturation with production feedback. I still think we should not introduce that kind of filters. However, now that we have an official public API to get data from the |
d29d8e1
to
c179f2b
Compare
Rebased as the branch this was based on #36907 has landed and, apparently, the automated change of base branch that GitHub didn't work as expected. |
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.
Provided the functions are being part of the core, I think this short-circuit behavior is a good way to allow us to change things on the plugin.
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 a "pre" and not a "post" filter. In other places in FSE we have post filters I believe.
See
|
I thought in this case it'd be more convenient for the kind of things we may want to do: not modifying internal data that is pre-calculated by WordPress core but short-circuiting core implementation altogether. For example, useful if the |
That reasoning is sound but in general I feel like the general guidelines (probably not everywhere) for core filters has been to filter a value that is computed by Core. Granted that it's less performant though. |
I actually think see that there's a lot of places in core where there's both but can't stop but think that a "post" should be the default. |
What do you think of the filter names? In this case, given these are for short-circuiting core's implementation of a particular function, I'd think it's best they are I'm less opinionated about the actual names of the functions (whether or not to use the |
The naming itself make sense for pre filters, I just wonder about the consistency and whether "pre" make sense without "post" (without the actual |
Inspecting a bit my gut feeling for a "pre" filter and against a "post" filter and this is what I came up with. This is the usage of these functions in WordPress core:
|
By doing this, we allow both the Gutenberg plugin and any 3rd party to change the behavior of these functions. This is useful specially for Gutenberg, where we may need to introduce future changes so we need a way to hook into the core functions. It's inspired by the pre_render_block filter.
c179f2b
to
9ae37db
Compare
(rebased for the CI jobs to restart, it seems they didn't like the changing of base branches) |
Also: if there was a "post" filter for settings/styles in |
That makes sense to me but for me, I have the same expectation but I also have the same expectations for |
I've been thinking more about this, it seems this expectation is almost impossible to meet. Let me explain:
In other words, this lead me to think, that these filters here are not good filters or at least they might be good for the Gutenberg plugin for potential future behavior change for these functions but that's it. So maybe internal filters is better for now or no filters (and just build new functions and use new functions in Gutenberg when the time comes to introduce new behavior) |
Discussed our options with Riad. This approach:
No filters:
All in all, we decided to go with no filters so far. It's the hardest option for us (Gutenberg) but it's more consistent with how WordPress core works: when we add filters they should let consumers filter every place the global styles settings/styles/stylesheet are used. |
@youknowriad @jorgefilipecosta I've run into a couple of places that add changes targeted to WordPress 6.0: webfonts API by @aristath and axial block gap support by @ramonjd @andrewserong I'm thinking that we already need to bootstrap something for 6.0, so people can continue working on GS features slated for 6.0 while the WordPress 5.9 is still ongoing. |
Related: allow users to specific custom filters #38055 (comment) and #38150 |
A follow-up to #34843 #36610 #36907
This PR introduces a shortcircuit filter for each one of the public functions we're introducing for global styles in WordPress 5.9.
It works this way (pseudo-code):
By doing this, we allow the Gutenberg plugin (and any 3rd party) to modify the behavior of these functions once they are in WordPress core. This is useful especially for Gutenberg, where we may need the ability to introduce future changes to how these functions work. Examples of changes that we're considering: support for multiple
theme.json
files ("global styles variations"), new schema versions, etc.It's inspired by the
pre_render_block
filter.