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.
Parameters Parameters
- $blocks
-
(array[]) (Required) An array of blocks from
parse_blocks()
, where each block is usually an array cast fromWP_Block_Parser_Block
.
Return Return
(array[])
Source Source
File: includes/forms/class-llms-forms.php
* * @return array[] */ 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 ) ) { continue; } $loaded = array_merge( $loaded, $this->parse_blocks( $post->post_content ) ); continue; } // Does this block's inner blocks have references to reusable blocks? if ( $block['innerBlocks'] ) { $block['innerBlocks'] = $this->load_reusable_blocks( $block['innerBlocks'] ); } $loaded[] = $block; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.1.0 | Access turned to public. |
5.0.0 | Introduced. |