-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Closed
Labels
[Block] NavigationAffects the Navigation BlockAffects the Navigation Block[Status] In ProgressTracking issues with work in progressTracking issues with work in progress[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
Stack trace:
PHP Fatal error: Uncaught TypeError:
iterator_to_array(): Argument #1 ($iterator) must be of type Traversable|array, string given in /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/navigation.php:376
Stack trace:
#0 /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/navigation.php(376): iterator_to_array('')
#1 /srv/htdocs/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php(273): gutenberg_block_core_navigation_get_post_ids('')
#2 /srv/htdocs/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php(628): WP_Navigation_Block_Renderer::get_inner_blocks(Array, Object(WP_Block))
#3 /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/navigation.php(413): WP_Navigation_Block_Renderer::render(Array, '', Object(WP_Block))
#4 /wordpress/core/6.4.1/wp-includes/class-wp-block.php(258): gutenberg_render_block_core_navigation(Array, '', Object(WP_Block))
#5 /wordpress/core/6.4.1/wp-includes/class-wp-block.php(244): WP_Block->render()
#6 /wordpress/core/6.4.1/wp-includes/blocks.php(1484): WP_Block->render()
#7 /wordpress/core/6.4.1/wp-includes/blocks.php(1522): render_block(Array)
#8 /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/template-part.php(144): do_blocks('<!-- wp:group {...')
#9 /srv/htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTemplatesController.php(171): gutenberg_render_block_core_template_part(Array)
#10 /wordpress/core/6.4.1/wp-includes/class-wp-block.php(258): Automattic\WooCommerce\Blocks\BlockTemplatesController->render_woocommerce_template_part(Array, '', Object(WP_Block))
#11 /wordpress/core/6.4.1/wp-includes/blocks.php(1484): WP_Block->render()
#12 /wordpress/core/6.4.1/wp-includes/blocks.php(1522): render_block(Array)
#13 /wordpress/core/6.4.1/wp-includes/block-template.php(263): do_blocks('<!-- wp:templat...')
#14 /wordpress/core/6.4.1/wp-includes/template-canvas.php(12): get_the_block_template_html()
#15 /wordpress/core/6.4.1/wp-includes/template-loader.php(106): include('/wordpress/core...')
#16 /wordpress/core/6.4.1/wp-blog-header.php(19): require_once('/wordpress/core...')
#17 /wordpress/core/6.4.1/index.php(17): require('/wordpress/core...')
#18 {main} thrown in /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/navigation.php on line 376
TL:DR We have a site in the latest Gutenberg release (17.1.3) that's throwing a fatal through the use of __unstableLocation
in a navigation block in a template part.
Here's the block markup:
<!-- wp:navigation {"isResponsive":true,"__unstableLocation":"primary","style":{"typography":{"fontStyle":"normal","fontWeight":"500"}}} /-->
Investigation so far:
- The fatal appears when trying to get navigation post IDs as the
iterator_to_array()
function is expecting a WP_Block_List but is given an empty string. - At the
block_core_navigation_render_inner_blocks
filter,$inner_blocks
is just an empty string. - I believe the issue is caused here
where an empty menu returns an empty string, or perhaps it's returning\n\n
as noted by this navigation function.
I appreciate this is quite a vague report that I cannot currently re-produce on a standard theme, any insight appreciated.
This PR seems related to a similar area, but not the root cause of this issue: #56459
Step-by-step reproduction instructions
I can't currently reproduce this issue.
Screenshots, screen recording, code snippet
Current theme patch that's resolving this issue:
/**
* Fixes a fatal error if inner_blocks is empty.
*
* This function addresses a potential issue where empty inner_blocks can cause a fatal error. It ensures that the inner_blocks parameter always returns a valid array.
*
* @param array $inner_blocks The array of inner blocks provided to the navigation block. These are the blocks nested within the navigation block.
*
* @return array Returns an empty array if $inner_blocks is empty, or the unmodified $inner_blocks array otherwise.
*/
function prefix_navigation_render_inner_blocks( $inner_blocks ) {
if ( empty( $inner_blocks ) ) {
return array();
}
return $inner_blocks;
}
add_filter( 'block_core_navigation_render_inner_blocks', 'prefix_navigation_render_inner_blocks', 10 );
Environment info
- WordPress 6.4.1
- Gutenberg Plugin 17.1.3
- Custom FSE child theme of blockbase
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Metadata
Metadata
Assignees
Labels
[Block] NavigationAffects the Navigation BlockAffects the Navigation Block[Status] In ProgressTracking issues with work in progressTracking issues with work in progress[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended