WP_Duotone::get_all_global_style_block_names()private staticWP 6.3.0

Scrape all block names from global styles and store in self::$global_styles_block_names.

Used in conjunction with self::render_duotone_support to output the duotone filters defined in the theme.json global styles.

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

Хуков нет.

Возвращает

Строку[]. An array of global style block slugs, keyed on the block name.

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

$result = WP_Duotone::get_all_global_style_block_names();

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

С версии 6.3.0 Введена.

Код WP_Duotone::get_all_global_style_block_names() WP 6.6.2

private static function get_all_global_style_block_names() {
	if ( isset( self::$global_styles_block_names ) ) {
		return self::$global_styles_block_names;
	}
	// Get the per block settings from the theme.json.
	$tree        = WP_Theme_JSON_Resolver::get_merged_data();
	$block_nodes = $tree->get_styles_block_nodes();
	$theme_json  = $tree->get_raw_data();

	self::$global_styles_block_names = array();

	foreach ( $block_nodes as $block_node ) {
		// This block definition doesn't include any duotone settings. Skip it.
		if ( empty( $block_node['duotone'] ) ) {
			continue;
		}

		// Value looks like this: 'var(--wp--preset--duotone--blue-orange)' or 'var:preset|duotone|blue-orange'.
		$duotone_attr_path = array_merge( $block_node['path'], array( 'filter', 'duotone' ) );
		$duotone_attr      = _wp_array_get( $theme_json, $duotone_attr_path, array() );

		if ( empty( $duotone_attr ) ) {
			continue;
		}
		// If it has a duotone filter preset, save the block name and the preset slug.
		$slug = self::get_slug_from_attribute( $duotone_attr );

		if ( $slug && $slug !== $duotone_attr ) {
			self::$global_styles_block_names[ $block_node['name'] ] = $slug;
		}
	}
	return self::$global_styles_block_names;
}