WordPress.org

Make WordPress Core

Changeset 50959


Ignore:
Timestamp:
05/24/2021 08:36:11 AM (4 months ago)
Author:
youknowriad
Message:

Block Editor: Add Global Settings support using theme.json file.

This is the first piece of landing the theme.json processing in WordPress core.
It allows themes to configure the different editor settings, allow cusomizations and define presets in theme.json file.

Props jorgefilipecosta, nosolosw.
See #53175.

Location:
trunk
Files:
14 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r50956 r50959  
    244244    );
    245245
     246    $editor_settings['__experimentalFeatures'] = WP_Theme_JSON_Resolver::get_merged_data( $editor_settings )->get_settings();
     247
     248    // These settings may need to be updated based on data coming from theme.json sources.
     249    if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) {
     250        $editor_settings['colors'] = $editor_settings['__experimentalFeatures']['color']['palette'];
     251        unset( $editor_settings['__experimentalFeatures']['color']['palette'] );
     252    }
     253    if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) {
     254        $editor_settings['gradients'] = $editor_settings['__experimentalFeatures']['color']['gradients'];
     255        unset( $editor_settings['__experimentalFeatures']['color']['gradients'] );
     256    }
     257    if ( isset( $editor_settings['__experimentalFeatures']['color']['custom'] ) ) {
     258        $editor_settings['disableCustomColors'] = $editor_settings['__experimentalFeatures']['color']['custom'];
     259        unset( $editor_settings['__experimentalFeatures']['color']['custom'] );
     260    }
     261    if ( isset( $editor_settings['__experimentalFeatures']['color']['customGradient'] ) ) {
     262        $editor_settings['disableCustomGradients'] = $editor_settings['__experimentalFeatures']['color']['customGradient'];
     263        unset( $editor_settings['__experimentalFeatures']['color']['customGradient'] );
     264    }
     265    if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
     266        $editor_settings['fontSizes'] = $editor_settings['__experimentalFeatures']['typography']['fontSizes'];
     267        unset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] );
     268    }
     269    if ( isset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] ) ) {
     270        $editor_settings['disableCustomFontSizes'] = $editor_settings['__experimentalFeatures']['typography']['customFontSize'];
     271        unset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] );
     272    }
     273    if ( isset( $editor_settings['__experimentalFeatures']['typography']['customLineHeight'] ) ) {
     274        $editor_settings['enableCustomLineHeight'] = $editor_settings['__experimentalFeatures']['typography']['customLineHeight'];
     275        unset( $editor_settings['__experimentalFeatures']['typography']['customLineHeight'] );
     276    }
     277    if ( isset( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) {
     278        if ( ! is_array( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) {
     279            $editor_settings['enableCustomUnits'] = false;
     280        } else {
     281            $editor_settings['enableCustomUnits'] = count( $editor_settings['__experimentalFeatures']['spacing']['units'] ) > 0;
     282        }
     283        unset( $editor_settings['__experimentalFeatures']['spacing']['units'] );
     284    }
     285    if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customPadding'] ) ) {
     286        $editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['customPadding'];
     287        unset( $editor_settings['__experimentalFeatures']['spacing']['customPadding'] );
     288    }
     289
    246290    /**
    247291     * Filters the settings to pass to the block editor for all editor type.
  • trunk/src/wp-settings.php

    r50956 r50959  
    296296require ABSPATH . WPINC . '/blocks.php';
    297297require ABSPATH . WPINC . '/blocks/index.php';
     298require ABSPATH . WPINC . '/class-wp-theme-json.php';
     299require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php';
    298300require ABSPATH . WPINC . '/block-editor.php';
    299301require ABSPATH . WPINC . '/block-patterns.php';
Note: See TracChangeset for help on using the changeset viewer.