Repository navigation
Closed
Closed
Copy link
Labels
[Block] NavigationAffects the Navigation Block[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended
Description
Description
This fatal is bringing down some sites:
[22-Nov-2023 21:01:30 UTC] PHP Fatal error: Uncaught Error: Call to undefined function block_core_navigation_get_menu_items_at_location() in /srv/htdocs/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php:248
Step-by-step reproduction instructions
- Update to a Gutenberg version greater than 17.0.1
- Update to WordPress 6.4.1
- Get a critical error screen
Deactivating Gutenberg brings the site back.
Screenshots, screen recording, code snippet
[22-Nov-2023 21:01:30 UTC] PHP Fatal error: Uncaught Error: Call to undefined function block_core_navigation_get_menu_items_at_location() in /srv/htdocs/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php:248
Stack trace:
#0 /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))
#1 /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/navigation.php(413): WP_Navigation_Block_Renderer::render(Array, '', Object(WP_Block))
#2 /wordpress/core/6.4.1/wp-includes/class-wp-block.php(258): gutenberg_render_block_core_navigation(Array, '', Object(WP_Block))
#3 /wordpress/core/6.4.1/wp-includes/class-wp-block.php(244): WP_Block->render()
#4 /wordpress/core/6.4.1/wp-includes/blocks.php(1484): WP_Block->render()
#5 /wordpress/core/6.4.1/wp-includes/blocks.php(1522): render_block(Array)
#6 /srv/htdocs/wp-content/plugins/gutenberg/build/block-library/blocks/template-part.php(144): do_blocks('<!-- wp:group {...')
#7 /srv/htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTemplatesController.php(171): gutenberg_render_block_core_template_part(Array)
#8 /wordpress/core/6.4.1/wp-includes/class-wp-block.php(258): Automattic\WooCommerce\Blocks\BlockTemplatesController->render_woocommerce_template_part(Array, '', Object(WP_Block))
#9 /wordpress/core/6.4.1/wp-includes/blocks.php(1484): WP_Block->render()
#10 /wordpress/core/6.4.1/wp-includes/blocks.php(1522): render_block(Array)
#11 /wordpress/core/6.4.1/wp-includes/block-template.php(263): do_blocks('<!-- wp:templat...')
#12 /wordpress/core/6.4.1/wp-includes/template-canvas.php(12): get_the_block_template_html()
#13 /wordpress/core/6.4.1/wp-includes/template-loader.php(106): include('/wordpress/core...')
#14 /wordpress/core/6.4.1/wp-blog-header.php(19): require_once('/wordpress/core...')
#15 /wordpress/core/6.4.1/index.php(17): require('/wordpress/core...')
#16 {main}
thrown in /srv/htdocs/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php on line 248
Environment info
WordPress 6.4.1
Gutenberg Plugin versions > 17.0.1
(rolling back to 17.0.1 fixes the problem)
We have access to a development site which is currently displaying this fatal, if anyone would like a testing environment. We can also help verify any fixes.
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 Block[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended
Activity
tellthemachines commentedon Nov 23, 2023
I can reproduce a similar error, in the following way:
Fatal error: Uncaught Error: Call to undefined function block_core_navigation_add_directives_to_submenu().I believe the issue was introduced in #55605 due to some functions defined in
block-librarybeing called inlib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php. The problem with this is allblock-libraryPHP functions are prefixed withgutenberg_at build time, so that they don't conflict with their core equivalents. So essentially the built plugin is calling the wrong function name.Edit: for posterity, adding that usually this would not cause a fatal when the function is already defined in core. But in this case, the function in core was behind the
IS_GUTENBERG_PLUGINflag, which is always false in core, which means the function is in practice inaccessible.Best practice is probably to always use the
gutenberg_prefixed version of block library functions when calling them from elsewhere in the plugin, to avoid issues if the function happens to not exist in core.