-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix/wp get global styles for custom props returns internal variable #50366
Fix/wp get global styles for custom props returns internal variable #50366
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @samnajian! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
aa61fb1
to
c3ae73e
Compare
c3ae73e
to
e95e75b
Compare
This is a great start, thanks!
The only thing left would be to copy back from core the |
d0417a4
to
adc1de9
Compare
5cc4576
to
df27629
Compare
I've left a few suggestions for improving |
366ed4a
to
2ae9672
Compare
The logic that converts internal css variables to custom css variables is extracted to a function
As of the changes to WP_Theme_JSON_Resolver_Gutenberg, this function had to get defined to keep in sync with core
Co-authored-by: André <583546+oandregal@users.noreply.github.com>
Since convert_custom_properties is applied in constructor the other methods don't need to apply it again
Since the data is already checked against the schema sanitize_variables doesn't need to know about the schema anymore
05229a0
to
5833401
Compare
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.
This is great work, thanks for your contributions, Sam!
Congratulations on your first merged pull request, @samnajian! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
* Gets the styles resulting of merging core, theme, and user data. | ||
* | ||
* @since 5.9.0 | ||
* @since 6.3.0 the internal link format "var:preset|color|secondary" is resolved |
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.
Once introduced in WP Core, this modifies the value format for the returned styles from wp_get_global_styles()
. As such, it is a backwards-compatibility (BC) break for extenders expecting and using this structure.
The result could mean broken styling experiences for users.
Is this a truly a bugfix, meaning wp_get_global_styles()
should always have returned the style value structure? Or is this a new improvement to avoid leaking internal structures?
cc @oandregal
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.
This is why I think it's a fine change.
Let say we had the following input:
"core/post-terms": {
"typography": { "fontSize": "var(--wp--preset--font-size--small)" },
"color":{ "background": "var:preset|color|secondary" }
}
Before this PR, the output of wp_get_global_styles
would be:
(
[typography] => Array( [fontSize] => var(--wp--preset--font-size--small) )
[color] => Array( [background] => var:preset|color|secondary )
)
After this PR, the output of wp_get_global_styles
would be:
(
[typography] => Array( [fontSize] => var(--wp--preset--font-size--small) )
[color] => Array( [background] => var(--wp--preset--color--secondary) )
)
Before this PR, the consumers had to deal with two formats: var(--wp--preset--color--secondary)
and var:preset|color|secondary
, as a possible representation of the same value.
After this PR, they only have to deal with one format that's been always present: var(--wp--preset--color--secondary)
. I don't remember when the var:preset|color|secondary
was introduced for people to use in theme.json
but it was later and added as a convenience. It should have never leaked to consumers, in my view. I did some quick search but didn't find when it was, I can do some archeology if this is important.
An important note is that the format doesn't carry any meaning about where this data comes from. Any origin (default, block, theme, user) can use var:preset|color|secondary
. Consumers cannot use that format as a hint of it being data from the user origin.
Does this help?
Follow-up to fix PHP docblock at #50527 |
Backport at WordPress/wordpress-develop#4556 |
What?
This PR fixes #49693 so that
wp_get_global_styles
for the following in theme.jsonreturns:
Why?
#49693
The internal syntax shouldn't leak out.
How?
This PR extract the already existing logic that converts
var:preset|color|secondary
tovar(--wp--preset--font-size--small)
to a separate method, then uses the same method to sanitize the output ofwp_get_global_styles
to only include custom CSS variables and not internal variable syntax.Testing Instructions
Please refer to the issues for testing instructions, but please note the following:
wp_get_global_styles
exchangeWP_Theme_JSON_Resolver
withWP_Theme_JSON_Resolver_Gutenberg
wp_get_global_styles
doesn't include internal variable syntax.