WP_Theme_JSON::get_from_editor_settings() – Transforms the given editor settings according the add_theme_support format to the theme.json format.

You appear to be a bot. Output may be restricted

Description

Transforms the given editor settings according the add_theme_support format to the theme.json format.

Usage

$array = WP_Theme_JSON::get_from_editor_settings( $settings );

Parameters

$settings
( array ) required – Existing editor settings.

Returns

array Config that adheres to the theme.json schema.

Source

File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:

1 to 81 of 81
  public static function get_from_editor_settings( $settings ) {
    $theme_settings = array(
      'version'  => static::LATEST_SCHEMA,
      'settings' => array(),
    );

    // Deprecated theme supports.
    if ( isset( $settings['disableCustomColors'] ) ) {
      if ( ! isset( $theme_settings['settings']['color'] ) ) {
        $theme_settings['settings']['color'] = array();
      }
      $theme_settings['settings']['color']['custom'] = ! $settings['disableCustomColors'];
    }

    if ( isset( $settings['disableCustomGradients'] ) ) {
      if ( ! isset( $theme_settings['settings']['color'] ) ) {
        $theme_settings['settings']['color'] = array();
      }
      $theme_settings['settings']['color']['customGradient'] = ! $settings['disableCustomGradients'];
    }

    if ( isset( $settings['disableCustomFontSizes'] ) ) {
      if ( ! isset( $theme_settings['settings']['typography'] ) ) {
        $theme_settings['settings']['typography'] = array();
      }
      $theme_settings['settings']['typography']['customFontSize'] = ! $settings['disableCustomFontSizes'];
    }

    if ( isset( $settings['enableCustomLineHeight'] ) ) {
      if ( ! isset( $theme_settings['settings']['typography'] ) ) {
        $theme_settings['settings']['typography'] = array();
      }
      $theme_settings['settings']['typography']['lineHeight'] = $settings['enableCustomLineHeight'];
    }

    if ( isset( $settings['enableCustomUnits'] ) ) {
      if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
        $theme_settings['settings']['spacing'] = array();
      }
      $theme_settings['settings']['spacing']['units'] = ( true === $settings['enableCustomUnits'] ) ?
        array( 'px', 'em', 'rem', 'vh', 'vw', '%' ) :
        $settings['enableCustomUnits'];
    }

    if ( isset( $settings['colors'] ) ) {
      if ( ! isset( $theme_settings['settings']['color'] ) ) {
        $theme_settings['settings']['color'] = array();
      }
      $theme_settings['settings']['color']['palette'] = $settings['colors'];
    }

    if ( isset( $settings['gradients'] ) ) {
      if ( ! isset( $theme_settings['settings']['color'] ) ) {
        $theme_settings['settings']['color'] = array();
      }
      $theme_settings['settings']['color']['gradients'] = $settings['gradients'];
    }

    if ( isset( $settings['fontSizes'] ) ) {
      $font_sizes = $settings['fontSizes'];
      // Back-compatibility for presets without units.
      foreach ( $font_sizes as $key => $font_size ) {
        if ( is_numeric( $font_size['size'] ) ) {
          $font_sizes[ $key ]['size'] = $font_size['size'] . 'px';
        }
      }
      if ( ! isset( $theme_settings['settings']['typography'] ) ) {
        $theme_settings['settings']['typography'] = array();
      }
      $theme_settings['settings']['typography']['fontSizes'] = $font_sizes;
    }

    if ( isset( $settings['enableCustomSpacing'] ) ) {
      if ( ! isset( $theme_settings['settings']['spacing'] ) ) {
        $theme_settings['settings']['spacing'] = array();
      }
      $theme_settings['settings']['spacing']['padding'] = $settings['enableCustomSpacing'];
    }

    return $theme_settings;
  }
 

 View on GitHub View on Trac