-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 global styles #1287
Add global styles #1287
Conversation
Need to update the unit tests and prepare the corresponding Gutenberg PR, but the code is ready for review. |
* @return void | ||
*/ | ||
function wp_enqueue_global_styles() { | ||
if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { |
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.
In cases where there is link color enabled add_theme_support('experimental-link-color'); we need to output the preset classes, should we have a condition for that here?
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.
I'm not familiar with prior context on how to deal with this so I'd welcome advice. My thinking is that we should do the following:
- We shouldn't port
experimental-link-color
to WordPress core. Themes that want that should use enable it viatheme.json
. - In the plugin, I'd expect we remove support for
experimental-link-color
at some point. Probably when the minimum WordPress version for the plugin is 5.8.
Thoughts?
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.
Yes this seems like a plan 👍
$stylesheet = $theme_json->get_stylesheet(); | ||
|
||
if ( $can_use_cache ) { | ||
set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS ); |
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.
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 worked well on my tests and should be ready to merge 👍
I found some issues setting an empty color palette does not work (it defaults to core) but that's a regression setting an empty color palette is a way to disable the color picker. I guess we should look into these issues separately.
Committed in 3d3aa3c this PR can be closed. |
Part of https://core.trac.wordpress.org/ticket/53175
Follow-up to #1262
To do
How to test
A theme without theme.json (use the TwentyTwentyOne theme):
global-styles-inline-css
embedded stylesheet. The expected result is that none should be found.--wp--preset--color
. The expected result is that none should be found.A theme with theme.json support:
global-styles-inline-css
embedded stylesheet. The expected result is that there's a stylesheet that contains the CSS generated by the engine. Depending on the theme's theme.json, it should be something along these lines:--wp--preset--color
. The expected result is that there's an embedded stylesheet that contains the CSS Custom Properties..has-black-color{ ... }
. The expected result is that there's an embedded stylesheet that contains the classes for the presets as well as any other block styles defined by the theme viatheme.json
.