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: Only show post template actions to users with correct capabilities #33392

Merged
merged 5 commits into from
Aug 9, 2021
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
9 changes: 6 additions & 3 deletions packages/edit-post/src/components/sidebar/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function TemplatePanel() {
isViewable,
template,
supportsTemplateMode,
canUserCreate,
} = useSelect( ( select ) => {
const {
isEditorPanelEnabled,
Expand All @@ -45,7 +46,7 @@ export function TemplatePanel() {
getEditorSettings,
getCurrentPostType,
} = select( editorStore );
const { getPostType, getEntityRecords } = select( coreStore );
const { getPostType, getEntityRecords, canUser } = select( coreStore );
const _isViewable =
getPostType( getCurrentPostType() )?.viewable ?? false;
const _supportsTemplateMode =
Expand All @@ -72,6 +73,7 @@ export function TemplatePanel() {
template: _supportsTemplateMode && getEditedPostTemplate(),
isViewable: _isViewable,
supportsTemplateMode: _supportsTemplateMode,
canUserCreate: canUser( 'create', 'templates' ),
};
}, [] );

Expand All @@ -88,7 +90,8 @@ export function TemplatePanel() {
if (
! isEnabled ||
! isViewable ||
( isEmpty( availableTemplates ) && ! supportsTemplateMode )
( isEmpty( availableTemplates ) &&
( ! supportsTemplateMode || ! canUserCreate ) )
) {
return null;
}
Expand Down Expand Up @@ -128,7 +131,7 @@ export function TemplatePanel() {
label: templateName,
} ) ) }
/>
<PostTemplateActions />
{ canUserCreate && <PostTemplateActions /> }
</PanelBody>
);
}
Expand Down