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_path( array $block, array[] $block_list, int $iterations )

Returns a list of block parents plus the block itself in reverse order


Parameters Parameters

$block

(array) (Required) Parsed block array.

$block_list

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

$iterations

(int) (Required) Stores the number of iterations.


Top ↑

Return Return

(array[]) List of WP_Block arrays or an empty array if $block cannot be found within $block_list.


Top ↑

Source Source

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

	 * @param int     $iterations Stores the number of iterations.
	 * @return array[] List of WP_Block arrays or an empty array if `$block` cannot be found within `$block_list`.
	 */
	private function get_block_path( $block, $block_list, $iterations = 0 ) {

		foreach ( $block_list as $_block ) {

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

			// No innerblocks, proceed to the next block.
			if ( empty( $_block['innerBlocks'] ) ) {
				continue;
			}

			// Look in innerblocks for the block.
			foreach ( $_block['innerBlocks'] as $inner_block ) {

				// The inner block needs to be merged to the path.
				$to_merge = array( $inner_block );

				if ( $block === $inner_block ) { // Inner block is the one we're looking for.
					$path     = array( $block );
					$to_merge = array(); // Inner block equals the path, no need to merge it.
				} else {
					$path = $this->get_block_path( $block, array( $inner_block ), $iterations + 1 );
				}

				if ( $path ) {

					// First iteration, append first block too.
					if ( ! $iterations ) {
						$to_merge[] = $_block;
					}

					// Merge.
					return array_merge( $path, $to_merge );

				}
			}
		}

		// Block not found in the list.


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.