Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0840074
Enqueuing block support styles version 1.
ramonjd Jul 15, 2022
6a42821
Linter, this one's for you.
ramonjd Jul 15, 2022
1f2b4a8
Post trunk merge cleanup and update tests.
ramonjd Jul 15, 2022
5a51073
Removed spacing around curly braces in CSS rules. Updated tests.
ramonjd Jul 18, 2022
55576b9
Splitting `wp_style_engine_enqueue_block_supports_styles` and `wp_sty…
ramonjd Jul 19, 2022
acc6209
Integrate the processor class
ramonjd Jul 24, 2022
7a22c5b
Migrate layout styles to style engine store.
ramonjd Jul 25, 2022
7a6aa60
Update packages/style-engine/class-wp-style-engine.php
ramonjd Jul 27, 2022
49b1433
Tweaks for #42452 (#42691)
aristath Jul 27, 2022
d7893a6
Adding check for the context argument.
ramonjd Jul 28, 2022
bc6e39a
Updating the processor so that it's ignorant of stores. Why? So that …
ramonjd Jul 29, 2022
e8a621d
dump var_dump()
ramonjd Jul 29, 2022
9ba5232
Improve the processor
aristath Jul 29, 2022
b41af7d
remove trailing commas - compatibility with PHP < 7.2
aristath Jul 29, 2022
4ccf650
rename css_declarations to declarations
aristath Jul 29, 2022
e30e4fb
remove unused variable
aristath Jul 29, 2022
062b920
Switch parse_block_styles from public to protected static
ramonjd Aug 1, 2022
5e4164a
Now that all methods are static, there's no need to call `get_instanc…
ramonjd Aug 1, 2022
fcebf93
Revert get_instance() in wp_style_engine_add_to_store because we want…
ramonjd Aug 1, 2022
d0d5fe5
Adding a test for the 'enqueue' flag.
ramonjd Aug 1, 2022
e59eb10
Update lib/block-supports/layout.php
ramonjd Aug 1, 2022
5d7b827
Adding a test for the 'enqueue' flag.
ramonjd Aug 1, 2022
4d9f6c8
Merge branch 'try/style-engine-enqueue-block-supports-styles' of gith…
ramonjd Aug 1, 2022
8d021ee
Add named stores to the processor
aristath Aug 1, 2022
5f60026
avoid setting var for something that only gets used once
aristath Aug 1, 2022
a63f9cb
Only use "else" if absolutely necessary
aristath Aug 1, 2022
0eaef08
Add a set_name method
aristath Aug 1, 2022
e4c791b
combine & simplify conditions
aristath Aug 1, 2022
787f793
use empty() instead of isset() checks here
aristath Aug 1, 2022
7dd5773
shorten it
aristath Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Splitting wp_style_engine_enqueue_block_supports_styles and `wp_sty…
…le_engine_get_block_supports_styles` so we can enqueue styles that don't need parsing, e.g., layout
  • Loading branch information
ramonjd authored and aristath committed Jul 29, 2022
commit 55576b9faf2e0f6e355a504485a2325aa75327ca
8 changes: 7 additions & 1 deletion lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ function gutenberg_render_elements_support_styles( $pre_render, $block ) {
$class_name = gutenberg_get_elements_class_name( $block );
$link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null;

gutenberg_style_engine_enqueue_block_supports_styles( ".$class_name a", $link_block_styles );
gutenberg_style_engine_get_block_supports_styles(
$link_block_styles,
array(
'selector' => ".$class_name a",
'enqueue' => true,
)
);

return null;
}
Expand Down
32 changes: 18 additions & 14 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,17 +646,26 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
$defaults = array(
'selector' => null,
'convert_vars_to_classnames' => false,
'enqueue' => false,
);

$options = wp_parse_args( $options, $defaults );
$style_engine = WP_Style_Engine::get_instance();
$parsed_styles = $style_engine->parse_block_supports_styles( $block_styles, $options );

// Output.
$styles_output = array();
$styles_output['css'] = $style_engine->compile_css( $parsed_styles['css_declarations'], $options['selector'] );
$styles_output['declarations'] = $parsed_styles['css_declarations'];
$styles_output['classnames'] = $style_engine->compile_classnames( $parsed_styles['classnames'] );
$styles_output = array();
if ( ! empty( $parsed_styles['css_declarations'] ) ) {
$styles_output['css'] = $style_engine->compile_css( $parsed_styles['css_declarations'], $options['selector'] );
$styles_output['declarations'] = $parsed_styles['css_declarations'];
if ( true === $options['enqueue'] ) {
$style_engine->store_css_rule( $options['selector'], $parsed_styles['css_declarations'], 'block-supports' );
}
}

if ( ! empty( $parsed_styles['classnames'] ) ) {
$styles_output['classnames'] = $style_engine->compile_classnames( $parsed_styles['classnames'] );
}

return array_filter( $styles_output );
}
Expand All @@ -669,22 +678,17 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
*
* @access public
*
* @param string $selector A CSS selector.
* @param array $block_styles The value of a block's attributes.style.
* @param string $selector A CSS selector.
* @param array $css_declarations An array of CSS definitions, e.g., array( "$property" => "$value" ).
*
* @return boolean Whether the storage process was successful.
*/
function wp_style_engine_enqueue_block_supports_styles( $selector, $block_styles ) {
if ( empty( $selector ) || empty( $block_styles ) ) {
function wp_style_engine_enqueue_block_supports_styles( $selector, $css_declarations ) {
if ( empty( $selector ) || empty( $css_declarations ) ) {
return false;
}
if ( class_exists( 'WP_Style_Engine' ) ) {
$options = array(
'selector' => $selector,
);
$style_engine = WP_Style_Engine::get_instance();
$parsed_styles = $style_engine->parse_block_supports_styles( $block_styles, $options );
return $style_engine->store_css_rule( $selector, $parsed_styles['css_declarations'], 'block-supports' );
return WP_Style_Engine::get_instance()->store_css_rule( $selector, $css_declarations, 'block-supports' );
}
return false;
}