-
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
[WIP] Style engine: register styles for enqueuing and rendering #41424
Conversation
a6b7318
to
a55525a
Compare
This looks very promising! 👍 |
Architecture need more thought.
if ( class_exists( 'WP_Style_Engine' ) ) { | ||
$style_engine = WP_Style_Engine::get_instance(); | ||
// Get style rules, then register/enqueue. | ||
$new_options = array_merge( $options, array( 'enqueue' => true ) ); |
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.
Try wp_parse_args here
/** | ||
* Builds layers and styles rules from registered layers and styles for output. | ||
*/ | ||
public static function enqueue_cascade_layers() { |
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.
Just testing outputting cascade layers for now to test the concept.
We really want registered styles to be the focus beforehand.
TODO:
- Needs to be tested against other styles for specificity
- How to make this opt-in? (We're instantiating
WP_Style_Engine
as a singleton, so should it be passed to the constructor somehow)
05b577f
to
c72366e
Compare
* @param array $options An array of options to determine the output. | ||
* @return void | ||
*/ | ||
function wp_style_engine_enqueue_styles( $block_styles, $options = array() ) { |
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.
Here we're generating and enqueuing block styles, a.k.a values from a styles object { spacing: { ... }, typography: { ... }, ... }
So maybe it should be called wp_style_engine_enqueue_block_styles
.
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.
That would make sense, yes 👍
/** | ||
* Creates a string consisting of CSS property declarations suitable for the value of an HTML element's style attribute. | ||
* | ||
* @param array $css_definitions An collection of CSS definitions `[ [ 'color' => 'red' ] ]`. |
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.
References to $css_definitions
should rather be $css_declarations
since they contain property: value
pairs
WIP
What?
Background context: #40987 (comment)
Why?
One of the aims is to be able to bundle output styles, and also open up the possibility of pre-processing, e.g., deduping
How?
Creating separate methods to handle style registration, taking into account the various "levels" of styles e.g., global and block supports.
Testing Instructions
Using Empty Theme:
Example
Instead of a
<style />
tag for each rule, we're collating them into one:The plan is to allow opt-in support for cascade layers as well: