LLMS_Forms::get_field_blocks( array $blocks )

Pull LifterLMS Form Field blocks from an array of parsed WP Blocks.


Description Description

Searches innerBlocks arrays recursively.


Top ↑

Parameters Parameters

$blocks

(array) (Required) Array of WP Block arrays from parse_blocks().


Top ↑

Return Return

(array)


Top ↑

Source Source

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

	public function get_field_blocks( $blocks ) {

		$fields = array();

		foreach ( $blocks as $block ) {

			if ( ! empty( $block['innerBlocks'] ) ) {
				$fields = array_merge( $fields, $this->get_field_blocks( $block['innerBlocks'] ) );
			} elseif ( false !== strpos( $block['blockName'] ?? '', 'llms/form-field-' ) ) {
				$fields[] = $block;
			} elseif ( 'core/html' === $block['blockName'] && ! empty( $block['attrs']['type'] ) ) {
				$fields[] = $block;
			}
		}

		return $fields;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.9.0 Pass an empty string to strpos() instead of null.
5.1.0 First check block's innerBlock attribute exists when checking for inner blocks. Also made the access visibility public.
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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