WP_Theme_JSON::get_data(): array

In this article

Returns a valid theme.json as provided by a theme.

Description

Unlike get_raw_data() this returns the presets flattened, as provided by a theme.
This also uses appearanceTools instead of their opt-ins if all of them are true.

Return

array

Source

 */
private static function remove_indirect_properties( $input, &$output ) {
	foreach ( static::INDIRECT_PROPERTIES_METADATA as $property => $paths ) {
		foreach ( $paths as $path ) {
			$value = _wp_array_get( $input, $path );
			if (
				is_string( $value ) &&
				static::is_safe_css_declaration( $property, $value )
			) {
				_wp_array_set( $output, $path, $value );
			}
		}
	}
}

/**
 * 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'];
	}

	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;
}

/**
 * Returns the current theme's wanted patterns(slugs) to be
 * registered from Pattern Directory.
 *
 * @since 6.0.0
 *
 * @return string[]
 */
public function get_patterns() {
	if ( isset( $this->theme_json['patterns'] ) && is_array( $this->theme_json['patterns'] ) ) {
		return $this->theme_json['patterns'];
	}
	return array();
}

/**
 * Returns a valid theme.json as provided by a theme.
 *
 * Unlike get_raw_data() this returns the presets flattened, as provided by a theme.
 * This also uses appearanceTools instead of their opt-ins if all of them are true.
 *
 * @since 6.0.0
 *

Changelog

VersionDescription
6.0.0Introduced.

User Contributed Notes

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