Skip to content

Commit

Permalink
Only opt-in into tools if it is actually true
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Dec 9, 2021
1 parent 30aab8a commit 35498b3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php
Expand Up @@ -359,13 +359,16 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) {
private static function maybe_opt_in_into_settings( $theme_json ) {
$new_theme_json = $theme_json;

if ( isset( $new_theme_json['settings']['appearanceTools'] ) ) {
if (
isset( $new_theme_json['settings']['appearanceTools'] ) &&
true === $new_theme_json['settings']['appearanceTools']
) {
self::do_opt_in_into_settings( $new_theme_json['settings'] );
}

if ( isset( $new_theme_json['settings']['blocks'] ) && is_array( $new_theme_json['settings']['blocks'] ) ) {
foreach ( $new_theme_json['settings']['blocks'] as &$block ) {
if ( isset( $block['appearanceTools'] ) ) {
if ( isset( $block['appearanceTools'] ) && ( true === $block['appearanceTools'] ) ) {
self::do_opt_in_into_settings( $block );
}
}
Expand Down
55 changes: 53 additions & 2 deletions phpunit/class-wp-theme-json-test.php
Expand Up @@ -188,12 +188,15 @@ function test_get_settings_presets_are_keyed_by_origin() {
$this->assertEqualSetsWithIndex( $expected_no_origin, $actual_no_origin );
}

function test_get_settings_using_opt_in_key() {
function test_get_settings_appearance_true_opts_in() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'appearanceTools' => true,
'spacing' => array(
'blockGap' => false, // This should override appearanceTools.
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
Expand Down Expand Up @@ -223,7 +226,7 @@ function test_get_settings_using_opt_in_key() {
'link' => true,
),
'spacing' => array(
'blockGap' => true,
'blockGap' => false,
'margin' => true,
'padding' => true,
),
Expand Down Expand Up @@ -261,6 +264,54 @@ function test_get_settings_using_opt_in_key() {
$this->assertEqualSetsWithIndex( $expected, $actual );
}

function test_get_settings_appearance_false_does_not_opt_in() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'appearanceTools' => false,
'border' => array(
'width' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => false,
),
),
'core/group' => array(
'typography' => array(
'lineHeight' => false,
),
),
),
),
)
);

$actual = $theme_json->get_settings();
$expected = array(
'appearanceTools' => false,
'border' => array(
'width' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => false,
),
),
'core/group' => array(
'typography' => array(
'lineHeight' => false,
),
),
),
);

$this->assertEqualSetsWithIndex( $expected, $actual );
}

function test_get_stylesheet_support_for_shorthand_and_longhand_values() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
Expand Down

0 comments on commit 35498b3

Please sign in to comment.