Alert: 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.

WP_Theme_JSON::get_block_nodes( array $theme_json ): array

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


Parameters

$theme_json array Required
The theme.json converted to an array.

Top ↑

Return

array The block nodes in theme.json.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php. View all references

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 ]['features'] ) ) {
			$feature_selectors = $selectors[ $name ]['features'];
		}

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

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

				// Handle any pseudo selectors for the element.
				if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
					foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
						if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) {
							$nodes[] = array(
								'path'     => array( 'styles', 'blocks', $name, 'elements', $element ),
								'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ),
							);
						}
					}
				}
			}
		}
	}

	return $nodes;
}

Top ↑

Changelog

Changelog
Version Description
6.1.0 Introduced.

Top ↑

User Contributed Notes

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