Skip to content

Commit

Permalink
fix hide button from template part if user cannot edit templates
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Apr 17, 2024
1 parent 7a2c1db commit 0eb074a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default function TemplatePartEdit( {
area,
onNavigateToEntityRecord,
title,
canEditTemplate,
} = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
Expand All @@ -150,6 +151,9 @@ export default function TemplatePartEdit( {
)
: false;

const _canEditTemplate =
select( coreStore ).canUser( 'create', 'templates' ) ?? false;

return {
hasInnerBlocks: getBlockCount( clientId ) > 0,
isResolved: hasResolvedEntity,
Expand All @@ -161,6 +165,7 @@ export default function TemplatePartEdit( {
onNavigateToEntityRecord:
getSettings().onNavigateToEntityRecord,
title: entityRecord?.title,
canEditTemplate: _canEditTemplate,
};
},
[ templatePartId, attributes.area, clientId ]
Expand Down Expand Up @@ -228,20 +233,22 @@ export default function TemplatePartEdit( {
return (
<>
<RecursionProvider uniqueId={ templatePartId }>
{ isEntityAvailable && onNavigateToEntityRecord && (
<BlockControls group="other">
<ToolbarButton
onClick={ () =>
onNavigateToEntityRecord( {
postId: templatePartId,
postType: 'wp_template_part',
} )
}
>
{ __( 'Edit' ) }
</ToolbarButton>
</BlockControls>
) }
{ isEntityAvailable &&
onNavigateToEntityRecord &&
canEditTemplate && (
<BlockControls group="other">
<ToolbarButton
onClick={ () =>
onNavigateToEntityRecord( {
postId: templatePartId,
postType: 'wp_template_part',
} )
}
>
{ __( 'Edit' ) }
</ToolbarButton>
</BlockControls>
) }
<InspectorControls group="advanced">
<TemplatePartAdvancedControls
tagName={ tagName }
Expand Down

0 comments on commit 0eb074a

Please sign in to comment.