Registered inserter media categories are reset #52832
Labels
[Feature] Inserter
The main way to insert blocks using the + button in the editing interface
[Package] Block editor
/packages/block-editor
[Status] In Progress
Tracking issues with work in progress
[Type] Bug
An existing feature does not function as intended
Description
When registering new inserter media categories with
dispatch( 'core/block-editor' ).registerInserterMediaCategory()
, they are removed by the editor initialization.Consider this snippet of code that is loaded by a plugin which registers an "Openverse 2" media category:
There is a
console.log
call at the end to confirm that indeed the media category has been registered.However, it never shows up in the Media tab of the inserter menu because it has been replaced by the default categories (which can be confirmed by checking
wp.data.select( 'core/block-editor' ).getSettings().inserterMediaCategories
):Seems that any category registered before the default categories are added here is completely ignored and removed, and they need to be registered afterwards.
The problem is that there isn't any straightforward way to know when it is safe to register new categories.
There are several ways to solve this:
core/block-editor
action) that guarantees that custom media categories are registered and remain registered.cc @ntsekouras
Step-by-step reproduction instructions
wp-admin/post-new.php
.wp.data.select( 'core/block-editor' ).getSettings().inserterMediaCategories
in the browser JS console.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
The text was updated successfully, but these errors were encountered: