Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Forms::get_block_tree( array $block, array[] $block_list )

Returns a filtered version of $block_list containing only the passed $block and its parents.


Parameters Parameters

$block

(array) (Required) Parsed block array.

$block_list

(array[]) (Required) The list of WP Block array $block comes from.


Top ↑

Return Return

(array[]) Filtered version of $block_list containing only the passed $block and its parents. Or an empty array if $block cannot be found within $block_list.


Top ↑

Source Source

File: includes/forms/class-llms-forms.php

	 * @return array[] Filtered version of `$block_list` containing only the passed `$block` and its parents.
	 *                 Or an empty array if `$block` cannot be found within `$block_list`.
	 */
	private function get_block_tree( $block, $block_list ) {

		foreach ( $block_list as &$_block ) {

			// Found the block.
			if ( $block === $_block ) {
				return array( $block );
			}

			if ( ! empty( $_block['innerBlocks'] ) ) {
				$tree = $this->get_block_tree( $block, $_block['innerBlocks'] );
			}

			if ( ! empty( $tree ) ) { // Break as soon as the desired block is removed from one of the innerBlocks.
				if ( $_block['innerBlocks'] !== $tree ) { // Update innerBlocks/innerContent structure if needed.
					$_block['innerBlocks'] = $tree;
					// Update innerContent to reflect the innerBlocks changes = only 1 innerBlock.
					$inner_block_in_content_index = 0;
					foreach ( $_block['innerContent'] as $index => $chunk ) {
						if ( ! is_string( $chunk ) && $inner_block_in_content_index++ ) {
							unset( $_block['innerContent'][ $index ] );
						}
					}
					// Re-index.
					$_block['innerContent'] = array_values( $_block['innerContent'] );
				}

				return array( $_block );
			}
		}



Top ↑

Changelog Changelog

Changelog
Version Description
5.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.