Skip to content

Render empty Nav block if no fallback block can be utilised#36849

Merged
getdave merged 1 commit intotrunkfrom
fix/nav-block-handle-unregistered-page-list
Nov 25, 2021
Merged

Render empty Nav block if no fallback block can be utilised#36849
getdave merged 1 commit intotrunkfrom
fix/nav-block-handle-unregistered-page-list

Conversation

@getdave
Copy link
Copy Markdown
Contributor

@getdave getdave commented Nov 25, 2021

Description

In #36740 (comment) we learnt that if a page list block isn't registered then the block will still render wrapping markup even though it is empty.

This PR fixes things by first checking whether the core/page-list fallback is registered. If it is not and the fallback mechanic attempts to use it then the block will not render.

How has this been tested?

  • Delete all Navigation Menu posts from your site - http://localhost:8888/wp-admin/edit.php?post_type=wp_navigation.
  • Add several Pages to your site.
  • Add a Nav block to your site. Remove all items from the Nav block.
  • Save the Site Editor.
  • Visit front of site. You should see the core/page-list block used to render the default fallback experience.
  • Now...unregister the core/page-list block. I used a mu-plugin on my test site. Simply copy the following into a file and save with any name you like. Then zip it up and upload it to your WP site as a Plugin. Then activate the Plugin.
function my_plugin_deny_list_blocks() {
	$registry = WP_Block_Type_Registry::get_instance();

	if ( $registry->is_registered( 'core/page-list' ) ) {
		unregister_block_type( 'core/page-list' );
	}
}
add_action( 'wp_loaded', 'my_plugin_deny_list_blocks' );
  • Double check you can no longer access the Page List block in the editors.
  • Go to the front of your site - check that the Nav block is no longer being rendered at all. No markup or anything.

Screenshots

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@getdave getdave merged commit a1e01eb into trunk Nov 25, 2021
@getdave getdave deleted the fix/nav-block-handle-unregistered-page-list branch November 25, 2021 14:34
@github-actions github-actions bot added this to the Gutenberg 12.1 milestone Nov 25, 2021
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants