Skip to content

Commit 90f1f77

Browse files
committed
Global Styles: Avoid unnecessary processing of theme.json variation partials.
Props aaronrobertshaw, oandregal, mukesh27. See #61451. git-svn-id: https://develop.svn.wordpress.org/trunk@58423 602fd350-edb4-49c9-b593-d223f7449a82
1 parent fb20072 commit 90f1f77

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/wp-includes/block-supports/block-style-variations.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,23 @@ function wp_register_block_style_variations_from_theme_json_data( $variations )
474474
* @access private
475475
*/
476476
function wp_register_block_style_variations_from_theme() {
477+
/*
478+
* Skip any registration of styles if no theme.json or variation partials are present.
479+
*
480+
* Given the possibility of hybrid themes, this check can't rely on if the theme
481+
* is a block theme or not. Instead:
482+
* - If there is a primary theme.json, continue.
483+
* - If there is a partials directory, continue.
484+
* - The only variations to be registered from the global styles user origin,
485+
* are those that have been copied in from the selected theme style variation.
486+
* For a theme style variation to be selected it would have to have a partial
487+
* theme.json file covered by the previous check.
488+
*/
489+
$has_partials_directory = is_dir( get_stylesheet_directory() . '/styles' ) || is_dir( get_template_directory() . '/styles' );
490+
if ( ! wp_theme_has_theme_json() && ! $has_partials_directory ) {
491+
return;
492+
}
493+
477494
// Partials from `/styles`.
478495
$variations_partials = WP_Theme_JSON_Resolver::get_style_variations( 'block' );
479496
wp_register_block_style_variations_from_theme_json_data( $variations_partials );

0 commit comments

Comments
 (0)