Skip to content

Commit

Permalink
Revert "Adds a setting property that enables some other ones (#36246)" (
Browse files Browse the repository at this point in the history
#36477)

This reverts commit ed922a1.
  • Loading branch information
noisysocks committed Nov 15, 2021
1 parent ed83554 commit 94f0cb1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 123 deletions.
8 changes: 0 additions & 8 deletions docs/how-to-guides/themes/theme-json.md
Expand Up @@ -280,14 +280,6 @@ Each block can configure any of these settings separately, providing a more fine

Note, however, that not all settings are relevant for all blocks. The settings section provides an opt-in/opt-out mechanism for themes, but it's the block's responsibility to add support for the features that are relevant to it. For example, if a block doesn't implement the `dropCap` feature, a theme can't enable it for such a block through `theme.json`.

### Opt-in into appearance controls

There's one special setting property, `appareance`, which can be a boolean and its default value is true. When this is enabled, the following setting properties will be on by default:

- border: color, radius, style, width
- spacing: margin, padding, units
- typography: customFontSize, lineHeight

#### Backward compatibility with add_theme_support

To retain backward compatibility, the existing `add_theme_support` declarations that configure the block editor are retrofit in the proper categories for the top-level section. For example, if a theme uses `add_theme_support('disable-custom-colors')`, it'll be the same as setting `settings.color.custom` to `false`. If the `theme.json` contains any settings, these will take precedence over the values declared via `add_theme_support`. This is the complete list of equivalences:
Expand Down
46 changes: 1 addition & 45 deletions lib/class-wp-theme-json-gutenberg.php
Expand Up @@ -81,7 +81,6 @@ class WP_Theme_JSON_Gutenberg {
);

const VALID_SETTINGS = array(
'appearance' => null,
'border' => array(
'color' => null,
'radius' => null,
Expand Down Expand Up @@ -291,8 +290,7 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) {

$valid_block_names = array_keys( self::get_blocks_metadata() );
$valid_element_names = array_keys( self::ELEMENTS );
$theme_json = self::sanitize( $theme_json, $valid_block_names, $valid_element_names );
$this->theme_json = self::maybe_opt_in_into_settings( $theme_json );
$this->theme_json = self::sanitize( $theme_json, $valid_block_names, $valid_element_names );

// Internally, presets are keyed by origin.
$nodes = self::get_setting_nodes( $this->theme_json );
Expand All @@ -307,48 +305,6 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) {
}
}

/**
* Enables some opt-in settings if theme declared support.
*
* @param array $theme_json A theme.json structure to modify.
* @return array The modified theme.json structure.
*/
private static function maybe_opt_in_into_settings( $theme_json ) {
$new_theme_json = $theme_json;

if ( isset( $new_theme_json['settings']['appearance'] ) ) {
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['appearance'] ) ) {
self::do_opt_in_into_settings( $block );
}
}
}

return $new_theme_json;
}

/**
* Enables some settings.
*
* @param array $context The context to which the settings belong.
*/
private static function do_opt_in_into_settings( &$context ) {
gutenberg_experimental_set( $context, array( 'border', 'color' ), true );
gutenberg_experimental_set( $context, array( 'border', 'radius' ), true );
gutenberg_experimental_set( $context, array( 'border', 'style' ), true );
gutenberg_experimental_set( $context, array( 'border', 'width' ), true );
gutenberg_experimental_set( $context, array( 'spacing', 'margin' ), true );
gutenberg_experimental_set( $context, array( 'spacing', 'padding' ), true );
gutenberg_experimental_set( $context, array( 'spacing', 'units' ), true );
gutenberg_experimental_set( $context, array( 'typography', 'customFontSize' ), true );
gutenberg_experimental_set( $context, array( 'typography', 'lineHeight' ), true );
unset( $context['appearance'] );
}

/**
* Sanitizes the input according to the schemas.
*
Expand Down
1 change: 0 additions & 1 deletion lib/theme.json
@@ -1,7 +1,6 @@
{
"version": 2,
"settings": {
"appearance": true,
"color": {
"background": true,
"palette": [
Expand Down
69 changes: 0 additions & 69 deletions phpunit/class-wp-theme-json-test.php
Expand Up @@ -188,75 +188,6 @@ 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() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'appearance' => true,
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => false,
),
),
'core/group' => array(
'appearance' => true,
'typography' => array(
'lineHeight' => false, // This is overridden by appearance.
),
),
),
),
)
);

$actual = $theme_json->get_settings();
$expected = array(
'border' => array(
'width' => true,
'style' => true,
'radius' => true,
'color' => true,
),
'spacing' => array(
'margin' => true,
'padding' => true,
'units' => true,
),
'typography' => array(
'customFontSize' => true,
'lineHeight' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => false,
),
),
'core/group' => array(
'border' => array(
'width' => true,
'style' => true,
'radius' => true,
'color' => true,
),
'spacing' => array(
'margin' => true,
'padding' => true,
'units' => true,
),
'typography' => array(
'customFontSize' => true,
'lineHeight' => true,
),
),
),
);

$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 94f0cb1

Please sign in to comment.