Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined function block_core_navigation_get_menu_items_at_location #56453

Closed
NickGreen opened this issue Nov 22, 2023 · 1 comment · Fixed by #56459
Closed

Call to undefined function block_core_navigation_get_menu_items_at_location #56453

NickGreen opened this issue Nov 22, 2023 · 1 comment · Fixed by #56459
Assignees
Labels
[Block] Navigation Affects the Navigation Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@NickGreen
Copy link

NickGreen commented Nov 22, 2023

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

  1. Update to a Gutenberg version greater than 17.0.1
  2. Update to WordPress 6.4.1
  3. 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

@NickGreen NickGreen added the [Type] Bug An existing feature does not function as intended label Nov 22, 2023
@jordesign jordesign added Needs Testing Needs further testing to be confirmed. [Block] Navigation Affects the Navigation Block labels Nov 22, 2023
@tellthemachines
Copy link
Contributor

tellthemachines commented Nov 23, 2023

I can reproduce a similar error, in the following way:

  • With WP 6.3.2, install and activate the latest Gutenberg (17.1)
  • Navigating to the post editor should now show 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-library being called in lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php. The problem with this is all block-library PHP functions are prefixed with gutenberg_ 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_PLUGIN flag, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants