WP_Theme_JSON::get_stylesheet()publicWP 5.8.0

Returns the stylesheet that results of processing the theme.json structure this object represents.

Метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

Строку. The resulting stylesheet.

Использование

$WP_Theme_JSON = new WP_Theme_JSON();
$WP_Theme_JSON->get_stylesheet( $types, fooo, foooo ), $origins );
$types(массив)
Types of styles to load. Will load all by default. It accepts:
  • variables: only the CSS Custom Properties for presets & custom ones.
  • styles: only the styles section in theme.json.
  • presets: only the classes for the presets.
    По умолчанию: array( foo
fooo (обязательный)
-
foooo ) (обязательный)
-
$origins(массив)
A list of origins to include. By default it includes VALID_ORIGINS.
По умолчанию: null

Список изменений

С версии 5.8.0 Введена.
С версии 5.9.0 Removed the $type parameter, added the$typesand$origins` parameters.

Код WP_Theme_JSON::get_stylesheet() WP 6.1.1

public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null ) {
	if ( null === $origins ) {
		$origins = static::VALID_ORIGINS;
	}

	if ( is_string( $types ) ) {
		// Dispatch error and map old arguments to new ones.
		_deprecated_argument( __FUNCTION__, '5.9.0' );
		if ( 'block_styles' === $types ) {
			$types = array( 'styles', 'presets' );
		} elseif ( 'css_variables' === $types ) {
			$types = array( 'variables' );
		} else {
			$types = array( 'variables', 'styles', 'presets' );
		}
	}

	$blocks_metadata = static::get_blocks_metadata();
	$style_nodes     = static::get_style_nodes( $this->theme_json, $blocks_metadata );
	$setting_nodes   = static::get_setting_nodes( $this->theme_json, $blocks_metadata );

	$stylesheet = '';

	if ( in_array( 'variables', $types, true ) ) {
		$stylesheet .= $this->get_css_variables( $setting_nodes, $origins );
	}

	if ( in_array( 'styles', $types, true ) ) {
		$root_block_key = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $style_nodes, 'selector' ), true );

		if ( false !== $root_block_key ) {
			$stylesheet .= $this->get_root_layout_rules( static::ROOT_BLOCK_SELECTOR, $style_nodes[ $root_block_key ] );
		}
		$stylesheet .= $this->get_block_classes( $style_nodes );
	} elseif ( in_array( 'base-layout-styles', $types, true ) ) {
		// Base layout styles are provided as part of `styles`, so only output separately if explicitly requested.
		// For backwards compatibility, the Columns block is explicitly included, to support a different default gap value.
		$base_styles_nodes = array(
			array(
				'path'     => array( 'styles' ),
				'selector' => static::ROOT_BLOCK_SELECTOR,
			),
			array(
				'path'     => array( 'styles', 'blocks', 'core/columns' ),
				'selector' => '.wp-block-columns',
				'name'     => 'core/columns',
			),
		);

		foreach ( $base_styles_nodes as $base_style_node ) {
			$stylesheet .= $this->get_layout_styles( $base_style_node );
		}
	}

	if ( in_array( 'presets', $types, true ) ) {
		$stylesheet .= $this->get_preset_classes( $setting_nodes, $origins );
	}

	return $stylesheet;
}