Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateSelectiveApplier::insert_recursive
Recursive worker for {@see self::insert_block_at_path()}.
Method of the class: WCEmailTemplateSelectiveApplier{}
No Hooks.
Returns
Array
Usage
$result = WCEmailTemplateSelectiveApplier::insert_recursive( $blocks, $path, $depth, $new_block ): array;
- $blocks(array) (required)
- .
- $path(array<int|string>) (required)
- Path indices.
- $depth(int) (required)
- Current depth.
- $new_block(array) (required)
- .
WCEmailTemplateSelectiveApplier::insert_recursive() WCEmailTemplateSelectiveApplier::insert recursive code WC 10.9.1
private static function insert_recursive( array $blocks, array $path, int $depth, array $new_block ): array {
$idx = (int) $path[ $depth ];
if ( count( $path ) - 1 === $depth ) {
$insert_at = max( 0, min( $idx, count( $blocks ) ) );
array_splice( $blocks, $insert_at, 0, array( $new_block ) );
return $blocks;
}
if ( ! isset( $blocks[ $idx ] ) ) {
// The parent on the core side doesn't exist in the post tree —
// fall back to appending at this level so the block isn't lost.
$blocks[] = $new_block;
return $blocks;
}
$inner = $blocks[ $idx ]['innerBlocks'] ?? array();
$blocks[ $idx ]['innerBlocks'] = self::insert_recursive( is_array( $inner ) ? $inner : array(), $path, $depth + 1, $new_block );
return $blocks;
}