diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index 57d6d187db8e3a..c89c87b7c89750 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -80,10 +80,19 @@ export default function BlockEditor( { setIsInserterOpen } ) { [] ); - const blockPatterns = useMemo( - () => unionBy( settingsBlockPatterns, restBlockPatterns, 'name' ), - [ settingsBlockPatterns, restBlockPatterns ] - ); + const blockPatterns = useMemo( () => { + return unionBy( + settingsBlockPatterns, + restBlockPatterns, + 'name' + ).filter( ( { postTypes } ) => { + return ( + ! postTypes || + ( Array.isArray( postTypes ) && + postTypes.includes( templateType ) ) + ); + } ); + }, [ settingsBlockPatterns, restBlockPatterns, templateType ] ); const blockPatternCategories = useMemo( () => diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index 67cce96cde058f..7091fc8a5aeca9 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -36,8 +36,10 @@ function useBlockEditorSettings( settings, hasTemplate ) { canUseUnfilteredHTML, userCanCreatePages, pageOnFront, + postType, } = useSelect( ( select ) => { - const { canUserUseUnfilteredHTML } = select( editorStore ); + const { canUserUseUnfilteredHTML, getCurrentPostType } = + select( editorStore ); const isWeb = Platform.OS === 'web'; const { canUser, getEntityRecord } = select( coreStore ); @@ -55,6 +57,7 @@ function useBlockEditorSettings( settings, hasTemplate ) { hasUploadPermissions: canUser( 'create', 'media' ) ?? true, userCanCreatePages: canUser( 'create', 'pages' ), pageOnFront: siteSettings?.page_on_front, + postType: getCurrentPostType(), }; }, [] ); @@ -74,10 +77,18 @@ function useBlockEditorSettings( settings, hasTemplate ) { [] ); - const blockPatterns = useMemo( - () => unionBy( settingsBlockPatterns, restBlockPatterns, 'name' ), - [ settingsBlockPatterns, restBlockPatterns ] - ); + const blockPatterns = useMemo( () => { + return unionBy( + settingsBlockPatterns, + restBlockPatterns, + 'name' + ).filter( ( { postTypes } ) => { + return ( + ! postTypes || + ( Array.isArray( postTypes ) && postTypes.includes( postType ) ) + ); + } ); + }, [ settingsBlockPatterns, restBlockPatterns, postType ] ); const blockPatternCategories = useMemo( () =>