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

Global Styles: Skip registration of variation styles when unsupported #62529

Merged
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
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 @@ -486,6 +486,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
Loading