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 Введена.
С версии 6.3.0 Refactored and stabilized selectors API.

Код WP_Theme_JSON::get_block_nodes() WP 6.5.3

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(
					'path'     => array( 'styles', 'blocks', $name, 'elements', $element ),
					'selector' => $selectors[ $name ]['elements'][ $element ],
				);

				// Handle any pseudo selectors for the element.
				if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
					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;
}