Skip to content

Call to undefined function block_core_navigation_get_menu_items_at_location #56453

Closed

Description

@NickGreen

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

Activity

  1. added
    [Type] Bug
    on Nov 22, 2023
  2. added
    Needs Testing
    [Block] Navigation
    on Nov 22, 2023
  3. tellthemachines commented on Nov 23, 2023

    @tellthemachines
    Contributor

    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.

  4. removed
    Needs Testing
    on Nov 23, 2023
  5. added
    [Status] In Progress
    on Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Block] Navigation[Status] In Progress[Type] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions