Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateSelectiveApplier::block_at_path
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
Usage
$result = WCEmailTemplateSelectiveApplier::block_at_path( $blocks, $path ): ?array;
- $blocks(array) (required)
- .
- $path(array<int|string>) (required)
- Index path.
WCEmailTemplateSelectiveApplier::block_at_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;
}