diff --git a/packages/edit-site/src/components/add-new-template/utils.js b/packages/edit-site/src/components/add-new-template/utils.js index 1e544aeaadfe1..a2644ec4ad4da 100644 --- a/packages/edit-site/src/components/add-new-template/utils.js +++ b/packages/edit-site/src/components/add-new-template/utils.js @@ -166,9 +166,11 @@ export function usePostTypeArchiveMenuItems() { // `icon` is the `menu_icon` property of a post type. We // only handle `dashicons` for now, even if the `menu_icon` // also supports urls and svg as values. - icon: postType.icon?.startsWith( 'dashicons-' ) - ? postType.icon.slice( 10 ) - : archive, + icon: + typeof postType.icon === 'string' && + postType.icon.startsWith( 'dashicons-' ) + ? postType.icon.slice( 10 ) + : archive, templatePrefix: 'archive', }; } ) || [], @@ -272,9 +274,11 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => { // `icon` is the `menu_icon` property of a post type. We // only handle `dashicons` for now, even if the `menu_icon` // also supports urls and svg as values. - icon: icon?.startsWith( 'dashicons-' ) - ? icon.slice( 10 ) - : post, + icon: + typeof icon === 'string' && + icon.startsWith( 'dashicons-' ) + ? icon.slice( 10 ) + : post, templatePrefix: templatePrefixes[ slug ], }; const hasEntities = postTypesInfo?.[ slug ]?.hasEntities; diff --git a/packages/editor/src/store/private-selectors.js b/packages/editor/src/store/private-selectors.js index ed4672bc435cd..6a6c8702a0221 100644 --- a/packages/editor/src/store/private-selectors.js +++ b/packages/editor/src/store/private-selectors.js @@ -110,7 +110,10 @@ export const getPostIcon = createRegistrySelector( // `icon` is the `menu_icon` property of a post type. We // only handle `dashicons` for now, even if the `menu_icon` // also supports urls and svg as values. - if ( postTypeEntity?.icon?.startsWith( 'dashicons-' ) ) { + if ( + typeof postTypeEntity?.icon === 'string' && + postTypeEntity.icon.startsWith( 'dashicons-' ) + ) { return postTypeEntity.icon.slice( 10 ); } return pageIcon;