WP_Navigation_Block_Renderer::get_inner_blocks_from_navigation_postprivate staticWP 6.5.0

Gets the inner blocks for the navigation block from the navigation post.

Метод класса: WP_Navigation_Block_Renderer{}

Хуков нет.

Возвращает

WP_Block_List. Returns the inner blocks for the navigation block.

Использование

$result = WP_Navigation_Block_Renderer::get_inner_blocks_from_navigation_post( $attributes );
$attributes(массив) (обязательный)
The block attributes.

Список изменений

С версии 6.5.0 Введена.

Код WP_Navigation_Block_Renderer::get_inner_blocks_from_navigation_post() WP 7.0

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 );

		// Re-serialize, and run Block Hooks algorithm to inject hooked blocks.
		// TODO: See if we can move the apply_block_hooks_to_content_from_post_object() call
		// before the parse_blocks() call further above, to avoid the extra serialization/parsing.
		$markup = serialize_blocks( $blocks );
		$markup = apply_block_hooks_to_content_from_post_object( $markup, $navigation_post );
		$blocks = parse_blocks( $markup );

		// TODO - this uses the full navigation block attributes for the
		// context which could be refined.
		return new WP_Block_List( $blocks, $attributes );
	}
}