Skip to content

Commit

Permalink
Avoid errors for post types without a 'menu_icon' (#64015)
Browse files Browse the repository at this point in the history
Unlinked contributors: karan4official.

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 50e12e4 commit 30c6dfb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/edit-site/src/components/add-new-template/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
} ) || [],
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion packages/editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 30c6dfb

Please sign in to comment.