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

Fix: Navigation block: allow extending the list of allowed inner blocks #39492

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dinhtungdu
Copy link
Contributor

What?

This PR adds a new filter allowing plugins to register inner blocks for <Navigation/>.

Why?

Fixes #31387.

With the current implementation, plugins can still register Navigation inner blocks by listing core/navigation as a parent block. This workaround has a limitation described in #31387 (comment).

How?

By using a filter, blocks can be added to <Navigation> but can still be the top-level blocks.

Testing Instructions

  1. From a plugin, add a block to the allowed list using the new filter:
addFilter(
	'blocks.navigation.additionalAllowedBlocks',
	'woocommerce/mini-cart',
	( allowedBlocks ) => {
		return [ ...allowedBlocks, 'woocommerce/mini-cart' ];
	}
);
  1. Edit header template part which contains the Navigation block.
  2. Try adding an inner block.
  3. See the block added above in the block inserter.
  4. Can insert that block to the <Navigation>.

Screenshots or screencast

image

…al blocks to be available inside the navigation block.
@skorasaurus skorasaurus added the [Block] Navigation Affects the Navigation Block label Apr 25, 2022
@poof86
Copy link

poof86 commented Nov 15, 2022

I really need this for my projects.
Not just the WC Mini-Cart but also a shortcode for the WPML language switcher.

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
Status: PR needs review
Development

Successfully merging this pull request may close these issues.

Navigation block: allow extending the list of allowed inner blocks
3 participants