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_Dynamic_Fields::find_block( string $id, array[] $blocks, integer $parent_index = null )

Finds a block with the specified ID within a list of blocks


Description Description

There’s a gotcha with this function… if a user password field is placed within a wp core columns block the password strength meter will be added outside the column the password is contained within.


Top ↑

Parameters Parameters

$id

(string) (Required) The ID of the field to find.

$blocks

(array[]) (Required) WP_Block list.

$parent_index

(integer) (Optional) Top level index of the parent block. Used to hold a reference to the current index within the toplevel blocks of the form when looking into the innerBlocks of a block.

Default value: null


Top ↑

Return Return

(boolean|array) Returns false when the block cannot be found in the given list, otherwise returns a numeric array where item 0 is the index of the block within the list (the index of the items parent if it's in a group) and item 1 is the block array.


Top ↑

Source Source

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

	private function find_block( $id, $blocks, $parent_index = null ) {

		foreach ( $blocks as $index => $block ) {

			if ( ! empty( $block['attrs']['id'] ) && $id === $block['attrs']['id'] ) {
				return array( is_null( $parent_index ) ? $index : $parent_index, $block );
			}

			if ( $block['innerBlocks'] ) {
				$inner = $this->find_block( $id, $block['innerBlocks'], is_null( $parent_index ) ? $index : $parent_index );
				if ( false !== $inner ) {
					return $inner;
				}
			}
		}

		return false;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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