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

Post Editor: Avoid 403 errors for users with low permissions #42413

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/compat/wordpress-6.1/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
function gutenberg_preload_template_permissions( $preload_paths, $context ) {
if ( ! empty( $context->post ) ) {
$preload_paths[] = array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' );
$preload_paths[] = array( '/wp/v2/settings', 'OPTIONS' );
}

return $preload_paths;
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Editor( {
getEditedPostTemplate,
getHiddenBlockTypes,
} = select( editPostStore );
const { getEntityRecord, getPostType, getEntityRecords } =
const { getEntityRecord, getPostType, getEntityRecords, canUser } =
select( coreStore );
const { getEditorSettings } = select( editorStore );
const { getBlockTypes } = select( blocksStore );
Expand All @@ -77,6 +77,7 @@ function Editor( {
const supportsTemplateMode =
getEditorSettings().supportsTemplateMode;
const isViewable = getPostType( postType )?.viewable ?? false;
const canEditTemplate = canUser( 'create', 'templates' );

return {
hasFixedToolbar:
Expand All @@ -94,7 +95,7 @@ function Editor( {
keepCaretInsideBlock: isFeatureActive( 'keepCaretInsideBlock' ),
isTemplateMode: isEditingTemplate(),
template:
supportsTemplateMode && isViewable
supportsTemplateMode && isViewable && canEditTemplate
? getEditedPostTemplate()
: null,
post: postObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function useBlockEditorSettings( settings, hasTemplate ) {
const isWeb = Platform.OS === 'web';
const { canUser, getEntityRecord } = select( coreStore );

const siteSettings = getEntityRecord( 'root', 'site' );
const siteSettings = canUser( 'read', 'settings' )
? getEntityRecord( 'root', 'site' )
: {};
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved

return {
canUseUnfilteredHTML: canUserUseUnfilteredHTML(),
Expand Down