Skip to content
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

Global styles: filter block level styles before compiling global stylesheet #42207

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions lib/compat/wordpress-6.1/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ function gutenberg_enqueue_global_styles() {
return;
}

/**
* If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally.
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
* This filter has to be registered before we call gutenberg_get_global_stylesheet();
*/
add_filter( 'gutenberg_get_style_nodes', 'filter_out_block_nodes', 10, 1 );

$stylesheet = gutenberg_get_global_stylesheet();
if ( empty( $stylesheet ) ) {
return;
Expand All @@ -93,11 +100,6 @@ function gutenberg_enqueue_global_styles() {
wp_add_inline_style( 'global-styles', $stylesheet );
wp_enqueue_style( 'global-styles' );

/**
* If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally.
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
*/
add_filter( 'gutenberg_get_style_nodes', 'filter_out_block_nodes' );
// add each block as an inline css.
wp_add_global_styles_for_blocks();
}
Expand Down