LLMS_Forms::load_reusable_blocks( array[] $blocks )

Loads reusable blocks into a block list.

Description Description

A reusable block contains a reference to the block post, e.g. <!-- wp:block {"ref":2198} /-->, which will be loaded during rendering.

Dereferencing the reusable blocks allows the entire block list to be reviewed and to validate all form fields. This function will replace each reusable block with the parsed blocks from its reference post.

Top ↑

Parameters Parameters


(array[]) (Required) An array of blocks from parse_blocks(), where each block is usually an array cast from WP_Block_Parser_Block.

Top ↑

Return Return


Top ↑

Source Source

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

	public function load_reusable_blocks( $blocks ) {

		$loaded = array();

		foreach ( $blocks as $block ) {

			// Skip blocks that are not reusable blocks.
			if ( 'core/block' === $block['blockName'] ) {

				// Skip reusable blocks that do not exist or are not published.
				$post = get_post( $block['attrs']['ref'] );
				if ( ! $post || 'publish' !== get_post_status( $post ) ) {

				$loaded = array_merge( $loaded, $this->parse_blocks( $post->post_content ) );

			// Does this block's inner blocks have references to reusable blocks?
			if ( $block['innerBlocks'] ) {
				$block['innerBlocks'] = $this->load_reusable_blocks( $block['innerBlocks'] );

			$loaded[] = $block;

		return $loaded;


Top ↑

Changelog Changelog

Version Description
5.1.0 Access turned to 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.