Skip to content

Commit

Permalink
Prefix block style variations option with include for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jun 17, 2024
1 parent 1d8e2a5 commit 0933c7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/wp-includes/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ function wp_render_block_style_variation_support_styles( $parsed_block ) {
array( 'styles' ),
array( 'custom' ),
array(
'block_style_variations' => true,
'skip_root_layout_styles' => true,
'scope' => ".$class_name",
'include_block_style_variations' => true,
'skip_root_layout_styles' => true,
'scope' => ".$class_name",
)
);

Expand Down
21 changes: 11 additions & 10 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public static function get_element_class_name( $element ) {
* @param string $origin Optional. What source of data this object represents.
* One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
*/
public function __construct( $theme_json = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ), $origin = 'theme' ) {
public function __construct( $theme_json = array( 'version' => self::LATEST_SCHEMA ), $origin = 'theme' ) {
if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) {
$origin = 'theme';
}
Expand Down Expand Up @@ -1247,7 +1247,8 @@ public function get_settings() {
* @since 5.8.0
* @since 5.9.0 Removed the `$type` parameter, added the `$types` and `$origins` parameters.
* @since 6.3.0 Add fallback layout styles for Post Template when block gap support isn't available.
* @since 6.6.0 Added boolean `skip_root_layout_styles` option to omit layout styles if desired.
* @since 6.6.0 Added boolean `skip_root_layout_styles` and `include_block_style_variations` options
* to control styles output as desired.
*
* @param string[] $types Types of styles to load. Will load all by default. It accepts:
* - `variables`: only the CSS Custom Properties for presets & custom ones.
Expand All @@ -1257,10 +1258,10 @@ public function get_settings() {
* @param array $options {
* Optional. An array of options for now used for internal purposes only (may change without notice).
*
* @type string $scope Makes sure all style are scoped to a given selector
* @type string $root_selector Overwrites and forces a given selector to be used on the root node
* @type bool $skip_root_layout_styles Omits root layout styles from the generated stylesheet. Default false.
* @type bool $block_style_variations Includes styles for block style variations in the generated stylesheet. Default false.
* @type string $scope Makes sure all style are scoped to a given selector
* @type string $root_selector Overwrites and forces a given selector to be used on the root node
* @type bool $skip_root_layout_styles Omits root layout styles from the generated stylesheet. Default false.
* @type bool $include_block_style_variations Includes styles for block style variations in the generated stylesheet. Default false.
* }
* @return string The resulting stylesheet.
*/
Expand Down Expand Up @@ -2454,7 +2455,7 @@ protected static function get_setting_nodes( $theme_json, $selectors = array() )
* @param array $options {
* Optional. An array of options for now used for internal purposes only (may change without notice).
*
* @type bool $block_style_variations Includes style nodes for block style variations. Default false.
* @type bool $include_block_style_variations Includes style nodes for block style variations. Default false.
* }
* @return array An array of style nodes metadata.
*/
Expand Down Expand Up @@ -2578,7 +2579,7 @@ private static function update_separator_declarations( $declarations ) {
* @param array $options {
* Optional. An array of options for now used for internal purposes only (may change without notice).
*
* @type bool $block_style_variations Includes nodes for block style variations. Default false.
* @type bool $include_block_style_variations Includes nodes for block style variations. Default false.
* }
* @return array The block nodes in theme.json.
*/
Expand Down Expand Up @@ -2611,7 +2612,7 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt
}

$variation_selectors = array();
$include_variations = $options['block_style_variations'] ?? false;
$include_variations = $options['include_block_style_variations'] ?? false;
if ( $include_variations && isset( $node['variations'] ) ) {
foreach ( $node['variations'] as $variation => $node ) {
$variation_selectors[] = array(
Expand Down Expand Up @@ -3281,7 +3282,7 @@ public static function remove_insecure_properties( $theme_json, $origin = 'theme
$theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names, $valid_variations );

$blocks_metadata = static::get_blocks_metadata();
$style_options = array( 'block_style_variations' => true ); // Allow variations data.
$style_options = array( 'include_block_style_variations' => true ); // Allow variations data.
$style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata, $style_options );

foreach ( $style_nodes as $metadata ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -5567,7 +5567,7 @@ public function test_opt_in_to_block_style_variations() {
),
);
$selectors = array();
$options = array( 'block_style_variations' => true );
$options = array( 'include_block_style_variations' => true );

$block_nodes = $func->invoke( null, $theme_json, $selectors, $options );
$button_variations = $block_nodes[0]['variations'] ?? array();
Expand Down

0 comments on commit 0933c7d

Please sign in to comment.