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
Show file tree
Hide file tree
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
5 changes: 4 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,4 @@ function gutenberg_migrate_old_typography_shape( $metadata ) {
return $metadata;
}


add_filter( 'block_type_metadata', 'gutenberg_migrate_old_typography_shape' );
24 changes: 24 additions & 0 deletions lib/compat/wordpress-5.8/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,27 @@ function gutenberg_block_editor_rest_api_preload( array $preload_paths, $block_e
'after'
);
}

/**
* Filters the arguments for registering a block type.
*
* @todo Remove from the Gutenberg plugin when WordPress 5.8 is the minimum required version.
*
* @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 ) {
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' );