Skip to content

support multiple namespaces in registerBlockCollection() #69656

Closed

Description

@acketon

What problem does this address?

It would be nice if a block collection could contain blocks from more than one namespace to better organize and consolidate block categories & collections in the block inserter.

Currently:

registerBlockCollection( 'myname', {
	title: 'My Blocks',
} );

Could we pass an optional array?

registerBlockCollection( ['myname', myname2], {
	title: 'My Blocks',
} );

We have an older block plugin with many blocks in it. However many of the blocks are using inconsistent prefixes in their block names. It was built in 2019 against the beta of the Gutenberg plugin so we didn't have good guidance on this.

Renaming the existing blocks in use on many sites is a challenge but I'd still like to be able to combine them into one collection.

What is your proposed solution?

Support passing an array of namespaces and display blocks from all of those namespaces into that single collection in the inserter.

Activity

  1. Mayank-Tripathi32 commented on Mar 21, 2025

    @Mayank-Tripathi32
    Member

    I see how this could be useful in your use case, but I'm not sure if it should be a part of block collections. It might be helpful to hear from others to see if they have a similar use case for this.

  2. Mamaduka commented on Aug 1, 2025

    @Mamaduka
    Member

    I think this is easy to resolve on the consumer side by calling registerBlockCollection inside the loop.

    [ 'myname', 'myname2' ].forEach( ( namespace ) => {
        registerBlockCollection( namespace, {
        	title: 'My Blocks',
        } );
    } );
  3. acketon commented on Aug 1, 2025

    @acketon
    Author

    I think this is easy to resolve on the consumer side by calling registerBlockCollection inside the loop.

    [ 'myname', 'myname2' ].forEach( ( namespace ) => {
    registerBlockCollection( namespace, {
    title: 'My Blocks',
    } );
    } );

    I don't see how this is different from calling registerBlockCollection() twice with different namesspaces but the same title. I've attempted that of course, but it results in multiple Block Collections being registered in the Block Inserter with different blocks from each namespace in each. They are not combined into a single Collection.

    Example:

    import { registerBlockCollection } from '@wordpress/blocks';
    
    // Register Block Collection for `bu` prefix in existing block names.
    registerBlockCollection( 'bu', {
    	title: 'BU: Blocks',
    } );
    
    // Register Block Collection for `editorial` prefix in existing block names.
    registerBlockCollection( 'editorial', {
    	title: 'BU: Blocks Editorial',
    } );
    
    // Register Block Collections for both `bu` and `editorial` namespaces.
    // This does not work, it creates two separate collections with the same name.
    [ 'bu', 'editorial' ].forEach( ( namespace ) => {
    	registerBlockCollection( namespace, {
    		title: 'My Blocks,
    	} );
    } );
    

    Results in:

    Image
  4. acketon commented on Aug 1, 2025

    @acketon
    Author

    While I know my particular issue might be rarer, it's a frustrating issue as an organization that invested early in Block Development in 2019 against poorly documented guidance at the time which did not make clear that the namespace in a block is considered immutable. (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/#block-name) and so now with a plugin with 2 dozen blocks in use within the post content of thousands of pages we can't change the namespace of the existing blocks to be consistently prefixed for all blocks in the same plugin.

    Aside:
    Yes, I know and we have discussed using wp-cli to attempt a find/replace of old block namespaces across the network. It's possible, but a risky content change when dealing with thousands of WordPress sites and with instances of each block being used dozens to thousands of times in many of those sites.

    It is concerning that the WordPress docs on block registration is so light on providing guidance on the very real consequences of poorly thought out namespaces in blocks. It's not even clear that they can never be changed and need to be considered stable or immutable. (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/#block-name) (#40749)

    Block Collections would be very helpful in the block inserter to help organize blocks better and they work well if all of your blocks are in the same namespace. I do think they could be much more useful for everyone if people can create collections of blocks from multiple namespaces. Not just for my issue, but to have greater editorial control over the organization of blocks within a site in a large WordPress network with a lot of plugins adding blocks.

    As another example think of it this way:

    There are two ways to approach building lots of blocks to use in an organization. Either a single plugin with multiple blocks registered in it or separate plugin with 1 block per plugin (how @wordpress/scripts originally expected the architecture).

    If you pursue a single block === plugin approach and you are building many blocks you'd either have to have each block share the same prefix in their namespace such as: myblocks/some-block across multiple plugins in order to register a Collection with all of them grouped together. Alternatively if you name them with unique prefixed namespaces for each plugin you'd end up with separate Block Collections for each plugin with a single block in each.

    Are Block Collections meant to only be associated with a single namespace?

  5. Mamaduka commented on Aug 11, 2025

    @Mamaduka
    Member

    Thanks for the clarification, @acketon!

    Are Block Collections meant to only be associated with a single namespace?

    As far as I know, collections are meant to be used with a single namespace. cc @gziolo

  6. gziolo commented on Aug 12, 2025

    @gziolo
    Member

    Collections are associated with a unique namespace, see the reducer in the store:

    export function collections( state = {}, action ) {
    switch ( action.type ) {
    case 'ADD_BLOCK_COLLECTION':
    return {
    ...state,
    [ action.namespace ]: {
    title: action.title,
    icon: action.icon,
    },
    };
    case 'REMOVE_BLOCK_COLLECTION':
    return omit( state, action.namespace );
    }
    return state;
    }

  7. youknowriad commented on Oct 6, 2026

    @youknowriad
    Contributor

    Thanks for the detailed explanation of your use case. Block collections are designed around one namespace each (see the blocks store reducer), and we don't plan to extend them to several namespaces. For mixed-prefix legacy blocks, a custom block category is the closest option today. Closing as not planned; we're sorry there isn't a cleaner path for blocks whose names can't change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs DecisionNeeds a decision to be actionable or relevant[Feature] Block APIAPI that allows to express the block paradigm.[Package] Blocks/packages/blocks[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions