Skip to content

Commit

Permalink
Global Styles: Skip registration of variation styles when unsupported (
Browse files Browse the repository at this point in the history
…#62529)

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
  • Loading branch information
4 people authored and ellatrix committed Jun 18, 2024
1 parent ecc7107 commit f0327a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backport-changelog/6.6/6837.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/6837

* https://github.com/WordPress/gutenberg/pull/62529
* https://github.com/WordPress/gutenberg/pull/62610
17 changes: 17 additions & 0 deletions lib/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,23 @@ function gutenberg_register_block_style_variations_from_theme_json_data( $variat
* @access private
*/
function gutenberg_register_block_style_variations_from_theme() {
/*
* Skip any registration of styles if no theme.json or variation partials are present.
*
* Given the possibility of hybrid themes, this check can't rely on if the theme
* is a block theme or not. Instead:
* - If there is a primary theme.json, continue.
* - If there is a partials directory, continue.
* - The only variations to be registered from the global styles user origin,
* are those that have been copied in from the selected theme style variation.
* For a theme style variation to be selected it would have to have a partial
* theme.json file covered by the previous check.
*/
$has_partials_directory = is_dir( get_stylesheet_directory() . '/styles' ) || is_dir( get_template_directory() . '/styles' );
if ( ! wp_theme_has_theme_json() && ! $has_partials_directory ) {
return;
}

// Partials from `/styles`.
$variations_partials = WP_Theme_JSON_Resolver_Gutenberg::get_style_variations( 'block' );
gutenberg_register_block_style_variations_from_theme_json_data( $variations_partials );
Expand Down

0 comments on commit f0327a0

Please sign in to comment.