Skip to content

Commit

Permalink
Post Template: Don't fetch settings and templates for non-admin users (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Aug 16, 2022
1 parent c1f96c2 commit 8389ee5
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions packages/edit-post/src/components/sidebar/post-template/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,26 @@ export default function PostTemplateForm( { onClose } ) {
canCreate,
canEdit,
} = useSelect( ( select ) => {
const { canUser, getEntityRecord, getEntityRecords } =
select( coreStore );
const editorSettings = select( editorStore ).getEditorSettings();
const siteSettings = select( coreStore ).getEntityRecord(
'root',
'site'
);
const siteSettings = canUser( 'read', 'settings' )
? getEntityRecord( 'root', 'site' )
: undefined;
const _isPostsPage =
select( editorStore ).getCurrentPostId() ===
siteSettings?.page_for_posts;
const canCreateTemplates = select( coreStore ).canUser(
'create',
'templates'
);
const canCreateTemplates = canUser( 'create', 'templates' );

return {
isPostsPage: _isPostsPage,
availableTemplates: editorSettings.availableTemplates,
fetchedTemplates: select( coreStore ).getEntityRecords(
'postType',
'wp_template',
{
post_type: select( editorStore ).getCurrentPostType(),
per_page: -1,
}
),
fetchedTemplates: canCreateTemplates
? getEntityRecords( 'postType', 'wp_template', {
post_type: select( editorStore ).getCurrentPostType(),
per_page: -1,
} )
: undefined,
selectedTemplateSlug:
select( editorStore ).getEditedPostAttribute( 'template' ),
canCreate:
Expand Down

0 comments on commit 8389ee5

Please sign in to comment.