WP_Navigation_Block_Renderer::get_inner_blocks_from_navigation_post()
Gets the inner blocks for the navigation block from the navigation post.
Method of the class: WP_Navigation_Block_Renderer{}
No Hooks.
Return
WP_Block_List
. Returns the inner blocks for the navigation block.
Usage
$result = WP_Navigation_Block_Renderer::get_inner_blocks_from_navigation_post( $attributes );
- $attributes(array) (required)
- The block attributes.
Changelog
Since 6.5.0 | Introduced. |
WP_Navigation_Block_Renderer::get_inner_blocks_from_navigation_post() WP Navigation Block Renderer::get inner blocks from navigation post code WP 6.7.1
private static function get_inner_blocks_from_navigation_post( $attributes ) { $navigation_post = get_post( $attributes['ref'] ); if ( ! isset( $navigation_post ) ) { return new WP_Block_List( array(), $attributes ); } // Only published posts are valid. If this is changed then a corresponding change // must also be implemented in `use-navigation-menu.js`. if ( 'publish' === $navigation_post->post_status ) { $parsed_blocks = parse_blocks( $navigation_post->post_content ); // 'parse_blocks' includes a null block with '\n\n' as the content when // it encounters whitespace. This code strips it. $blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks ); // Run Block Hooks algorithm to inject hooked blocks. $markup = block_core_navigation_insert_hooked_blocks( $blocks, $navigation_post ); $root_nav_block = parse_blocks( $markup )[0]; $blocks = isset( $root_nav_block['innerBlocks'] ) ? $root_nav_block['innerBlocks'] : $blocks; // TODO - this uses the full navigation block attributes for the // context which could be refined. return new WP_Block_List( $blocks, $attributes ); } }