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.

Method of the class: WP_Duotone{}

No Hooks.

Return

String[]. An array of global style block slugs, keyed on the block name.

Usage

$result = WP_Duotone::get_all_global_style_block_names();

Changelog

Since 6.3.0 Introduced.

WP_Duotone::get_all_global_style_block_names() code WP 6.5.3

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