WP_Theme_JSON::get_block_nodes( array $theme_json ): array

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

An internal method to get the block nodes from a theme.json file.

Parameters

$theme_jsonarrayrequired
The theme.json converted to an array.

Return

array The block nodes in theme.json.

Source


		if ( $background_color && $border_color_matches && $text_color_matches ) {
			break;
		}
	}

	if ( $background_color && ! $border_color_matches && ! $text_color_matches ) {
		$declarations[] = array(
			'name'  => 'color',
			'value' => $background_color,
		);
	}

	return $declarations;
}

/**
 * An internal method to get the block nodes from a theme.json file.
 *
 * @since 6.1.0
 * @since 6.3.0 Refactored and stabilized selectors API.
 *
 * @param array $theme_json The theme.json converted to an array.
 * @return array The block nodes in theme.json.
 */
private static function get_block_nodes( $theme_json ) {
	$selectors = static::get_blocks_metadata();
	$nodes     = array();
	if ( ! isset( $theme_json['styles'] ) ) {
		return $nodes;
	}

	// Blocks.
	if ( ! isset( $theme_json['styles']['blocks'] ) ) {
		return $nodes;
	}

	foreach ( $theme_json['styles']['blocks'] as $name => $node ) {
		$selector = null;
		if ( isset( $selectors[ $name ]['selector'] ) ) {
			$selector = $selectors[ $name ]['selector'];
		}

		$duotone_selector = null;
		if ( isset( $selectors[ $name ]['duotone'] ) ) {
			$duotone_selector = $selectors[ $name ]['duotone'];
		}

		$feature_selectors = null;
		if ( isset( $selectors[ $name ]['selectors'] ) ) {
			$feature_selectors = $selectors[ $name ]['selectors'];
		}

		$variation_selectors = array();
		if ( isset( $node['variations'] ) ) {
			foreach ( $node['variations'] as $variation => $node ) {
				$variation_selectors[] = array(
					'path'     => array( 'styles', 'blocks', $name, 'variations', $variation ),
					'selector' => $selectors[ $name ]['styleVariations'][ $variation ],
				);
			}
		}

		$nodes[] = array(
			'name'       => $name,
			'path'       => array( 'styles', 'blocks', $name ),
			'selector'   => $selector,
			'selectors'  => $feature_selectors,
			'duotone'    => $duotone_selector,
			'features'   => $feature_selectors,
			'variations' => $variation_selectors,
		);

		if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) {
			foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) {
				$nodes[] = array(

Changelog

VersionDescription
6.3.0Refactored and stabilized selectors API.
6.1.0Introduced.

User Contributed Notes

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