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

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

Merged
merged 1 commit into from Nov 25, 2021

Conversation

getdave
Copy link
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 added the [Block] Navigation Affects the Navigation Block label Nov 25, 2021
@getdave getdave added this to 👀 PRs needing review in Navigation block via automation Nov 25, 2021
@getdave getdave self-assigned this Nov 25, 2021
@getdave getdave added the Backport to WP Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 25, 2021
@getdave getdave merged commit a1e01eb into trunk Nov 25, 2021
Navigation block automation moved this from 👀 PRs needing review to ✅ Done 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
@noisysocks noisysocks removed the Backport to WP Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 29, 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
Development

Successfully merging this pull request may close these issues.

None yet

3 participants