Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Part: Fix 'can user edit' check #64137

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading