From 09bd43cee6cc197b0c3dc8a13bcad58f307de9ce Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Fri, 5 Mar 2021 17:35:42 +0000 Subject: [PATCH] WP Block Styles: Only load in the editor if a theme opts in (#29252) * WP Block Styles: Only load in the editor if a theme opts in, or if it doesn't add any editor styles * Check that the array exists * Update lib/client-assets.php Co-authored-by: Jeff Ong Co-authored-by: Jeff Ong --- lib/client-assets.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index d686310288594..289c37b55ed06 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -368,18 +368,24 @@ function gutenberg_register_packages_styles( $styles ) { ); $styles->add_data( 'wp-format-library', 'rtl', 'replace' ); + $wp_edit_blocks_dependencies = array( + 'wp-components', + 'wp-editor', + 'wp-block-library', + 'wp-reusable-blocks', + ); + + global $editor_styles; + if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) { + // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken. + $wp_edit_blocks_dependencies[] = 'wp-block-library-theme'; + } + gutenberg_override_style( $styles, 'wp-edit-blocks', gutenberg_url( 'build/block-library/editor.css' ), - array( - 'wp-components', - 'wp-editor', - 'wp-block-library', - 'wp-reusable-blocks', - // Always include visual styles so the editor never appears broken. - 'wp-block-library-theme', - ), + $wp_edit_blocks_dependencies, filemtime( gutenberg_dir_path() . 'build/block-library/editor.css' ) ); $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );