diff --git a/packages/edit-site/src/index.js b/packages/edit-site/src/index.js index b3c4b5dc161037..a09133c956f957 100644 --- a/packages/edit-site/src/index.js +++ b/packages/edit-site/src/index.js @@ -18,6 +18,7 @@ import { store as preferencesStore } from '@wordpress/preferences'; import { __ } from '@wordpress/i18n'; import { store as viewportStore } from '@wordpress/viewport'; import { getQueryArgs } from '@wordpress/url'; +import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies @@ -51,6 +52,26 @@ export function reinitializeEditor( target, settings ) { return; } + /* + * Prevent adding the Clasic block in the site editor. + * Only add the filter when the site editor is initialized, not imported. + * Also only add the filter(s) after registerCoreBlocks() + * so that common filters in the block library are not overwritten. + * + * This usage here is inspired by previous usage of the filter in the post editor: + * https://github.com/WordPress/gutenberg/pull/37157 + */ + addFilter( + 'blockEditor.__unstableCanInsertBlockType', + 'removeClassicBlockFromInserter', + ( canInsert, blockType ) => { + if ( blockType.name === 'core/freeform' ) { + return false; + } + return canInsert; + } + ); + // This will be a no-op if the target doesn't have any React nodes. unmountComponentAtNode( target ); const reboot = reinitializeEditor.bind( null, target, settings );