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

Allow themes to add inline styles for all blocks when using lazy styles loading #32275

Merged
merged 7 commits into from
Jun 8, 2021
Merged
27 changes: 26 additions & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ function gutenberg_register_core_block_styles( $block_name ) {

// Add a reference to the stylesheet's path to allow calculations for inlining styles in `wp_head`.
wp_style_add_data( "wp-block-{$block_name}", 'path', gutenberg_dir_path() . $style_path );
} else {
wp_register_style( "wp-block-{$block_name}", false );
aristath marked this conversation as resolved.
Show resolved Hide resolved
}

if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) {
Expand All @@ -210,6 +212,8 @@ function gutenberg_register_core_block_styles( $block_name ) {
filemtime( gutenberg_dir_path() . $editor_style_path )
);
wp_style_add_data( "wp-block-{$block_name}-editor", 'rtl', 'replace' );
} else {
wp_register_style( "wp-block-{$block_name}-editor", false );
aristath marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -466,5 +470,26 @@ function gutenberg_migrate_old_typography_shape( $metadata ) {
return $metadata;
}


add_filter( 'block_type_metadata', 'gutenberg_migrate_old_typography_shape' );

/**
* Filters the content of a single block.
*
* @param array $args Array of arguments for registering a block type.
*
* @return array Returns the $metadata with any missing `style` and `editorStyle` added.
*/
function gutenberg_add_missing_styles_to_core_block_json( $args ) {
aristath marked this conversation as resolved.
Show resolved Hide resolved
if ( ! empty( $args['name'] ) && 0 === strpos( $args['name'], 'core/' ) ) {
$block_name = str_replace( 'core/', '', $args['name'] );

if ( ! isset( $args['style'] ) ) {
$args['style'] = "wp-block-$block_name";
}
if ( ! isset( $args['editor_style'] ) ) {
$args['editor_style'] = "wp-block-$block_name-editor";
}
}
return $args;
}
add_filter( 'register_block_type_args', 'gutenberg_add_missing_styles_to_core_block_json' );