diff --git a/editor/components/block-settings-menu/block-settings-menu-plugins-item.js b/editor/components/block-settings-menu/block-settings-menu-plugins-item.js index b6ae2b754f01f..e20e7da782eaf 100644 --- a/editor/components/block-settings-menu/block-settings-menu-plugins-item.js +++ b/editor/components/block-settings-menu/block-settings-menu-plugins-item.js @@ -14,8 +14,21 @@ import { compose } from '@wordpress/element'; */ import BlockSettingsMenuPluginsGroup from './block-settings-menu-plugins-group'; +const isEverySelectedBlockAllowed = ( selected, allowed ) => difference( selected, allowed ).length === 0; + +/** + * Plugins may want to add an item to the menu either for every block + * or only for the specific ones provided in the `allowedBlocks` component property. + * + * If there are multiple blocks selected the item will be rendered if every block + * is of one allowed type (not necesarily the same). + * + * @param {string[]} selectedBlockNames Array containing the names of the blocks selected + * @param {string[]} allowedBlockNames Array containing the names of the blocks allowed + * @return {boolean} Whether the item will be rendered or not. + */ const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.isArray( allowedBlockNames ) || - difference( selectedBlockNames, allowedBlockNames ).length === 0; + isEverySelectedBlockAllowed( selectedBlockNames, allowedBlockNames ); const BlockSettingsMenuPluginsItem = ( { allowedBlocks, icon, label, onClick, small, role } ) => (