Skip to content

Commit

Permalink
Template Part: Fix 'can user edit' check
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 31, 2024
1 parent 43846b0 commit ec7b2a0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function TemplatePartEdit( {
area,
onNavigateToEntityRecord,
title,
canEditTemplate,
canUserEdit,
} = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
Expand All @@ -151,10 +151,13 @@ export default function TemplatePartEdit( {
)
: false;

const _canEditTemplate = select( coreStore ).canUser( 'create', {
kind: 'postType',
name: 'wp_template_part',
} );
const _canUserEdit = hasResolvedEntity
? select( coreStore ).canUser( 'update', {
kind: 'postType',
name: 'wp_template_part',
id: templatePartId,
} )
: false;

return {
hasInnerBlocks: getBlockCount( clientId ) > 0,
Expand All @@ -167,7 +170,7 @@ export default function TemplatePartEdit( {
onNavigateToEntityRecord:
getSettings().onNavigateToEntityRecord,
title: entityRecord?.title,
canEditTemplate: !! _canEditTemplate,
canUserEdit: !! _canUserEdit,
};
},
[ templatePartId, attributes.area, clientId ]
Expand Down Expand Up @@ -237,7 +240,7 @@ export default function TemplatePartEdit( {
<RecursionProvider uniqueId={ templatePartId }>
{ isEntityAvailable &&
onNavigateToEntityRecord &&
canEditTemplate && (
canUserEdit && (
<BlockControls group="other">
<ToolbarButton
onClick={ () =>
Expand Down

0 comments on commit ec7b2a0

Please sign in to comment.