Skip to content

Commit

Permalink
Register theme & custom variations.
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jun 17, 2024
1 parent 90f1f77 commit 5d18c8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/wp-includes/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,24 +495,5 @@ function wp_register_block_style_variations_from_theme() {
$variations_partials = WP_Theme_JSON_Resolver::get_style_variations( 'block' );
wp_register_block_style_variations_from_theme_json_data( $variations_partials );

/*
* Pull the data from the specific origin instead of the merged data.
* This is because, for 6.6, we only support registering block style variations
* for the 'theme' and 'custom' origins but not for 'default' (core theme.json)
* or 'custom' (theme.json in a block).
*
* When/If we add support for every origin, we should switch to using the public API
* instead, e.g.: wp_get_global_styles( array( 'blocks', 'variations' ) ).
*/

// theme.json of the theme.
$theme_json_theme = WP_Theme_JSON_Resolver::get_theme_data();
$variations_theme = $theme_json_theme->get_data()['styles']['blocks']['variations'] ?? array();
wp_register_block_style_variations_from_theme_json_data( $variations_theme );

// User data linked for this theme.
$theme_json_user = WP_Theme_JSON_Resolver::get_user_data();
$variations_user = $theme_json_user->get_data()['styles']['blocks']['variations'] ?? array();
wp_register_block_style_variations_from_theme_json_data( $variations_user );
}
add_action( 'init', 'wp_register_block_style_variations_from_theme' );
12 changes: 12 additions & 0 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ public static function get_theme_data( $deprecated = array(), $options = array()
$theme_json_data = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA );
}

// Register variations defined by the theme.
$variations = $theme_json_data['styles']['blocks']['variations'] ?? array();
wp_register_block_style_variations_from_theme_json_data( $variations );

// Process theme partials (theme.json files in the styles directory).
$variations = self::get_style_variations( 'block' );
wp_register_block_style_variations_from_theme_json_data( $variations );

/**
* Filters the data provided by the theme for global styles and settings.
*
Expand Down Expand Up @@ -528,6 +536,10 @@ public static function get_user_data() {
unset( $decoded_data['isGlobalStylesUserThemeJSON'] );
$config = $decoded_data;
}

// Register variations defined by the user.
$variations = $config['styles']['blocks']['variations'] ?? array();
wp_register_block_style_variations_from_theme_json_data( $variations );
}

/** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
Expand Down

0 comments on commit 5d18c8c

Please sign in to comment.