Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateSelectiveApplier::block_at_pathprivate staticWC 1.0

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

Method of the class: WCEmailTemplateSelectiveApplier{}

No Hooks.

Returns

Array. mixed>|null

Usage

$result = WCEmailTemplateSelectiveApplier::block_at_path( $blocks, $path ): ?array;
$blocks(array) (required)
.
$path(array<int|string>) (required)
Index path.

WCEmailTemplateSelectiveApplier::block_at_path() code WC 10.9.1

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;
}