Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateSelectiveApplier::block_at_path │ private static │ WC 1.0

Walk a parsed block tree along a path and return the block at that path, or null if any segment is missing.

Метод класса: WCEmailTemplateSelectiveApplier{}

Хуков нет.

Возвращает

array<string, mixed>|null.

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

$result = WCEmailTemplateSelectiveApplier::block_at_path( $blocks, $path ): ?array;
$blocks(массив) (обязательный)
.
$path(array<int|string>) (обязательный)
Index path.

Код WCEmailTemplateSelectiveApplier::block_at_path() WC 11.2.2

private static function block_at_path( array $blocks, array $path ): ?array {
	if ( empty( $path ) ) {
		return null;
	}
	$current = $blocks;
	$last    = count( $path ) - 1;
	foreach ( array_values( $path ) as $depth => $idx ) {
		$idx = (int) $idx;
		if ( ! isset( $current[ $idx ] ) || ! is_array( $current[ $idx ] ) ) {
			return null;
		}
		if ( $depth === $last ) {
			return $current[ $idx ];
		}
		$inner   = $current[ $idx ]['innerBlocks'] ?? array();
		$current = is_array( $inner ) ? $inner : array();
	}
	return null;
}