Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateSelectiveApplier::insert_recursive
Recursive worker for {@see self::insert_block_at_path()}.
Метод класса: WCEmailTemplateSelectiveApplier{}
Хуков нет.
Возвращает
array<int|string,. array<string, mixed>>
Использование
$result = WCEmailTemplateSelectiveApplier::insert_recursive( $blocks, $path, $depth, $new_block ): array;
- $blocks(массив) (обязательный)
- .
- $path(array<int|string>) (обязательный)
- Path indices.
- $depth(int) (обязательный)
- Current depth.
- $new_block(array<string, mixed>) (обязательный)
- Block to insert.
Код WCEmailTemplateSelectiveApplier::insert_recursive() WCEmailTemplateSelectiveApplier::insert recursive WC 11.2.2
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;
}