WP_Theme_JSON::get_block_nodes()private staticWP 6.1.0

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

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

Хуков нет.

Возвращает

Массив. The block nodes in theme.json.

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

$result = WP_Theme_JSON::get_block_nodes( $theme_json );
$theme_json(массив) (обязательный)
The theme.json converted to an array.

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

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

Код WP_Theme_JSON::get_block_nodes() WP 6.1.1

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.
				// TODO: Replace array_key_exists() with isset() check once WordPress drops
				// support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
				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;
}