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
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 | * * @ 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. |