WP_Theme_JSON::get_from_editor_settings( array $settings ): array

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


Parameters

$settings array Required
Existing editor settings.

Top ↑

Return

array Config that adheres to the theme.json schema.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php. View all references

			}
		}
	}
}

/**
 * Returns the raw data.
 *
 * @since 5.8.0
 *
 * @return array Raw data.
 */
public function get_raw_data() {
	return $this->theme_json;
}

/**
 * Transforms the given editor settings according the
 * add_theme_support format to the theme.json format.
 *
 * @since 5.8.0
 *
 * @param array $settings Existing editor settings.
 * @return array Config that adheres to the theme.json schema.
 */
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'];

Top ↑

Changelog

Changelog
Version Description
5.8.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.